and more cleanup
authorAnas Nashif <anas.nashif@intel.com>
Tue, 24 Jul 2012 15:52:40 +0000 (16:52 +0100)
committerAnas Nashif <anas.nashif@intel.com>
Tue, 24 Jul 2012 15:52:40 +0000 (16:52 +0100)
Change-Id: I80a2637458b240b3a3c65badd198b4675dc0e682

depanneur

index 3e888558cf65970d5748faea50ece7ac9d010631..4f2d552ec52fd76c5bf64aef17a52acaa4844926 100755 (executable)
--- a/depanneur
+++ b/depanneur
@@ -70,6 +70,7 @@ my $dryrun = 0;
 my $help = 0;
 my $keepgoing = 0;
 
+my $virtualenv = "$ENV{'VIRTUAL_ENV'}";
 my $build_root = $ENV{TIZEN_BUILD_ROOT};
 my $localrepo = "$build_root/local/repos";
 my $order_dir = "$build_root/local/order";
@@ -78,11 +79,10 @@ my $scratch_dir = "$build_root/local/scratch.$arch";
 
 my $cache_dir = "$build_root/local/cache";
 my $groupfile="$build_root/meta/group.xml";
-my $virtualenv = "$ENV{'VIRTUAL_ENV'}";
 my $build_dir = "$virtualenv/usr/lib/build";
 my $config_filename = "$build_root/meta/local.yaml";
 my $dist_configs = "$build_root/meta/dist";
-my $man = 0;
+my $exclude_from_file = "$build_root/meta/exclude";
 my $cleanonce = 0;
 my $debug = 0;
 my $incremental = 0;
@@ -90,7 +90,6 @@ my $run_configure = 0;
 my $overwrite = 0;
 my $MAX_THREADS = 1;
 my $suffix = "";
-my $exclude_from_file = "$build_root/meta/exclude";
 
 my @tobuild = ();
 my @tofind = ();
@@ -98,6 +97,7 @@ my @final = ();
 my %to_build = ();
 my @done = ();
 my @skipped = ();
+my @original_specs = ();
 
 my @cleaned : shared = ();
 my @errors :shared;
