Separated C++ wrappers into separate files in a backward-compatible way. (#265)
This makes both the C (.h) and C++ (.hpp) files read nicer
and keeps the core of upb C-only.
Existing users of the C++ wrappers will have to add manual
#includes of the .hpp files.
diff --git a/tools/amalgamate.py b/tools/amalgamate.py
index bc083b3..dff1bc3 100755
--- a/tools/amalgamate.py
+++ b/tools/amalgamate.py
@@ -45,15 +45,25 @@
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(include)
- else:
+ if not self._process_include(line, outfile):
outfile.write(line)
+ def _process_include(self, line, outfile):
+ include = parse_include(line)
+ if not include:
+ return False
+ if not (include.startswith("upb") or include.startswith("google")):
+ return False
+ if include.endswith("hpp"):
+ # Skip, we don't support the amalgamation from C++.
+ return True
+ else:
+ # Include this upb header inline.
+ if include not in self.included:
+ self.included.add(include)
+ self._add_header(include)
+ return True
+
def _add_header(self, filename):
self._process_file(filename, self.output_h)