Skip to content

Commit

Permalink
Support batched Makefile queries
Browse files Browse the repository at this point in the history
  • Loading branch information
Jake-Carter committed Aug 23, 2024
1 parent 89e7344 commit 3e2bd49
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
21 changes: 10 additions & 11 deletions .github/workflows/scripts/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,16 +110,18 @@ def build_project(project:Path, target, board, maxim_path:Path, distclean=False,
return (return_code, project_info)

def query_build_variable(project:Path, variable:str) -> list:
result = run(f"make query QUERY_VAR={variable}", cwd=project, shell=True, capture_output=True, encoding="utf-8")
result = run(f"make query QUERY_VAR=\"{variable}\"", cwd=project, shell=True, capture_output=True, encoding="utf-8")
if result.returncode != 0:
return []

for line in result.stdout.splitlines():
if variable in line:
# query output string will be "{variable}={item1, item2, ..., itemN}"
return str(line).split("=")[1].split(" ")
output = []
for v in variable.split(" "):
for line in result.stdout.splitlines():
if v in line:
# query output string will be "{variable}={item1, item2, ..., itemN}"
output += str(line).split("=")[1].split(" ")

raise Exception(f"Bad variable query for {variable} in {project}")
return output

"""
Create a dictionary mapping each target micro to its dependencies in the MSDK.
Expand Down Expand Up @@ -149,11 +151,8 @@ def create_dependency_map(maxim_path:Path, targets:list) -> dict:
projects = [Path(i).parent for i in examples_dir.rglob("**/project.mk")]
for project in projects:
console.print(f"\t- Checking dependencies: {project}")
IPATH = query_build_variable(project, "IPATH")
VPATH = query_build_variable(project, "VPATH")
SRCS = query_build_variable(project, "SRCS")
LIBS = query_build_variable(project, "SRCS")
dependencies = list(set(IPATH + VPATH + SRCS + LIBS))
dependencies = query_build_variable(project, "IPATH VPATH SRCS LIBS")
dependencies = list(set(dependencies))
for i in dependencies:
if i == ".":
dependencies.remove(i)
Expand Down
3 changes: 2 additions & 1 deletion Libraries/CMSIS/Device/Maxim/GCC/gcc.mk
Original file line number Diff line number Diff line change
Expand Up @@ -740,8 +740,9 @@ SUPPRESS_HELP := 1
endif
.PHONY: query
query:
@echo
ifneq "$(QUERY_VAR)" ""
@echo $(QUERY_VAR)=$($(QUERY_VAR))
$(foreach QUERY_VAR,$(QUERY_VAR),$(info $(QUERY_VAR)=$($(QUERY_VAR))))
else
$(MAKE) debug
endif
Expand Down
6 changes: 3 additions & 3 deletions Libraries/CMSIS/Device/Maxim/GCC/gcc_riscv.mk
Original file line number Diff line number Diff line change
Expand Up @@ -698,9 +698,9 @@ SUPPRESS_HELP := 1
endif
.PHONY: query
query:
@echo
ifneq "$(QUERY_VAR)" ""
@echo $(QUERY_VAR)=$($(QUERY_VAR))
$(foreach QUERY_VAR,$(QUERY_VAR),$(info $(QUERY_VAR)=$($(QUERY_VAR))))
else
$(MAKE) debug
$(MAKE) debug
endif

0 comments on commit 3e2bd49

Please sign in to comment.