Skip to content

Commit

Permalink
Update ab.
Browse files Browse the repository at this point in the history
  • Loading branch information
davidgiven committed Sep 28, 2024
1 parent 4c4b6ee commit d890383
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
6 changes: 3 additions & 3 deletions build/ab.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 $@
12 changes: 10 additions & 2 deletions build/ab.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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}'"
Expand Down Expand Up @@ -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)
Expand Down
11 changes: 6 additions & 5 deletions build/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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):
Expand All @@ -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
Expand Down

0 comments on commit d890383

Please sign in to comment.