mirror of
				https://github.com/davidgiven/fluxengine.git
				synced 2025-10-24 11:11:02 -07:00 
			
		
		
		
	Refactor a lot of the proto stuff.
This commit is contained in:
		| @@ -1,7 +1,7 @@ | ||||
| from build.ab import Rule, Targets, emit, simplerule, filenamesof | ||||
| from build.utils import filenamesmatchingof, collectattrs | ||||
| from types import SimpleNamespace | ||||
| from os.path import join | ||||
| from os.path import join, abspath, dirname | ||||
| import build.pkg  # to get the protobuf package check | ||||
|  | ||||
| emit( | ||||
| @@ -14,18 +14,54 @@ endif | ||||
| ) | ||||
|  | ||||
|  | ||||
| def _getprotodeps(deps): | ||||
|     r = set() | ||||
|     for d in deps: | ||||
|         r.update(d.args.get("protodeps", {d})) | ||||
|     return sorted(r) | ||||
|  | ||||
|  | ||||
| @Rule | ||||
| def proto(self, name, srcs: Targets = [], deps: Targets = []): | ||||
|     protodeps = _getprotodeps(deps) | ||||
|     descriptorlist = ":".join( | ||||
|         [abspath(f) for f in filenamesmatchingof(protodeps, "*.descriptor")] | ||||
|     ) | ||||
|  | ||||
|     dirs = sorted({"{dir}/" + dirname(f) for f in filenamesof(srcs)}) | ||||
|     simplerule( | ||||
|         replaces=self, | ||||
|         ins=srcs, | ||||
|         outs=[f"={name}.descriptor"], | ||||
|         deps=deps, | ||||
|         commands=[ | ||||
|             "$(PROTOC) --include_source_info --descriptor_set_out={outs[0]} {ins}" | ||||
|         ], | ||||
|         outs=[f"={self.localname}.descriptor"], | ||||
|         deps=protodeps, | ||||
|         commands=( | ||||
|             ["mkdir -p " + (" ".join(dirs))] | ||||
|             + [f"$(CP) {f} {{dir}}/{f}" for f in filenamesof(srcs)] | ||||
|             + [ | ||||
|                 "cd {dir} && " | ||||
|                 + ( | ||||
|                     " ".join( | ||||
|                         [ | ||||
|                             "$(PROTOC)", | ||||
|                             "--proto_path=.", | ||||
|                             "--include_source_info", | ||||
|                             f"--descriptor_set_out={self.localname}.descriptor", | ||||
|                         ] | ||||
|                         + ( | ||||
|                             [f"--descriptor_set_in={descriptorlist}"] | ||||
|                             if descriptorlist | ||||
|                             else [] | ||||
|                         ) | ||||
|                         + ["{ins}"] | ||||
|                     ) | ||||
|                 ) | ||||
|             ] | ||||
|         ), | ||||
|         label="PROTO", | ||||
|         args={"protosrcs": filenamesof(srcs)}, | ||||
|         args={ | ||||
|             "protosrcs": filenamesof(srcs), | ||||
|             "protodeps": set(protodeps) | {self}, | ||||
|         }, | ||||
|     ) | ||||
|  | ||||
|  | ||||
| @@ -40,16 +76,33 @@ def protocc(self, name, srcs: Targets = [], deps: Targets = []): | ||||
|         cc = f.replace(".proto", ".pb.cc") | ||||
|         h = f.replace(".proto", ".pb.h") | ||||
|         protos += [f] | ||||
|         srcs += [f] | ||||
|         outs += ["=" + cc, "=" + h] | ||||
|  | ||||
|     protodeps = _getprotodeps(deps + srcs) | ||||
|     descriptorlist = ":".join( | ||||
|         [abspath(f) for f in filenamesmatchingof(protodeps, "*.descriptor")] | ||||
|     ) | ||||
|  | ||||
|     r = simplerule( | ||||
|         name=f"{self.localname}_srcs", | ||||
|         cwd=self.cwd, | ||||
|         ins=protos, | ||||
|         ins=srcs, | ||||
|         outs=outs, | ||||
|         deps=deps, | ||||
|         commands=["$(PROTOC) --cpp_out={dir} {ins}"], | ||||
|         deps=protodeps, | ||||
|         commands=[ | ||||
|             "cd {dir} && " | ||||
|             + ( | ||||
|                 " ".join( | ||||
|                     [ | ||||
|                         "$(PROTOC)", | ||||
|                         "--proto_path=.", | ||||
|                         "--cpp_out=.", | ||||
|                         f"--descriptor_set_in={descriptorlist}", | ||||
|                     ] | ||||
|                     + protos | ||||
|                 ) | ||||
|             ) | ||||
|         ], | ||||
|         label="PROTOCC", | ||||
|     ) | ||||
|  | ||||
| @@ -76,6 +129,10 @@ def protojava(self, name, srcs: Targets = [], deps: Targets = []): | ||||
|         protos += [f] | ||||
|         srcs += [f] | ||||
|  | ||||
|     descriptorlist = ":".join( | ||||
|         [abspath(f) for f in filenamesmatchingof(srcs + deps, "*.descriptor")] | ||||
|     ) | ||||
|  | ||||
|     r = simplerule( | ||||
|         name=f"{self.localname}_srcs", | ||||
|         cwd=self.cwd, | ||||
| @@ -84,7 +141,18 @@ def protojava(self, name, srcs: Targets = [], deps: Targets = []): | ||||
|         deps=deps, | ||||
|         commands=[ | ||||
|             "mkdir -p {dir}/srcs", | ||||
|             "$(PROTOC) --java_out={dir}/srcs {ins}", | ||||
|             "cd {dir} && " | ||||
|             + ( | ||||
|                 " ".join( | ||||
|                     [ | ||||
|                         "$(PROTOC)", | ||||
|                         "--proto_path=.", | ||||
|                         "--java_out=.", | ||||
|                         f"--descriptor_set_in={descriptorlist}", | ||||
|                     ] | ||||
|                     + protos | ||||
|                 ) | ||||
|             ), | ||||
|             "$(JAR) cf {outs[0]} -C {dir}/srcs .", | ||||
|         ], | ||||
|         traits={"srcjar"}, | ||||
|   | ||||
		Reference in New Issue
	
	Block a user