-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Meta: Pass compiler's builtin includes to jakt too #25573
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 |
---|---|---|
@@ -0,0 +1,109 @@ | ||
import argparse | ||
import os | ||
import subprocess | ||
import sys | ||
|
||
|
||
def get_includes_from_version_output(compiler, target_args): | ||
try: | ||
output = subprocess.check_output( | ||
[compiler, *target_args, "-xc++", "/dev/null", "-E", "-Wp,-v"], stderr=subprocess.STDOUT | ||
) | ||
except subprocess.CalledProcessError as e: | ||
print("Error getting includes from compiler version output: " + e.output) | ||
sys.exit(1) | ||
|
||
includes = [] | ||
in_search_list = False | ||
for line in output.splitlines(): | ||
line = line.strip() | ||
if not in_search_list: | ||
if line == "#include <...> search starts here:": | ||
in_search_list = True | ||
continue | ||
continue | ||
if line == "End of search list.": | ||
break | ||
includes.append(line) | ||
|
||
return includes | ||
|
||
|
||
def get_includes_from_preprocessor_output(compiler, test_file, target_args): | ||
try: | ||
output = subprocess.check_output( | ||
[compiler, *target_args, "-E", test_file], stderr=subprocess.STDOUT | ||
) | ||
except subprocess.CalledProcessError as e: | ||
print(b"Error getting includes from preprocessor output: " + e.output) | ||
sys.exit(1) | ||
|
||
includes = [] | ||
for line in output.splitlines(): | ||
if not line.startswith(b"# 1 "): | ||
continue | ||
include = line.removeprefix(b"# 1 ") | ||
include = include[1:-1] # Remove quotes | ||
includes.append(include) | ||
|
||
return includes | ||
|
||
|
||
def convert_includes_to_dirs(includes): | ||
dirs = [] | ||
for include in includes: | ||
if not os.path.isabs(include): | ||
continue | ||
include_dir = os.path.dirname(include) | ||
if include_dir.endswith(b"/bits"): | ||
include_dir = os.path.dirname(include_dir) | ||
|
||
while not os.path.isdir(include_dir): | ||
include_dir = os.path.dirname(include_dir) | ||
|
||
if os.path.basename(include_dir).startswith(b"_"): | ||
continue | ||
|
||
dirs.append(include_dir) | ||
|
||
return dirs | ||
|
||
|
||
def main(): | ||
parser = argparse.ArgumentParser( | ||
description="Extract System Includes from C++ Compiler" | ||
) | ||
|
||
parser.add_argument("--compiler", required=True, help="Specify C++ compiler to extract includes from") | ||
parser.add_argument("--target", help="Specify target platform for compiler") | ||
|
||
parser.add_argument( | ||
"--test-file", required=True, help="Specify the path to the test file containing '#include' directives" | ||
) | ||
|
||
args = parser.parse_args() | ||
compiler = args.compiler | ||
test_file = args.test_file | ||
target = args.target | ||
|
||
target_args = [] | ||
if target is not None and target != "": | ||
target_args = [f"--target={target}"] | ||
|
||
includes = get_includes_from_version_output(compiler, target_args) | ||
system_includes = get_includes_from_preprocessor_output(compiler, test_file, target_args) | ||
system_includes = convert_includes_to_dirs(system_includes) | ||
|
||
out = [] | ||
seen = set() | ||
for p in system_includes + includes: | ||
if p in seen: | ||
continue | ||
seen.add(p) | ||
out.append(p.decode("utf-8")) | ||
|
||
print(";".join(out), end="") | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.