Simplify wscript and remove -x c++-header

This commit is contained in:
Fangrui Song 2018-01-08 20:55:09 -08:00
parent 9d64a76fec
commit 53134b679c
2 changed files with 16 additions and 25 deletions

View File

@ -88,8 +88,6 @@ optional<std::string> SourceFileType(const std::string& path) {
return std::string("objective-c++"); return std::string("objective-c++");
else if (EndsWith(path, ".m")) else if (EndsWith(path, ".m"))
return std::string("objective-c"); return std::string("objective-c");
else if (path.find('.') == std::string::npos)
return std::string("c++-header");
return nullopt; return nullopt;
} }
@ -152,7 +150,7 @@ Project::Entry GetCompilationEntryFromCompileCommandEntry(
if (!AnyStartsWith(entry.args, "-std=")) { if (!AnyStartsWith(entry.args, "-std=")) {
if (*source_file_type == "c") if (*source_file_type == "c")
result.args.push_back("-std=gnu11"); result.args.push_back("-std=gnu11");
else if (*source_file_type == "c++" || *source_file_type == "c++-header") else if (*source_file_type == "c++")
result.args.push_back("-std=c++14"); result.args.push_back("-std=c++14");
} }
} }

33
wscript
View File

@ -304,34 +304,27 @@ def build(bld):
lib.append('ncurses') lib.append('ncurses')
if bld.env['use_system_clang']: if bld.env['use_system_clang']:
if bld.env['llvm_config']:
# If --llvm-config is specified, set RPATH and use $bindir/bin/clang -###
# to detect recource directory.
output = str(subprocess.check_output(
[bld.env['llvm_config'], '--bindir'],
stderr=subprocess.STDOUT).decode()).strip()
# Use --check-cxx-compiler value if it is "clang".
# See https://github.com/jacobdufault/cquery/issues/237
clang = bld.env.get_flat('CXX')
if 'clang' not in clang:
clang = os.path.join(output, 'clang')
rpath = str(subprocess.check_output( rpath = str(subprocess.check_output(
[bld.env['llvm_config'], '--libdir'], [bld.env['llvm_config'], '--libdir'],
stderr=subprocess.STDOUT).decode()).strip() stderr=subprocess.STDOUT).decode()).strip()
else:
clang = 'clang'
if sys.platform == 'darwin':
rpath = bld.env['LIBPATH_clang'][0]
else:
rpath = []
# Use CXX set by --check-cxx-compiler if it is "clang".
# See https://github.com/jacobdufault/cquery/issues/237
clang = bld.env.get_flat('CXX')
if 'clang' not in clang:
# Otherwise, infer the clang executable path with llvm-config --bindir
output = str(subprocess.check_output(
[bld.env['llvm_config'], '--bindir'],
stderr=subprocess.STDOUT).decode()).strip()
clang = os.path.join(output, 'clang')
# Use the detected clang executable to infer resource directory
# Use `clang -### -xc /dev/null` instead of `clang -print-resource-dir` because the option is unavailable in 4.0.0
devnull = '/dev/null' if sys.platform != 'win32' else 'NUL' devnull = '/dev/null' if sys.platform != 'win32' else 'NUL'
output = subprocess.check_output( output = subprocess.check_output(
[clang, '-###', '-xc', devnull], [clang, '-###', '-xc', devnull],
stderr=subprocess.STDOUT).decode() stderr=subprocess.STDOUT).decode()
match = re.search(r'"-resource-dir" "([^"]*)"', output, re.M | re.I) match = re.search(r'"-resource-dir" "([^"]*)"', output, re.M)
if match: if match:
default_resource_directory = match.group(1) default_resource_directory = match.group(1)
else: else: