diff options
-rw-r--r-- | morphlib/plugins/branch_and_merge_plugin.py | 99 | ||||
-rwxr-xr-x | tests.as-root/build-handles-stratum-build-depends.script | 6 | ||||
-rwxr-xr-x | tests.as-root/building-a-system-branch-works-anywhere.script | 2 | ||||
-rw-r--r-- | tests.as-root/disk-builds-rootfs-and-kernel.stdout | 6 | ||||
-rwxr-xr-x | tests.as-root/setup | 34 | ||||
-rw-r--r-- | tests.as-root/syslinux-disk-builds-rootfs-and-kernel.stdout | 6 |
6 files changed, 117 insertions, 36 deletions
diff --git a/morphlib/plugins/branch_and_merge_plugin.py b/morphlib/plugins/branch_and_merge_plugin.py index 0f07c431..e17ef740 100644 --- a/morphlib/plugins/branch_and_merge_plugin.py +++ b/morphlib/plugins/branch_and_merge_plugin.py @@ -695,51 +695,84 @@ class BranchAndMergePlugin(cliapp.Plugin): # Test that the specified stratum exists in the system self.get_edit_info(system_name, system_morphology, stratum_name) - for stratum_spec in system_morphology['strata']: + all_strata = system_morphology['strata'] + stratum_refs_to_correct = set() + + # Petrify the chunk + for stratum_spec in (s for s in all_strata + if s['morph'] == stratum_name): stratum_repo_dir = self.make_available( stratum_spec, branch, branch_dir, root_repo, root_repo_dir) stratum_morphology = self.load_morphology( stratum_repo_dir, stratum_spec['morph']) - changed = False - if stratum_spec['morph'] == stratum_name: - if chunk_name is not None: - # Change the stratum's ref to the chunk - chunk_spec = self.get_edit_info( - stratum_name, stratum_morphology, chunk_name, - collection='chunks') + if chunk_name is not None: + # Change the stratum's ref to the chunk + chunk_spec = self.get_edit_info( + stratum_name, stratum_morphology, chunk_name, + collection='chunks') - if 'unpetrify-ref' in chunk_spec: - chunk_spec['ref'] = chunk_spec['unpetrify-ref'] - del chunk_spec['unpetrify-ref'] + if 'unpetrify-ref' in chunk_spec: + chunk_spec['ref'] = chunk_spec['unpetrify-ref'] + del chunk_spec['unpetrify-ref'] - self.make_available( - chunk_spec, branch, branch_dir, root_repo, - root_repo_dir) + self.make_available( + chunk_spec, branch, branch_dir, root_repo, + root_repo_dir) - if chunk_spec['ref'] != branch: - chunk_spec['ref'] = branch + if chunk_spec['ref'] != branch: + chunk_spec['ref'] = branch - self.log_change(stratum_spec['repo'], - '"%s" now includes "%s" from "%s"' % - (stratum_name, chunk_name, branch)) - changed = True - else: - # Update build-depends in other strata that point to this one - if stratum_morphology['build-depends'] is not None: + self.log_change(stratum_spec['repo'], + '"%s" now includes "%s" from "%s"' % + (stratum_name, chunk_name, branch)) + stratum_refs_to_correct.add((stratum_spec['repo'], + stratum_spec['ref'], + stratum_spec['morph'])) + # Correct the System Morphology's reference + stratum_spec['ref'] = branch + self.save_morphology(stratum_repo_dir, stratum_spec['morph'], + stratum_morphology) + self.log_change(root_repo, + '"%s" now includes "%s" from "%s"' % + (system_name, stratum_name, branch)) + + # Correct all references to altered strata + while stratum_refs_to_correct: + repo, ref, morph = stratum_refs_to_correct.pop() + spec = {"repo": repo, "ref": ref, "morph": morph} + for stratum_spec in all_strata: + changed = False + if repo == root_repo: + stratum_repo_dir = root_repo_dir + else: + stratum_repo_dir = self.checkout_repository( + branch_dir, stratum_spec['repo'], + branch, stratum_spec['ref']) + stratum_morphology = self.load_morphology( + stratum_repo_dir, stratum_spec['morph']) + if ('build-depends' in stratum_morphology + and stratum_morphology['build-depends'] is not None): for bd_spec in stratum_morphology['build-depends']: - if bd_spec['morph'] == stratum_name: + bd_triplet = (bd_spec['repo'], + bd_spec['ref'], + bd_spec['morph']) + if (bd_triplet == (repo, ref, morph)): bd_spec['ref'] = branch changed = True - break - - if changed: - stratum_spec['ref'] = branch - self.save_morphology(stratum_repo_dir, stratum_spec['morph'], - stratum_morphology) - self.log_change(root_repo, - '"%s" now includes "%s" from "%s"' % - (system_name, stratum_name, branch)) + if changed: + stratum_refs_to_correct.add((stratum_spec['repo'], + stratum_spec['ref'], + stratum_spec['morph'])) + # Update the System morphology to use + # the modified version of the Stratum + stratum_spec['ref'] = branch + self.save_morphology(stratum_repo_dir, + stratum_spec['morph'], + stratum_morphology) + self.log_change(root_repo, + '"%s" now includes "%s" from "%s"' % + (system_name, stratum_name, branch)) self.save_morphology(root_repo_dir, system_name, system_morphology) diff --git a/tests.as-root/build-handles-stratum-build-depends.script b/tests.as-root/build-handles-stratum-build-depends.script index 1d1aa4ee..32b9b5ee 100755 --- a/tests.as-root/build-handles-stratum-build-depends.script +++ b/tests.as-root/build-handles-stratum-build-depends.script @@ -25,8 +25,10 @@ cd "$DATADIR/workspace" cd test/stratum-build-depends/test:morphs -# Both 'linux-system' and the build-depends field of 'linux-stratum' need to -# be updated here. If they are not, the build command will fail. +# 'linux-system' and the build-depends fields of 'linux-stratum' need to +# be updated here. Any build-depends of any altered strata also need to +# be altered, such as the 'tools-stratum' which depends on linux-stratum +# If they are not updated, the build command will fail. "$SRCDIR/scripts/test-morph" edit linux-system hello-stratum # Likewise, this command must update build-depends or the 'repo' field will diff --git a/tests.as-root/building-a-system-branch-works-anywhere.script b/tests.as-root/building-a-system-branch-works-anywhere.script index 87b49199..fac07e21 100755 --- a/tests.as-root/building-a-system-branch-works-anywhere.script +++ b/tests.as-root/building-a-system-branch-works-anywhere.script @@ -48,7 +48,7 @@ cd "$DATADIR/workspace/branch1/test:kernel-repo" rm -rf "$DATADIR/cache/artifacts"/* # Verify that we build the right number of artifacts -[ $(wc < "$DATADIR/output1" -l) -eq 16 ] +[ $(wc < "$DATADIR/output1" -l) -eq 22 ] # List of files in the artifact cache should be identical after each build diff "$DATADIR/output1" "$DATADIR/output2" diff --git a/tests.as-root/disk-builds-rootfs-and-kernel.stdout b/tests.as-root/disk-builds-rootfs-and-kernel.stdout index af3a936b..4e8a67ae 100644 --- a/tests.as-root/disk-builds-rootfs-and-kernel.stdout +++ b/tests.as-root/disk-builds-rootfs-and-kernel.stdout @@ -10,8 +10,11 @@ ./factory-run/baserock/linux-stratum.meta ./factory-run/baserock/linux-system-rootfs.meta ./factory-run/baserock/linux.meta +./factory-run/baserock/tools-stratum.meta +./factory-run/baserock/tools.meta ./factory-run/bin ./factory-run/bin/hello +./factory-run/bin/strace ./factory-run/boot ./factory-run/boot/System.map ./factory-run/boot/vmlinuz @@ -25,8 +28,11 @@ ./factory/baserock/linux-stratum.meta ./factory/baserock/linux-system-rootfs.meta ./factory/baserock/linux.meta +./factory/baserock/tools-stratum.meta +./factory/baserock/tools.meta ./factory/bin ./factory/bin/hello +./factory/bin/strace ./factory/boot ./factory/boot/System.map ./factory/boot/vmlinuz diff --git a/tests.as-root/setup b/tests.as-root/setup index 285a3143..03a438e0 100755 --- a/tests.as-root/setup +++ b/tests.as-root/setup @@ -79,6 +79,22 @@ git commit --quiet -m "add a hello world program and morph" git checkout --quiet master +# Create tools repository, so there is an extra layer of build-depends +toolsrepo="$DATADIR/tools-repo" +mkdir -p "$toolsrepo" +cd "$toolsrepo" +git init --quiet +cat <<'EOF' >tools.morph +name: tools +kind: chunk +build-commands: + - echo 'echo dummy strace' >strace +install-commands: + - mkdir -p "$DESTDIR/bin" + - install strace "$DESTDIR/bin/strace" +EOF +git add tools.morph +git commit --quiet -m "add morphology" # Create morph repository. @@ -98,6 +114,21 @@ chunks: EOF git add hello-stratum.morph +cat <<EOF > tools-stratum.morph +name: tools-stratum +kind: stratum +build-depends: + - morph: linux-stratum + repo: test:morphs + ref: master +chunks: + - name: tools + repo: test:tools-repo + ref: master + build-depends: [] +EOF +git add tools-stratum.morph + cat <<EOF > hello-system.morph name: hello-system kind: system @@ -139,6 +170,9 @@ strata: - morph: linux-stratum repo: test:morphs ref: master + - morph: tools-stratum + repo: test:morphs + ref: master EOF git add linux-system.morph diff --git a/tests.as-root/syslinux-disk-builds-rootfs-and-kernel.stdout b/tests.as-root/syslinux-disk-builds-rootfs-and-kernel.stdout index dfa7d9d3..ecc10ba6 100644 --- a/tests.as-root/syslinux-disk-builds-rootfs-and-kernel.stdout +++ b/tests.as-root/syslinux-disk-builds-rootfs-and-kernel.stdout @@ -11,8 +11,11 @@ ./factory-run/baserock/linux-stratum.meta ./factory-run/baserock/linux-system-rootfs.meta ./factory-run/baserock/linux.meta +./factory-run/baserock/tools-stratum.meta +./factory-run/baserock/tools.meta ./factory-run/bin ./factory-run/bin/hello +./factory-run/bin/strace ./factory-run/boot ./factory-run/boot/System.map ./factory-run/boot/vmlinuz @@ -26,8 +29,11 @@ ./factory/baserock/linux-stratum.meta ./factory/baserock/linux-system-rootfs.meta ./factory/baserock/linux.meta +./factory/baserock/tools-stratum.meta +./factory/baserock/tools.meta ./factory/bin ./factory/bin/hello +./factory/bin/strace ./factory/boot ./factory/boot/System.map ./factory/boot/vmlinuz |