diff options
author | Tristan Maat <tristan.maat@codethink.co.uk> | 2017-10-02 13:41:18 +0100 |
---|---|---|
committer | Tristan Maat <tristan.maat@codethink.co.uk> | 2017-10-13 15:59:26 +0100 |
commit | c1954f6d78278b5b8ea1851b73ec8803e1caba56 (patch) | |
tree | 0c246015fdde87f7794c0581009c9189bddbaa21 | |
parent | 96af5cdb25fa0272957e297a7585962f824c97a7 (diff) | |
download | buildstream-c1954f6d78278b5b8ea1851b73ec8803e1caba56.tar.gz |
Add %{script} format to `buildstream show`
-rw-r--r-- | buildstream/_frontend/main.py | 1 | ||||
-rw-r--r-- | buildstream/_frontend/widget.py | 9 | ||||
-rw-r--r--[-rwxr-xr-x] | buildstream/_platform/platform.py | 0 | ||||
-rw-r--r-- | buildstream/element.py | 22 |
4 files changed, 27 insertions, 5 deletions
diff --git a/buildstream/_frontend/main.py b/buildstream/_frontend/main.py index c05c44135..c96e26eaf 100644 --- a/buildstream/_frontend/main.py +++ b/buildstream/_frontend/main.py @@ -405,6 +405,7 @@ def show(app, target, deps, except_, order, format): %{public} Public domain data %{workspaced} If the element is workspaced %{workspace-dirs} A list of workspace directories + %{script} The script executed by the element The value of the %{symbol} without the leading '%' character is understood as a pythonic formatting string, so python formatting features apply, diff --git a/buildstream/_frontend/widget.py b/buildstream/_frontend/widget.py index 8b55b39ee..e0fe59a73 100644 --- a/buildstream/_frontend/widget.py +++ b/buildstream/_frontend/widget.py @@ -644,6 +644,15 @@ class LogLine(Widget): line = p.fmt_subst( line, 'workspace-dirs', '') + # Script + if "%{script" in format: + try: + script = element._generate_script() + except ImplError: + script = "" + + line = p.fmt_subst(line, 'script', script) + report += line + '\n' return report.rstrip('\n') diff --git a/buildstream/_platform/platform.py b/buildstream/_platform/platform.py index 920fddbde..920fddbde 100755..100644 --- a/buildstream/_platform/platform.py +++ b/buildstream/_platform/platform.py diff --git a/buildstream/element.py b/buildstream/element.py index aa7c7e5ff..e008c4bf9 100644 --- a/buildstream/element.py +++ b/buildstream/element.py @@ -615,18 +615,24 @@ class Element(Plugin): # Private Methods used in BuildStream # ############################################################# - # _write_script(): + # _generate_script(): # - # Writes a script to the given directory. - def _write_script(self, directory): - with open(_site.build_module_template, "r") as f: + # Create a build script by substituting + # _site.build_module_template with the correct values for this + # element. + # + # Returns: + # (str): The build script. + # + def _generate_script(self): + with open(_site.build_module_template, 'r') as f: script_template = f.read() variable_string = "" for var, val in self.get_environment().items(): variable_string += "{0}={1} ".format(var, val) - script = script_template.format( + return script_template.format( name=self.normal_name, build_root=self.get_variable('build-root'), install_root=self.get_variable('install-root'), @@ -634,6 +640,12 @@ class Element(Plugin): commands=self.generate_script() ) + # _write_script(): + # + # Writes a script to the given directory. + def _write_script(self, directory): + script = self._generate_script() + os.makedirs(directory, exist_ok=True) script_path = os.path.join(directory, "build-" + self.normal_name) |