1. Make resource dir unique and global.
2. Use our custom CDB loader.
This commit is contained in:
19
include/Compiler/Command.h
Normal file
19
include/Compiler/Command.h
Normal file
@@ -0,0 +1,19 @@
|
||||
#pragma once
|
||||
|
||||
#include "Clang.h"
|
||||
|
||||
namespace clice {
|
||||
|
||||
/// Processes and adjusts a raw compile command from compile_commands.json.
|
||||
///
|
||||
/// This function tokenizes the input command, removes unnecessary arguments,
|
||||
/// and ensures the resulting format is suitable for execution.
|
||||
///
|
||||
/// @param command The raw shell-escaped compile command.
|
||||
/// @param out A vector to hold pointers to the processed arguments.
|
||||
/// @param buffer A storage buffer for the actual argument strings.
|
||||
llvm::Error mangleCommand(llvm::StringRef command,
|
||||
llvm::SmallVectorImpl<const char*>& out,
|
||||
llvm::SmallVectorImpl<char>& buffer);
|
||||
|
||||
} // namespace clice
|
||||
@@ -129,11 +129,17 @@ struct PCMInfo {
|
||||
};
|
||||
|
||||
struct CompliationParams {
|
||||
/// Source file content.
|
||||
llvm::StringRef content;
|
||||
|
||||
/// Source file path.
|
||||
llvm::SmallString<128> srcPath;
|
||||
|
||||
/// Source file content.
|
||||
llvm::StringRef content;
|
||||
/// Output file path.
|
||||
llvm::SmallString<128> outPath;
|
||||
|
||||
/// Responsible for storing the arguments.
|
||||
llvm::SmallString<1024> command;
|
||||
|
||||
/// - If we are building PCH, we need a size to verify the bounds of preamble. That is
|
||||
/// which source code range the PCH will cover.
|
||||
@@ -148,12 +154,6 @@ struct CompliationParams {
|
||||
/// - If the header is not empty, the preprocessor must be executed to compute the bounds.
|
||||
void computeBounds(llvm::StringRef header = "");
|
||||
|
||||
/// Command line arguments.
|
||||
llvm::ArrayRef<const char*> args;
|
||||
|
||||
/// Output file path.
|
||||
llvm::SmallString<128> outPath;
|
||||
|
||||
llvm::IntrusiveRefCntPtr<vfs::FileSystem> vfs = new ThreadSafeFS();
|
||||
|
||||
/// Information about reuse PCH.
|
||||
|
||||
@@ -9,9 +9,16 @@ class CommandManager {
|
||||
public:
|
||||
void update(llvm::StringRef dir);
|
||||
|
||||
std::vector<std::string> lookup(llvm::StringRef file);
|
||||
/// Return the commands of first meet file.
|
||||
llvm::StringRef lookupFirst(llvm::StringRef file);
|
||||
|
||||
llvm::ArrayRef<std::string> lookup(llvm::StringRef file);
|
||||
|
||||
private:
|
||||
llvm::StringMap<std::unique_ptr<clang::tooling::CompilationDatabase>> CDBs;
|
||||
/// CDB file -> file -> [commands]
|
||||
using Commands = std::vector<std::string>;
|
||||
using CDB = llvm::StringMap<Commands>;
|
||||
llvm::StringMap<CDB> CDBs;
|
||||
};
|
||||
|
||||
} // namespace clice
|
||||
|
||||
@@ -73,7 +73,7 @@ class Scheduler {
|
||||
private:
|
||||
async::promise<void> updatePCH(llvm::StringRef path,
|
||||
llvm::StringRef content,
|
||||
llvm::ArrayRef<const char*> args);
|
||||
llvm::StringRef command);
|
||||
|
||||
async::promise<void> updatePCM() {
|
||||
co_return;
|
||||
|
||||
@@ -7,10 +7,31 @@
|
||||
|
||||
namespace clice {
|
||||
|
||||
namespace vfs = llvm::vfs;
|
||||
namespace fs = llvm::sys::fs;
|
||||
namespace path = llvm::sys::path;
|
||||
|
||||
namespace fs {
|
||||
|
||||
using namespace llvm::sys::fs;
|
||||
|
||||
inline std::string resource_dir = "";
|
||||
|
||||
inline llvm::Error init_resource_dir(llvm::StringRef execute) {
|
||||
llvm::SmallString<128> path;
|
||||
path::append(path, path::parent_path(execute), "..");
|
||||
path::append(path, "lib", "clang", "20");
|
||||
|
||||
if(auto error = real_path(path, path)) {
|
||||
return llvm::make_error<llvm::StringError>(error.message(), error);
|
||||
}
|
||||
|
||||
resource_dir = path.str();
|
||||
return llvm::Error::success();
|
||||
}
|
||||
|
||||
} // namespace fs
|
||||
|
||||
namespace vfs = llvm::vfs;
|
||||
|
||||
class ThreadSafeFS : public vfs::ProxyFileSystem {
|
||||
public:
|
||||
explicit ThreadSafeFS() : ProxyFileSystem(vfs::createPhysicalFileSystem()) {}
|
||||
|
||||
Reference in New Issue
Block a user