From 33feda72089a8057edfcda564fd731be61b9f8be Mon Sep 17 00:00:00 2001 From: David Given Date: Wed, 23 Oct 2024 14:34:38 +0200 Subject: [PATCH 1/3] Update ab. --- build/ab.mk | 6 +++++- build/ab.py | 10 +++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/build/ab.mk b/build/ab.mk index 2122439e..b272585a 100644 --- a/build/ab.mk +++ b/build/ab.mk @@ -1,4 +1,8 @@ -ifeq ($(findstring 4.,$(MAKE_VERSION)),) +MAKENOT4 := $(if $(findstring 3.9999, $(lastword $(sort 3.9999 $(MAKE_VERSION)))),yes,no) +MAKE4.3 := $(if $(findstring 4.3, $(firstword $(sort 4.3 $(MAKE_VERSION)))),yes,no) +MAKE4.1 := $(if $(findstring no_no,$(MAKENOT4)_$(MAKE4.3)),yes,no) + +ifeq ($(MAKENOT3),yes) $(error You need GNU Make 4.x for this (if you're on OSX, use gmake).) endif diff --git a/build/ab.py b/build/ab.py index 9afd62b5..5ad3ca8f 100644 --- a/build/ab.py +++ b/build/ab.py @@ -420,7 +420,15 @@ def emit_rule(name, ins, outs, cmds=[], label=None): emit(".PHONY:", name, into=lines) if outs: emit(name, ":", *fouts, into=lines) - emit(*fouts, "&:" if len(fouts) > 1 else ":", *fins, "\x01", into=lines) + if len(fouts) == 1: + emit(*fouts, ":", *fins, "\x01", into=lines) + else: + emit("ifeq ($(MAKE4.3),yes)", into=lines) + emit(*fouts, "&:", *fins, "\x01", into=lines) + emit("else", into=lines) + emit(*(fouts[1:]), ":", fouts[0], into=lines) + emit(fouts[0], ":", *fins, "\x01", into=lines) + emit("endif", into=lines) if label: emit("\t$(hide)", "$(ECHO) $(PROGRESSINFO)", label, into=lines) From 6ff68f3f06a6d08f05016c903dc62c3ddd54c155 Mon Sep 17 00:00:00 2001 From: David Given Date: Thu, 7 Nov 2024 21:06:56 +0100 Subject: [PATCH 2/3] Update ab. --- build/ab.mk | 6 ++- build/ab.py | 13 ++++- build/c.py | 143 +++++++++++++++------------------------------------ build/pkg.py | 6 --- 4 files changed, 58 insertions(+), 110 deletions(-) diff --git a/build/ab.mk b/build/ab.mk index 2122439e..b272585a 100644 --- a/build/ab.mk +++ b/build/ab.mk @@ -1,4 +1,8 @@ -ifeq ($(findstring 4.,$(MAKE_VERSION)),) +MAKENOT4 := $(if $(findstring 3.9999, $(lastword $(sort 3.9999 $(MAKE_VERSION)))),yes,no) +MAKE4.3 := $(if $(findstring 4.3, $(firstword $(sort 4.3 $(MAKE_VERSION)))),yes,no) +MAKE4.1 := $(if $(findstring no_no,$(MAKENOT4)_$(MAKE4.3)),yes,no) + +ifeq ($(MAKENOT3),yes) $(error You need GNU Make 4.x for this (if you're on OSX, use gmake).) endif diff --git a/build/ab.py b/build/ab.py index 9afd62b5..5ae17c24 100644 --- a/build/ab.py +++ b/build/ab.py @@ -32,7 +32,8 @@ class PathFinderImpl(PathFinder): def find_spec(self, fullname, path, target=None): - if not path: + # The second test here is needed for Python 3.9. + if not path or not path[0]: path = ["."] if len(path) != 1: return None @@ -420,7 +421,15 @@ def emit_rule(name, ins, outs, cmds=[], label=None): emit(".PHONY:", name, into=lines) if outs: emit(name, ":", *fouts, into=lines) - emit(*fouts, "&:" if len(fouts) > 1 else ":", *fins, "\x01", into=lines) + if len(fouts) == 1: + emit(*fouts, ":", *fins, "\x01", into=lines) + else: + emit("ifeq ($(MAKE4.3),yes)", into=lines) + emit(*fouts, "&:", *fins, "\x01", into=lines) + emit("else", into=lines) + emit(*(fouts[1:]), ":", fouts[0], into=lines) + emit(fouts[0], ":", *fins, "\x01", into=lines) + emit("endif", into=lines) if label: emit("\t$(hide)", "$(ECHO) $(PROGRESSINFO)", label, into=lines) diff --git a/build/c.py b/build/c.py index 85a5cef9..0045e634 100644 --- a/build/c.py +++ b/build/c.py @@ -14,51 +14,27 @@ emit( """ ifeq ($(OSX),no) -HOSTSTARTGROUP ?= -Wl,--start-group -HOSTENDGROUP ?= -Wl,--end-group +STARTGROUP ?= -Wl,--start-group +ENDGROUP ?= -Wl,--end-group endif -STARTGROUP ?= $(HOSTSTARTGROUP) -ENDGROUP ?= $(HOSTENDGROUP) """ ) - -class Toolchain: - label = "" - cfile = ["$(CC) -c -o {outs[0]} {ins[0]} $(CFLAGS) {cflags}"] - cxxfile = ["$(CXX) -c -o {outs[0]} {ins[0]} $(CFLAGS) {cflags}"] - clibrary = ["rm -f {outs[0]} && $(AR) cqs {outs[0]} {ins}"] - cxxlibrary = ["rm -f {outs[0]} && $(AR) cqs {outs[0]} {ins}"] - cprogram = [ - "$(CC) -o {outs[0]} $(STARTGROUP) {ins} {ldflags} $(LDFLAGS) $(ENDGROUP)" - ] - cxxprogram = [ - "$(CXX) -o {outs[0]} $(STARTGROUP) {ins} {ldflags} $(LDFLAGS) $(ENDGROUP)" - ] - - -class HostToolchain: - label = "HOST " - cfile = ["$(HOSTCC) -c -o {outs[0]} {ins[0]} $(HOSTCFLAGS) {cflags}"] - cxxfile = ["$(HOSTCXX) -c -o {outs[0]} {ins[0]} $(HOSTCFLAGS) {cflags}"] - clibrary = ["rm -f {outs[0]} && $(HOSTAR) cqs {outs[0]} {ins}"] - cxxlibrary = ["rm -f {outs[0]} && $(HOSTAR) cqs {outs[0]} {ins}"] - cprogram = [ - "$(HOSTCC) -o {outs[0]} $(HOSTSTARTGROUP) {ins} {ldflags} $(HOSTLDFLAGS) $(HOSTENDGROUP)" - ] - cxxprogram = [ - "$(HOSTCXX) -o {outs[0]} $(HOSTSTARTGROUP) {ins} {ldflags} $(HOSTLDFLAGS) $(HOSTENDGROUP)" - ] - +def _combine(list1, list2): + r = list(list1) + for i in list2: + if i not in r: + r.append(i) + return r def _indirect(deps, name): - r = set() + r = [] for d in deps: - r.update(d.args.get(name, {d})) + r = _combine(r, d.args.get(name, [d])) return r -def cfileimpl(self, name, srcs, deps, suffix, commands, label, kind, cflags): +def cfileimpl(self, name, srcs, deps, suffix, commands, label, cflags): outleaf = "=" + stripext(basename(filenameof(srcs[0]))) + suffix hdr_deps = _indirect(deps, "cheader_deps") @@ -85,15 +61,10 @@ def cfile( deps: Targets = None, cflags=[], suffix=".o", - toolchain=Toolchain, - commands=None, - label=None, + commands=["$(CC) -c -o {outs[0]} {ins[0]} $(CFLAGS) {cflags}"], + label="CC", ): - if not label: - label = toolchain.label + "CC" - if not commands: - commands = toolchain.cfile - cfileimpl(self, name, srcs, deps, suffix, commands, label, "cfile", cflags) + cfileimpl(self, name, srcs, deps, suffix, commands, label, cflags) @Rule @@ -104,20 +75,13 @@ def cxxfile( deps: Targets = None, cflags=[], suffix=".o", - toolchain=Toolchain, - commands=None, - label=None, + commands=["$(CXX) -c -o {outs[0]} {ins[0]} $(CFLAGS) {cflags}"], + label="CXX", ): - if not label: - label = toolchain.label + "CXX" - if not commands: - commands = toolchain.cxxfile - cfileimpl( - self, name, srcs, deps, suffix, commands, label, "cxxfile", cflags - ) + cfileimpl(self, name, srcs, deps, suffix, commands, label, cflags) -def findsources(name, srcs, deps, cflags, toolchain, filerule, cwd): +def findsources(name, srcs, deps, cflags, filerule, cwd): for f in filenamesof(srcs): if f.endswith(".h") or f.endswith(".hh"): cflags = cflags + [f"-I{dirname(f)}"] @@ -130,7 +94,6 @@ def findsources(name, srcs, deps, cflags, toolchain, filerule, cwd): srcs=[f], deps=deps, cflags=sorted(set(cflags)), - toolchain=toolchain, cwd=cwd, ) for f in filenamesof([s]) @@ -156,13 +119,12 @@ def libraryimpl( caller_ldflags, cflags, ldflags, - toolchain, commands, label, - kind, + filerule, ): - hdr_deps = _indirect(deps, "cheader_deps") | {self} - lib_deps = _indirect(deps, "clibrary_deps") | {self} + hdr_deps = _combine(_indirect(deps, "cheader_deps"), [self]) + lib_deps = _combine(_indirect(deps, "clibrary_deps"), [self]) hr = None hf = [] @@ -198,8 +160,7 @@ def libraryimpl( srcs, deps + ([hr] if hr else []), cflags + hf, - toolchain, - kind, + filerule, self.cwd, ) @@ -233,15 +194,10 @@ def clibrary( caller_ldflags=[], cflags=[], ldflags=[], - toolchain=Toolchain, - commands=None, - label=None, + commands=["rm -f {outs[0]} && $(AR) cqs {outs[0]} {ins}"], + label="LIB", cfilerule=cfile, ): - if not label: - label = toolchain.label + "LIB" - if not commands: - commands = toolchain.clibrary libraryimpl( self, name, @@ -252,7 +208,6 @@ def clibrary( caller_ldflags, cflags, ldflags, - toolchain, commands, label, cfilerule, @@ -270,15 +225,10 @@ def cxxlibrary( caller_ldflags=[], cflags=[], ldflags=[], - toolchain=Toolchain, - commands=None, - label=None, + commands=["rm -f {outs[0]} && $(AR) cqs {outs[0]} {ins}"], + label="CXXLIB", cxxfilerule=cxxfile, ): - if not label: - label = toolchain.label + "LIB" - if not commands: - commands = toolchain.cxxlibrary libraryimpl( self, name, @@ -289,7 +239,6 @@ def cxxlibrary( caller_ldflags, cflags, ldflags, - toolchain, commands, label, cxxfilerule, @@ -303,20 +252,16 @@ def programimpl( deps, cflags, ldflags, - toolchain, commands, label, filerule, - kind, ): - cfiles = findsources( - self.localname, srcs, deps, cflags, toolchain, filerule, self.cwd - ) + cfiles = findsources(self.localname, srcs, deps, cflags, filerule, self.cwd) - lib_deps = set() + lib_deps = [] for d in deps: - lib_deps.update(d.args.get("clibrary_deps", {d})) - libs = sorted(filenamesmatchingof(lib_deps, "*.a")) + lib_deps = _combine(lib_deps, d.args.get("clibrary_deps", {d})) + libs = filenamesmatchingof(lib_deps, "*.a") ldflags = collectattrs( targets=lib_deps, name="caller_ldflags", initial=ldflags ) @@ -325,8 +270,8 @@ def programimpl( replaces=self, ins=cfiles + libs, outs=[f"={self.localname}$(EXT)"], - deps=sorted(_indirect(lib_deps, "clibrary_files")), - label=toolchain.label + label, + deps=_indirect(lib_deps, "clibrary_files"), + label=label, commands=commands, args={ "ldflags": collectattrs( @@ -344,12 +289,12 @@ def cprogram( deps: Targets = None, cflags=[], ldflags=[], - toolchain=Toolchain, - commands=None, + commands=[ + "$(CC) -o {outs[0]} $(STARTGROUP) {ins} {ldflags} $(LDFLAGS) $(ENDGROUP)" + ], label="CLINK", + cfilerule=cfile, ): - if not commands: - commands = toolchain.cprogram programimpl( self, name, @@ -357,11 +302,9 @@ def cprogram( deps, cflags, ldflags, - toolchain, commands, label, - cfile, - "cprogram", + cfilerule, ) @@ -373,12 +316,12 @@ def cxxprogram( deps: Targets = None, cflags=[], ldflags=[], - toolchain=Toolchain, - commands=None, + commands=[ + "$(CXX) -o {outs[0]} $(STARTGROUP) {ins} {ldflags} $(LDFLAGS) $(ENDGROUP)" + ], label="CXXLINK", + cxxfilerule=cxxfile, ): - if not commands: - commands = toolchain.cxxprogram programimpl( self, name, @@ -386,9 +329,7 @@ def cxxprogram( deps, cflags, ldflags, - toolchain, commands, label, - cxxfile, - "cxxprogram", + cxxfilerule, ) diff --git a/build/pkg.py b/build/pkg.py index a9c5118b..c8deb1fb 100644 --- a/build/pkg.py +++ b/build/pkg.py @@ -33,7 +33,6 @@ def get_property(self, name, flag): TargetPkgConfig = _PkgConfig(os.getenv("PKG_CONFIG")) -HostPkgConfig = _PkgConfig(os.getenv("HOST_PKG_CONFIG")) def _package(self, name, package, fallback, pkgconfig): @@ -70,8 +69,3 @@ def _package(self, name, package, fallback, pkgconfig): @Rule def package(self, name, package=None, fallback: Target = None): _package(self, name, package, fallback, TargetPkgConfig) - - -@Rule -def hostpackage(self, name, package=None, fallback: Target = None): - _package(self, name, package, fallback, HostPkgConfig) From 49a0a6fdb364efaf32d1ed12014153a2ab8ad2f1 Mon Sep 17 00:00:00 2001 From: David Given Date: Thu, 7 Nov 2024 21:16:27 +0100 Subject: [PATCH 3/3] Fix things caused by the ab upgrade. --- build.py | 7 +------ dep/fmt/build.py | 2 +- scripts/build.py | 2 +- 3 files changed, 3 insertions(+), 8 deletions(-) diff --git a/build.py b/build.py index 2c10acfd..c5a0b41f 100644 --- a/build.py +++ b/build.py @@ -1,7 +1,7 @@ from build.ab import export from build.c import clibrary, cxxlibrary from build.protobuf import proto, protocc -from build.pkg import package, hostpackage +from build.pkg import package from build.utils import test from glob import glob import config @@ -12,11 +12,6 @@ package(name="fmt_lib", package="fmt", fallback="dep/fmt") package(name="sqlite3_lib", package="sqlite3") -hostpackage(name="protobuf_host_lib", package="protobuf") -hostpackage(name="z_host_lib", package="zlib") -hostpackage(name="fmt_host_lib", package="fmt", fallback="dep/fmt") -hostpackage(name="sqlite3_host_lib", package="sqlite3") - clibrary(name="protocol", hdrs={"protocol.h": "./protocol.h"}) corpustests = [] diff --git a/dep/fmt/build.py b/dep/fmt/build.py index c968265f..7c589f56 100644 --- a/dep/fmt/build.py +++ b/dep/fmt/build.py @@ -1,4 +1,4 @@ -from build.c import cxxlibrary, HostToolchain +from build.c import cxxlibrary cxxlibrary( name="fmt", diff --git a/scripts/build.py b/scripts/build.py index fd894142..70a10d7e 100644 --- a/scripts/build.py +++ b/scripts/build.py @@ -1,5 +1,5 @@ from build.ab import Rule, simplerule, Targets, TargetsMap -from build.c import cxxprogram, HostToolchain +from build.c import cxxprogram encoders = {}