mirror of
https://github.com/nlohmann/json.git
synced 2026-09-30 11:40:30 +00:00
Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
33ef25099d |
@@ -8,3 +8,6 @@ The following changes have been made to the code with respect to <https://github
|
|||||||
- membership check
|
- membership check
|
||||||
- made function from `_is_within`
|
- made function from `_is_within`
|
||||||
- removed unused variable `actual_path`
|
- removed unused variable `actual_path`
|
||||||
|
- Added the optional config key `external`: include paths listed there are kept as
|
||||||
|
`#include` directives instead of being inlined (the first directive per path; the
|
||||||
|
repeated ones are commented out).
|
||||||
|
|||||||
@@ -57,6 +57,11 @@ Python v.2.7.0 or higher is required.
|
|||||||
amalgamation. Have a look at `test/source.c.json` and `test/include.h.json`
|
amalgamation. Have a look at `test/source.c.json` and `test/include.h.json`
|
||||||
to see two examples.
|
to see two examples.
|
||||||
|
|
||||||
|
The optional `external` list names include paths that are kept as `#include`
|
||||||
|
directives instead of being inlined, e.g. `["nlohmann/json.hpp"]` for a header
|
||||||
|
that includes another amalgamated header. Only the first directive for each
|
||||||
|
of these paths is kept; the repeated ones are commented out.
|
||||||
|
|
||||||
* The `-s, --source` option should specify the path to the source directory.
|
* The `-s, --source` option should specify the path to the source directory.
|
||||||
This is useful for supporting separate source and build directories.
|
This is useful for supporting separate source and build directories.
|
||||||
|
|
||||||
|
|||||||
@@ -62,6 +62,10 @@ class Amalgamation(object):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
def __init__(self, args):
|
def __init__(self, args):
|
||||||
|
# include paths that are kept as #include directives instead of
|
||||||
|
# being inlined (e.g. a header amalgamated on its own)
|
||||||
|
self.external = []
|
||||||
|
self.included_external = []
|
||||||
with open(args.config, 'r') as f:
|
with open(args.config, 'r') as f:
|
||||||
config = json.loads(f.read())
|
config = json.loads(f.read())
|
||||||
for key in config:
|
for key in config:
|
||||||
@@ -220,6 +224,9 @@ class TranslationUnit(object):
|
|||||||
while include_match:
|
while include_match:
|
||||||
if not _is_within(include_match, skippable_contexts):
|
if not _is_within(include_match, skippable_contexts):
|
||||||
include_path = include_match.group("path")
|
include_path = include_match.group("path")
|
||||||
|
if include_path in self.amalgamation.external:
|
||||||
|
includes.append((include_match, None))
|
||||||
|
else:
|
||||||
search_same_dir = include_match.group(1) == '"'
|
search_same_dir = include_match.group(1) == '"'
|
||||||
found_included_path = self.amalgamation.find_included_file(
|
found_included_path = self.amalgamation.find_included_file(
|
||||||
include_path, self.file_dir if search_same_dir else None)
|
include_path, self.file_dir if search_same_dir else None)
|
||||||
@@ -235,6 +242,17 @@ class TranslationUnit(object):
|
|||||||
for include in includes:
|
for include in includes:
|
||||||
include_match, found_included_path = include
|
include_match, found_included_path = include
|
||||||
tmp_content += self.content[prev_end:include_match.start()]
|
tmp_content += self.content[prev_end:include_match.start()]
|
||||||
|
if found_included_path is None:
|
||||||
|
# an external header: keep the first directive and comment
|
||||||
|
# out the repeated ones
|
||||||
|
include_path = include_match.group("path")
|
||||||
|
if include_path in self.amalgamation.included_external:
|
||||||
|
tmp_content += "// {0}".format(include_match.group(0))
|
||||||
|
else:
|
||||||
|
self.amalgamation.included_external.append(include_path)
|
||||||
|
tmp_content += include_match.group(0)
|
||||||
|
prev_end = include_match.end()
|
||||||
|
continue
|
||||||
tmp_content += "// {0}\n".format(include_match.group(0))
|
tmp_content += "// {0}\n".format(include_match.group(0))
|
||||||
if found_included_path not in self.amalgamation.included_files:
|
if found_included_path not in self.amalgamation.included_files:
|
||||||
t = TranslationUnit(found_included_path, self.amalgamation, False)
|
t = TranslationUnit(found_included_path, self.amalgamation, False)
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"project": "JSON for Modern C++",
|
||||||
|
"target": "single_include/nlohmann/json_view.hpp",
|
||||||
|
"sources": [
|
||||||
|
"include/nlohmann/json_view.hpp"
|
||||||
|
],
|
||||||
|
"include_paths": ["include"],
|
||||||
|
"external": ["nlohmann/json.hpp"]
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user