[gnome-build-meta/abderrahim/bst2: 18/24] plugins/ostree.py: port to bst2




commit b60a8379218c78ed3f23728c0d7d3fc60a0dbbf5
Author: Abderrahim Kitouni <akitouni gnome org>
Date:   Mon Jan 3 22:01:22 2022 +0100

    plugins/ostree.py: port to bst2

 elements/vm/repo-devel.bst |  8 ++---
 elements/vm/repo.bst       |  8 ++---
 plugins/ostree.py          | 84 ++++++++++++++++++++--------------------------
 3 files changed, 42 insertions(+), 58 deletions(-)
---
diff --git a/elements/vm/repo-devel.bst b/elements/vm/repo-devel.bst
index 517bd38b7..76653c3ec 100644
--- a/elements/vm/repo-devel.bst
+++ b/elements/vm/repo-devel.bst
@@ -2,19 +2,17 @@ kind: ostree
 
 build-depends:
 - core-deps/libostree.bst
-- vm/filesystem-devel.bst
 - vm/initial-scripts-devel.bst
 - freedesktop-sdk.bst:vm/prepare-image.bst
+- filename: vm/filesystem-devel.bst
+  config:
+    sysroot: true
 
 variables:
   uuidnamespace: aea54278-2587-4075-ae67-8688ace4ce3d
   ostree-layer: devel
 
 config:
-  environment:
-  - core-deps/libostree.bst
-  - vm/prepare-image.bst
-  - vm/initial-scripts-devel.bst
   ostree-branch: '%{ostree-branch}'
   initial-commands:
   - |
diff --git a/elements/vm/repo.bst b/elements/vm/repo.bst
index f9ecc7ca1..a73313111 100644
--- a/elements/vm/repo.bst
+++ b/elements/vm/repo.bst
@@ -2,18 +2,16 @@ kind: ostree
 
 build-depends:
 - core-deps/libostree.bst
-- vm/filesystem.bst
 - vm/initial-scripts.bst
 - freedesktop-sdk.bst:vm/prepare-image.bst
+- filename: vm/filesystem.bst
+  config:
+    sysroot: true
 
 variables:
   uuidnamespace: aea54278-2587-4075-ae67-8688ace4ce3d
 
 config:
-  environment:
-  - core-deps/libostree.bst
-  - vm/prepare-image.bst
-  - vm/initial-scripts.bst
   ostree-branch: '%{ostree-branch}'
   initial-commands:
   - |
diff --git a/plugins/ostree.py b/plugins/ostree.py
index d5de139d7..132afe5a4 100644
--- a/plugins/ostree.py
+++ b/plugins/ostree.py
@@ -1,8 +1,10 @@
-from buildstream import Element, Scope, SandboxFlags, ElementError
+from buildstream import Element, ElementError
 import os
 
 
 class OstreeElement(Element):
+    BST_MIN_VERSION = "2.0"
+
     BST_FORBID_RDEPENDS = True
     BST_FORBID_SOURCES = True
     BST_STRICT_REBUILD = True
@@ -11,71 +13,58 @@ class OstreeElement(Element):
         pass
 
     def configure(self, node):
-        self.node_validate(node, ["environment", "ostree-branch", "initial-commands"])
+        node.validate_keys(["ostree-branch", "initial-commands"])
+
+        self.branch = node.get_str("ostree-branch")
+        self.initial_commands = node.get_str_list("initial-commands")
+
+        self.env = []
+        self.sysroot = []
+
+    def configure_dependencies(self, dependencies):
+        for dep in dependencies:
+            if dep.config:
+                dep.config.validate_keys(["sysroot"])
 
-        self.env = self.node_subst_list(node, "environment")
-        self.branch = self.node_subst_member(node, "ostree-branch")
-        self.initial_commands = self.node_subst_list(node, "initial-commands")
+                if dep.config.get_bool("sysroot", False):
+                    self.sysroot.append(dep.element)
+                    continue
+
+            self.env.append(dep.element)
 
     def get_unique_key(self):
         return {"branch": self.branch, "initial-commands": self.initial_commands}
 
     def configure_sandbox(self, sandbox):
-        sandbox.mark_directory(self.get_variable("build-root"), artifact=True)
+        sandbox.mark_directory(self.get_variable("build-root"))
         sandbox.mark_directory(self.get_variable("install-root"))
 
         sandbox.set_environment(self.get_environment())
 
     def stage(self, sandbox):
-        env = []
-        source_deps = []
-        for dep in self.dependencies(Scope.BUILD, recurse=False):
-            if dep.name in self.env:
-                self.status("{} in environment".format(dep.name))
-                env.append(dep)
-            else:
-                self.status("{} in sysroot".format(dep.name))
-                source_deps.append(dep)
-
         with self.timed_activity("Staging environment", silent_nested=True):
-            for build_dep in env:
-                build_dep.stage_dependency_artifacts(sandbox, Scope.RUN)
+            self.stage_dependency_artifacts(sandbox, self.env)
 
         with self.timed_activity("Integrating sandbox", silent_nested=True):
-            for build_dep in env:
-                for dep in build_dep.dependencies(Scope.RUN):
-                    dep.integrate(sandbox)
+            for dep in self.dependencies(self.env):
+                dep.integrate(sandbox)
 
-        for build_dep in source_deps:
-            build_dep.stage_dependency_artifacts(
-                sandbox, Scope.RUN, path=self.get_variable("sysroot")
-            )
+        with self.timed_activity("Staging sysroot", silent_nested=True):
+            for dep in self.sysroot:
+                self.stage_dependency_artifacts(sandbox, self.sysroot, path=self.get_variable("sysroot"))
 
     def assemble(self, sandbox):
-        def run_command(*command):
-            exitcode = sandbox.run(command, SandboxFlags.ROOT_READ_ONLY)
-            if exitcode != 0:
-                raise ElementError(
-                    "Command '{}' failed with exitcode {}".format(
-                        " ".join(command), exitcode
-                    )
-                )
-
         sysroot = self.get_variable("sysroot")
         barerepopath = os.path.join(self.get_variable("build-root"), "barerepo")
         repopath = self.get_variable("install-root")
 
-        with self.timed_activity("Running initial commands"):
+        #with self.timed_activity("Running commands"):
+        with sandbox.batch():
             for command in self.initial_commands:
-                run_command("sh", "-c", command)
-
-        with self.timed_activity("Initial commit"):
-            # ostree doesn't like the fuse filesystem buildstream uses to prevent artifact corruption
-            # so disable it. This should be safe as ostree shouldn't modify the files contents now
-            sandbox.mark_directory(self.get_variable("build-root"), artifact=False)
+                sandbox.run(["sh", "-c", "-e", command])
 
-            run_command("ostree", "init", "--repo", barerepopath)
-            run_command(
+            sandbox.run(["ostree", "init", "--repo", barerepopath])
+            sandbox.run([
                 "ostree",
                 "commit",
                 "--repo",
@@ -85,12 +74,11 @@ class OstreeElement(Element):
                 "--branch",
                 self.branch,
                 "--timestamp",
-                "2011-11-11 11:11:11+00:00",
-            )
+                "2011-11-11 11:11:11+00:00"
+            ])
 
-        with self.timed_activity("Pull"):
-            run_command("ostree", "init", "--repo", repopath, "--mode", "archive")
-            run_command("ostree", "pull-local", "--repo", repopath, barerepopath)
+            sandbox.run(["ostree", "init", "--repo", repopath, "--mode", "archive"])
+            sandbox.run(["ostree", "pull-local", "--repo", repopath, barerepopath])
 
         return repopath
 


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