From 985145ca16e4926420416e3a5f41f3e6e736c590 Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Wed, 24 Apr 2019 17:36:17 +0000 Subject: Fixed amalgamation and CMake build. --- tools/amalgamate.py | 43 +++++++++++++++++++++++++++++++++---------- tools/make_cmakelists.py | 15 ++++++++++++++- 2 files changed, 47 insertions(+), 11 deletions(-) (limited to 'tools') diff --git a/tools/amalgamate.py b/tools/amalgamate.py index ed5f665..16b34aa 100755 --- a/tools/amalgamate.py +++ b/tools/amalgamate.py @@ -2,6 +2,7 @@ import sys import re +import os INCLUDE_RE = re.compile('^#include "([^"]*)"$') @@ -10,8 +11,8 @@ def parse_include(line): return match.groups()[0] if match else None class Amalgamator: - def __init__(self, include_path, output_path): - self.include_path = include_path + def __init__(self, output_path): + self.include_paths = ["."] self.included = set(["upb/port_def.inc", "upb/port_undef.inc"]) self.output_h = open(output_path + "upb.h", "w") self.output_c = open(output_path + "upb.c", "w") @@ -24,18 +25,32 @@ class Amalgamator: self.output_h.write('#include ') self.output_h.write(open("upb/port_def.inc").read()) + def add_include_path(self, path): + self.include_paths.append(path) + def finish(self): self.output_c.write(open("upb/port_undef.inc").read()) self.output_h.write(open("upb/port_undef.inc").read()) def _process_file(self, infile_name, outfile): - for line in open(infile_name): + file = None + for path in self.include_paths: + try: + full_path = os.path.join(path, infile_name) + file = open(full_path) + break + except IOError: + pass + if not file: + raise RuntimeError("Couldn't open file " + infile_name) + + for line in file: include = parse_include(line) if include is not None and (include.startswith("upb") or include.startswith("google")): if include not in self.included: self.included.add(include) - self._add_header(self.include_path + include) + self._add_header(include) else: outfile.write(line) @@ -47,12 +62,20 @@ class Amalgamator: # ---- main ---- -include_path = sys.argv[1] -output_path = sys.argv[2] -amalgamator = Amalgamator(include_path, output_path) +output_path = sys.argv[1] +amalgamator = Amalgamator(output_path) +files = [] + +for arg in sys.argv[3:]: + arg = arg.strip() + if arg.startswith("-I"): + amalgamator.add_include_path(arg[2:]) + elif arg.endswith(".h") or arg.endswith(".inc"): + pass + else: + files.append(arg) -for filename in sys.argv[3:]: - if filename.endswith(".h") or filename.endswith(".inc"): - amalgamator.add_src(filename.strip()) +for filename in files: + amalgamator.add_src(filename) amalgamator.finish() diff --git a/tools/make_cmakelists.py b/tools/make_cmakelists.py index 9a7eaf5..1fa1615 100755 --- a/tools/make_cmakelists.py +++ b/tools/make_cmakelists.py @@ -11,6 +11,7 @@ from __future__ import print_function import sys import textwrap +import os def StripColons(deps): return map(lambda x: x[1:], deps) @@ -38,12 +39,20 @@ class BuildFileFunctions(object): if kwargs["name"] == "amalgamation" or kwargs["name"] == "upbc_generator": return files = kwargs.get("srcs", []) + kwargs.get("hdrs", []) + found_files = [] + for file in files: + if os.path.isfile(file): + found_files.append(file) + elif os.path.isfile("generated/" + file): + found_files.append("generated/" + file) + else: + print("Warning: no such file: " + file) if filter(IsSourceFile, files): # Has sources, make this a normal library. self.converter.toplevel += "add_library(%s\n %s)\n" % ( kwargs["name"], - "\n ".join(files) + "\n ".join(found_files) ) self._add_deps(kwargs) else: @@ -143,6 +152,9 @@ class BuildFileFunctions(object): def licenses(self, *args): pass + def filegroup(self, **kwargs): + pass + def map_dep(self, arg): return arg @@ -227,6 +239,7 @@ class Converter(object): endif() include_directories(.) + include_directories(generated) include_directories(${CMAKE_CURRENT_BINARY_DIR}) if(APPLE) -- cgit v1.2.3