From 13b075f1366d0082cd91abe28646fe367bd0f8da Mon Sep 17 00:00:00 2001 From: Phillip Smyth Date: Wed, 7 Mar 2018 15:02:01 +0000 Subject: Generate unique subdirs for built elements Based on issue 89 (https://gitlab.com/BuildStream/buildstream/issues/89) there has been interest in ensuring that elements are staged into unique subdirs while building. This patch supports that by doing the following: * Modify project config to add 2 new variables ("project-name" and "element") * Changed the default install-root from "/buildstream/install" to "/buildstream-install" * Update the tests to accommodate these changes * Update the expected cache keys in the tests --- buildstream/buildelement.py | 4 ++-- buildstream/data/projectconfig.yaml | 8 +++++--- buildstream/element.py | 1 + buildstream/plugins/elements/script.yaml | 8 -------- tests/cachekey/project/elements/build1.expected | 2 +- tests/cachekey/project/elements/script1.expected | 2 +- tests/cachekey/project/target.expected | 2 +- tests/integration/project/elements/stack/another-hi.bst | 4 ++-- tests/integration/project/elements/stack/hi.bst | 4 ++-- tests/integration/script.py | 12 ++++++------ tests/variables/variables.py | 10 +++++----- 11 files changed, 26 insertions(+), 31 deletions(-) diff --git a/buildstream/buildelement.py b/buildstream/buildelement.py index c275cfb9d..5a986bd11 100644 --- a/buildstream/buildelement.py +++ b/buildstream/buildelement.py @@ -90,7 +90,7 @@ of the staged sources. Result collection ~~~~~~~~~~~~~~~~~ Finally, the resulting build *artifact* is collected from the the ``%{install-root}`` -directory (which is normally configured as ``/buildstream/install``) inside the sandbox. +directory (which is normally configured as ``/buildstream-install``) inside the sandbox. All build elements must install into the ``%{install-root}`` using whatever semantic the given build system provides to do this. E.g. for standard autotools @@ -222,7 +222,7 @@ class BuildElement(Element): "will not be allowed to stage to %{build-root}.") # Return the payload, this is configurable but is generally - # always the /buildstream/install directory + # always the /buildstream-install directory return self.get_variable('install-root') def _get_commands(self, node, name): diff --git a/buildstream/data/projectconfig.yaml b/buildstream/data/projectconfig.yaml index d8fefc5e1..fe51febf8 100644 --- a/buildstream/data/projectconfig.yaml +++ b/buildstream/data/projectconfig.yaml @@ -28,7 +28,9 @@ variables: # # Note: this value defaults to the number of cores available max-jobs: 4 - + # Note: These variables are defined later on in element.py and _project.py + element-name: "" + project-name: "" # Path configuration, to be used in build instructions. # prefix: "/usr" @@ -50,10 +52,10 @@ variables: # Indicates the default build directory where input is # normally staged - build-root: /buildstream/build + build-root: /buildstream/%{project-name}/%{element-name} # Indicates the build installation directory in the sandbox - install-root: /buildstream/install + install-root: /buildstream-install # Arguments for tooling used when stripping debug symbols objcopy-link-args: --add-gnu-debuglink diff --git a/buildstream/element.py b/buildstream/element.py index b62945f4b..1429307a6 100644 --- a/buildstream/element.py +++ b/buildstream/element.py @@ -172,6 +172,7 @@ class Element(Plugin): # Collect the composited variables and resolve them variables = self.__extract_variables(meta) + variables['element-name'] = self.name self.__variables = Variables(variables) # Collect the composited environment now that we have variables diff --git a/buildstream/plugins/elements/script.yaml b/buildstream/plugins/elements/script.yaml index 56a656cf6..b388378da 100644 --- a/buildstream/plugins/elements/script.yaml +++ b/buildstream/plugins/elements/script.yaml @@ -1,15 +1,7 @@ # Common script element variables variables: - # Defines the directory that output is collected from once commands - # have been run. - install-root: /buildstream/install - # # Defines the directory commands will be run from. cwd: / - # - # Not directly used, but expected to be used when staging elements to be - # worked on. - build-root: /buildstream/build # Script element configuration config: diff --git a/tests/cachekey/project/elements/build1.expected b/tests/cachekey/project/elements/build1.expected index aeab7df30..a5d0bdba8 100644 --- a/tests/cachekey/project/elements/build1.expected +++ b/tests/cachekey/project/elements/build1.expected @@ -1 +1 @@ -4fa7a6fd4c7a499208be4ce0deb26f7ae2fad3bfe2a0579f95207e01189731f4 \ No newline at end of file +e627300631f39b713fc5aac9446efeda96b1c3f92ef3f2200a074539e49beaf7 diff --git a/tests/cachekey/project/elements/script1.expected b/tests/cachekey/project/elements/script1.expected index bdcdc75fd..e2b80ddb4 100644 --- a/tests/cachekey/project/elements/script1.expected +++ b/tests/cachekey/project/elements/script1.expected @@ -1 +1 @@ -465988b4812a13871f2c3e840a3b9ae6d95e04f2f0a5e4b5a61f45a8b3a4098d \ No newline at end of file +b8d8400afa31654600cb5eb3f1fbc7165e2316ba759cca197e6e5f54fd4cfd04 diff --git a/tests/cachekey/project/target.expected b/tests/cachekey/project/target.expected index e963f04f1..d82e11af7 100644 --- a/tests/cachekey/project/target.expected +++ b/tests/cachekey/project/target.expected @@ -1 +1 @@ -ad24471b89fa5fa27ea4d355e13a687e91d2cd55aad051230190b495d2e0044a \ No newline at end of file +186136daabb645cfe41bda51279bcfdbb630bc8cff12c3991bbcf685bcf0f898 diff --git a/tests/integration/project/elements/stack/another-hi.bst b/tests/integration/project/elements/stack/another-hi.bst index eb98dea36..f83fdee82 100644 --- a/tests/integration/project/elements/stack/another-hi.bst +++ b/tests/integration/project/elements/stack/another-hi.bst @@ -7,5 +7,5 @@ depends: config: commands: - - "mkdir -p /buildstream/install" - - "echo 'Another hi' > /buildstream/install/another-hi" + - "mkdir -p %{install-root}" + - "echo 'Another hi' > %{install-root}/another-hi" diff --git a/tests/integration/project/elements/stack/hi.bst b/tests/integration/project/elements/stack/hi.bst index adbf81537..0aa2d32f2 100644 --- a/tests/integration/project/elements/stack/hi.bst +++ b/tests/integration/project/elements/stack/hi.bst @@ -4,5 +4,5 @@ depends: type: build config: commands: - - "mkdir -p /buildstream/install" - - "echo 'Hi' > /buildstream/install/hi" + - "mkdir -p %{install-root}" + - "echo 'Hi' > %{install-root}/hi" diff --git a/tests/integration/script.py b/tests/integration/script.py index 5ecc51973..88226c0b7 100644 --- a/tests/integration/script.py +++ b/tests/integration/script.py @@ -39,8 +39,8 @@ def test_script(cli, tmpdir, datafiles): create_script_element(element_name, element_path, config={ 'commands': [ - "mkdir -p /buildstream/install", - "echo 'Hi' > /buildstream/install/test" + "mkdir -p %{install-root}", + "echo 'Hi' > %{install-root}/test" ], }) @@ -69,9 +69,9 @@ def test_script_root(cli, tmpdir, datafiles): # want to check the default here # 'root-read-only': False, 'commands': [ - "mkdir -p /buildstream/install", + "mkdir -p %{install-root}", "echo 'I can write to root' > /test", - "cp /test /buildstream/install" + "cp /test %{install-root}" ], }) @@ -97,9 +97,9 @@ def test_script_no_root(cli, tmpdir, datafiles): config={ 'root-read-only': True, 'commands': [ - "mkdir -p /buildstream/install", + "mkdir -p %{install-root}", "echo 'I can not write to root' > /test", - "cp /test /buildstream/install" + "cp /test %{install-root}" ], }) diff --git a/tests/variables/variables.py b/tests/variables/variables.py index b16511ad6..944d19818 100644 --- a/tests/variables/variables.py +++ b/tests/variables/variables.py @@ -43,16 +43,16 @@ def assert_command(datafiles, tmpdir, target, command, expected): # Test proper loading of some default commands from plugins # ############################################################### @pytest.mark.parametrize("target,command,expected", [ - ('autotools.bst', 'install-commands', "make -j1 DESTDIR=\"/buildstream/install\" install"), + ('autotools.bst', 'install-commands', "make -j1 DESTDIR=\"/buildstream-install\" install"), ('cmake.bst', 'configure-commands', "cmake -B_builddir -H. -DCMAKE_INSTALL_PREFIX:PATH=\"/usr\" \\\n" + "-DCMAKE_INSTALL_LIBDIR=lib"), ('distutils.bst', 'install-commands', "python3 setup.py install --prefix \"/usr\" \\\n" + - "--root \"/buildstream/install\""), - ('makemaker.bst', 'configure-commands', "perl Makefile.PL PREFIX=/buildstream/install/usr"), - ('modulebuild.bst', 'configure-commands', "perl Build.PL --prefix \"/buildstream/install/usr\""), - ('qmake.bst', 'install-commands', "make -j1 INSTALL_ROOT=\"/buildstream/install\" install"), + "--root \"/buildstream-install\""), + ('makemaker.bst', 'configure-commands', "perl Makefile.PL PREFIX=/buildstream-install/usr"), + ('modulebuild.bst', 'configure-commands', "perl Build.PL --prefix \"/buildstream-install/usr\""), + ('qmake.bst', 'install-commands', "make -j1 INSTALL_ROOT=\"/buildstream-install\" install"), ]) @pytest.mark.datafiles(os.path.join(DATA_DIR, 'defaults')) def test_defaults(datafiles, tmpdir, target, command, expected): -- cgit v1.2.1