-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[CMake] Merge Clang's features file with Swift's #41547
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,16 +6,20 @@ add_dependencies(swiftOption | |
target_link_libraries(swiftOption PRIVATE | ||
swiftBasic) | ||
|
||
set(features_file_src "${CMAKE_CURRENT_SOURCE_DIR}/features.json") | ||
set(features_merger "${SWIFT_SOURCE_DIR}/utils/merge-features.py") | ||
set(features_file_swift_src "${CMAKE_CURRENT_SOURCE_DIR}/features.json") | ||
set(features_file_clang_src "${LLVM_MAIN_SRC_DIR}/../clang/tools/driver/features.json") | ||
set(features_file_dest "${CMAKE_BINARY_DIR}/share/swift/features.json") | ||
|
||
add_custom_command( | ||
OUTPUT | ||
${features_file_dest} | ||
COMMAND | ||
${CMAKE_COMMAND} -E copy ${features_file_src} ${features_file_dest} | ||
${features_merger} -f ${features_file_swift_src} -p \"\" -f ${features_file_clang_src} -p clang- ${features_file_dest} | ||
DEPENDS | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You should also add a dependency on the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh nice catch, thanks! |
||
${features_file_src} | ||
${features_merger} | ||
${features_file_swift_src} | ||
${features_file_clang_src} | ||
) | ||
|
||
add_custom_target(swift-features-file DEPENDS ${features_file_dest}) | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import argparse | ||
import json | ||
import sys | ||
|
||
|
||
def error(message): | ||
sys.stderr.write(message) | ||
sys.stderr.write("\n") | ||
sys.exit(1) | ||
|
||
|
||
def invalid_file(features_file, message): | ||
error(f"Invalid features file '{features_file}': {message}") | ||
|
||
|
||
def parse_args(): | ||
parser = argparse.ArgumentParser( | ||
formatter_class=argparse.RawDescriptionHelpFormatter, | ||
description=""" | ||
Merges the given feature files together into DEST (or stdout if DEST | ||
is not given). Each file FILE must be given a corresponding PREFIX to | ||
prefix the name of each entry in its features list, though these could | ||
be empty if no prefix is required. | ||
|
||
Note that the files and prefixes are treated as an ordered list, ie. | ||
the first FILE corresponds to the first PREFIX. | ||
""") | ||
|
||
parser.add_argument( | ||
"--file", "-f", action="append", dest="files", | ||
help="path of a file to merge" | ||
) | ||
parser.add_argument( | ||
"--prefix", "-p", action="append", dest="prefixes", | ||
help="prefix to prepend to the name of each feature" | ||
) | ||
parser.add_argument( | ||
"dest", nargs="?", | ||
help="path to store the merged file" | ||
) | ||
|
||
return parser.parse_known_args() | ||
|
||
|
||
def read_features(from_file, add_prefix): | ||
with open(from_file, "r") as f: | ||
features_dict = json.load(f) | ||
|
||
if "features" not in features_dict: | ||
invalid_file(from_file, "missing 'features' key") | ||
|
||
features = [] | ||
for feature in features_dict["features"]: | ||
if "name" not in feature: | ||
invalid_file(from_file, "missing name in features list") | ||
|
||
features.append({"name": add_prefix + feature["name"]}) | ||
return features | ||
|
||
|
||
def main(): | ||
(args, _) = parse_args() | ||
|
||
if not args.files: | ||
error("No files to merge were provided") | ||
|
||
if len(args.files) != len(args.prefixes): | ||
error("Must supply the same number of files and prefixes") | ||
|
||
features = [] | ||
for i, (f, prefix) in enumerate(zip(args.files, args.prefixes)): | ||
features.extend(read_features(f, prefix)) | ||
|
||
data = { | ||
"features": features | ||
} | ||
|
||
if args.dest: | ||
with open(args.dest, "w") as f: | ||
json.dump(data, f, indent=2) | ||
else: | ||
sys.stdout.write(json.dumps(data, indent=2)) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This feels very wrong to me, if there's a better way to do this please let me know 🙇