Update ab.

This commit is contained in:
David Given
2024-10-02 19:46:50 +02:00
parent f48d1c5196
commit a777470cda
3 changed files with 29 additions and 16 deletions

View File

@@ -95,7 +95,9 @@ def cxxfile(
def findsources(name, srcs, deps, cflags, toolchain, filerule, cwd):
headers = filenamesmatchingof(srcs, "*.h")
cflags = cflags + ["-I" + dirname(h) for h in headers]
deps = deps + headers
for d in deps:
headers += d.args.get("cheaders", [d])
objs = []
for s in flatten(srcs):
@@ -103,7 +105,7 @@ def findsources(name, srcs, deps, cflags, toolchain, filerule, cwd):
filerule(
name=join(name, f.removeprefix("$(OBJ)/")),
srcs=[f],
deps=deps,
deps=headers,
cflags=cflags,
toolchain=toolchain,
cwd=cwd,
@@ -129,8 +131,16 @@ def cheaders(
caller_cflags=[],
deps: Targets = None,
):
hdr_deps = []
for d in deps:
hdr_deps += d.args.get("cheaders", [d])
hdr_caller_cflags = collectattrs(
targets=hdr_deps, name="caller_cflags", initial=caller_cflags
)
cs = []
ins = list(hdrs.values())
ins = hdrs.values()
outs = []
i = 0
for dest, src in hdrs.items():
@@ -139,7 +149,7 @@ def cheaders(
len(s) == 1
), "the target of a header must return exactly one file"
cs += ["cp {ins[" + str(i) + "]} {outs[" + str(i) + "]}"]
cs += ["$(CP) {ins[" + str(i) + "]} {outs[" + str(i) + "]}"]
outs += ["=" + dest]
i = i + 1
@@ -148,9 +158,9 @@ def cheaders(
ins=ins,
outs=outs,
commands=cs,
deps=deps,
deps=hdr_deps,
label="CHEADERS",
args={"caller_cflags": caller_cflags + ["-I" + self.dir]},
args={"caller_cflags": hdr_caller_cflags + ["-I" + self.dir]},
)
@@ -174,7 +184,7 @@ def libraryimpl(
cheaders(
replaces=self,
hdrs=hdrs,
deps=targetswithtraitsof(deps, "cheaders"),
deps=deps,
caller_cflags=caller_cflags,
)
return
@@ -182,7 +192,7 @@ def libraryimpl(
hr = cheaders(
name=self.localname + "_hdrs",
hdrs=hdrs,
deps=targetswithtraitsof(deps, "cheaders"),
deps=deps,
caller_cflags=caller_cflags,
)
hr.materialise()
@@ -191,7 +201,7 @@ def libraryimpl(
objs = findsources(
self.localname,
srcs,
targetswithtraitsof(deps, "cheaders"),
deps,
cflags,
toolchain,
kind,
@@ -205,13 +215,15 @@ def libraryimpl(
label=label,
commands=commands,
args={
"caller_cflags": collectattrs(
targets=deps + ([hr] if hr else []), name="caller_cflags"
),
"caller_ldflags": collectattrs(
targets=deps, name="caller_ldflags", initial=caller_ldflags
),
},
}
| (
{"cheaders": [hr], "caller_cflags": hr.args["caller_cflags"]}
if hr
else {}
),
traits={"cheaders"},
)
self.outs = self.outs + (hr.outs if hr else [])