[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [kdesrc-build] modules/ksb: Eliminate first-run errors without metadata.
From:       Michael Pyne <mpyne () kde ! org>
Date:       2015-02-28 16:59:40
Message-ID: E1YRkjs-0004lX-Gx () scm ! kde ! org
[Download RAW message or body]

Git commit 0647ad270cef0f842b7f7f19f992fe4ac550c8a4 by Michael Pyne.
Committed on 28/02/2015 at 16:08.
Pushed by mpyne into branch 'master'.

Eliminate first-run errors without metadata.

This is a 2-part change:

1. Always download needed metadata, even in --pretend mode. This means
that even --pretend won't stop kdesrc-build from trying to hit the
network, but --pretend was always intended to let you test command lines
to ensure you got the right build list before you wasted hours trying to
build something. If you don't want kdesrc-build to touch the network
ever, don't run it. :)

2. Check for JSON decoding errors specifically (since it may happen that
the JSON is corrupted on download somehow, or accidentally broken
upstream).

This should allow "kdesrc-build -p --print-modules", or even
"kdesrc-build -p" to work even as the very first command ever run.

BUG:340481
FIXED-IN:1.16

M  +8    -5    modules/ksb/Application.pm
M  +1    -16   modules/ksb/BuildContext.pm
M  +9    -3    modules/ksb/Updater/KDEProjectMetadata.pm

http://commits.kde.org/kdesrc-build/0647ad270cef0f842b7f7f19f992fe4ac550c8a4

diff --git a/modules/ksb/Application.pm b/modules/ksb/Application.pm
index 37a58cf..5ad19ce 100644
--- a/modules/ksb/Application.pm
+++ b/modules/ksb/Application.pm
@@ -674,23 +674,26 @@ sub _downloadKDEProjectMetadata
         super_mkdir($sourceDir);
 
         my $updateDesired = !$ctx->getOption('no-metadata') && \
                $ctx->phases()->has('update');
-        $updateNeeded = (! -e "$sourceDir/dependency-data-common");
+        $updateNeeded = (! -e $metadataModule->fullpath('source') . \
                "/dependency-data-common");
         my $lastUpdate = $ctx->getPersistentOption('global', 'last-metadata-update') \
// 0; +        my $wasPretending = pretending();
 
         if (!$updateDesired && $updateNeeded && (time - ($lastUpdate)) >= 7200) {
             warning (" r[b[*] Skipping build metadata update, but it hasn't been \
updated recently!");  }
 
-        if ($updateNeeded && pretending() && ! -e $sourceDir) {
-            croak_runtime("\n\tCan't use --pretend without having metadata
-                available, and can't download it in pretend mode. Try running
-                \"kdesrc-build --metadata-only\" first and try again.");
+        if ($updateNeeded && pretending()) {
+            warning (" y[b[*] Ignoring y[b[--pretend] option to download required \
metadata\n" . +                     " y[b[*] --pretend mode will resume after \
metadata is available."); +            ksb::Debug::setPretending(0);
         }
 
         if ($updateDesired && (!pretending() || $updateNeeded)) {
             $metadataModule->scm()->updateInternal();
             $ctx->setPersistentOption('global', 'last-metadata-update', time);
         }
+
+        ksb::Debug::setPretending($wasPretending);
     };
 
     if ($@) {
diff --git a/modules/ksb/BuildContext.pm b/modules/ksb/BuildContext.pm
index 3235cbf..c6482f2 100644
--- a/modules/ksb/BuildContext.pm
+++ b/modules/ksb/BuildContext.pm
@@ -897,25 +897,10 @@ sub getKDEProjectMetadataFilehandle
     my $updating = grep { /^update$/ } (@{$self->phases()});
     $updating &&= !$self->getOption('no-metadata');
 
-    if (!pretending() && $updating) {
+    if ($updating && (! -e $file || !pretending())) {
         info (" * Downloading projects.kde.org project database...");
         $result = download_file($url, $file, $self->getOption('http-proxy'));
     }
-    elsif (! -e $file) {
-        if (pretending()) {
-            note (" * Downloading projects.kde.org project database (will not be \
                saved due to pretend mode)...");
-        } else {
-            note (" * Downloading projects.kde.org project database");
-        }
-
-        # Unfortunately dumping the HTTP output straight to the XML parser is a
-        # wee bit more complicated than I feel like dealing with => use a temp
-        # file.
-        (undef, $file) = tempfile('kde_projectsXXXXXX',
-            SUFFIX=>'.xml', TMPDIR=>1, UNLINK=>0);
-        $result = download_file($url, $file, $self->getOption('http-proxy'));
-        open ($fileHandleResult, '<', $file) or croak_runtime("Unable to open KDE \
                Project database $file: $!");
-    }
     else {
         info (" * y[Using existing projects.kde.org project database], output may \
change");  info (" * when database is updated next.");
diff --git a/modules/ksb/Updater/KDEProjectMetadata.pm \
b/modules/ksb/Updater/KDEProjectMetadata.pm index 9eb3d2c..1ea925d 100644
--- a/modules/ksb/Updater/KDEProjectMetadata.pm
+++ b/modules/ksb/Updater/KDEProjectMetadata.pm
@@ -58,10 +58,16 @@ sub logicalModuleGroups
     my $fh = pretend_open($path) or
         croak_internal("Unable to read logical module structure: $!");
 
-    # The 'local $/' disables line-by-line reading; slurps the whole file
-    my $json_hashref = do { local $/; decode_json(<$fh>); };
-    close $fh;
+    my ($json_hashref, $e) = do {
+        local $/; # The 'local $/' disables line-by-line reading; slurps the whole \
file +        undef $@;
+        my $json = eval { decode_json(<$fh>) };
+        close $fh;
 
+        ($json, $@); # Implicit return
+    };
+
+    croak_runtime ("Unable to load module group data! :(\n\t$e") if $e;
     return $json_hashref;
 }
 


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic