[ostree: 11/19] ostbuild: More work on partial builds



commit 92244c80ccf6e406bb02586ef2b982662bc272d8
Author: Colin Walters <walters verbum org>
Date:   Sat May 12 10:42:23 2012 -0400

    ostbuild: More work on partial builds

 src/ostbuild/pyostbuild/buildutil.py               |    2 +-
 .../pyostbuild/builtin_build_components.py         |   17 ++--
 src/ostbuild/pyostbuild/builtin_checkout.py        |   92 ++++++++++---------
 3 files changed, 58 insertions(+), 53 deletions(-)
---
diff --git a/src/ostbuild/pyostbuild/buildutil.py b/src/ostbuild/pyostbuild/buildutil.py
index 386a35c..9bddeb1 100755
--- a/src/ostbuild/pyostbuild/buildutil.py
+++ b/src/ostbuild/pyostbuild/buildutil.py
@@ -40,7 +40,7 @@ def parse_src_key(srckey):
     if idx < 0:
         raise ValueError("Invalid SRC uri=%s" % (srckey, ))
     keytype = srckey[:idx]
-    if keytype not in ['git', 'dirty-git']:
+    if keytype not in ['git', 'local']:
         raise ValueError("Unsupported SRC uri=%s" % (srckey, ))
     uri = srckey[idx+1:]
     return (keytype, uri)
diff --git a/src/ostbuild/pyostbuild/builtin_build_components.py b/src/ostbuild/pyostbuild/builtin_build_components.py
index fba621d..b1b0102 100755
--- a/src/ostbuild/pyostbuild/builtin_build_components.py
+++ b/src/ostbuild/pyostbuild/builtin_build_components.py
@@ -68,7 +68,7 @@ class OstbuildBuildComponents(builtins.Builtin):
         name = '%s/%s' % (basename, architecture)
         buildname = 'components/%s' % (name, )
 
-        current_vcs_version = component['revision']
+        current_vcs_version = component.get('revision')
 
         # TODO - deduplicate this with chroot_compile_one
         current_meta_io = StringIO()
@@ -88,7 +88,8 @@ class OstbuildBuildComponents(builtins.Builtin):
                                                           'rev-parse', buildname],
                                                          stderr=open('/dev/null', 'w'),
                                                          none_on_error=True)
-        if previous_build_version is not None:
+        if (current_vcs_version is not None
+            and previous_build_version is not None):
             log("Previous build of '%s' is %s" % (name, previous_build_version))
 
             previous_metadata_text = run_sync_get_output(['ostree', '--repo=' + self.repo,
@@ -103,7 +104,6 @@ class OstbuildBuildComponents(builtins.Builtin):
                 log("Metadata is unchanged from previous")
                 return False
             else:
-                current_vcs_version = component['revision']
                 previous_metadata = json.loads(previous_metadata_text)
                 previous_vcs_version = previous_metadata['revision']
                 if current_vcs_version == previous_vcs_version:
@@ -123,7 +123,8 @@ class OstbuildBuildComponents(builtins.Builtin):
         fileutil.ensure_dir(checkoutdir)
         component_src = os.path.join(checkoutdir, basename)
         run_sync(['ostbuild', 'checkout', '--snapshot=' + self.snapshot_path,
-                  '--clean', '--overwrite', basename], cwd=checkoutdir)
+                  '--checkoutdir=' + component_src,
+                  '--clean', '--overwrite', basename])
 
         artifact_meta = dict(component)
 
@@ -207,10 +208,10 @@ class OstbuildBuildComponents(builtins.Builtin):
 
         if len(component_refs_to_resolve) > 0:
             resolved_refs = self._resolve_refs(component_refs_to_resolve)
-            for name,rev in zip(components.iterkeys(), resolved_refs):
-                for architecture in component_architectures[name]:
-                    archname = '%s/%s' % (name, architecture)
-                    component_revisions[archname] = rev
+            for name,rev in zip(component_refs_to_resolve, resolved_refs):
+                assert name.startswith('components/')
+                archname = name[len('components/'):]
+                component_revisions[archname] = rev
 
         bin_snapshot['component-revisions'] = component_revisions
 
diff --git a/src/ostbuild/pyostbuild/builtin_checkout.py b/src/ostbuild/pyostbuild/builtin_checkout.py
index 9a2d1f9..e9c1142 100755
--- a/src/ostbuild/pyostbuild/builtin_checkout.py
+++ b/src/ostbuild/pyostbuild/builtin_checkout.py
@@ -42,35 +42,32 @@ class OstbuildCheckout(builtins.Builtin):
         parser.add_argument('--overwrite', action='store_true')
         parser.add_argument('--prefix')
         parser.add_argument('--snapshot')
+        parser.add_argument('--checkoutdir')
         parser.add_argument('-a', '--active-tree', action='store_true')
         parser.add_argument('--clean', action='store_true')
-        parser.add_argument('components', nargs='*')
+        parser.add_argument('component') 
 
         args = parser.parse_args(argv)
         self.args = args
         
         self.parse_config()
 
-        if len(args.components) > 0:
-            checkout_components = args.components
-        else:
-            checkout_components = [os.path.basename(os.getcwd())]
-
         if args.active_tree:
             self.parse_active_branch()
         else:
             self.parse_snapshot(args.prefix, args.snapshot)
 
-        for component_name in checkout_components:
-            found = False
-            component = self.get_component_meta(component_name)
-            (keytype, uri) = buildutil.parse_src_key(component['src'])
-            checkoutdir = os.path.join(os.getcwd(), component_name)
-            fileutil.ensure_parent_dir(checkoutdir)
+        component_name = args.component
+
+        found = False
+        component = self.get_component_meta(component_name)
+        (keytype, uri) = buildutil.parse_src_key(component['src'])
 
-            is_dirty = (keytype == 'dirty-git')
+        is_local = (keytype == 'local')
 
-            if is_dirty:
+        if is_local:
+            if args.checkoutdir:
+                checkoutdir = args.checkoutdir
                 # Kind of a hack, but...
                 if os.path.islink(checkoutdir):
                     os.unlink(checkoutdir)
@@ -78,42 +75,49 @@ class OstbuildCheckout(builtins.Builtin):
                     shutil.rmtree(checkoutdir)
                 os.symlink(uri, checkoutdir)
             else:
+                checkoutdir = uri
+        else:
+            if args.checkoutdir:
+                checkoutdir = args.checkoutdir
+            else:
+                checkoutdir = os.path.join(os.getcwd(), component_name)
+                fileutil.ensure_parent_dir(checkoutdir)
                 vcs.get_vcs_checkout(self.mirrordir, keytype, uri, checkoutdir,
                                      component['revision'],
                                      overwrite=args.overwrite)
-                
-            if args.clean:
-                if is_dirty:
-                    log("note: ignoring --clean argument due to \"dirty-git:\" specification")
-                else:
-                    vcs.clean(keytype, checkoutdir)
 
-            patches = component.get('patches')
-            if patches is not None:
-                (patches_keytype, patches_uri) = buildutil.parse_src_key(patches['src'])
-                if patches_keytype == 'git':
-                    patches_mirror = buildutil.get_mirrordir(self.mirrordir, patches_keytype, patches_uri)
-                    vcs.get_vcs_checkout(self.mirrordir, patches_keytype, patches_uri,
-                                         self.patchdir, patches['branch'],
-                                         overwrite=True)
-                    patchdir = self.patchdir
-                else:
-                    patchdir = patches_uri
+        if args.clean:
+            if is_local:
+                log("note: ignoring --clean argument due to \"local:\" specification")
+            else:
+                vcs.clean(keytype, checkoutdir)
+
+        patches = component.get('patches')
+        if patches is not None:
+            (patches_keytype, patches_uri) = buildutil.parse_src_key(patches['src'])
+            if patches_keytype == 'git':
+                patches_mirror = buildutil.get_mirrordir(self.mirrordir, patches_keytype, patches_uri)
+                vcs.get_vcs_checkout(self.mirrordir, patches_keytype, patches_uri,
+                                     self.patchdir, patches['branch'],
+                                     overwrite=True)
+                patchdir = self.patchdir
+            else:
+                patchdir = patches_uri
 
-                patch_subdir = patches.get('subdir', None)
-                if patch_subdir is not None:
-                    patchdir = os.path.join(patchdir, patch_subdir)
-                else:
-                    patchdir = self.patchdir
-                for patch in patches['files']:
-                    patch_path = os.path.join(patchdir, patch)
-                    run_sync(['git', 'am', '--ignore-date', '-3', patch_path], cwd=checkoutdir)
+            patch_subdir = patches.get('subdir', None)
+            if patch_subdir is not None:
+                patchdir = os.path.join(patchdir, patch_subdir)
+            else:
+                patchdir = self.patchdir
+            for patch in patches['files']:
+                patch_path = os.path.join(patchdir, patch)
+                run_sync(['git', 'am', '--ignore-date', '-3', patch_path], cwd=checkoutdir)
 
-            metadata_path = os.path.join(checkoutdir, '_ostbuild-meta.json')
-            f = open(metadata_path, 'w')
-            json.dump(component, f, indent=4, sort_keys=True)
-            f.close()
+        metadata_path = os.path.join(checkoutdir, '_ostbuild-meta.json')
+        f = open(metadata_path, 'w')
+        json.dump(component, f, indent=4, sort_keys=True)
+        f.close()
         
-            log("Checked out: %r" % (checkoutdir, ))
+        log("Checked out: %r" % (checkoutdir, ))
         
 builtins.register(OstbuildCheckout)



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]