@@ -57,18 +57,16 @@ namespace CompilationUtils {
5757 }
5858 }
5959
60- void substituteRemotePathToCCJsonForFile (const fs::path &projectPath,
61- const std::string &buildDirRelativePath,
62- const std::string &jsonFileName,
63- const fs::path &newJsonDir) {
64- fs::path compileCommandsJsonPath = projectPath / buildDirRelativePath / jsonFileName;
65- fs::create_directories (newJsonDir);
60+ void substituteRemotePathToCCJsonForFile (const utbot::ProjectContext &projectContext,
61+ const std::string &jsonFileName) {
62+ fs::path compileCommandsJsonPath = projectContext.buildDir () / jsonFileName;
63+ fs::create_directories (Paths::getUTBotBuildDir (projectContext));
6664 if (!fs::exists (compileCommandsJsonPath)) {
6765 throw CompilationDatabaseException (" Can't find " + compileCommandsJsonPath.string ());
6866 }
6967 std::ifstream ifs (compileCommandsJsonPath);
7068 json json = json::parse (ifs);
71- std::string projectPathStr = Paths::normalizedTrimmed (fs::absolute (projectPath)).string ();
69+ std::string projectPathStr = Paths::normalizedTrimmed (fs::absolute (projectContext. projectPath )).string ();
7270 Paths::removeBackTrailedSlash (projectPathStr);
7371
7472 const std::string directoryFieldName = " directory" ;
@@ -79,8 +77,7 @@ namespace CompilationUtils {
7977
8078 for (auto &cmd : json) {
8179 std::string directoryField = cmd[directoryFieldName];
82- std::string userSystemProjectPath =
83- Paths::subtractPath (directoryField, buildDirRelativePath);
80+ std::string userSystemProjectPath = Paths::normalizedTrimmed (projectContext.clientProjectPath );
8481 Paths::removeBackTrailedSlash (userSystemProjectPath);
8582
8683 if (cmd.contains (commandFieldName)) {
@@ -106,25 +103,23 @@ namespace CompilationUtils {
106103 } else {
107104 for (auto ¤tFile : cmd[filesFieldName]) {
108105 std::string currentFileField = currentFile;
109- StringUtils::replaceAll (currentFileField, userSystemProjectPath,
110- projectPathStr);
106+ StringUtils::replaceAll (currentFileField, userSystemProjectPath, projectPathStr);
111107 currentFile = currentFileField;
112108 }
113109 }
114110 }
115- fs::path newJsonPath = newJsonDir / jsonFileName;
111+ fs::path newJsonPath = Paths::getUTBotBuildDir (projectContext) / jsonFileName;
116112 JsonUtils::writeJsonToFile (newJsonPath, json);
117- LOG_S (DEBUG) << jsonFileName << " for mount is written to: " << newJsonDir ;
113+ LOG_S (DEBUG) << jsonFileName << " for mount is written to: " << newJsonPath ;
118114 }
119115
120116 fs::path substituteRemotePathToCompileCommandsJsonPath (const utbot::ProjectContext &projectContext) {
121117 const std::string ccJsonFileName = " compile_commands.json" ;
122- fs::path utbotBuildDir = Paths::getUTBotBuildDir (projectContext);
123- substituteRemotePathToCCJsonForFile (projectContext.projectPath , projectContext.buildDirRelativePath ,
124- ccJsonFileName, utbotBuildDir);
125- substituteRemotePathToCCJsonForFile (projectContext.projectPath , projectContext.buildDirRelativePath ,
126- " link_commands.json" , utbotBuildDir);
127- return utbotBuildDir;
118+ const std::string lcJsonFileName = " link_commands.json" ;
119+
120+ substituteRemotePathToCCJsonForFile (projectContext, ccJsonFileName);
121+ substituteRemotePathToCCJsonForFile (projectContext, lcJsonFileName);
122+ return Paths::getUTBotBuildDir (projectContext);
128123 }
129124
130125 fs::path getClangCompileCommandsJsonPath (const fs::path &buildCommandsJsonPath) {
0 commit comments