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");
} }
} }

37
wscript
View File

@ -304,38 +304,31 @@ 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']: rpath = str(subprocess.check_output(
# If --llvm-config is specified, set RPATH and use $bindir/bin/clang -### [bld.env['llvm_config'], '--libdir'],
# to detect recource directory. stderr=subprocess.STDOUT).decode()).strip()
# 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( output = str(subprocess.check_output(
[bld.env['llvm_config'], '--bindir'], [bld.env['llvm_config'], '--bindir'],
stderr=subprocess.STDOUT).decode()).strip() stderr=subprocess.STDOUT).decode()).strip()
clang = os.path.join(output, 'clang')
# Use --check-cxx-compiler value if it is "clang". # Use the detected clang executable to infer resource directory
# See https://github.com/jacobdufault/cquery/issues/237 # Use `clang -### -xc /dev/null` instead of `clang -print-resource-dir` because the option is unavailable in 4.0.0
clang = bld.env.get_flat('CXX')
if 'clang' not in clang:
clang = os.path.join(output, 'clang')
rpath = str(subprocess.check_output(
[bld.env['llvm_config'], '--libdir'],
stderr=subprocess.STDOUT).decode()).strip()
else:
clang = 'clang'
if sys.platform == 'darwin':
rpath = bld.env['LIBPATH_clang'][0]
else:
rpath = []
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:
bld.fatal("Failed to found system clang resource directory.") bld.fatal("Failed to found system clang resource directory.")
else: else:
clang_tarball_name = os.path.basename(os.path.dirname(bld.env['LIBPATH_clang'][0])) clang_tarball_name = os.path.basename(os.path.dirname(bld.env['LIBPATH_clang'][0]))