You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@buildstream.apache.org by ro...@apache.org on 2020/12/29 13:43:48 UTC

[buildstream] branch non-sandbox-builds created (now 12d86fc)

This is an automated email from the ASF dual-hosted git repository.

root pushed a change to branch non-sandbox-builds
in repository https://gitbox.apache.org/repos/asf/buildstream.git.


      at 12d86fc  Add tests for %{script} format

This branch includes the following new commits:

     new c1954f6  Add %{script} format to `buildstream show`
     new 12d86fc  Add tests for %{script} format

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[buildstream] 02/02: Add tests for %{script} format

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

root pushed a commit to branch non-sandbox-builds
in repository https://gitbox.apache.org/repos/asf/buildstream.git

commit 12d86fc144f994131d706ae4027bf8d6f88eed32
Author: Tristan Maat <tr...@codethink.co.uk>
AuthorDate: Wed Oct 4 14:02:06 2017 +0100

    Add tests for %{script} format
---
 .../project/elements/manual-build-output.txt       | 60 ++++++++++++++++++++++
 tests/frontend/project/elements/manual-build.bst   | 12 +++++
 tests/frontend/show.py                             | 17 ++++--
 3 files changed, 86 insertions(+), 3 deletions(-)

diff --git a/tests/frontend/project/elements/manual-build-output.txt b/tests/frontend/project/elements/manual-build-output.txt
new file mode 100755
index 0000000..a6a98ef
--- /dev/null
+++ b/tests/frontend/project/elements/manual-build-output.txt
@@ -0,0 +1,60 @@
+#!/bin/sh
+#
+# DO NOT EDIT THIS FILE
+#
+# This is a build script generated by
+# [BuildStream](https://wiki.gnome.org/Projects/BuildStream/).
+#
+# Builds the module manual-build.
+
+set -e
+
+# Prepare the build environment
+echo 'Building manual-build'
+
+if [ -d '/buildstream/build' ]; then
+    rm -rf '/buildstream/build'
+fi
+
+if [ -d '/buildstream/install' ]; then
+    rm -rf '/buildstream/install'
+fi
+
+mkdir -p '/buildstream/build'
+mkdir -p '/buildstream/install'
+
+if [ -d "$SRCDIR/manual-build/" ]; then
+    cp -a "$SRCDIR/manual-build/." '/buildstream/build'
+fi
+cd '/buildstream/build'
+
+export PREFIX='/buildstream/install'
+
+export HOME=/tmp LC_ALL=C LOGNAME=tomjon MAKEFLAGS=-j1 PATH=/usr/bin:/bin:/usr/sbin:/sbin SHELL=/bin/sh TERM=dumb TZ=UTC USER=tomjon USERNAME=tomjon V=1 
+
+# Build the module
+(set -ex; echo 'Hi :)'
+) || exit 1
+(set -ex; find "/buildstream/install" -type f \
+  '(' -perm -111 -o -name '*.so*' \
+      -o -name '*.cmxs' -o -name '*.node' ')' \
+  -exec sh -ec \
+  'read -n4 hdr <"$1" # check for elf header
+   if [ "$hdr" != "$(printf \\x7fELF)" ]; then
+       exit 0
+   fi
+   debugfile="/buildstream/install/usr/lib/debug/$(basename "$1")"
+   mkdir -p "$(dirname "$debugfile")"
+   objcopy --only-keep-debug "$1" "$debugfile"
+   chmod 644 "$debugfile"
+   strip --remove-section=.comment --remove-section=.note --strip-unneeded "$1"
+   objcopy --add-gnu-debuglink "$debugfile" "$1"' - {} ';'
+) || exit 1
+
+
+rm -rf '/buildstream/build'
+
+# Install the module
+echo 'Installing manual-build'
+
+(cd '/buildstream/install'; find . | cpio -umdp /)
\ No newline at end of file
diff --git a/tests/frontend/project/elements/manual-build.bst b/tests/frontend/project/elements/manual-build.bst
new file mode 100644
index 0000000..ec70c68
--- /dev/null
+++ b/tests/frontend/project/elements/manual-build.bst
@@ -0,0 +1,12 @@
+kind: manual
+
+depends:
+  - filename: import-bin.bst
+    type: build
+
+config:
+  build-commands:
+    - echo 'Hi :)'
+
+environment:
+  MAKEFLAGS: -j1
diff --git a/tests/frontend/show.py b/tests/frontend/show.py
index e6c754f..69d5e59 100644
--- a/tests/frontend/show.py
+++ b/tests/frontend/show.py
@@ -1,5 +1,7 @@
 import os
+import io
 import pytest
+import difflib
 from tests.testutils.runcli import cli
 
 # Project directory
@@ -9,11 +11,16 @@ DATA_DIR = os.path.join(
 )
 
 
+with open(os.path.join(DATA_DIR, 'elements', 'manual-build-output.txt'), 'r') as f:
+    MANUAL_OUTPUT = f.read()
+
+
 @pytest.mark.datafiles(DATA_DIR)
 @pytest.mark.parametrize("target,format,expected", [
     ('import-bin.bst', '%{name}', 'import-bin.bst'),
     ('import-bin.bst', '%{state}', 'buildable'),
-    ('compose-all.bst', '%{state}', 'waiting')
+    ('compose-all.bst', '%{state}', 'waiting'),
+    ('manual-build.bst', '%{script}', MANUAL_OUTPUT)
 ])
 def test_show(cli, datafiles, target, format, expected):
     project = os.path.join(datafiles.dirname, datafiles.basename)
@@ -26,8 +33,12 @@ def test_show(cli, datafiles, target, format, expected):
     assert result.exit_code == 0
 
     if result.output.strip() != expected:
-        raise AssertionError("Expected output:\n{}\nInstead received output:\n{}"
-                             .format(expected, result.output))
+        diff = difflib.context_diff(result.output.strip().splitlines(True),
+                                    expected.splitlines(True),
+                                    fromfile='output', tofile='expected')
+
+        raise AssertionError("Received unexpected output:\n{}\n"
+                             .format(''.join(diff)))
 
 
 @pytest.mark.datafiles(DATA_DIR)


[buildstream] 01/02: Add %{script} format to `buildstream show`

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

root pushed a commit to branch non-sandbox-builds
in repository https://gitbox.apache.org/repos/asf/buildstream.git

commit c1954f6d78278b5b8ea1851b73ec8803e1caba56
Author: Tristan Maat <tr...@codethink.co.uk>
AuthorDate: Mon Oct 2 13:41:18 2017 +0100

    Add %{script} format to `buildstream show`
---
 buildstream/_frontend/main.py     |  1 +
 buildstream/_frontend/widget.py   |  9 +++++++++
 buildstream/_platform/platform.py |  0
 buildstream/element.py            | 22 +++++++++++++++++-----
 4 files changed, 27 insertions(+), 5 deletions(-)

diff --git a/buildstream/_frontend/main.py b/buildstream/_frontend/main.py
index c05c441..c96e26e 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 8b55b39..e0fe59a 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
old mode 100755
new mode 100644
diff --git a/buildstream/element.py b/buildstream/element.py
index aa7c7e5..e008c4b 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)