Add remove and append options for CompilationDatabase (#268)
This commit is contained in:
@@ -11,6 +11,15 @@
|
||||
namespace clice {
|
||||
|
||||
struct CommandOptions {
|
||||
/// Ignore unknown commands.
|
||||
bool ignore_unknown = true;
|
||||
|
||||
/// The commands that you want to remove from original commands list.
|
||||
llvm::ArrayRef<std::string> remove;
|
||||
|
||||
/// The commands that you want to add to original commands list.
|
||||
llvm::ArrayRef<std::string> append;
|
||||
|
||||
/// Attach resource directory to the command.
|
||||
bool resource_dir = false;
|
||||
|
||||
@@ -19,7 +28,7 @@ struct CommandOptions {
|
||||
|
||||
/// Suppress the warning log if failed to query driver info.
|
||||
/// Set true in unittests to avoid cluttering test output.
|
||||
bool suppress_log = false;
|
||||
bool suppress_logging = false;
|
||||
};
|
||||
|
||||
class CompilationDatabase {
|
||||
@@ -39,6 +48,12 @@ public:
|
||||
|
||||
/// The canonical command list.
|
||||
llvm::ArrayRef<const char*> arguments;
|
||||
|
||||
/// The extra command @...
|
||||
llvm::StringRef response_file;
|
||||
|
||||
/// The original index of the response file argument in the command list.
|
||||
std::uint32_t response_file_index = 0;
|
||||
};
|
||||
|
||||
struct DriverInfo {
|
||||
@@ -81,6 +96,12 @@ public:
|
||||
|
||||
CompilationDatabase();
|
||||
|
||||
CompilationDatabase(CompilationDatabase&& other);
|
||||
|
||||
CompilationDatabase& operator= (CompilationDatabase&& other);
|
||||
|
||||
~CompilationDatabase();
|
||||
|
||||
auto save_string(this Self& self, llvm::StringRef string) -> llvm::StringRef;
|
||||
|
||||
auto save_cstring_list(this Self& self, llvm::ArrayRef<const char*> arguments)
|
||||
@@ -95,13 +116,13 @@ public:
|
||||
|
||||
/// Update with arguments.
|
||||
auto update_command(this Self& self,
|
||||
llvm::StringRef dictionary,
|
||||
llvm::StringRef directory,
|
||||
llvm::StringRef file,
|
||||
llvm::ArrayRef<const char*> arguments) -> UpdateInfo;
|
||||
|
||||
/// Update with full command.
|
||||
auto update_command(this Self& self,
|
||||
llvm::StringRef dictionary,
|
||||
llvm::StringRef directory,
|
||||
llvm::StringRef file,
|
||||
llvm::StringRef command) -> UpdateInfo;
|
||||
|
||||
@@ -109,6 +130,11 @@ public:
|
||||
auto load_commands(this Self& self, llvm::StringRef json_content, llvm::StringRef workspace)
|
||||
-> std::expected<std::vector<UpdateInfo>, std::string>;
|
||||
|
||||
auto process_command(this Self& self,
|
||||
llvm::StringRef file,
|
||||
const CommandInfo& info,
|
||||
const CommandOptions& options) -> std::vector<const char*>;
|
||||
|
||||
/// Get compile command from database. `file` should has relative path of workspace.
|
||||
auto get_command(this Self& self, llvm::StringRef file, CommandOptions options = {})
|
||||
-> LookupInfo;
|
||||
@@ -124,6 +150,9 @@ private:
|
||||
auto guess_or_fallback(this Self& self, llvm::StringRef file) -> LookupInfo;
|
||||
|
||||
private:
|
||||
/// The opaque handle of `ArgumentParser`.
|
||||
void* parser;
|
||||
|
||||
/// The memory pool to hold all cstring and command list.
|
||||
llvm::BumpPtrAllocator allocator;
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@ struct Tester {
|
||||
CommandOptions options;
|
||||
options.resource_dir = true;
|
||||
options.query_driver = true;
|
||||
options.suppress_log = true;
|
||||
options.suppress_logging = true;
|
||||
params.arguments = database.get_command(src_path, options).arguments;
|
||||
|
||||
for(auto& [file, source]: sources.all_files) {
|
||||
@@ -76,7 +76,7 @@ struct Tester {
|
||||
CommandOptions options;
|
||||
options.resource_dir = true;
|
||||
options.query_driver = true;
|
||||
options.suppress_log = true;
|
||||
options.suppress_logging = true;
|
||||
params.arguments = database.get_command(src_path, options).arguments;
|
||||
|
||||
auto path = fs::createTemporaryFile("clice", "pch");
|
||||
|
||||
Reference in New Issue
Block a user