[gnome-build-meta/abderrahim/bst2: 17/24] plugins/collect_initial_scripts.py: port to buildstream 2




commit 8b85efcfe9be7a7e7cf44b34ad4ccd5b1247c9de
Author: Abderrahim Kitouni <akitouni gnome org>
Date:   Fri Feb 14 08:23:31 2020 +0100

    plugins/collect_initial_scripts.py: port to buildstream 2
    
    copied from freedesktop-sdk

 plugins/collect_initial_scripts.py | 44 ++++++++++++++++++++++++--------------
 1 file changed, 28 insertions(+), 16 deletions(-)
---
diff --git a/plugins/collect_initial_scripts.py b/plugins/collect_initial_scripts.py
index f0d8c413d..2503d5e9e 100644
--- a/plugins/collect_initial_scripts.py
+++ b/plugins/collect_initial_scripts.py
@@ -1,20 +1,31 @@
+"""
+BuildStream does not save file permissions, and ownership.
+include/excludes with integration commands is so complex that only
+the "compose" plugin does it correctly
+
+Because "compose" does not save file permissions and loses integration
+commands (because they are executed), that means we need to save it another
+file permissions another way.
+
+This is where collect_initial_scripts works around the issue. It provides a
+way to have integration scripts that we execute when we pack into an image
+(filesystem, tar, ostree, etc.)
+"""
+
 import os
 import re
-from buildstream import Element, ElementError, Scope
+from buildstream import Element
 
 class ExtractInitialScriptsElement(Element):
+
+    BST_MIN_VERSION = "2.0"
     BST_FORBID_RDEPENDS = True
     BST_FORBID_SOURCES = True
 
-    BST_STRICT_REBUILD = True
-    BST_ARTIFACT_VERSION = 1
-
     def configure(self, node):
-        self.node_validate(node, [
-            'path',
-        ])
+        node.validate_keys(['path'])
 
-        self.path = self.node_subst_member(node, 'path')
+        self.path = node.get_str('path')
 
     def preflight(self):
         pass
@@ -32,21 +43,22 @@ class ExtractInitialScriptsElement(Element):
         pass
 
     def assemble(self, sandbox):
-        basedir = sandbox.get_directory()
-        path = os.path.join(basedir, self.path.lstrip(os.sep))
+        basedir = sandbox.get_virtual_directory()
+        relative_path = self.path.strip(os.sep)
+
         index = 0
-        for dependency in self.dependencies(Scope.BUILD):
+        for dependency in self.dependencies():
             public = dependency.get_public_data('initial-script')
             if public and 'script' in public:
-                script = self.node_subst_member(public, 'script')
+                script = self.node_subst_vars(public.get_scalar('script'))
                 index += 1
                 depname = re.sub('[^A-Za-z0-9]', '_', dependency.name)
                 basename = '{:03}-{}'.format(index, depname)
-                filename = os.path.join(path, basename)
-                os.makedirs(path, exist_ok=True)
-                with open(filename, 'w') as f:
+
+                pathdir = basedir.open_directory(relative_path, create=True)
+                with pathdir.open_file(basename, mode='w') as f:
                     f.write(script)
-                os.chmod(filename, 0o755)
+                    os.chmod(f.fileno(), 0o755)
 
         return os.sep
 


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