summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xsrc/BuildPackage.pm65
-rw-r--r--src/XibUtil.pm52
-rwxr-xr-xsrc/xib.pl4
3 files changed, 92 insertions, 29 deletions
diff --git a/src/BuildPackage.pm b/src/BuildPackage.pm
index afcb65a..61087f2 100755
--- a/src/BuildPackage.pm
+++ b/src/BuildPackage.pm
@@ -3,35 +3,19 @@ package BuildPackage;
use strict;
use warnings;
-use File::Basename "basename";
-use Digest::MD5;
+use File::Basename;
+use XibUtil qw/extract_from_file extract md5_sum/;
-sub md5_sum{
- my ($file) = @_;
-
- open(my $fh, "<", $file) or die "Cannot open $file: $!";
- binmode($fh);
-
- return Digest::MD5->new->addfile($fh)->hexdigest;
+sub extract_source{
+ return XibUtil::extract_from_file(@_, qr/^SOURCE=(.+)$/);
}
-sub extract_ver_hash{
- my $info_file = $_;
- open (my $fh, "<", $info_file) or warn "Cannot open $info_file";
- while (my $line = <$fh>) {
- if ($line =~ /^VER_HASH=(.+)$/) {
- return $1;
- }
- }
+sub extract_branch{
+ return XibUtil::extract_from_file(@_, qr/^BRANCH=(.+)$/);
}
-sub extract_ver_hash{
- my $info_file = $_;
- open (my $fh, "<", $info_file) or warn "Cannot open $info_file";
- while (my $line = <$fh>) {
- if ($line =~ /^VER_HASH=(.+)$/) {
- return $1;
- }
- }
+
+sub extract_version{
+ return XibUtil::extract_from_file(@_, qr/^PKG_VER=(.+)$/);
}
sub get_built_version{
@@ -55,10 +39,29 @@ sub clear_build_folder{
}
sub fetch_source{
- my $source_url = $_;
+ my ($build_file) = @_;
- mkdir("$main::chroot/build")
- mkdir("$main::chroot/build/source")
+ mkdir("$main::chroot/build");
+ mkdir("$main::chroot/build/source");
+ chdir("$main::chroot/build/source");
+
+ my $source = extract_source($build_file);
+ my $branch = extract_branch($build_file);
+ my $PKG_VER = extract_version($build_file);
+
+ if (XibUtil::is_git_repo($source, $branch)) {
+ print("Fetching git repo $source version $PKG_VER\n");
+ system("git clone $source .");
+ system("git checkout $branch");
+
+ } else {
+ print("downloading file $source\n");
+ my $downloaded_file = basename($source);
+ system("curl $source $downloaded_file");
+ extract("$downloaded_file");
+ system("pwd; cp -r */* .")
+
+ }
# download source to $chroot/build/mysource.tgz
# extract source to $chroot/build/source
@@ -67,12 +70,16 @@ sub fetch_source{
sub build_package{
my ($build_file) = @_;
- $existing_version = get_built_version($build_file);
+ my $existing_version = get_built_version($build_file);
if (defined($existing_version) && $existing_version eq md5_sum($build_file)) {
# do not build
+ print("do not build\n");
return
}
# build
+ fetch_source($build_file);
+
}
+1;
diff --git a/src/XibUtil.pm b/src/XibUtil.pm
new file mode 100644
index 0000000..1aa02a8
--- /dev/null
+++ b/src/XibUtil.pm
@@ -0,0 +1,52 @@
+package XibUtil;
+
+use v5.12;
+
+use strict;
+use warnings;
+
+use File::Basename;
+
+sub md5_sum{
+ my ($file) = @_;
+
+ open(my $fh, "<", $file) or die "Cannot open $file: $!";
+ binmode($fh);
+
+ return Digest::MD5->new->addfile($fh)->hexdigest;
+}
+
+sub extract_from_file{
+ my ($file, $regex) = @_;
+ open (my $fh, "<", $file) or warn "Cannot open $file";
+ while (my $line = <$fh>) {
+ if ($line =~ $regex) {
+ return $1;
+ }
+ }
+}
+
+sub is_git_repo{
+ return system("git ls-remote -q @_");
+}
+
+sub extract{
+ my ($file) = @_;
+ my $ext = (fileparse($file, qr/\.[^.]*/))[2];
+ print("$ext\n");
+
+ my $cmd = "";
+ given($ext) {
+ $cmd = "tar -zxf $file" when ".gz";
+ $cmd = "tar -xf $file" when ".xz";
+ $cmd = "unzip $file" when ".zip";
+ $cmd = "tar --lzip -xf $file" when ".lz";
+ default {
+ $cmd = "tar -xf $file";
+ }
+ }
+
+ system($cmd);
+}
+
+1;
diff --git a/src/xib.pl b/src/xib.pl
index ba3afc9..fcdbeb2 100755
--- a/src/xib.pl
+++ b/src/xib.pl
@@ -21,6 +21,8 @@
# - add some info to package info
# - if requested, install to the chroot
+use v5.12;
+
use strict;
use warnings;
use Getopt::Long "HelpMessage";
@@ -28,6 +30,7 @@ use Getopt::Long "HelpMessage";
use File::Basename;
use lib dirname (__FILE__);
use BuildOrder "determine_build_order";
+use XibUtil "extract";
use BuildPackage;
our $BUILDFILES_REPO = "https://xi.davidovski.xyz/git/buildfiles.git";
@@ -60,4 +63,5 @@ unless (caller) {
prepare_xib_environment();
my $file = "$chroot/buildorder";
BuildOrder::determine_build_order($file);
+ BuildPackage::build_package("$buildfiles/repo/util/vim.xibuild");
}