Add lock for multi spec export 87/150487/1
authoryang.zhang <y0169.zhang@samsung.com>
Tue, 23 May 2017 10:01:04 +0000 (18:01 +0800)
committerJun Wang <junbill.wang@samsung.com>
Sat, 16 Sep 2017 07:40:59 +0000 (15:40 +0800)
Change-Id: I63d6123432bf46730e36ac1ba2212cbb36de6e71
Signed-off-by: Jun Wang <junbill.wang@samsung.com>
depanneur

index 33717da..153cba2 100755 (executable)
--- a/depanneur
+++ b/depanneur
@@ -43,6 +43,10 @@ my $DETACHING:shared;
 # Flag to inform main thread update pkgdeps
 my $dirty:shared=0;
 
+my %export_packs:shared = ();
+my $export_lock:shared;
+my $SINGLE_SPEC = 1;
+my $MULTI_SPEC = 2;
 # Set the variable $File::Find::dont_use_nlink if you're using AFS,
 # since AFS cheats.
 
@@ -757,8 +761,17 @@ sub read_cache {
 sub write_cache {
     my ($cache_key, $cache_val, $base, $spec, $packaging_dir, $upstream_branch, $upstream_tag) = @_;
     my $cache_fname = "$cache_path/$cache_key";
-    my @export_out = gbs_export($base, $spec, $packaging_dir, $upstream_branch, $upstream_tag);
-
+    my @export_out;
+    my $n = $export_packs{$base};
+    if ($n ne $SINGLE_SPEC) {
+        info("multi spec export in order:$base\t$spec");
+        {
+            lock($export_lock);
+            @export_out = gbs_export($base, $spec, $packaging_dir, $upstream_branch, $upstream_tag);
+        }
+    } else {
+            @export_out = gbs_export($base, $spec, $packaging_dir, $upstream_branch, $upstream_tag);
+    }
     if (shift @export_out) {
         # if export failed, collect export error to report
         push(@export_errors, {package_name => $cache_key,
@@ -2348,9 +2361,21 @@ if ($style eq 'git') {
                     } else {
                         info("package $name not support skip export source");
                         $data_queue->enqueue($pack);
+                        my $lock_name = $pack->{"project_base_path"};
+                        if (exists $export_packs{$lock_name}) {
+                            $export_packs{$lock_name} = $MULTI_SPEC;
+                        } else {
+                            $export_packs{$lock_name} = $SINGLE_SPEC;
+                        }
                     }
                 } else {
                     $data_queue->enqueue($pack);
+                    my $lock_name = $pack->{"project_base_path"};
+                    if (exists $export_packs{$lock_name}) {
+                        $export_packs{$lock_name} = $MULTI_SPEC;
+                    } else {
+                        $export_packs{$lock_name} = $SINGLE_SPEC;
+                    }
                 }
        }