| 1 | package VIM::Packager::Git; | ||
| 2 | use warnings; | ||
| 3 | use strict; | ||
| 4 | use File::Path qw(mkpath rmtree); | ||
| 5 | |||
| 6 | use constant build_dir => ( $ENV{VIM_BUILD_DIR} || '/' . File::Spec->join( qw(tmp vim-build) ) ); | ||
| 7 | |||
| 8 | sub rand_hash { join "", map { ( 'a' .. 'z' )[ rand(26) ] } 1 .. $_[0] } | ||
| 9 | |||
| 10 | |||
| 11 | sub new { | ||
| 12 | return bless {} , shift; | ||
| 13 | } | ||
| 14 | |||
| 15 | sub clone { | ||
| 16 | my ($self , $clone_path) = @_; | ||
| 17 | |||
| 18 | mkpath [ build_dir ] unless -e build_dir; | ||
| 19 | chdir build_dir; | ||
| 20 | |||
| 21 | my ($build_name) = ( $clone_path =~ m{\/([a-zA-Z0-9-_.]+?)$} ); | ||
| 22 | |||
| 23 | my $hash = rand_hash(5); | ||
| 24 | $build_name =~ s{\.git$}{}g; | ||
| 25 | $build_name .= '-' . $hash; | ||
| 26 | |||
| 27 | $self->{build_name} = $build_name; | ||
| 28 | $self->{build_path} = File::Spec->join( build_dir , $build_name ); | ||
| 29 | |||
| 30 | my $ret = system(qq{git clone $clone_path $build_name}); | ||
| 31 | chdir $build_name; | ||
| 32 | |||
| 33 | # do install | ||
| 34 | # from here | ||
| 35 | return $build_name; | ||
| 36 | } | ||
| 37 | |||
| 38 | |||
| 39 | sub build_path { $_[0]->{build_path} } | ||
| 40 | sub build_name { $_[0]->{build_name} } | ||
| 41 | |||
| 42 | |||
| 43 | sub cleanup { | ||
| 44 | chdir ".."; | ||
| 45 | my $self = shift; | ||
| 46 | rmtree [ $self->{build_name} ]; | ||
| 47 | } | ||
| 48 | |||
| 49 | 1; |