@@ -119,7 +119,6 @@ GetOptions (
     "help|?" => \$help,
     "keepgoing" => \$keepgoing,
     "localrepo=s" => \$localrepo,
-    "man" => \$man,
     "overwrite" => \$overwrite,
     "suffix=s" => \$suffix,
     "debug" => \$debug,
@@ -128,6 +127,22 @@ GetOptions (
     "threads=s" => \$MAX_THREADS,
     );
 
+my $Config = LoadFile($config_filename);
+my @package_repos = ();
+foreach my $r (@{$Config->{Repositories}}) {
+    my $uri = URI->new($r->{Url});
+    if ( $r->{Password} && $r->{Username} ) {
+        $uri->userinfo($r->{Username} . ":" . $r->{Password});
+    }
+    if ($uri->scheme ne "file") {
+        push(@package_repos, $uri);
+    }
+}
+
+my $pkg_path = "$build_root/local/sources/$dist";
+my $cache_path = "$build_root/local/sources/$dist/cache";
+
+
 sub mkdir_p($) {
     my $path = shift;
     my $err_msg;
@@ -154,6 +169,8 @@ sub info {
     print GREEN, "$msg\n", RESET;
 }
 
+my $config = Build::read_config_dist($dist, $arch, $dist_configs);
+
 if ( $exclude_from_file ne "" && -e $exclude_from_file ) {
     debug("using $exclude_from_file for package exclusion");
     open FILE, "<", $exclude_from_file  or die $!;
@@ -166,64 +183,37 @@ if ( $exclude_from_file ne "" && -e $exclude_from_file ) {
 mkdir_p($order_dir);
 mkdir_p "$localrepo/$dist/$arch/logs/success";
 mkdir_p "$localrepo/$dist/$arch/logs/fail";
+mkdir_p($cache_path);
 
 my @packs = @ARGV;
 my $package_path = "";
 # FIXME
+
 my @archs = ("i586", "i686", "noarch");
 my $archpath;
 foreach my $ap (@archs) {
     $archpath .= $ap.":"; 
 }
 
-my $Config = LoadFile($config_filename);
-my @package_repos = ();
-foreach my $r (@{$Config->{Repositories}}) {
-    my $uri = URI->new($r->{Url});
-    if ( $r->{Password} && $r->{Username} ) {
-        $uri->userinfo($r->{Username} . ":" . $r->{Password});
-    }
-    if ($uri->scheme ne "file") {
-        push(@package_repos, $uri);
-    }
-}
-
-
 if ( -d "packaging" && -d ".git" ) {
-    $path = cwd();
-}
-
-if ( $path eq "" ) {
-    $package_path = "$build_root/packages";
+    $package_path = cwd();
 } else {
-    $package_path = $path;
+    if ( $path eq "" ) {
+        $package_path = "$build_root/packages";
+    } else {
+        $package_path = $path;
+    }
 }
-
-print "Start building packages from: " . $package_path . " ($style)\n";
-
 if ($binarylist ne "") {
     $buildall = 1;
 }
 
-if ($buildall || @packs == 0 ) {
-    if ($style eq "git") {
-        File::Find::find({wanted => \&git_wanted}, $package_path );
-    } elsif ($style eq "obs") {
-        File::Find::find({wanted => \&obs_wanted}, $package_path );
-    }
-} else {
-    if (@packs == 0 && $path eq "") {
-        print "Please provide a list of packages to build.";
-        exit 1;
-    }
-}
-
 sub git_wanted {
     my ($dev,$ino,$mode,$nlink,$uid,$gid);
     /^packaging\z/s &&
     (($dev,$ino,$mode,$nlink,$uid,$gid) = lstat($_)) &&
     -d _
-    && fill_packs_from_git($name);
+    && fill_packs_from_git($name, $config);
 }
 
 
@@ -236,21 +226,19 @@ sub fill_packs_from_obs() {
     $name =~ m/\.osc/ || push(@packs, $name);
 }
 
-sub fill_packs_from_git() {
+
+sub fill_packs_from_git {
     my $name = shift;
     my $base = dirname($name);
+    my $prj = basename($base);
     if ( ! -e "$base/.git" ) {
         debug("$base is not a git checkout");
         return;
     }
-    my $prj = basename($base);
     if ( (grep $_ eq $prj, @exclude) ) {
         return;
     }
     debug("working on $base");
-    my $pkg_path = "$build_root/local/sources/$dist";
-    my $cache_path = "$build_root/local/sources/$dist/cache";
-    mkdir_p($cache_path);
     my $pattern = "$name/*.spec";
     my @specs = glob $pattern;
     my $spec = "";
@@ -265,7 +253,18 @@ sub fill_packs_from_git() {
     } else {
         return;
     }
-    my $config = Build::read_config_dist($dist, $arch, $dist_configs);
+    push (@original_specs, $spec);
+}
+
+
+sub prepare_git {
+    my $config = shift;
+    my $spec = shift;
+
+    my $packaging = dirname($spec);
+    my $base = dirname($packaging);
+    my $prj = basename($base);
+
     my $pack = Build::Rpm::parse($config, $spec);
     my $pkg_name = $pack->{name};
     my $pkg_version = $pack->{version};
@@ -325,25 +324,15 @@ sub fill_packs_from_git() {
 
 
 sub parse_packs {
-    my @packs = @_;
+    my ($config, @packs) = @_;
+    print Dumper($config);
+
     my %packs = ();
     foreach my $spec (@packs) {
-        my $config = Build::read_config_dist($dist, $arch, $dist_configs);
-        my $path_to_spec = "";
-        if ( -e $spec ) {
-            $path_to_spec =  $spec;
-        } else {
-            if ( $style eq 'obs') {
-                $path_to_spec =  "$package_path/$spec/$spec.spec";
-            } else {
-                $path_to_spec =  "$package_path/$spec/$spec.spec";
-            }
-        }
-        my $pack = Build::Rpm::parse($config, $path_to_spec);
+        my $pack = Build::Rpm::parse($config, $spec);
         if ( ( $pack->{'exclarch'} ) && ( ! grep $_ eq $arch, $pack->{'exclarch'} ) ) {
             next;
         }
-        debug("path to spec: $path_to_spec");
         my $name = $pack->{name};
         my $version = $pack->{version};
         my $release = $pack->{release};
@@ -355,7 +344,7 @@ sub parse_packs {
             release => $release,
             deps => @buildrequires,
             subpacks => @subpacks,
-            filename => $path_to_spec
+            filename => $spec
         }
     }
     return %packs;
@@ -505,11 +494,41 @@ sub set_idle {
     $workers{$worker} = { 'state' => 'idle' , 'tid' => undef};
 }
 
+sub source_of {
+    my ($sub, %packs) = @_;
+    foreach my $x (keys %packs) {
+        my @sp = @{$packs{$x}->{subpacks}};
+        if (grep $_ eq $sub, @sp ) {
+            return $x;
+        }
+    }
+    return undef;
+}
+# MAIN
+print "Start building packages from: " . $package_path . " ($style)\n";
+
+if ($buildall || @packs == 0 ) {
+    if ($style eq "git") {
+        File::Find::find({wanted => \&git_wanted}, $package_path );
+    } elsif ($style eq "obs") {
+        File::Find::find({wanted => \&obs_wanted}, $package_path );
+    }
+} else {
+    if (@packs == 0 && $path eq "") {
+        print "Please provide a list of packages to build.";
+        exit 1;
+    }
+}
+
+print "Prepare sources...\n";
+foreach my $sp (@original_specs) {
+    prepare_git($config, $sp);
+}
+
 print "Parsing package data...\n";
-my %packs = parse_packs(@packs);
+my %packs = parse_packs($config, @packs);
 
 if ($binarylist ne "" && -e $binarylist ) {
-    my %repo_assist = expand_deps();
     open FILE, "<", $binarylist or die $!;
     my @bins = <FILE>;
     chomp(@bins);
@@ -529,7 +548,7 @@ if ($binarylist ne "" && -e $binarylist ) {
 
     print "Initial set:\n";
     foreach my $p (@tobuild) {
-        print "$p, ";
+        print " $p, ";
     }
     print "\n";
 
@@ -568,28 +587,16 @@ if ($binarylist ne "" && -e $binarylist ) {
     foreach my $m (@tofind_2) {
         debug($m);
     }
+    %to_build = parse_packs($config, @final);
 } elsif ( $binarylist ne "") {
     print STDERR "Cant find binary list for image\n";
     exit 1;
-}
-
-sub source_of {
-    my ($sub, %packs) = @_;
-    foreach my $x (keys %packs) {
-        my @sp = @{$packs{$x}->{subpacks}};
-        if (grep $_ eq $sub, @sp ) {
-            return $x;
-        }
-    }
-    return undef;
-}
-
-if ($binarylist ne "") {
-    %to_build = parse_packs(@final);
 } else {
-    %to_build = parse_packs(@packs);
+    %to_build = %packs
 }
 
+
+# Prepare Workers
 for(my $w = 0; $w < $MAX_THREADS; $w++) {
     $workers{$w} = { 'state' => 'idle' , 'tid' => undef };
 }