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




commit 211fe7fc3772650e92bba9f079b86894c8d8b34a
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          | 81 +++++++++++++++++++++++-----------------------
 3 files changed, 46 insertions(+), 51 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..2699555c2 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,11 +13,24 @@ 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}
@@ -27,33 +42,20 @@ class OstreeElement(Element):
         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)
+            exitcode = sandbox.run(command, root_read_only=True)
             if exitcode != 0:
                 raise ElementError(
                     "Command '{}' failed with exitcode {}".format(
@@ -66,31 +68,28 @@ class OstreeElement(Element):
         repopath = self.get_variable("install-root")
 
         with self.timed_activity("Running initial commands"):
-            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)
-
-            run_command("ostree", "init", "--repo", barerepopath)
-            run_command(
+            with sandbox.batch():
+                for command in self.initial_commands:
+                    sandbox.run(["sh", "-c", "-e", command])
+
+        with self.timed_activity("Initial commit"), sandbox.batch(root_read_only=True):
+            #sandbox.run(["ostree", "init", "--repo", barerepopath], SandboxFlags.NONE)
+            sandbox.run(["ostree", "init", "--repo", repopath, "--mode", "archive"], root_read_only=True)
+            sandbox.run([
                 "ostree",
                 "commit",
                 "--repo",
-                barerepopath,
+                repopath,
                 "--consume",
                 sysroot,
                 "--branch",
                 self.branch,
                 "--timestamp",
-                "2011-11-11 11:11:11+00:00",
-            )
+                "2011-11-11 11:11:11+00:00"
+            ], root_read_only=True)
 
-        with self.timed_activity("Pull"):
-            run_command("ostree", "init", "--repo", repopath, "--mode", "archive")
-            run_command("ostree", "pull-local", "--repo", repopath, barerepopath)
+        #with self.timed_activity("Pull"), sandbox.batch(SandboxFlags.ROOT_READ_ONLY):
+        #    sandbox.run(["ostree", "pull-local", "--repo", repopath, barerepopath], 
SandboxFlags.ROOT_READ_ONLY)
 
         return repopath
 


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