-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix unnecessary file creation bug (#1)
Cxbuild no longer makes __test_dummy_source__.o
- Loading branch information
1 parent
d24807b
commit a6b8373
Showing
1 changed file
with
43 additions
and
48 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
@@ -1,48 +1,43 @@ | ||
import os | ||
import re | ||
import cslib | ||
import subprocess | ||
import libcsbuild | ||
from .icompiler_tool import * | ||
|
||
|
||
class _GnuCompilerTool(ICompilerTool): | ||
def __init__(self, compiler_path: str, command: list): | ||
self.toolchain_name = "GnuCompilerTool" | ||
self.command = command | ||
self.compiler_path = compiler_path | ||
|
||
def get_include_option_name(self): | ||
return "-I" | ||
|
||
def split_command(self): | ||
sources = [command for command in self.command if cslib.is_source_file(command)] | ||
options = [command for command in self.command if command not in sources] | ||
return options, sources | ||
|
||
def get_system_include_list(self): | ||
"""find system includes from 'gcc -c -v __test_dummy_source__.c'""" | ||
dummy_src_path = libcsbuild.get_new_file_path("__test_dummy_source__.c") | ||
redirect_path = libcsbuild.get_new_file_path("__redirect__.stdout") | ||
with open(dummy_src_path, "w") as f: | ||
f.flush() | ||
pass | ||
|
||
with open(redirect_path, "w") as f: | ||
f.flush() | ||
subprocess.call([self.compiler_path, '-v', '-c', dummy_src_path], stdout=f, stderr=f) | ||
|
||
collect = False | ||
collected = [] | ||
with open(redirect_path, "r") as f: | ||
|
||
for line in f.readlines(): | ||
if line.strip().startswith("#include <...>"): | ||
collect = True | ||
elif line.strip().startswith("End of"): | ||
collect = False | ||
|
||
if collect: | ||
collected.append(line.strip()) | ||
# remove 0 index cuz, collected[0] == "#include <...>" | ||
return collected[1:] | ||
import os | ||
import re | ||
import cslib | ||
import subprocess | ||
import libcsbuild | ||
|
||
from .icompiler_tool import * | ||
|
||
|
||
class _GnuCompilerTool(ICompilerTool): | ||
def __init__(self, compiler_path: str, command: list): | ||
self.toolchain_name = "GnuCompilerTool" | ||
self.command = command | ||
self.compiler_path = compiler_path | ||
|
||
def get_include_option_name(self): | ||
return "-I" | ||
|
||
def split_command(self): | ||
sources = [command for command in self.command if cslib.is_source_file(command)] | ||
options = [command for command in self.command if command not in sources] | ||
return options, sources | ||
|
||
def get_system_include_list(self): | ||
compiler_kind = os.path.basename(self.compiler_path) | ||
if compiler_kind == "gcc": | ||
command = "gcc -E -Wp,-v -xc /dev/null" | ||
elif compiler_kind == "g++" or compiler_kind == "c++": | ||
command = "g++ -E -Wp,-v -xc++ /dev/null" | ||
else: | ||
# TODO: Make no such compiler exception, and Exit gracefully | ||
raise Exception("No Such Compiler Exception") | ||
output = subprocess.check_output(command, stderr=subprocess.STDOUT, shell=True).decode("utf-8") | ||
collect = False | ||
collected = [] | ||
for line in output.splitlines(): | ||
if line.strip().startswith("#include <...>"): | ||
collect = True | ||
elif line.strip().startswith("End of"): | ||
collect = False | ||
if collect: | ||
collected.append(line.strip()) | ||
return collected[1:] |