mirror of
https://github.com/davidgiven/fluxengine.git
synced 2025-10-31 11:17:01 -07:00
Update ab.
This commit is contained in:
@@ -1,17 +1,9 @@
|
||||
from os.path import join
|
||||
from build.ab import (
|
||||
Rule,
|
||||
Targets,
|
||||
emit,
|
||||
normalrule,
|
||||
filenamesof,
|
||||
filenamesmatchingof,
|
||||
bubbledattrsof,
|
||||
targetswithtraitsof,
|
||||
)
|
||||
from build.ab import Rule, Targets, emit, simplerule, filenamesof
|
||||
from build.utils import filenamesmatchingof, collectattrs
|
||||
from build.c import cxxlibrary
|
||||
from types import SimpleNamespace
|
||||
from build.pkg import package
|
||||
from os.path import join
|
||||
import build.pkg # to get the protobuf package check
|
||||
|
||||
emit(
|
||||
"""
|
||||
@@ -22,52 +14,51 @@ endif
|
||||
"""
|
||||
)
|
||||
|
||||
lib = package(name="protobuf_lib", package="protobuf")
|
||||
|
||||
@Rule
|
||||
def proto(self, name, srcs: Targets = None, deps: Targets = None):
|
||||
normalrule(
|
||||
def proto(self, name, srcs: Targets = [], deps: Targets = []):
|
||||
simplerule(
|
||||
replaces=self,
|
||||
ins=srcs,
|
||||
outs=[f"{name}.descriptor"],
|
||||
outs=[f"={name}.descriptor"],
|
||||
deps=deps,
|
||||
commands=[
|
||||
"$(PROTOC) --include_source_info --descriptor_set_out={outs[0]} {ins}"
|
||||
],
|
||||
label="PROTO",
|
||||
protosrcs=filenamesof(srcs),
|
||||
)
|
||||
self.attr.protosrcs = filenamesof(srcs)
|
||||
self.bubbleattr("protosrcs", deps)
|
||||
|
||||
|
||||
@Rule
|
||||
def protocc(self, name, srcs: Targets = None, deps: Targets = None):
|
||||
def protocc(self, name, srcs: Targets = [], deps: Targets = []):
|
||||
outs = []
|
||||
protos = []
|
||||
|
||||
for f in filenamesmatchingof(bubbledattrsof(srcs, "protosrcs"), "*.proto"):
|
||||
allsrcs = collectattrs(targets=srcs, name="protosrcs")
|
||||
assert allsrcs, "no sources provided"
|
||||
for f in filenamesmatchingof(allsrcs, "*.proto"):
|
||||
cc = f.replace(".proto", ".pb.cc")
|
||||
h = f.replace(".proto", ".pb.h")
|
||||
protos += [f]
|
||||
srcs += [f]
|
||||
outs += [cc, h]
|
||||
outs += ["=" + cc, "=" + h]
|
||||
|
||||
srcname = f"{name}_srcs"
|
||||
objdir = join("$(OBJ)", srcname)
|
||||
r = normalrule(
|
||||
name=srcname,
|
||||
r = simplerule(
|
||||
name=f"{self.localname}_srcs",
|
||||
cwd=self.cwd,
|
||||
ins=protos,
|
||||
outs=outs,
|
||||
deps=deps,
|
||||
commands=["$(PROTOC) --cpp_out={self.attr.objdir} {ins}"],
|
||||
commands=["$(PROTOC) --cpp_out={dir} {ins}"],
|
||||
label="PROTOCC",
|
||||
)
|
||||
|
||||
headers = {f: join(objdir, f) for f in outs if f.endswith(".pb.h")}
|
||||
headers = {f[1:]: join(r.dir, f[1:]) for f in outs if f.endswith(".pb.h")}
|
||||
|
||||
cxxlibrary(
|
||||
replaces=self,
|
||||
srcs=[r],
|
||||
deps=targetswithtraitsof(deps, "cheaders") + [lib],
|
||||
deps=deps,
|
||||
hdrs=headers,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user