← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] ~cjwatson/lpbuildbot-worker:build-variables into lpbuildbot-worker:main

 

Colin Watson has proposed merging ~cjwatson/lpbuildbot-worker:build-variables into lpbuildbot-worker:main.

Commit message:
lp-setup-lxd-build: Accept --variable option

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~cjwatson/lpbuildbot-worker/+git/lpbuildbot-worker/+merge/391047

This allows passing extra variables to "make build".

I'm particularly thinking about this in order to run a job with PYTHON=python3.
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/lpbuildbot-worker:build-variables into lpbuildbot-worker:main.
diff --git a/lp-setup-lxd-build b/lp-setup-lxd-build
index 971d290..2081944 100755
--- a/lp-setup-lxd-build
+++ b/lp-setup-lxd-build
@@ -110,13 +110,17 @@ def copy_workdir_to_container(container, work_dir):
     _exec(container, ["chown", "-R", "buildbot:buildbot", str(work_dir)])
 
 
-def build_launchpad_in_container(container, work_dir):
+def build_launchpad_in_container(container, work_dir, variables):
     print("Building Launchpad in container")
     for build_step in BUILD_STEPS:
         print("Build step: {}".format(build_step))
+        command = ["make", build_step]
+        if build_step == "build":
+            for key, value in variables:
+                command.append("{}={}".format(key, value))
         _exec(
             container,
-            ["make", build_step],
+            command,
             user="buildbot",
             cwd="{}/devel".format(work_dir),
         )
@@ -130,6 +134,11 @@ if __name__ == "__main__":
     parser.add_argument(
         "work_dir", type=str, help="Base directory for code and dependencies"
     )
+    parser.add_argument(
+        "--variable", dest="variables", action="append", default=[],
+        type=lambda s: s.split("=", 1), metavar="KEY=value",
+        help="Variable to pass to 'make build'",
+    )
     args = parser.parse_args()
 
     # Work around xenial's pylxd not understanding the lxd snap.
@@ -144,5 +153,5 @@ if __name__ == "__main__":
     client = Client()
 
     container = start_new_container(client, args.name, args.work_dir)
-    build_launchpad_in_container(container, args.work_dir)
+    build_launchpad_in_container(container, args.work_dir, args.variables)
     copy_workdir_to_container(container, args.work_dir)