Rewrite the lunabuild toolchain with enhanced feature (#60)
[lunaix-os.git] / lunaix-os / scripts / build-tools / shared / scopes.py
diff --git a/lunaix-os/scripts/build-tools/shared/scopes.py b/lunaix-os/scripts/build-tools/shared/scopes.py
new file mode 100644 (file)
index 0000000..507280b
--- /dev/null
@@ -0,0 +1,26 @@
+import os
+
+from lbuild.scope import ScopeProvider
+from lcfg2.common import NodeProperty
+
+class ConfigScope(ScopeProvider):
+    def __init__(self, env):
+        super().__init__("config")
+        self.__env = env
+
+    def __getitem__(self, name):
+        node = self.__env.get_node(name)
+        if node is None:
+            raise Exception(f"config '{name}' not exists")
+        
+        if not NodeProperty.Enabled[node]:
+            return None
+
+        return NodeProperty.Value[node]
+
+class EnvScope(ScopeProvider):
+    def __init__(self):
+        super().__init__("env")
+
+    def __getitem__(self, name):
+        return os.environ.get(name)
\ No newline at end of file