gnunet-svn
[Top][All Lists]
Advanced

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

[taler-build-common] branch master updated: buildconfig: allow options


From: gnunet
Subject: [taler-build-common] branch master updated: buildconfig: allow options
Date: Tue, 04 May 2021 20:45:17 +0200

This is an automated email from the git hooks/post-receive script.

dold pushed a commit to branch master
in repository build-common.

The following commit(s) were added to refs/heads/master by this push:
     new d7cb231  buildconfig: allow options
d7cb231 is described below

commit d7cb231e63afb32665481fc8c28a5458adde3414
Author: Florian Dold <florian@dold.me>
AuthorDate: Tue May 4 20:45:12 2021 +0200

    buildconfig: allow options
---
 talerbuildconfig.py | 69 ++++++++++++++++++++++++++++++++++++++++-------------
 testconfigure.py    |  1 +
 2 files changed, 54 insertions(+), 16 deletions(-)

diff --git a/talerbuildconfig.py b/talerbuildconfig.py
index 79bdd3a..ab3ec4a 100644
--- a/talerbuildconfig.py
+++ b/talerbuildconfig.py
@@ -59,12 +59,15 @@ serialversion = 2
 # TODO: We need a smallest version argument.
 
 class Tool(ABC):
-    def args(self):
+    def args(self, parser):
         ...
 
     def check(self, buildconfig):
         ...
 
+class Plugin(ABC):
+    def args(self, parser):
+        ...
 
 class BuildConfig:
     def __init__(self):
@@ -72,16 +75,25 @@ class BuildConfig:
         self.make_variables = []
         self.tools = []
         self.tool_results = {}
+        self.plugins = []
         self.args = None
         self.prefix_enabled = False
-        self.variant_enabled = False
         self.configmk_enabled = False
 
     def add_tool(self, tool):
+        """Deprecated.  Prefer the 'use' method."""
         if isinstance(tool, Tool):
             self.tools.append(tool)
         else:
-            raise Exception("Not a tool instance: " + repr(tool))
+            raise Exception("Not a 'Tool' instance: " + repr(tool))
+
+    def use(self, plugin):
+        if isinstance(plugin, Plugin):
+            self.plugins.append(plugin)
+        elif isinstance(plugin, Tool):
+            self.tools.append(plugin)
+        else:
+            raise Exception("Not a 'Plugin' or 'Tool' instance: " + 
repr(plugin))
 
     def _set_tool(self, name, value, version=None):
         self.tool_results[name] = (value, version)
@@ -90,10 +102,6 @@ class BuildConfig:
         """If enabled, process the --prefix argument."""
         self.prefix_enabled = True
 
-    def enable_variant(self):
-        """If enable, process the --variant argument."""
-        self.variant_enabled = True
-
     def _warn(self, msg):
         print("Warning", msg)
 
@@ -113,17 +121,17 @@ class BuildConfig:
                 default="/usr/local",
                 help="Directory prefix for installation",
             )
-        if self.variant_enabled:
-            parser.add_argument(
-                "--variant",
-                type=str,
-                default="",
-                help="Directory for installation",
-            )
         for tool in self.tools:
             tool.args(parser)
+
+        for plugin in self.plugins:
+            plugin.args(parser)
+
         args = self.args = parser.parse_args()
 
+        for plugin in self.plugins:
+            res = plugin.run(self)
+
         for tool in self.tools:
             res = tool.check(self)
             if not res:
@@ -154,17 +162,46 @@ class BuildConfig:
                 f.write("# this makefile fragment is autogenerated by 
configure.py\n")
                 if self.prefix_enabled:
                     f.write(f"prefix = {args.prefix}\n")
-                if self.variant_enabled:
-                    f.write(f"variant = {args.variant}\n")
                 for tool in self.tools:
                     path, version = self.tool_results[tool.name]
                     f.write(f"{tool.name} = {path}\n")
+                for plugin in self.plugins:
+                    d = plugin.get_configmk(self)
+                    for k, v in d.items():
+                        f.write(f"{k} = {v}\n")
 
 
 def existence(name):
     return find_executable(name) is not None
 
 
+class Option(Plugin):
+
+    def __init__(self, optname, help, required=True, default=None):
+        self.optname = optname
+        self.help = help
+        self.default = default
+        self.required = required
+        self._arg = None
+
+    def args(self, parser):
+        parser.add_argument("--" + self.optname, action="store")
+
+    def run(self, buildconfig):
+        arg = getattr(buildconfig.args, self.optname)
+        if arg is None:
+            if self.required:
+                print(f"required option '--{self.optname}' missing")
+                sys.exit(1)
+            else:
+                arg = default
+        self._arg = arg
+
+    def get_configmk(self, buildconfig):
+        key = "opt_" + self.optname
+        return {"opt_" + self.optname: self._arg}
+
+
 class YarnTool(Tool):
     name = "yarn"
     description = "The yarn package manager for node"
diff --git a/testconfigure.py b/testconfigure.py
index 3db0aa4..46645f4 100644
--- a/testconfigure.py
+++ b/testconfigure.py
@@ -11,4 +11,5 @@ b.add_tool(PythonTool())
 b.add_tool(PosixTool("find"))
 b.add_tool(PosixTool("xargs"))
 b.add_tool(PosixTool("msgmerge"))
+b.use(Option("foo", help="What is foo?"))
 b.run()

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]