[buildbot] phase1: factor out populateTargetsForBranch

LEDE Commits lede-commits at lists.infradead.org
Wed Jun 12 11:35:38 PDT 2024


ynezz pushed a commit to buildbot.git, branch main:
https://git.openwrt.org/867356244ac2ed9abb4be3e7ccda55c96b10b71a

commit 867356244ac2ed9abb4be3e7ccda55c96b10b71a
Author: Petr Štetiar <ynezz at true.cz>
AuthorDate: Sat Jun 1 11:21:23 2024 +0000

    phase1: factor out populateTargetsForBranch
    
    Going to make builders (build targets) configurable, so lets factor
    current populateTargets into separate function populateTargetsForBranch
    which takes a branch as argument. No functional changes.
    
    Signed-off-by: Petr Štetiar <ynezz at true.cz>
---
 phase1/master.cfg | 73 +++++++++++++++++++++++++++++--------------------------
 1 file changed, 39 insertions(+), 34 deletions(-)

diff --git a/phase1/master.cfg b/phase1/master.cfg
index 4e7cbc1..970f7f9 100644
--- a/phase1/master.cfg
+++ b/phase1/master.cfg
@@ -300,48 +300,53 @@ targets = dict()
 
 
 def populateTargets():
-    """fetch a shallow clone of each configured branch in turn:
-    execute dump-target-info.pl and collate the results to ensure
+    for branch in branchNames:
+        populateTargetsForBranch(branch)
+
+
+def populateTargetsForBranch(branch):
+    """fetches a shallow clone for passed `branch` and then
+    executes dump-target-info.pl and collates the results to ensure
     targets that only exist in specific branches get built.
     This takes a while during master startup but is executed only once.
     """
+    targets[branch] = set()
     sourcegit = work_dir + "/source.git"
-    for branch in branchNames:
-        log.msg(f"Populating targets for {branch}, this will take time")
-
-        if os.path.isdir(sourcegit):
-            subprocess.call(["rm", "-rf", sourcegit])
-
-        subprocess.call(
-            [
-                "git",
-                "clone",
-                "-q",
-                "--depth=1",
-                "--branch=" + branch,
-                repo_url,
-                sourcegit,
-            ]
-        )
-
-        os.makedirs(sourcegit + "/tmp", exist_ok=True)
-        findtargets = subprocess.Popen(
-            ["./scripts/dump-target-info.pl", "targets"],
-            stdout=subprocess.PIPE,
-            stderr=subprocess.DEVNULL,
-            cwd=sourcegit,
-        )
 
-        targets[branch] = set()
-        while True:
-            line = findtargets.stdout.readline()
-            if not line:
-                break
-            ta = line.decode().strip().split(" ")
-            targets[branch].add(ta[0])
+    log.msg(f"Populating targets for {branch}, this will take time")
 
+    if os.path.isdir(sourcegit):
         subprocess.call(["rm", "-rf", sourcegit])
 
+    subprocess.call(
+        [
+            "git",
+            "clone",
+            "-q",
+            "--depth=1",
+            "--branch=" + branch,
+            repo_url,
+            sourcegit,
+        ]
+    )
+
+    os.makedirs(sourcegit + "/tmp", exist_ok=True)
+    findtargets = subprocess.Popen(
+        ["./scripts/dump-target-info.pl", "targets"],
+        stdout=subprocess.PIPE,
+        stderr=subprocess.DEVNULL,
+        cwd=sourcegit,
+    )
+
+    while True:
+        line = findtargets.stdout.readline()
+        if not line:
+            break
+        ta = line.decode().strip().split(" ")
+        targets[branch].add(ta[0])
+
+    subprocess.call(["rm", "-rf", sourcegit])
+
 
 populateTargets()
 




More information about the lede-commits mailing list