Last active
October 6, 2015 17:54
-
-
Save bradclawsie/e5f3e3c0af212952cf05 to your computer and use it in GitHub Desktop.
gp.pl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use Cwd; | |
use Env; | |
use File::Copy; | |
use v5.20; | |
my $argc = scalar @ARGV; | |
die "use gp.pl basepath reponame" unless ($argc == 2); | |
my $base = $ARGV[0]; | |
my $repo = $ARGV[1]; | |
my $cwd = getcwd(); | |
die "$base must be a prefix of $cwd" unless ($cwd =~ /^$base/); | |
die "must define GOPATH env var" unless (defined($ENV{'GOPATH'})); | |
my $gopath = $ENV{'GOPATH'}; | |
$gopath .= '/src/' . $repo; | |
die "$gopath: not there" unless (-d $gopath); | |
my $src = $cwd; | |
$src =~ s/$base/$gopath/o; | |
die "$src: not there" unless (-d $src); | |
my @files = glob($cwd . '/*' ); | |
my @pkg_files = (); | |
for my $file (@files) { | |
push(@pkg_files,$file) if ((-f $file) && ($file =~ /\.go$/) && ($file !~ /_test\.go$/)); | |
} | |
if (0 == (scalar @pkg_files)) { | |
say "no files"; | |
exit; | |
} | |
for my $file (@pkg_files) { | |
copy($file,$src) || die "cannot copy $file -> $src: $!"; | |
} | |
my $install_cmd = 'cd ' . $src . '; go build && go install; cd ' . $cwd . ';'; | |
say $install_cmd; | |
system($install_cmd); | |
1; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
use like:
gp.pl /mnt/data/brad/repos/hovitos repo.hovitos.engineering