diff --git a/build/ab.mk b/build/ab.mk index 177d0edd..2b0b6343 100644 --- a/build/ab.mk +++ b/build/ab.mk @@ -29,7 +29,7 @@ endif EXT ?= ifeq ($(PROGRESSINFO),) -rulecount := $(shell test -f $(OBJ)/build.mk && $(MAKE) -n $(MAKECMDGOALS) PROGRESSINFO=XXXPROGRESSINFOXXX | grep XXXPROGRESSINFOXXX | wc -l) +rulecount := $(shell $(MAKE) -q $(OBJ)/build.mk PROGRESSINFO=1 && $(MAKE) -n $(MAKECMDGOALS) PROGRESSINFO=XXXPROGRESSINFOXXX | grep XXXPROGRESSINFOXXX | wc -l) ruleindex := 1 PROGRESSINFO = "$(shell $(PYTHON) build/_progress.py $(ruleindex) $(rulecount))$(eval ruleindex := $(shell expr $(ruleindex) + 1))" endif @@ -53,8 +53,8 @@ clean:: export PYTHONHASHSEED = 1 build-files = $(shell find . -name 'build.py') $(wildcard build/*.py) $(wildcard config.py) -$(OBJ)/build.mk: Makefile $(build-files) +$(OBJ)/build.mk: Makefile $(build-files) build/ab.mk @echo "AB" @mkdir -p $(OBJ) - $(hide) $(PYTHON) -X pycache_prefix=$(OBJ) build/ab.py -o $@ build.py \ + $(hide) $(PYTHON) -X pycache_prefix=$(OBJ)/__pycache__ build/ab.py -o $@ build.py \ || rm -f $@ diff --git a/build/ab.py b/build/ab.py index d10e7da9..9eeea485 100644 --- a/build/ab.py +++ b/build/ab.py @@ -154,6 +154,9 @@ def __init__(self, cwd, name): def __eq__(self, other): return self.name is other.name + def __lt__(self, other): + return self.name < other.name + def __hash__(self): return id(self) @@ -314,7 +317,12 @@ def targetof(value, cwd=None): # Load the new build file. path = join(path, "build.py") - loadbuildfile(path) + try: + loadbuildfile(path) + except ModuleNotFoundError: + error( + f"no such build file '{path}' while trying to resolve '{value}'" + ) assert ( value in targets ), f"build file at '{path}' doesn't contain '+{target}' when trying to resolve '{value}'" @@ -411,7 +419,7 @@ def emit_rule(name, ins, outs, cmds=[], label=None): emit(".PHONY:", name, into=lines) if outs: emit(name, ":", *fouts, into=lines) - emit(*fouts, "&:", *fins, "\x01", into=lines) + emit(*fouts, "&:" if len(fouts) > 1 else ":", *fins, "\x01", into=lines) if label: emit("\t$(hide)", "$(ECHO) $(PROGRESSINFO) ", label, into=lines) diff --git a/build/utils.py b/build/utils.py index ac57304e..17040a8f 100644 --- a/build/utils.py +++ b/build/utils.py @@ -8,8 +8,8 @@ error, simplerule, ) -from os.path import relpath, splitext, join, basename -from glob import glob +from os.path import relpath, splitext, join, basename, isfile +from glob import iglob import fnmatch import itertools @@ -30,7 +30,7 @@ def collectattrs(*, targets, name, initial=[]): s = set(initial) for a in [t.args.get(name, []) for t in targets]: s.update(a) - return list(s) + return sorted(list(s)) def itemsof(pattern, root=None, cwd=None): @@ -43,9 +43,10 @@ def itemsof(pattern, root=None, cwd=None): root = join(cwd, root) result = {} - for f in glob(pattern, recursive=True): + for f in iglob(pattern, recursive=True): try: - result[relpath(f, root)] = f + if isfile(f): + result[relpath(f, root)] = f except ValueError: error(f"file '{f}' is not in root '{root}'") return result