ccls/src/project.cc

1455 lines
50 KiB
C++
Raw Normal View History

#include "project.h"
#include "clang_utils.h"
2017-09-22 01:14:57 +00:00
#include "match.h"
2017-03-31 04:21:52 +00:00
#include "platform.h"
#include "serializer.h"
2017-10-25 01:39:38 +00:00
#include "timer.h"
2017-10-31 19:49:19 +00:00
#include "utils.h"
2017-03-31 04:21:52 +00:00
#include <clang-c/CXCompilationDatabase.h>
#include <doctest/doctest.h>
2017-07-28 02:14:33 +00:00
#include <loguru.hpp>
2017-03-31 04:21:52 +00:00
#include <iostream>
#include <limits>
#include <sstream>
#include <unordered_set>
#include <vector>
2017-03-31 04:21:52 +00:00
struct CompileCommandsEntry {
std::string directory;
2017-04-17 20:40:50 +00:00
std::string file;
std::string command;
2017-03-31 04:21:52 +00:00
std::vector<std::string> args;
};
2017-04-17 20:40:50 +00:00
MAKE_REFLECT_STRUCT(CompileCommandsEntry, directory, file, command, args);
2017-03-31 04:21:52 +00:00
namespace {
2017-03-31 04:21:52 +00:00
bool g_disable_normalize_path_for_test = false;
std::string NormalizePathWithTestOptOut(const std::string& path) {
if (g_disable_normalize_path_for_test) {
// Add a & so we can test to verify a path is normalized.
return "&" + path;
}
return NormalizePath(path);
}
2018-01-11 04:07:50 +00:00
bool IsUnixAbsolutePath(const std::string& path) {
return !path.empty() && path[0] == '/';
}
bool IsWindowsAbsolutePath(const std::string& path) {
auto is_drive_letter = [](char c) {
return (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z');
};
return path.size() > 3 && path[1] == ':' && path[2] == '/' &&
is_drive_letter(path[0]);
}
2017-09-22 03:09:11 +00:00
struct ProjectConfig {
std::unordered_set<std::string> quote_dirs;
std::unordered_set<std::string> angle_dirs;
2017-09-22 03:09:11 +00:00
std::vector<std::string> extra_flags;
std::string project_dir;
2017-10-25 01:02:15 +00:00
std::string resource_dir;
};
2017-10-18 06:23:07 +00:00
// TODO: See
// https://github.com/Valloric/ycmd/blob/master/ycmd/completers/cpp/flags.py.
std::vector<std::string> kBlacklistMulti = {
2017-10-18 06:23:07 +00:00
"-MF", "-MT", "-MQ", "-o", "--serialize-diagnostics", "-Xclang"};
2017-05-09 01:21:21 +00:00
// Blacklisted flags which are always removed from the command line.
std::vector<std::string> kBlacklist = {
2017-12-23 16:01:43 +00:00
"-c", "-MP", "-MD", "-MMD", "--fcolor-diagnostics",
};
// Arguments which are followed by a potentially relative path. We need to make
// all relative paths absolute, otherwise libclang will not resolve them.
std::vector<std::string> kPathArgs = {
"-I", "-iquote", "-isystem", "--sysroot=",
"-isysroot", "-gcc-toolchain", "-include-pch", "-iframework",
"-F", "-imacros", "-include"};
2017-03-31 04:21:52 +00:00
// Arguments which always require an absolute path, ie, clang -working-directory
// does not work as expected. Argument processing assumes that this is a subset
// of kPathArgs.
std::vector<std::string> kNormalizePathArgs = {"--sysroot="};
2017-10-18 06:23:07 +00:00
// Arguments whose path arguments should be injected into include dir lookup
// for #include completion.
std::vector<std::string> kQuoteIncludeArgs = {"-iquote"};
std::vector<std::string> kAngleIncludeArgs = {"-I", "-isystem"};
2017-05-21 07:37:53 +00:00
bool ShouldAddToQuoteIncludes(const std::string& arg) {
return StartsWithAny(arg, kQuoteIncludeArgs);
2017-05-21 07:37:53 +00:00
}
bool ShouldAddToAngleIncludes(const std::string& arg) {
return StartsWithAny(arg, kAngleIncludeArgs);
2017-05-21 07:37:53 +00:00
}
2017-12-15 05:18:43 +00:00
optional<std::string> SourceFileType(const std::string& path) {
if (EndsWith(path, ".c"))
return std::string("c");
else if (EndsWith(path, ".cpp") || EndsWith(path, ".cc"))
return std::string("c++");
else if (EndsWith(path, ".mm"))
return std::string("objective-c++");
else if (EndsWith(path, ".m"))
return std::string("objective-c");
return nullopt;
}
2017-05-21 07:37:53 +00:00
Project::Entry GetCompilationEntryFromCompileCommandEntry(
Config* init_opts,
2017-09-22 03:09:11 +00:00
ProjectConfig* config,
2017-09-22 01:14:57 +00:00
const CompileCommandsEntry& entry) {
auto cleanup_maybe_relative_path = [&](const std::string& path) {
// TODO/FIXME: Normalization will fail for paths that do not exist. Should
// it return an optional<std::string>?
assert(!path.empty());
2018-01-11 04:07:50 +00:00
if (entry.directory.empty() || IsUnixAbsolutePath(path) ||
IsWindowsAbsolutePath(path)) {
// We still want to normalize, as the path may contain .. characters.
return NormalizePathWithTestOptOut(path);
2018-01-11 04:07:50 +00:00
}
if (EndsWith(entry.directory, "/"))
return NormalizePathWithTestOptOut(entry.directory + path);
return NormalizePathWithTestOptOut(entry.directory + "/" + path);
};
2017-04-20 05:01:36 +00:00
Project::Entry result;
result.filename = NormalizePathWithTestOptOut(entry.file);
std::string base_name = GetBaseName(entry.file);
2017-10-18 06:23:07 +00:00
size_t i = 0;
// Strip all arguments consisting the compiler command,
// as there may be non-compiler related commands beforehand,
// ie, compiler schedular such as goma. This allows correct parsing for
// command lines like "goma clang -c foo".
2018-01-05 19:10:58 +00:00
std::string::size_type dot;
while (i < entry.args.size() && entry.args[i][0] != '-' &&
// Do not skip over main source filename
NormalizePathWithTestOptOut(entry.args[i]) != result.filename &&
// There may be other filenames (e.g. more than one source filenames)
2018-01-05 19:10:58 +00:00
// preceding main source filename. We use a heuristic here. `.` may
// occur in both command names and source filenames. If `.` occurs in
// the last 4 bytes of entry.args[i] and not followed by a digit, e.g.
// .c .cpp, We take it as a source filename. Others (like ./a/b/goma
// clang-4.0) are seen as commands.
((dot = entry.args[i].rfind('.')) == std::string::npos ||
dot + 4 < entry.args[i].size() || isdigit(entry.args[i][dot + 1]) ||
!entry.args[i].compare(dot + 1, 3, "exe")))
2017-10-18 06:23:07 +00:00
++i;
2017-10-18 07:02:33 +00:00
// Include the compiler in the args.
if (i > 0)
result.args.push_back(entry.args[i - 1]);
else {
// TODO Drop this back compatibility
// Args probably came from a /.cquery file, which likely has just flags.
// clang_parseTranslationUnit2FullArgv() expects the binary path as the
// first arg, so the first flag would end up being ignored. Add a dummy.
result.args.push_back("clang++");
}
2017-10-18 06:23:07 +00:00
// Add -working-directory if not provided.
if (!AnyStartsWith(entry.args, "-working-directory")) {
result.args.emplace_back("-working-directory");
result.args.push_back(entry.directory);
}
// Clang does not have good hueristics for determining source language, we
// should explicitly specify it.
if (optional<std::string> file_type = SourceFileType(entry.file)) {
if (!AnyStartsWith(entry.args, "-x")) {
result.args.push_back("-x" + *file_type);
}
if (!AnyStartsWith(entry.args, "-std=")) {
if (*file_type == "c")
result.args.push_back("-std=gnu11");
else if (*file_type == "c++")
result.args.push_back("-std=c++14");
}
}
bool next_flag_is_path = false;
bool add_next_flag_to_quote_dirs = false;
bool add_next_flag_to_angle_dirs = false;
// Note that when processing paths, some arguments support multiple forms, ie,
// {"-Ifoo"} or {"-I", "foo"}. Support both styles.
2017-09-22 03:09:11 +00:00
result.args.reserve(entry.args.size() + config->extra_flags.size());
2017-10-18 06:23:07 +00:00
for (; i < entry.args.size(); ++i) {
std::string arg = entry.args[i];
2017-11-19 23:46:02 +00:00
// If blacklist skip.
if (!next_flag_is_path) {
if (StartsWithAny(arg, kBlacklistMulti)) {
++i;
continue;
}
if (StartsWithAny(arg, kBlacklist))
continue;
}
// Finish processing path for the previous argument, which was a switch.
// {"-I", "foo"} style.
if (next_flag_is_path) {
std::string normalized_arg = cleanup_maybe_relative_path(arg);
if (add_next_flag_to_quote_dirs)
config->quote_dirs.insert(normalized_arg);
if (add_next_flag_to_angle_dirs)
config->angle_dirs.insert(normalized_arg);
2017-09-22 06:50:27 +00:00
next_flag_is_path = false;
add_next_flag_to_quote_dirs = false;
add_next_flag_to_angle_dirs = false;
}
else {
// Check to see if arg is a path and needs to be updated.
for (const std::string& flag_type : kPathArgs) {
// {"-I", "foo"} style.
if (arg == flag_type) {
next_flag_is_path = true;
add_next_flag_to_quote_dirs = ShouldAddToQuoteIncludes(arg);
add_next_flag_to_angle_dirs = ShouldAddToAngleIncludes(arg);
break;
}
// {"-Ifoo"} style.
if (StartsWith(arg, flag_type)) {
std::string path = arg.substr(flag_type.size());
assert(!path.empty());
path = cleanup_maybe_relative_path(path);
if (StartsWithAny(arg, kNormalizePathArgs))
arg = flag_type + path;
if (ShouldAddToQuoteIncludes(flag_type))
config->quote_dirs.insert(path);
if (ShouldAddToAngleIncludes(flag_type))
config->angle_dirs.insert(path);
break;
}
}
// This is most likely the file path we will be passing to clang.
if (EndsWith(arg, base_name))
arg = cleanup_maybe_relative_path(arg);
}
result.args.push_back(arg);
}
// We don't do any special processing on user-given extra flags.
2017-09-22 03:09:11 +00:00
for (const auto& flag : config->extra_flags)
result.args.push_back(flag);
2017-10-25 01:02:15 +00:00
// Add -resource-dir so clang can correctly resolve system includes like
// <cstddef>
if (!AnyStartsWith(result.args, "-resource-dir"))
result.args.push_back("-resource-dir=" + config->resource_dir);
2017-12-01 18:11:09 +00:00
// There could be a clang version mismatch between what the project uses and
// what cquery uses. Make sure we do not emit warnings for mismatched options.
if (!AnyStartsWith(result.args, "-Wno-unknown-warning-option"))
result.args.push_back("-Wno-unknown-warning-option");
2017-12-27 15:56:17 +00:00
// Using -fparse-all-comments enables documententation in the indexer and in
// code completion.
2018-01-21 06:55:29 +00:00
if (init_opts->index.comments > 1 &&
2018-01-11 02:43:01 +00:00
!AnyStartsWith(result.args, "-fparse-all-comments")) {
2017-12-27 15:56:17 +00:00
result.args.push_back("-fparse-all-comments");
}
2017-12-27 15:56:17 +00:00
return result;
}
2018-01-11 02:43:01 +00:00
std::vector<Project::Entry> LoadFromDirectoryListing(Config* init_opts,
ProjectConfig* config) {
2017-04-20 05:01:36 +00:00
std::vector<Project::Entry> result;
std::vector<std::string> args;
for (std::string line :
ReadLinesWithEnding(config->project_dir + "/.cquery")) {
TrimInPlace(line);
if (line.empty() || StartsWith(line, "#"))
continue;
args.push_back(line);
}
LOG_IF_S(INFO, !args.empty())
<< "Using .cquery arguments " << StringJoin(args);
LOG_IF_S(WARNING, !FileExists(config->project_dir + "/.cquery") &&
config->extra_flags.empty())
<< "cquery has no clang arguments. Considering adding either a "
"compile_commands.json or .cquery file. See the cquery README for "
"more information.";
2017-09-22 01:14:57 +00:00
std::vector<std::string> files = GetFilesInFolder(
2017-09-22 03:09:11 +00:00
config->project_dir, true /*recursive*/, true /*add_folder_to_path*/);
for (const std::string& file : files) {
2017-12-15 05:18:43 +00:00
if (SourceFileType(file)) {
2017-05-21 07:37:53 +00:00
CompileCommandsEntry e;
e.directory = config->project_dir;
e.file = file;
e.args = args;
e.args.push_back(e.file);
2018-01-11 02:43:01 +00:00
result.push_back(
GetCompilationEntryFromCompileCommandEntry(init_opts, config, e));
}
}
return result;
}
2017-05-21 07:37:53 +00:00
std::vector<Project::Entry> LoadCompilationEntriesFromDirectory(
Config* init_opts,
ProjectConfig* config,
const std::string& opt_compilation_db_dir) {
// If there is a .cquery file always load using directory listing.
if (FileExists(config->project_dir + "/.cquery"))
return LoadFromDirectoryListing(init_opts, config);
2017-09-22 03:09:11 +00:00
// Try to load compile_commands.json, but fallback to a project listing.
2017-12-01 17:50:39 +00:00
const auto& compilation_db_dir = opt_compilation_db_dir.empty()
? config->project_dir
: opt_compilation_db_dir;
2017-09-22 03:09:11 +00:00
LOG_S(INFO) << "Trying to load compile_commands.json";
2017-03-31 04:21:52 +00:00
CXCompilationDatabase_Error cx_db_load_error;
2017-09-22 01:14:57 +00:00
CXCompilationDatabase cx_db = clang_CompilationDatabase_fromDirectory(
compilation_db_dir.c_str(), &cx_db_load_error);
2017-03-31 04:21:52 +00:00
if (cx_db_load_error == CXCompilationDatabase_CanNotLoadDatabase) {
2017-09-22 03:09:11 +00:00
LOG_S(INFO) << "Unable to load compile_commands.json located at \""
2017-12-01 17:50:39 +00:00
<< compilation_db_dir << "\"; using directory listing instead.";
return LoadFromDirectoryListing(init_opts, config);
2017-03-31 04:21:52 +00:00
}
2017-10-25 01:39:38 +00:00
Timer clang_time;
Timer our_time;
clang_time.Pause();
our_time.Pause();
clang_time.Resume();
2017-09-22 01:14:57 +00:00
CXCompileCommands cx_commands =
clang_CompilationDatabase_getAllCompileCommands(cx_db);
2017-03-31 04:21:52 +00:00
unsigned int num_commands = clang_CompileCommands_getSize(cx_commands);
2017-10-25 01:39:38 +00:00
clang_time.Pause();
2017-04-20 05:01:36 +00:00
std::vector<Project::Entry> result;
2017-03-31 04:21:52 +00:00
for (unsigned int i = 0; i < num_commands; i++) {
2017-10-25 01:39:38 +00:00
clang_time.Resume();
2017-09-22 01:14:57 +00:00
CXCompileCommand cx_command =
clang_CompileCommands_getCommand(cx_commands, i);
2017-03-31 04:21:52 +00:00
2017-09-22 01:14:57 +00:00
std::string directory =
ToString(clang_CompileCommand_getDirectory(cx_command));
2017-09-22 01:14:57 +00:00
std::string relative_filename =
ToString(clang_CompileCommand_getFilename(cx_command));
2017-03-31 04:21:52 +00:00
unsigned num_args = clang_CompileCommand_getNumArgs(cx_command);
2017-10-25 01:39:38 +00:00
CompileCommandsEntry entry;
2017-03-31 04:21:52 +00:00
entry.args.reserve(num_args);
2017-11-19 22:46:05 +00:00
for (unsigned j = 0; j < num_args; ++j) {
2017-09-22 01:14:57 +00:00
entry.args.push_back(
ToString(clang_CompileCommand_getArg(cx_command, j)));
2017-11-19 22:46:05 +00:00
}
clang_time.Pause(); // TODO: don't call ToString in this block.
2017-11-19 22:46:05 +00:00
// LOG_S(INFO) << "Got args " << StringJoin(entry.args);
2017-10-25 01:39:38 +00:00
our_time.Resume();
entry.directory = directory;
std::string absolute_filename;
if (IsUnixAbsolutePath(relative_filename) ||
IsWindowsAbsolutePath(relative_filename))
absolute_filename = relative_filename;
else
absolute_filename = directory + "/" + relative_filename;
2017-10-25 01:39:38 +00:00
entry.file = NormalizePathWithTestOptOut(absolute_filename);
2017-04-17 20:40:50 +00:00
2018-01-11 02:43:01 +00:00
result.push_back(
GetCompilationEntryFromCompileCommandEntry(init_opts, config, entry));
2017-10-25 01:39:38 +00:00
our_time.Pause();
2017-03-31 04:21:52 +00:00
}
2017-10-25 01:39:38 +00:00
clang_time.Resume();
2017-03-31 04:21:52 +00:00
clang_CompileCommands_dispose(cx_commands);
clang_CompilationDatabase_dispose(cx_db);
2017-10-25 01:39:38 +00:00
clang_time.Pause();
clang_time.ResetAndPrint("compile_commands.json clang time");
our_time.ResetAndPrint("compile_commands.json our time");
2017-03-31 04:21:52 +00:00
return result;
}
// Computes a score based on how well |a| and |b| match. This is used for
// argument guessing.
int ComputeGuessScore(const std::string& a, const std::string& b) {
const int kMatchPrefixWeight = 100;
const int kMismatchDirectoryWeight = 100;
const int kMatchPostfixWeight = 1;
int score = 0;
int i = 0;
// Increase score based on matching prefix.
for (i = 0; i < a.length() && i < b.length(); ++i) {
if (a[i] != b[i])
break;
score += kMatchPrefixWeight;
}
// Reduce score based on mismatched directory distance.
for (int j = i; j < a.length(); ++j) {
if (a[j] == '/')
score -= kMismatchDirectoryWeight;
}
for (int j = i; j < b.length(); ++j) {
if (b[j] == '/')
score -= kMismatchDirectoryWeight;
}
// Increase score based on common ending. Don't increase as much as matching
// prefix or directory distance.
for (int offset = 1; offset <= a.length() && offset <= b.length(); ++offset) {
if (a[a.size() - offset] != b[b.size() - offset])
break;
score += kMatchPostfixWeight;
}
return score;
}
2017-03-31 04:21:52 +00:00
} // namespace
void Project::Load(Config* init_opts,
const std::vector<std::string>& extra_flags,
const std::string& opt_compilation_db_dir,
const std::string& root_directory,
2017-10-25 01:02:15 +00:00
const std::string& resource_directory) {
2017-09-22 03:09:11 +00:00
// Load data.
ProjectConfig config;
config.extra_flags = extra_flags;
config.project_dir = root_directory;
2017-10-25 01:02:15 +00:00
config.resource_dir = resource_directory;
2018-01-11 02:43:01 +00:00
entries = LoadCompilationEntriesFromDirectory(init_opts, &config,
opt_compilation_db_dir);
2017-09-22 03:09:11 +00:00
// Cleanup / postprocess include directories.
quote_include_directories.assign(config.quote_dirs.begin(),
config.quote_dirs.end());
angle_include_directories.assign(config.angle_dirs.begin(),
config.angle_dirs.end());
2017-05-21 07:37:53 +00:00
for (std::string& path : quote_include_directories) {
EnsureEndsInSlash(path);
2017-07-28 02:14:33 +00:00
LOG_S(INFO) << "quote_include_dir: " << path;
2017-05-21 07:37:53 +00:00
}
for (std::string& path : angle_include_directories) {
EnsureEndsInSlash(path);
2017-07-28 02:14:33 +00:00
LOG_S(INFO) << "angle_include_dir: " << path;
2017-05-21 07:37:53 +00:00
}
2017-09-22 03:09:11 +00:00
// Setup project entries.
absolute_path_to_entry_index_.resize(entries.size());
for (int i = 0; i < entries.size(); ++i)
absolute_path_to_entry_index_[entries[i].filename] = i;
2017-03-31 04:21:52 +00:00
}
2017-09-22 01:14:57 +00:00
Project::Entry Project::FindCompilationEntryForFile(
const std::string& filename) {
auto it = absolute_path_to_entry_index_.find(filename);
if (it != absolute_path_to_entry_index_.end())
return entries[it->second];
// We couldn't find the file. Try to infer it.
// TODO: Cache inferred file in a separate array (using a lock or similar)
Entry* best_entry = nullptr;
int best_score = std::numeric_limits<int>::min();
for (Entry& entry : entries) {
int score = ComputeGuessScore(filename, entry.filename);
if (score > best_score) {
best_score = score;
best_entry = &entry;
}
}
Project::Entry result;
result.is_inferred = true;
result.filename = filename;
2018-01-16 01:38:28 +00:00
if (!best_entry) {
// FIXME
result.args.push_back("clang++");
result.args.push_back(filename);
2018-01-16 01:38:28 +00:00
} else {
result.args = best_entry->args;
// |best_entry| probably has its own path in the arguments. We need to remap
// that path to the new filename.
std::string best_entry_base_name = GetBaseName(best_entry->filename);
for (std::string& arg : result.args) {
if (arg == best_entry->filename ||
GetBaseName(arg) == best_entry_base_name) {
arg = filename;
}
}
}
return result;
}
2017-09-22 01:14:57 +00:00
void Project::ForAllFilteredFiles(
Config* config,
std::function<void(int i, const Entry& entry)> action) {
GroupMatch matcher(config->indexWhitelist, config->indexBlacklist);
for (int i = 0; i < entries.size(); ++i) {
const Project::Entry& entry = entries[i];
std::string failure_reason;
if (matcher.IsMatch(entry.filename, &failure_reason))
action(i, entries[i]);
else {
2017-07-30 04:46:21 +00:00
if (config->logSkippedPathsForIndex) {
2017-09-22 01:14:57 +00:00
LOG_S(INFO) << "[" << i + 1 << "/" << entries.size() << "]: Failed "
<< failure_reason << "; skipping " << entry.filename;
2017-07-30 04:46:21 +00:00
}
}
}
}
2017-11-19 18:05:06 +00:00
TEST_SUITE("Project") {
2017-11-19 22:11:54 +00:00
void CheckFlags(const std::string& directory, const std::string& file,
2017-11-19 18:05:06 +00:00
std::vector<std::string> raw,
std::vector<std::string> expected) {
g_disable_normalize_path_for_test = true;
Config init_opts;
2017-11-19 18:05:06 +00:00
ProjectConfig config;
config.project_dir = "/w/c/s/";
config.resource_dir = "/w/resource_dir/";
2017-11-19 18:05:06 +00:00
CompileCommandsEntry entry;
entry.directory = directory;
entry.args = raw;
entry.file = file;
Project::Entry result =
GetCompilationEntryFromCompileCommandEntry(&init_opts, &config, entry);
2017-11-19 18:05:06 +00:00
2017-11-19 22:46:05 +00:00
if (result.args != expected) {
std::cout << "Raw: " << StringJoin(raw) << std::endl;
std::cout << "Expected: " << StringJoin(expected) << std::endl;
std::cout << "Actual: " << StringJoin(result.args) << std::endl;
}
2017-11-19 18:05:06 +00:00
for (int i = 0; i < std::min(result.args.size(), expected.size()); ++i) {
if (result.args[i] != expected[i]) {
std::cout << std::endl;
std::cout << "mismatch at " << i << std::endl;
std::cout << " expected: " << expected[i] << std::endl;
std::cout << " actual: " << result.args[i] << std::endl;
}
}
2017-11-19 18:05:06 +00:00
REQUIRE(result.args == expected);
2017-10-18 06:23:07 +00:00
}
2017-11-19 18:05:06 +00:00
void CheckFlags(std::vector<std::string> raw,
std::vector<std::string> expected) {
CheckFlags("/dir/", "file.cc", raw, expected);
}
2017-11-19 18:05:06 +00:00
TEST_CASE("strip meta-compiler invocations") {
CheckFlags(
/* raw */ {"clang", "-lstdc++", "myfile.cc"},
2017-12-23 16:01:43 +00:00
/* expected */
2018-01-07 22:34:30 +00:00
{"clang", "-working-directory", "/dir/", "-xc++", "-std=c++14",
"-lstdc++", "&/dir/myfile.cc", "-resource-dir=/w/resource_dir/",
"-Wno-unknown-warning-option"});
2017-12-23 16:01:43 +00:00
2018-01-20 03:05:26 +00:00
CheckFlags(
/* raw */ {"clang.exe"},
/* expected */
{"clang.exe", "-working-directory", "/dir/", "-xc++", "-std=c++14",
"-resource-dir=/w/resource_dir/", "-Wno-unknown-warning-option"});
2017-12-23 16:01:43 +00:00
CheckFlags(
/* raw */ {"goma", "clang"},
/* expected */
2018-01-07 22:34:30 +00:00
{"clang", "-working-directory", "/dir/", "-xc++", "-std=c++14",
"-resource-dir=/w/resource_dir/", "-Wno-unknown-warning-option"});
2017-12-23 16:01:43 +00:00
CheckFlags(
/* raw */ {"goma", "clang", "--foo"},
/* expected */
2018-01-07 22:34:30 +00:00
{"clang", "-working-directory", "/dir/", "-xc++", "-std=c++14", "--foo",
"-resource-dir=/w/resource_dir/", "-Wno-unknown-warning-option"});
2017-11-19 18:05:06 +00:00
}
2017-10-18 06:23:07 +00:00
2018-01-11 04:07:50 +00:00
TEST_CASE("Windows path normalization") {
CheckFlags(
"E:/workdir", "E:/workdir/bar.cc", /* raw */ {"clang", "bar.cc"},
/* expected */
{"clang", "-working-directory", "E:/workdir", "-xc++", "-std=c++14",
"&E:/workdir/bar.cc", "-resource-dir=/w/resource_dir/",
"-Wno-unknown-warning-option"});
CheckFlags(
"E:/workdir", "E:/workdir/bar.cc",
/* raw */ {"clang", "E:/workdir/bar.cc"},
/* expected */
{"clang", "-working-directory", "E:/workdir", "-xc++", "-std=c++14",
"&E:/workdir/bar.cc", "-resource-dir=/w/resource_dir/",
"-Wno-unknown-warning-option"});
}
2017-11-19 22:46:05 +00:00
TEST_CASE("Path in args") {
2018-01-11 02:43:01 +00:00
CheckFlags(
"/home/user", "/home/user/foo/bar.c",
/* raw */ {"cc", "-O0", "foo/bar.c"},
/* expected */
{"cc", "-working-directory", "/home/user", "-xc", "-std=gnu11", "-O0",
"&/home/user/foo/bar.c", "-resource-dir=/w/resource_dir/",
"-Wno-unknown-warning-option"});
2017-11-19 22:46:05 +00:00
}
2017-12-19 06:16:21 +00:00
TEST_CASE("Implied binary") {
CheckFlags(
"/home/user", "/home/user/foo/bar.cc",
/* raw */ {"-DDONT_IGNORE_ME"},
/* expected */
2018-01-07 22:34:30 +00:00
{"clang++", "-working-directory", "/home/user", "-xc++", "-std=c++14",
"-DDONT_IGNORE_ME", "-resource-dir=/w/resource_dir/",
"-Wno-unknown-warning-option"});
2017-12-19 06:16:21 +00:00
}
2017-11-19 18:05:06 +00:00
// Checks flag parsing for a random chromium file in comparison to what
// YouCompleteMe fetches.
TEST_CASE("ycm") {
CheckFlags(
"/w/c/s/out/Release", "../../ash/login/lock_screen_sanity_unittest.cc",
/* raw */
{
"/work/goma/gomacc",
"../../third_party/llvm-build/Release+Asserts/bin/clang++",
"-MMD",
"-MF",
"obj/ash/ash_unittests/lock_screen_sanity_unittest.o.d",
"-DV8_DEPRECATION_WARNINGS",
"-DDCHECK_ALWAYS_ON=1",
"-DUSE_UDEV",
"-DUSE_AURA=1",
"-DUSE_NSS_CERTS=1",
"-DUSE_OZONE=1",
"-DFULL_SAFE_BROWSING",
"-DSAFE_BROWSING_CSD",
"-DSAFE_BROWSING_DB_LOCAL",
"-DCHROMIUM_BUILD",
"-DFIELDTRIAL_TESTING_ENABLED",
"-D_FILE_OFFSET_BITS=64",
"-D_LARGEFILE_SOURCE",
"-D_LARGEFILE64_SOURCE",
"-DCR_CLANG_REVISION=\"313786-1\"",
"-D__STDC_CONSTANT_MACROS",
"-D__STDC_FORMAT_MACROS",
"-DCOMPONENT_BUILD",
"-DOS_CHROMEOS",
"-DNDEBUG",
"-DNVALGRIND",
"-DDYNAMIC_ANNOTATIONS_ENABLED=0",
"-DGL_GLEXT_PROTOTYPES",
"-DUSE_GLX",
"-DUSE_EGL",
"-DANGLE_ENABLE_RELEASE_ASSERTS",
"-DTOOLKIT_VIEWS=1",
"-DGTEST_API_=",
"-DGTEST_HAS_POSIX_RE=0",
"-DGTEST_LANG_CXX11=1",
"-DUNIT_TEST",
"-DUSING_V8_SHARED",
"-DU_USING_ICU_NAMESPACE=0",
"-DU_ENABLE_DYLOAD=0",
"-DICU_UTIL_DATA_IMPL=ICU_UTIL_DATA_FILE",
"-DUCHAR_TYPE=uint16_t",
"-DGOOGLE_PROTOBUF_NO_RTTI",
"-DGOOGLE_PROTOBUF_NO_STATIC_INITIALIZER",
"-DHAVE_PTHREAD",
"-DPROTOBUF_USE_DLLS",
"-DBORINGSSL_SHARED_LIBRARY",
"-DSK_IGNORE_LINEONLY_AA_CONVEX_PATH_OPTS",
"-DSK_HAS_PNG_LIBRARY",
"-DSK_HAS_WEBP_LIBRARY",
"-DSK_HAS_JPEG_LIBRARY",
"-DSKIA_DLL",
"-DGR_GL_IGNORE_ES3_MSAA=0",
"-DSK_SUPPORT_GPU=1",
"-DMESA_EGL_NO_X11_HEADERS",
"-I../..",
"-Igen",
"-I../../third_party/libwebp/src",
"-I../../third_party/khronos",
"-I../../gpu",
"-I../../third_party/googletest/src/googletest/include",
"-I../../third_party/WebKit",
"-Igen/third_party/WebKit",
"-I../../v8/include",
"-Igen/v8/include",
"-I../../third_party/icu/source/common",
"-I../../third_party/icu/source/i18n",
"-I../../third_party/protobuf/src",
"-Igen/protoc_out",
"-I../../third_party/protobuf/src",
"-I../../third_party/boringssl/src/include",
"-I../../build/linux/debian_jessie_amd64-sysroot/usr/include/nss",
"-I../../build/linux/debian_jessie_amd64-sysroot/usr/include/nspr",
"-I../../skia/config",
"-I../../skia/ext",
"-I../../third_party/skia/include/c",
"-I../../third_party/skia/include/config",
"-I../../third_party/skia/include/core",
"-I../../third_party/skia/include/effects",
"-I../../third_party/skia/include/encode",
"-I../../third_party/skia/include/gpu",
"-I../../third_party/skia/include/images",
"-I../../third_party/skia/include/lazy",
"-I../../third_party/skia/include/pathops",
"-I../../third_party/skia/include/pdf",
"-I../../third_party/skia/include/pipe",
"-I../../third_party/skia/include/ports",
"-I../../third_party/skia/include/utils",
"-I../../third_party/skia/third_party/vulkan",
"-I../../third_party/skia/include/codec",
"-I../../third_party/skia/src/gpu",
"-I../../third_party/skia/src/sksl",
"-I../../third_party/ced/src",
"-I../../third_party/mesa/src/include",
"-I../../third_party/libwebm/source",
"-Igen",
"-I../../build/linux/debian_jessie_amd64-sysroot/usr/include/"
"dbus-1.0",
"-I../../build/linux/debian_jessie_amd64-sysroot/usr/lib/"
"x86_64-linux-gnu/dbus-1.0/include",
"-I../../third_party/googletest/custom",
"-I../../third_party/googletest/src/googlemock/include",
"-fno-strict-aliasing",
"-Wno-builtin-macro-redefined",
"-D__DATE__=",
"-D__TIME__=",
"-D__TIMESTAMP__=",
"-funwind-tables",
"-fPIC",
"-pipe",
"-B../../third_party/binutils/Linux_x64/Release/bin",
"-pthread",
"-fcolor-diagnostics",
"-no-canonical-prefixes",
"-m64",
"-march=x86-64",
"-Wall",
"-Werror",
"-Wextra",
"-Wno-missing-field-initializers",
"-Wno-unused-parameter",
"-Wno-c++11-narrowing",
"-Wno-covered-switch-default",
"-Wno-unneeded-internal-declaration",
"-Wno-inconsistent-missing-override",
"-Wno-undefined-var-template",
"-Wno-nonportable-include-path",
"-Wno-address-of-packed-member",
"-Wno-unused-lambda-capture",
"-Wno-user-defined-warnings",
"-Wno-enum-compare-switch",
"-Wno-tautological-unsigned-zero-compare",
"-Wno-null-pointer-arithmetic",
"-Wno-tautological-unsigned-enum-zero-compare",
"-O2",
"-fno-ident",
"-fdata-sections",
"-ffunction-sections",
"-fno-omit-frame-pointer",
"-g0",
"-fvisibility=hidden",
"-Xclang",
"-load",
"-Xclang",
"../../third_party/llvm-build/Release+Asserts/lib/"
"libFindBadConstructs.so",
"-Xclang",
"-add-plugin",
"-Xclang",
"find-bad-constructs",
"-Xclang",
"-plugin-arg-find-bad-constructs",
"-Xclang",
"check-auto-raw-pointer",
"-Xclang",
"-plugin-arg-find-bad-constructs",
"-Xclang",
"check-ipc",
"-Wheader-hygiene",
"-Wstring-conversion",
"-Wtautological-overlap-compare",
"-Wno-header-guard",
"-std=gnu++14",
"-fno-rtti",
"-nostdinc++",
"-isystem../../buildtools/third_party/libc++/trunk/include",
"-isystem../../buildtools/third_party/libc++abi/trunk/include",
"--sysroot=../../build/linux/debian_jessie_amd64-sysroot",
"-fno-exceptions",
"-fvisibility-inlines-hidden",
"-c",
"../../ash/login/ui/lock_screen_sanity_unittest.cc",
"-o",
"obj/ash/ash_unittests/lock_screen_sanity_unittest.o",
},
/* expected */
{"../../third_party/llvm-build/Release+Asserts/bin/clang++",
"-working-directory",
"/w/c/s/out/Release",
"-xc++",
2017-11-19 22:11:54 +00:00
"-DV8_DEPRECATION_WARNINGS",
"-DDCHECK_ALWAYS_ON=1",
"-DUSE_UDEV",
"-DUSE_AURA=1",
"-DUSE_NSS_CERTS=1",
"-DUSE_OZONE=1",
"-DFULL_SAFE_BROWSING",
"-DSAFE_BROWSING_CSD",
"-DSAFE_BROWSING_DB_LOCAL",
"-DCHROMIUM_BUILD",
"-DFIELDTRIAL_TESTING_ENABLED",
"-D_FILE_OFFSET_BITS=64",
"-D_LARGEFILE_SOURCE",
"-D_LARGEFILE64_SOURCE",
"-DCR_CLANG_REVISION=\"313786-1\"",
"-D__STDC_CONSTANT_MACROS",
"-D__STDC_FORMAT_MACROS",
"-DCOMPONENT_BUILD",
"-DOS_CHROMEOS",
"-DNDEBUG",
"-DNVALGRIND",
"-DDYNAMIC_ANNOTATIONS_ENABLED=0",
"-DGL_GLEXT_PROTOTYPES",
"-DUSE_GLX",
"-DUSE_EGL",
"-DANGLE_ENABLE_RELEASE_ASSERTS",
"-DTOOLKIT_VIEWS=1",
"-DGTEST_API_=",
"-DGTEST_HAS_POSIX_RE=0",
"-DGTEST_LANG_CXX11=1",
"-DUNIT_TEST",
"-DUSING_V8_SHARED",
"-DU_USING_ICU_NAMESPACE=0",
"-DU_ENABLE_DYLOAD=0",
"-DICU_UTIL_DATA_IMPL=ICU_UTIL_DATA_FILE",
"-DUCHAR_TYPE=uint16_t",
"-DGOOGLE_PROTOBUF_NO_RTTI",
"-DGOOGLE_PROTOBUF_NO_STATIC_INITIALIZER",
"-DHAVE_PTHREAD",
"-DPROTOBUF_USE_DLLS",
"-DBORINGSSL_SHARED_LIBRARY",
"-DSK_IGNORE_LINEONLY_AA_CONVEX_PATH_OPTS",
"-DSK_HAS_PNG_LIBRARY",
"-DSK_HAS_WEBP_LIBRARY",
"-DSK_HAS_JPEG_LIBRARY",
"-DSKIA_DLL",
"-DGR_GL_IGNORE_ES3_MSAA=0",
"-DSK_SUPPORT_GPU=1",
"-DMESA_EGL_NO_X11_HEADERS",
"-I../..",
"-Igen",
"-I../../third_party/libwebp/src",
"-I../../third_party/khronos",
"-I../../gpu",
"-I../../third_party/googletest/src/googletest/"
2017-11-19 22:11:54 +00:00
"include",
"-I../../third_party/WebKit",
"-Igen/third_party/WebKit",
"-I../../v8/include",
"-Igen/v8/include",
"-I../../third_party/icu/source/common",
"-I../../third_party/icu/source/i18n",
"-I../../third_party/protobuf/src",
"-Igen/protoc_out",
"-I../../third_party/protobuf/src",
"-I../../third_party/boringssl/src/include",
"-I../../build/linux/debian_jessie_amd64-sysroot/"
2017-11-19 22:11:54 +00:00
"usr/include/nss",
"-I../../build/linux/debian_jessie_amd64-sysroot/"
2017-11-19 22:11:54 +00:00
"usr/include/nspr",
"-I../../skia/config",
"-I../../skia/ext",
"-I../../third_party/skia/include/c",
"-I../../third_party/skia/include/config",
"-I../../third_party/skia/include/core",
"-I../../third_party/skia/include/effects",
"-I../../third_party/skia/include/encode",
"-I../../third_party/skia/include/gpu",
"-I../../third_party/skia/include/images",
"-I../../third_party/skia/include/lazy",
"-I../../third_party/skia/include/pathops",
"-I../../third_party/skia/include/pdf",
"-I../../third_party/skia/include/pipe",
"-I../../third_party/skia/include/ports",
"-I../../third_party/skia/include/utils",
"-I../../third_party/skia/third_party/vulkan",
"-I../../third_party/skia/include/codec",
"-I../../third_party/skia/src/gpu",
"-I../../third_party/skia/src/sksl",
"-I../../third_party/ced/src",
"-I../../third_party/mesa/src/include",
"-I../../third_party/libwebm/source",
"-Igen",
"-I../../build/linux/debian_jessie_amd64-sysroot/"
2017-11-19 22:11:54 +00:00
"usr/include/dbus-1.0",
"-I../../build/linux/debian_jessie_amd64-sysroot/"
2017-11-19 22:11:54 +00:00
"usr/lib/x86_64-linux-gnu/dbus-1.0/include",
"-I../../third_party/googletest/custom",
"-I../../third_party/googletest/src/googlemock/"
2017-11-19 22:11:54 +00:00
"include",
"-fno-strict-aliasing",
"-Wno-builtin-macro-redefined",
"-D__DATE__=",
"-D__TIME__=",
"-D__TIMESTAMP__=",
"-funwind-tables",
"-fPIC",
"-pipe",
"-B../../third_party/binutils/Linux_x64/Release/bin",
"-pthread",
"-fcolor-diagnostics",
"-no-canonical-prefixes",
"-m64",
"-march=x86-64",
"-Wall",
"-Werror",
"-Wextra",
"-Wno-missing-field-initializers",
"-Wno-unused-parameter",
"-Wno-c++11-narrowing",
"-Wno-covered-switch-default",
"-Wno-unneeded-internal-declaration",
"-Wno-inconsistent-missing-override",
"-Wno-undefined-var-template",
"-Wno-nonportable-include-path",
"-Wno-address-of-packed-member",
"-Wno-unused-lambda-capture",
"-Wno-user-defined-warnings",
"-Wno-enum-compare-switch",
"-Wno-tautological-unsigned-zero-compare",
"-Wno-null-pointer-arithmetic",
"-Wno-tautological-unsigned-enum-zero-compare",
"-O2",
"-fno-ident",
"-fdata-sections",
"-ffunction-sections",
"-fno-omit-frame-pointer",
"-g0",
"-fvisibility=hidden",
"-Wheader-hygiene",
"-Wstring-conversion",
"-Wtautological-overlap-compare",
"-Wno-header-guard",
"-std=gnu++14",
"-fno-rtti",
"-nostdinc++",
"-isystem../../buildtools/third_party/libc++/"
2017-11-19 22:11:54 +00:00
"trunk/"
"include",
"-isystem../../buildtools/third_party/libc++abi/"
2017-11-19 22:11:54 +00:00
"trunk/"
"include",
"--sysroot=&/w/c/s/out/Release/../../build/linux/"
2017-11-19 22:11:54 +00:00
"debian_jessie_amd64-sysroot",
"-fno-exceptions",
"-fvisibility-inlines-hidden",
2018-01-11 02:43:01 +00:00
"&/w/c/s/out/Release/../../ash/login/ui/"
"lock_screen_sanity_unittest.cc",
2017-12-01 18:11:09 +00:00
"-resource-dir=/w/resource_dir/",
"-Wno-unknown-warning-option"});
2017-11-19 18:05:06 +00:00
}
2017-10-18 06:23:07 +00:00
2017-11-19 18:05:06 +00:00
// Checks flag parsing for an example chromium file.
TEST_CASE("chromium") {
CheckFlags(
"/w/c/s/out/Release", "../../apps/app_lifetime_monitor.cc",
/* raw */
{"/work/goma/gomacc",
2017-11-19 22:11:54 +00:00
"../../third_party/llvm-build/Release+Asserts/bin/clang++",
"-MMD",
"-MF",
"obj/apps/apps/app_lifetime_monitor.o.d",
"-DV8_DEPRECATION_WARNINGS",
"-DDCHECK_ALWAYS_ON=1",
"-DUSE_UDEV",
"-DUSE_ASH=1",
"-DUSE_AURA=1",
"-DUSE_NSS_CERTS=1",
"-DUSE_OZONE=1",
"-DDISABLE_NACL",
"-DFULL_SAFE_BROWSING",
"-DSAFE_BROWSING_CSD",
"-DSAFE_BROWSING_DB_LOCAL",
"-DCHROMIUM_BUILD",
"-DFIELDTRIAL_TESTING_ENABLED",
"-DCR_CLANG_REVISION=\"310694-1\"",
"-D_FILE_OFFSET_BITS=64",
"-D_LARGEFILE_SOURCE",
"-D_LARGEFILE64_SOURCE",
"-D__STDC_CONSTANT_MACROS",
"-D__STDC_FORMAT_MACROS",
"-DCOMPONENT_BUILD",
"-DOS_CHROMEOS",
"-DNDEBUG",
"-DNVALGRIND",
"-DDYNAMIC_ANNOTATIONS_ENABLED=0",
"-DGL_GLEXT_PROTOTYPES",
"-DUSE_GLX",
"-DUSE_EGL",
"-DANGLE_ENABLE_RELEASE_ASSERTS",
"-DTOOLKIT_VIEWS=1",
"-DV8_USE_EXTERNAL_STARTUP_DATA",
"-DU_USING_ICU_NAMESPACE=0",
"-DU_ENABLE_DYLOAD=0",
"-DICU_UTIL_DATA_IMPL=ICU_UTIL_DATA_FILE",
"-DUCHAR_TYPE=uint16_t",
"-DGOOGLE_PROTOBUF_NO_RTTI",
"-DGOOGLE_PROTOBUF_NO_STATIC_INITIALIZER",
"-DHAVE_PTHREAD",
"-DPROTOBUF_USE_DLLS",
"-DSK_IGNORE_LINEONLY_AA_CONVEX_PATH_OPTS",
"-DSK_HAS_PNG_LIBRARY",
"-DSK_HAS_WEBP_LIBRARY",
"-DSK_HAS_JPEG_LIBRARY",
"-DSKIA_DLL",
"-DGR_GL_IGNORE_ES3_MSAA=0",
"-DSK_SUPPORT_GPU=1",
"-DMESA_EGL_NO_X11_HEADERS",
"-DBORINGSSL_SHARED_LIBRARY",
"-DUSING_V8_SHARED",
"-I../..",
"-Igen",
"-I../../third_party/libwebp/src",
"-I../../third_party/khronos",
"-I../../gpu",
"-I../../third_party/ced/src",
"-I../../third_party/icu/source/common",
"-I../../third_party/icu/source/i18n",
"-I../../third_party/protobuf/src",
"-I../../skia/config",
"-I../../skia/ext",
"-I../../third_party/skia/include/c",
"-I../../third_party/skia/include/config",
"-I../../third_party/skia/include/core",
"-I../../third_party/skia/include/effects",
"-I../../third_party/skia/include/encode",
"-I../../third_party/skia/include/gpu",
"-I../../third_party/skia/include/images",
"-I../../third_party/skia/include/lazy",
"-I../../third_party/skia/include/pathops",
"-I../../third_party/skia/include/pdf",
"-I../../third_party/skia/include/pipe",
"-I../../third_party/skia/include/ports",
"-I../../third_party/skia/include/utils",
"-I../../third_party/skia/third_party/vulkan",
"-I../../third_party/skia/src/gpu",
"-I../../third_party/skia/src/sksl",
"-I../../third_party/mesa/src/include",
"-I../../third_party/libwebm/source",
"-I../../third_party/protobuf/src",
"-Igen/protoc_out",
"-I../../third_party/boringssl/src/include",
"-I../../build/linux/debian_jessie_amd64-sysroot/usr/include/nss",
"-I../../build/linux/debian_jessie_amd64-sysroot/usr/include/nspr",
"-Igen",
"-I../../third_party/WebKit",
"-Igen/third_party/WebKit",
"-I../../v8/include",
"-Igen/v8/include",
"-Igen",
"-I../../third_party/flatbuffers/src/include",
"-Igen",
"-fno-strict-aliasing",
"-Wno-builtin-macro-redefined",
"-D__DATE__=",
"-D__TIME__=",
"-D__TIMESTAMP__=",
"-funwind-tables",
"-fPIC",
"-pipe",
"-B../../third_party/binutils/Linux_x64/Release/bin",
"-pthread",
"-fcolor-diagnostics",
"-m64",
"-march=x86-64",
"-Wall",
"-Werror",
"-Wextra",
"-Wno-missing-field-initializers",
"-Wno-unused-parameter",
"-Wno-c++11-narrowing",
"-Wno-covered-switch-default",
"-Wno-unneeded-internal-declaration",
"-Wno-inconsistent-missing-override",
"-Wno-undefined-var-template",
"-Wno-nonportable-include-path",
"-Wno-address-of-packed-member",
"-Wno-unused-lambda-capture",
"-Wno-user-defined-warnings",
"-Wno-enum-compare-switch",
"-O2",
"-fno-ident",
"-fdata-sections",
"-ffunction-sections",
"-fno-omit-frame-pointer",
"-g0",
"-fvisibility=hidden",
"-Xclang",
"-load",
"-Xclang",
"../../third_party/llvm-build/Release+Asserts/lib/"
"libFindBadConstructs.so",
"-Xclang",
"-add-plugin",
"-Xclang",
"find-bad-constructs",
"-Xclang",
"-plugin-arg-find-bad-constructs",
"-Xclang",
"check-auto-raw-pointer",
"-Xclang",
"-plugin-arg-find-bad-constructs",
"-Xclang",
"check-ipc",
"-Wheader-hygiene",
"-Wstring-conversion",
"-Wtautological-overlap-compare",
"-Wexit-time-destructors",
"-Wno-header-guard",
"-Wno-exit-time-destructors",
"-std=gnu++14",
"-fno-rtti",
"-nostdinc++",
"-isystem../../buildtools/third_party/libc++/trunk/include",
"-isystem../../buildtools/third_party/libc++abi/trunk/include",
"--sysroot=../../build/linux/debian_jessie_amd64-sysroot",
"-fno-exceptions",
"-fvisibility-inlines-hidden",
"../../apps/app_lifetime_monitor.cc"},
2017-11-19 18:05:06 +00:00
/* expected */
{"../../third_party/llvm-build/Release+Asserts/bin/clang++",
"-working-directory",
"/w/c/s/out/Release",
"-xc++",
2017-11-19 22:11:54 +00:00
"-DV8_DEPRECATION_WARNINGS",
"-DDCHECK_ALWAYS_ON=1",
"-DUSE_UDEV",
"-DUSE_ASH=1",
"-DUSE_AURA=1",
"-DUSE_NSS_CERTS=1",
"-DUSE_OZONE=1",
"-DDISABLE_NACL",
"-DFULL_SAFE_BROWSING",
"-DSAFE_BROWSING_CSD",
"-DSAFE_BROWSING_DB_LOCAL",
"-DCHROMIUM_BUILD",
"-DFIELDTRIAL_TESTING_ENABLED",
"-DCR_CLANG_REVISION=\"310694-1\"",
"-D_FILE_OFFSET_BITS=64",
"-D_LARGEFILE_SOURCE",
"-D_LARGEFILE64_SOURCE",
"-D__STDC_CONSTANT_MACROS",
"-D__STDC_FORMAT_MACROS",
"-DCOMPONENT_BUILD",
"-DOS_CHROMEOS",
"-DNDEBUG",
"-DNVALGRIND",
"-DDYNAMIC_ANNOTATIONS_ENABLED=0",
"-DGL_GLEXT_PROTOTYPES",
"-DUSE_GLX",
"-DUSE_EGL",
"-DANGLE_ENABLE_RELEASE_ASSERTS",
"-DTOOLKIT_VIEWS=1",
"-DV8_USE_EXTERNAL_STARTUP_DATA",
"-DU_USING_ICU_NAMESPACE=0",
"-DU_ENABLE_DYLOAD=0",
"-DICU_UTIL_DATA_IMPL=ICU_UTIL_DATA_FILE",
"-DUCHAR_TYPE=uint16_t",
"-DGOOGLE_PROTOBUF_NO_RTTI",
"-DGOOGLE_PROTOBUF_NO_STATIC_INITIALIZER",
"-DHAVE_PTHREAD",
"-DPROTOBUF_USE_DLLS",
"-DSK_IGNORE_LINEONLY_AA_CONVEX_PATH_OPTS",
"-DSK_HAS_PNG_LIBRARY",
"-DSK_HAS_WEBP_LIBRARY",
"-DSK_HAS_JPEG_LIBRARY",
"-DSKIA_DLL",
"-DGR_GL_IGNORE_ES3_MSAA=0",
"-DSK_SUPPORT_GPU=1",
"-DMESA_EGL_NO_X11_HEADERS",
"-DBORINGSSL_SHARED_LIBRARY",
"-DUSING_V8_SHARED",
"-I../..",
"-Igen",
"-I../../third_party/libwebp/src",
"-I../../third_party/khronos",
"-I../../gpu",
"-I../../third_party/ced/src",
"-I../../third_party/icu/source/common",
"-I../../third_party/icu/source/i18n",
"-I../../third_party/protobuf/src",
"-I../../skia/config",
"-I../../skia/ext",
"-I../../third_party/skia/include/c",
"-I../../third_party/skia/include/config",
"-I../../third_party/skia/include/core",
"-I../../third_party/skia/include/effects",
"-I../../third_party/skia/include/encode",
"-I../../third_party/skia/include/gpu",
"-I../../third_party/skia/include/images",
"-I../../third_party/skia/include/lazy",
"-I../../third_party/skia/include/pathops",
"-I../../third_party/skia/include/pdf",
"-I../../third_party/skia/include/pipe",
"-I../../third_party/skia/include/ports",
"-I../../third_party/skia/include/utils",
"-I../../third_party/skia/third_party/vulkan",
"-I../../third_party/skia/src/gpu",
"-I../../third_party/skia/src/sksl",
"-I../../third_party/mesa/src/include",
"-I../../third_party/libwebm/source",
"-I../../third_party/protobuf/src",
"-Igen/protoc_out",
"-I../../third_party/boringssl/src/include",
"-I../../build/linux/debian_jessie_amd64-sysroot/"
2017-11-19 22:11:54 +00:00
"usr/include/nss",
"-I../../build/linux/debian_jessie_amd64-sysroot/"
2017-11-19 22:11:54 +00:00
"usr/include/nspr",
"-Igen",
"-I../../third_party/WebKit",
"-Igen/third_party/WebKit",
"-I../../v8/include",
"-Igen/v8/include",
"-Igen",
"-I../../third_party/flatbuffers/src/include",
"-Igen",
2017-11-19 22:11:54 +00:00
"-fno-strict-aliasing",
"-Wno-builtin-macro-redefined",
"-D__DATE__=",
"-D__TIME__=",
"-D__TIMESTAMP__=",
"-funwind-tables",
"-fPIC",
"-pipe",
"-B../../third_party/binutils/Linux_x64/Release/bin",
"-pthread",
"-fcolor-diagnostics",
"-m64",
"-march=x86-64",
"-Wall",
"-Werror",
"-Wextra",
"-Wno-missing-field-initializers",
"-Wno-unused-parameter",
"-Wno-c++11-narrowing",
"-Wno-covered-switch-default",
"-Wno-unneeded-internal-declaration",
"-Wno-inconsistent-missing-override",
"-Wno-undefined-var-template",
"-Wno-nonportable-include-path",
"-Wno-address-of-packed-member",
"-Wno-unused-lambda-capture",
"-Wno-user-defined-warnings",
"-Wno-enum-compare-switch",
"-O2",
"-fno-ident",
"-fdata-sections",
"-ffunction-sections",
"-fno-omit-frame-pointer",
"-g0",
"-fvisibility=hidden",
"-Wheader-hygiene",
"-Wstring-conversion",
"-Wtautological-overlap-compare",
"-Wexit-time-destructors",
"-Wno-header-guard",
"-Wno-exit-time-destructors",
"-std=gnu++14",
"-fno-rtti",
"-nostdinc++",
"-isystem../../buildtools/third_party/libc++/"
2017-11-19 22:11:54 +00:00
"trunk/"
"include",
"-isystem../../buildtools/third_party/libc++abi/"
2017-11-19 22:11:54 +00:00
"trunk/"
"include",
"--sysroot=&/w/c/s/out/Release/../../build/linux/"
2017-11-19 22:11:54 +00:00
"debian_jessie_amd64-sysroot",
"-fno-exceptions",
"-fvisibility-inlines-hidden",
"&/w/c/s/out/Release/../../apps/app_lifetime_monitor.cc",
2017-12-01 18:11:09 +00:00
"-resource-dir=/w/resource_dir/",
"-Wno-unknown-warning-option"});
2017-11-19 18:05:06 +00:00
}
2017-11-19 18:05:06 +00:00
TEST_CASE("Directory extraction") {
Config init_opts;
2017-11-19 18:05:06 +00:00
ProjectConfig config;
config.project_dir = "/w/c/s/";
2017-11-19 18:05:06 +00:00
CompileCommandsEntry entry;
entry.directory = "/base";
entry.args = {"clang",
"-I/a_absolute1",
"--foobar",
"-I",
"/a_absolute2",
"--foobar",
"-Ia_relative1",
"--foobar",
"-I",
"a_relative2",
"--foobar",
"-iquote/q_absolute1",
"--foobar",
"-iquote",
"/q_absolute2",
"--foobar",
"-iquoteq_relative1",
"--foobar",
"-iquote",
"q_relative2",
"--foobar",
"foo.cc"};
entry.file = "foo.cc";
Project::Entry result =
GetCompilationEntryFromCompileCommandEntry(&init_opts, &config, entry);
2017-11-19 18:05:06 +00:00
std::unordered_set<std::string> angle_expected{
"&/a_absolute1", "&/a_absolute2", "&/base/a_relative1",
"&/base/a_relative2"};
std::unordered_set<std::string> quote_expected{
"&/q_absolute1", "&/q_absolute2", "&/base/q_relative1",
"&/base/q_relative2"};
REQUIRE(config.angle_dirs == angle_expected);
REQUIRE(config.quote_dirs == quote_expected);
}
2017-11-19 18:05:06 +00:00
TEST_CASE("Entry inference") {
Project p;
{
Project::Entry e;
e.args = {"arg1"};
e.filename = "/a/b/c/d/bar.cc";
p.entries.push_back(e);
}
{
Project::Entry e;
e.args = {"arg2"};
e.filename = "/a/b/c/baz.cc";
p.entries.push_back(e);
}
2017-11-19 18:05:06 +00:00
// Guess at same directory level, when there are parent directories.
{
optional<Project::Entry> entry =
p.FindCompilationEntryForFile("/a/b/c/d/new.cc");
REQUIRE(entry.has_value());
REQUIRE(entry->args == std::vector<std::string>{"arg1"});
}
2017-11-19 18:05:06 +00:00
// Guess at same directory level, when there are child directories.
{
optional<Project::Entry> entry =
p.FindCompilationEntryForFile("/a/b/c/new.cc");
REQUIRE(entry.has_value());
REQUIRE(entry->args == std::vector<std::string>{"arg2"});
}
2017-11-19 18:05:06 +00:00
// Guess at new directory (use the closest parent directory).
{
optional<Project::Entry> entry =
p.FindCompilationEntryForFile("/a/b/c/new/new.cc");
REQUIRE(entry.has_value());
REQUIRE(entry->args == std::vector<std::string>{"arg2"});
}
}
TEST_CASE("Entry inference remaps file names") {
Project p;
{
Project::Entry e;
e.args = {"a", "b", "aaaa.cc", "d"};
e.filename = "absolute/aaaa.cc";
p.entries.push_back(e);
}
{
optional<Project::Entry> entry = p.FindCompilationEntryForFile("ee.cc");
REQUIRE(entry.has_value());
REQUIRE(entry->args == std::vector<std::string>{"a", "b", "ee.cc", "d"});
}
}
2017-11-19 18:05:06 +00:00
TEST_CASE("Entry inference prefers same file endings") {
Project p;
{
Project::Entry e;
e.args = {"arg1"};
e.filename = "common/simple_browsertest.cc";
p.entries.push_back(e);
}
{
Project::Entry e;
e.args = {"arg2"};
e.filename = "common/simple_unittest.cc";
p.entries.push_back(e);
}
{
Project::Entry e;
e.args = {"arg3"};
e.filename = "common/a/simple_unittest.cc";
p.entries.push_back(e);
}
// Prefer files with the same ending.
{
optional<Project::Entry> entry =
p.FindCompilationEntryForFile("my_browsertest.cc");
REQUIRE(entry.has_value());
REQUIRE(entry->args == std::vector<std::string>{"arg1"});
}
{
optional<Project::Entry> entry =
p.FindCompilationEntryForFile("my_unittest.cc");
REQUIRE(entry.has_value());
REQUIRE(entry->args == std::vector<std::string>{"arg2"});
}
{
optional<Project::Entry> entry =
p.FindCompilationEntryForFile("common/my_browsertest.cc");
REQUIRE(entry.has_value());
REQUIRE(entry->args == std::vector<std::string>{"arg1"});
}
{
optional<Project::Entry> entry =
p.FindCompilationEntryForFile("common/my_unittest.cc");
REQUIRE(entry.has_value());
REQUIRE(entry->args == std::vector<std::string>{"arg2"});
}
2017-11-19 18:05:06 +00:00
// Prefer the same directory over matching file-ending.
{
optional<Project::Entry> entry =
p.FindCompilationEntryForFile("common/a/foo.cc");
REQUIRE(entry.has_value());
REQUIRE(entry->args == std::vector<std::string>{"arg3"});
}
}
}