From ecfa1b79206aa9f8af4a6e7160bda42ee14ac176 Mon Sep 17 00:00:00 2001 From: mlangkabel Date: Mon, 18 Jan 2021 22:00:05 +0100 Subject: [PATCH] split command line args for IndexerCommandCustom usages * this seems to be required when using the new QProcess API. * this also required to remove quotes that were added to path args because otherwise the Python indexer would mistake absolute paths for relative paths. --- .../expected_output/output_windows.txt | 21 ++++-- src/lib/data/indexer/IndexerCommandCustom.cpp | 53 ++++++++++----- src/lib/data/indexer/IndexerCommandCustom.h | 14 ++-- .../indexer/TaskExecuteCustomCommands.cpp | 14 ++-- src/lib/project/SourceGroupCustomCommand.cpp | 65 ++++++++++++++++++- .../content/QtProjectWizardContentSelect.cpp | 11 ++-- ...jectWizardContentPathPythonEnvironment.cpp | 11 ++-- .../cxx_header/CxxVs15HeaderPathDetector.cpp | 10 +-- .../cxx_header/utilityCxxHeaderDetection.cpp | 2 +- .../java_runtime/JavaPathDetectorLinux.cpp | 6 +- .../java_runtime/JavaPathDetectorMac.cpp | 2 +- .../MavenPathDetectorUnix.cpp | 2 +- .../MavenPathDetectorWindows.cpp | 4 +- src/lib_gui/utility/utilityApp.cpp | 15 ++++- .../project/SourceGroupPythonEmpty.cpp | 20 +++--- src/test/PythonIndexerTestSuite.cpp | 19 ++++-- src/test/SourceGroupTestSuite.cpp | 10 ++- 17 files changed, 203 insertions(+), 76 deletions(-) diff --git a/bin/test/data/SourceGroupTestSuite/custom_command/expected_output/output_windows.txt b/bin/test/data/SourceGroupTestSuite/custom_command/expected_output/output_windows.txt index 552d7d1e..a8329015 100644 --- a/bin/test/data/SourceGroupTestSuite/custom_command/expected_output/output_windows.txt +++ b/bin/test/data/SourceGroupTestSuite/custom_command/expected_output/output_windows.txt @@ -1,6 +1,15 @@ -SourceFilePath: "src/a.txt" - Custom Command: "echo "Hello World"" -SourceFilePath: "src/b.txt" - Custom Command: "echo "Hello World"" -SourceFilePath: "src/included/a.txt" - Custom Command: "echo "Hello World"" +IndexerCommandCustom + SourceFilePath: "src/a.txt" + Custom Command: "echo" + Arguments: + "Hello World" +IndexerCommandCustom + SourceFilePath: "src/b.txt" + Custom Command: "echo" + Arguments: + "Hello World" +IndexerCommandCustom + SourceFilePath: "src/included/a.txt" + Custom Command: "echo" + Arguments: + "Hello World" diff --git a/src/lib/data/indexer/IndexerCommandCustom.cpp b/src/lib/data/indexer/IndexerCommandCustom.cpp index bf9759a1..fc131439 100644 --- a/src/lib/data/indexer/IndexerCommandCustom.cpp +++ b/src/lib/data/indexer/IndexerCommandCustom.cpp @@ -11,7 +11,8 @@ IndexerCommandType IndexerCommandCustom::getStaticIndexerCommandType() } IndexerCommandCustom::IndexerCommandCustom( - const std::wstring& customCommand, + const std::wstring& command, + const std::vector& arguments, const FilePath& projectFilePath, const FilePath& databaseFilePath, const std::wstring& databaseVersion, @@ -19,7 +20,8 @@ IndexerCommandCustom::IndexerCommandCustom( bool runInParallel) : IndexerCommand(sourceFilePath) , m_type(getStaticIndexerCommandType()) - , m_customCommand(customCommand) + , m_command(command) + , m_arguments(arguments) , m_projectFilePath(projectFilePath) , m_databaseFilePath(databaseFilePath) , m_databaseVersion(databaseVersion) @@ -29,7 +31,8 @@ IndexerCommandCustom::IndexerCommandCustom( IndexerCommandCustom::IndexerCommandCustom( IndexerCommandType type, - const std::wstring& customCommand, + const std::wstring& command, + const std::vector& arguments, const FilePath& projectFilePath, const FilePath& databaseFilePath, const std::wstring& databaseVersion, @@ -37,7 +40,8 @@ IndexerCommandCustom::IndexerCommandCustom( bool runInParallel) : IndexerCommand(sourceFilePath) , m_type(type) - , m_customCommand(customCommand) + , m_command(command) + , m_arguments(arguments) , m_projectFilePath(projectFilePath) , m_databaseFilePath(databaseFilePath) , m_databaseVersion(databaseVersion) @@ -67,19 +71,19 @@ void IndexerCommandCustom::setDatabaseFilePath(const FilePath& databaseFilePath) m_databaseFilePath = databaseFilePath; } -std::wstring IndexerCommandCustom::getCustomCommand() const +std::wstring IndexerCommandCustom::getCommand() const { - std::wstring command = m_customCommand; + return replaceVariables(m_command); +} - command = utility::replace( - command, L"%{PROJECT_FILE_PATH}", L'\"' + m_projectFilePath.wstr() + L'\"'); - command = utility::replace( - command, L"%{DATABASE_FILE_PATH}", L'\"' + m_databaseFilePath.wstr() + L'\"'); - command = utility::replace(command, L"%{DATABASE_VERSION}", L'\"' + m_databaseVersion + L'\"'); - command = utility::replace( - command, L"%{SOURCE_FILE_PATH}", L'\"' + getSourceFilePath().wstr() + L'\"'); - - return command; +std::vector IndexerCommandCustom::getArguments() const +{ + std::vector args; + for (const std::wstring& argument: m_arguments) + { + args.push_back(replaceVariables(argument)); + } + return args; } bool IndexerCommandCustom::getRunInParallel() const @@ -92,7 +96,15 @@ QJsonObject IndexerCommandCustom::doSerialize() const QJsonObject jsonObject = IndexerCommand::doSerialize(); { - jsonObject["custom_command"] = QString::fromStdWString(m_customCommand); + jsonObject["command"] = QString::fromStdWString(m_command); + } + { + QJsonArray argumentsArray; + for (const std::wstring& argument: m_arguments) + { + argumentsArray.append(QString::fromStdWString(argument)); + } + jsonObject["arguments"] = argumentsArray; } { jsonObject["run_in_parallel"] = m_runInParallel; @@ -100,3 +112,12 @@ QJsonObject IndexerCommandCustom::doSerialize() const return jsonObject; } + +std::wstring IndexerCommandCustom::replaceVariables(std::wstring s) const +{ + s = utility::replace(s, L"%{PROJECT_FILE_PATH}", m_projectFilePath.wstr()); + s = utility::replace(s, L"%{DATABASE_FILE_PATH}", m_databaseFilePath.wstr()); + s = utility::replace(s, L"%{DATABASE_VERSION}", m_databaseVersion); + s = utility::replace(s, L"%{SOURCE_FILE_PATH}", getSourceFilePath().wstr()); + return s; +} diff --git a/src/lib/data/indexer/IndexerCommandCustom.h b/src/lib/data/indexer/IndexerCommandCustom.h index c0a007be..6b8c4032 100644 --- a/src/lib/data/indexer/IndexerCommandCustom.h +++ b/src/lib/data/indexer/IndexerCommandCustom.h @@ -12,7 +12,8 @@ public: static IndexerCommandType getStaticIndexerCommandType(); IndexerCommandCustom( - const std::wstring& customCommand, + const std::wstring& command, + const std::vector& arguments, const FilePath& projectFilePath, const FilePath& databaseFilePath, const std::wstring& databaseVersion, @@ -21,7 +22,8 @@ public: IndexerCommandCustom( IndexerCommandType type, - const std::wstring& customCommand, + const std::wstring& command, + const std::vector& arguments, const FilePath& projectFilePath, const FilePath& databaseFilePath, const std::wstring& databaseVersion, @@ -34,15 +36,19 @@ public: FilePath getDatabaseFilePath() const; void setDatabaseFilePath(const FilePath& databaseFilePath); - std::wstring getCustomCommand() const; + std::wstring getCommand() const; + std::vector getArguments() const; bool getRunInParallel() const; protected: QJsonObject doSerialize() const override; private: + std::wstring replaceVariables(std::wstring s) const; + IndexerCommandType m_type; - std::wstring m_customCommand; + std::wstring m_command; + std::vector m_arguments; FilePath m_projectFilePath; FilePath m_databaseFilePath; std::wstring m_databaseVersion; diff --git a/src/lib/data/indexer/TaskExecuteCustomCommands.cpp b/src/lib/data/indexer/TaskExecuteCustomCommands.cpp index 0ad359e4..0e858c2f 100644 --- a/src/lib/data/indexer/TaskExecuteCustomCommands.cpp +++ b/src/lib/data/indexer/TaskExecuteCustomCommands.cpp @@ -465,9 +465,12 @@ void TaskExecuteCustomCommands::runIndexerCommand( indexedSourceFileCount + 1, indexedSourceFileCount, m_indexerCommandCount, {sourcePath}); MessageIndexingStatus(true, indexedSourceFileCount * 100 / m_indexerCommandCount).dispatch(); - const std::wstring command = indexerCommand->getCustomCommand(); + const std::wstring command = indexerCommand->getCommand(); + const std::vector arguments = indexerCommand->getArguments(); - LOG_INFO("Start processing command \"" + utility::encodeToUtf8(command) + "\""); + LOG_INFO( + "Start processing command \"" + + utility::encodeToUtf8(command + L" " + utility::join(arguments, L" ")) + "\""); const ErrorCountInfo previousErrorCount = storage ? storage->getErrorCount() : ErrorCountInfo(); @@ -475,7 +478,7 @@ void TaskExecuteCustomCommands::runIndexerCommand( LOG_INFO("Starting to index"); std::wstring errorMessage; const int result = utility::executeProcessAndGetExitCode( - command, {}, m_projectDirectory, -1, true, &errorMessage); + command, arguments, m_projectDirectory, -1, true, &errorMessage); LOG_INFO("Finished indexing"); if (storage) @@ -508,8 +511,9 @@ void TaskExecuteCustomCommands::runIndexerCommand( } else { - std::wstring statusText = L"command \"" + indexerCommand->getCustomCommand() + - L"\" returned"; + std::wstring statusText = L"command \"" + indexerCommand->getCommand() + L" " + + utility::join(arguments, L" ") + L"\" returned"; + if (result != 0) { statusText += L" code \"" + std::to_wstring(result) + L"\""; diff --git a/src/lib/project/SourceGroupCustomCommand.cpp b/src/lib/project/SourceGroupCustomCommand.cpp index 27abf4b8..00b525a8 100644 --- a/src/lib/project/SourceGroupCustomCommand.cpp +++ b/src/lib/project/SourceGroupCustomCommand.cpp @@ -42,7 +42,67 @@ std::set SourceGroupCustomCommand::getAllSourceFilePaths() const std::vector> SourceGroupCustomCommand::getIndexerCommands( const RefreshInfo& info) const { - const std::wstring customCommand = m_settings->getCustomCommand(); + std::vector parts; + { + const std::wstring customCommand = m_settings->getCustomCommand(); + + std::wstring tmp; + int quoteCount = 0; + bool inQuote = false; + // handle quoting. tokens can be surrounded by double quotes + // "hello world". three consecutive double quotes represent + // the quote character itself. + for (int i = 0; i < customCommand.size(); ++i) + { + if (customCommand.at(i) == L'"') + { + ++quoteCount; + if (quoteCount == 3) // third consecutive quote + { + quoteCount = 0; + tmp += customCommand.at(i); + } + continue; + } + if (quoteCount) + { + if (quoteCount == 1) + { + inQuote = !inQuote; + } + quoteCount = 0; + } + if (!inQuote && customCommand.at(i) == L' ') + { + if (!tmp.empty()) + { + parts.push_back(tmp); + tmp.clear(); + } + } + else + { + tmp += customCommand.at(i); + } + } + if (!tmp.empty()) + { + parts.push_back(tmp); + } + } + + if (parts.empty()) + { + return {}; + } + + const std::wstring command = parts.front(); + std::vector args; + for (size_t i = 1; i < parts.size(); i++) + { + args.push_back(parts[i]); + } + const bool runInParallel = m_settings->getRunInParallel(); std::vector> indexerCommands; @@ -51,7 +111,8 @@ std::vector> SourceGroupCustomCommand::getIndexe if (info.filesToIndex.find(sourcePath) != info.filesToIndex.end()) { indexerCommands.push_back(std::make_shared( - customCommand, + command, + args, m_settings->getProjectSettings()->getProjectFilePath(), m_settings->getProjectSettings()->getTempDBFilePath(), std::to_wstring(SqliteIndexStorage::getStorageVersion()), diff --git a/src/lib_gui/qt/project_wizard/content/QtProjectWizardContentSelect.cpp b/src/lib_gui/qt/project_wizard/content/QtProjectWizardContentSelect.cpp index 02b6eb0e..9c3b1326 100644 --- a/src/lib_gui/qt/project_wizard/content/QtProjectWizardContentSelect.cpp +++ b/src/lib_gui/qt/project_wizard/content/QtProjectWizardContentSelect.cpp @@ -24,12 +24,13 @@ void QtProjectWizardContentSelect::populate(QGridLayout* layout, int& row) { std::string pythonIndexerVersion = " "; { - std::string str = utility::executeProcess( + std::string str = + utility::executeProcess( ResourcePaths::getPythonPath().wstr().append(L"SourcetrailPythonIndexer"), - std::vector{L"--version"}, - FilePath(), - 5000) - .second; + {L"--version"}, + FilePath(), + 5000) + .second; std::regex regex( "v\\d*\\.db\\d*\\.p\\d*"); // "\\d" matches any digit; "\\." matches the "." character std::smatch matches; diff --git a/src/lib_gui/qt/project_wizard/content/path/QtProjectWizardContentPathPythonEnvironment.cpp b/src/lib_gui/qt/project_wizard/content/path/QtProjectWizardContentPathPythonEnvironment.cpp index deed2011..d8f1a5fa 100644 --- a/src/lib_gui/qt/project_wizard/content/path/QtProjectWizardContentPathPythonEnvironment.cpp +++ b/src/lib_gui/qt/project_wizard/content/path/QtProjectWizardContentPathPythonEnvironment.cpp @@ -64,12 +64,11 @@ void QtProjectWizardContentPathPythonEnvironment::onTextChanged(const QString& t std::thread([=]() { std::pair out = utility::executeProcess( ResourcePaths::getPythonPath().wstr().append(L"SourcetrailPythonIndexer"), - std::vector{ - L"check-environment", - L"--environment-path " + utility::getExpandedAndAbsolutePath( - FilePath(text.toStdWString()), m_settings->getProjectDirectoryPath()) - .wstr() - }, + {L"check-environment", + L"--environment-path " + + utility::getExpandedAndAbsolutePath( + FilePath(text.toStdWString()), m_settings->getProjectDirectoryPath()) + .wstr()}, FilePath(), 5000); m_onQtThread([=]() { diff --git a/src/lib_gui/utility/path_detector/cxx_header/CxxVs15HeaderPathDetector.cpp b/src/lib_gui/utility/path_detector/cxx_header/CxxVs15HeaderPathDetector.cpp index 89459917..b3b4c508 100644 --- a/src/lib_gui/utility/path_detector/cxx_header/CxxVs15HeaderPathDetector.cpp +++ b/src/lib_gui/utility/path_detector/cxx_header/CxxVs15HeaderPathDetector.cpp @@ -20,10 +20,12 @@ std::vector CxxVs15HeaderPathDetector::doGetPaths() const .expandEnvironmentVariables(); if (!expandedPaths.empty()) { - const std::string output = - utility::executeProcess( - expandedPaths[0].wstr(), std::vector {L"-latest", L"-property installationPath"}, FilePath(), 10000) - .second; + const std::string output = utility::executeProcess( + expandedPaths[0].wstr(), + {L"-latest", L"-property installationPath"}, + FilePath(), + 10000) + .second; const FilePath vsInstallPath(output); if (vsInstallPath.exists()) diff --git a/src/lib_gui/utility/path_detector/cxx_header/utilityCxxHeaderDetection.cpp b/src/lib_gui/utility/path_detector/cxx_header/utilityCxxHeaderDetection.cpp index 7f1d36c1..7dddf93f 100644 --- a/src/lib_gui/utility/path_detector/cxx_header/utilityCxxHeaderDetection.cpp +++ b/src/lib_gui/utility/path_detector/cxx_header/utilityCxxHeaderDetection.cpp @@ -14,7 +14,7 @@ std::vector getCxxHeaderPaths(const std::string& compilerName) std::string command = compilerName + " -x c++ -v -E /dev/null"; std::string clangOutput = utility::executeProcess( utility::decodeFromUtf8(compilerName), - std::vector {L"-x c++", L"-v", L"-E /dev/null"}) + {L"-x c++", L"-v", L"-E /dev/null"}) .second; std::string standardHeaders = utility::substrBetween( clangOutput, "#include <...> search starts here:\n", "\nEnd of search list"); diff --git a/src/lib_gui/utility/path_detector/java_runtime/JavaPathDetectorLinux.cpp b/src/lib_gui/utility/path_detector/java_runtime/JavaPathDetectorLinux.cpp index 500dd89f..c60f6a2b 100644 --- a/src/lib_gui/utility/path_detector/java_runtime/JavaPathDetectorLinux.cpp +++ b/src/lib_gui/utility/path_detector/java_runtime/JavaPathDetectorLinux.cpp @@ -54,7 +54,7 @@ std::vector JavaPathDetectorLinux::doGetPaths() const FilePath JavaPathDetectorLinux::getJavaInPath() const { - std::string output = utility::executeProcess(L"which", std::vector{L"java"}).second; + std::string output = utility::executeProcess(L"which", {L"java"}).second; if (!output.empty()) { @@ -72,7 +72,7 @@ FilePath JavaPathDetectorLinux::getJavaInPath() const FilePath JavaPathDetectorLinux::readLink(const FilePath& path) const { - FilePath javaPath(utility::executeProcess(L"readlink", std::vector{L"-f " + path.wstr()}).second); + FilePath javaPath(utility::executeProcess(L"readlink", {L"-f " + path.wstr()}).second); if (!javaPath.empty()) { return javaPath; @@ -113,7 +113,7 @@ FilePath JavaPathDetectorLinux::getJavaInJavaHome() const bool JavaPathDetectorLinux::checkVersion(const FilePath& path) const { - std::string output = utility::executeProcess(path.wstr(), std::vector{L"-version"}).second; + std::string output = utility::executeProcess(path.wstr(), {L"-version"}).second; return output.find(m_javaVersion) != std::string::npos; } diff --git a/src/lib_gui/utility/path_detector/java_runtime/JavaPathDetectorMac.cpp b/src/lib_gui/utility/path_detector/java_runtime/JavaPathDetectorMac.cpp index 33c19d40..51416c00 100644 --- a/src/lib_gui/utility/path_detector/java_runtime/JavaPathDetectorMac.cpp +++ b/src/lib_gui/utility/path_detector/java_runtime/JavaPathDetectorMac.cpp @@ -14,7 +14,7 @@ std::vector JavaPathDetectorMac::doGetPaths() const std::vector paths; FilePath javaPath; - std::string output = utility::executeProcess(L"/usr/libexec/java_home", std::vector{}).second; + const std::string output = utility::executeProcess(L"/usr/libexec/java_home", {}).second; if (!output.empty()) { diff --git a/src/lib_gui/utility/path_detector/maven_executable/MavenPathDetectorUnix.cpp b/src/lib_gui/utility/path_detector/maven_executable/MavenPathDetectorUnix.cpp index ca8af480..3dc8c774 100644 --- a/src/lib_gui/utility/path_detector/maven_executable/MavenPathDetectorUnix.cpp +++ b/src/lib_gui/utility/path_detector/maven_executable/MavenPathDetectorUnix.cpp @@ -7,7 +7,7 @@ MavenPathDetectorUnix::MavenPathDetectorUnix(): PathDetector("Maven for Unix") { std::vector MavenPathDetectorUnix::doGetPaths() const { - FilePath mavenPath(utility::executeProcess(L"which", std::vector{L"mvn"}).second); + FilePath mavenPath(utility::executeProcess(L"which", {L"mvn"}).second); std::vector paths; if (mavenPath.exists()) diff --git a/src/lib_gui/utility/path_detector/maven_executable/MavenPathDetectorWindows.cpp b/src/lib_gui/utility/path_detector/maven_executable/MavenPathDetectorWindows.cpp index 9da9edf6..f2759efd 100644 --- a/src/lib_gui/utility/path_detector/maven_executable/MavenPathDetectorWindows.cpp +++ b/src/lib_gui/utility/path_detector/maven_executable/MavenPathDetectorWindows.cpp @@ -7,9 +7,7 @@ MavenPathDetectorWindows::MavenPathDetectorWindows(): PathDetector("Maven for Wi std::vector MavenPathDetectorWindows::doGetPaths() const { - FilePath mavenPath( - utility::executeProcess(L"cmd", std::vector {L"\"/c where mvn.cmd && exit\""}) - .second); + FilePath mavenPath(utility::executeProcess(L"cmd", {L"\"/c where mvn.cmd && exit\""}).second); std::vector paths; if (mavenPath.exists()) diff --git a/src/lib_gui/utility/utilityApp.cpp b/src/lib_gui/utility/utilityApp.cpp index a990483c..08e441c1 100644 --- a/src/lib_gui/utility/utilityApp.cpp +++ b/src/lib_gui/utility/utilityApp.cpp @@ -208,13 +208,24 @@ int utility::executeProcessAndGetExitCode( *errorMessage = L"An unknown error occurred while executing process."; break; } - }; + } }); QObject::connect( &process, static_cast(&QProcess::finished), - [&finished](int exitCode, QProcess::ExitStatus exitStatus) { finished = true; }); + [&finished, errorMessage](int exitCode, QProcess::ExitStatus exitStatus) { + finished = true; + if (errorMessage != nullptr) + { + switch (exitStatus) + { + case QProcess::CrashExit: + *errorMessage = L"Process crashed."; + break; + } + } + }); if (!workingDirectory.empty()) diff --git a/src/lib_python/project/SourceGroupPythonEmpty.cpp b/src/lib_python/project/SourceGroupPythonEmpty.cpp index dfe7a498..16aa82ae 100644 --- a/src/lib_python/project/SourceGroupPythonEmpty.cpp +++ b/src/lib_python/project/SourceGroupPythonEmpty.cpp @@ -49,25 +49,27 @@ std::set SourceGroupPythonEmpty::getAllSourceFilePaths() const std::vector> SourceGroupPythonEmpty::getIndexerCommands( const RefreshInfo& info) const { - std::wstring args = L""; + std::vector args; + args.push_back(L"index"); - args += L" --source-file-path=%{SOURCE_FILE_PATH}"; - args += L" --database-file-path=%{DATABASE_FILE_PATH}"; + args.push_back(L"--source-file-path=%{SOURCE_FILE_PATH}"); + args.push_back(L"--database-file-path=%{DATABASE_FILE_PATH}"); if (!m_settings->getEnvironmentPath().empty()) { - args += L" --environment-path=\"" + - m_settings->getEnvironmentPathExpandedAndAbsolute().wstr() + L"\""; + args.push_back( + L"--environment-path=\"" + m_settings->getEnvironmentPathExpandedAndAbsolute().wstr() + + L"\""); } if (ApplicationSettings::getInstance()->getVerboseIndexerLoggingEnabled()) { - args += L" --verbose"; + args.push_back(L"--verbose"); } if (info.shallow) { - args += L" --shallow"; + args.push_back(L"--shallow"); } std::vector> indexerCommands; @@ -77,8 +79,8 @@ std::vector> SourceGroupPythonEmpty::getIndexerC { indexerCommands.push_back(std::make_shared( INDEXER_COMMAND_PYTHON, - L"\"" + ResourcePaths::getPythonPath().wstr() + - L"SourcetrailPythonIndexer\" index" + args, + L"\"" + ResourcePaths::getPythonPath().wstr() + L"SourcetrailPythonIndexer\"", + args, m_settings->getProjectSettings()->getProjectFilePath(), m_settings->getProjectSettings()->getTempDBFilePath(), std::to_wstring(SqliteIndexStorage::getStorageVersion()), diff --git a/src/test/PythonIndexerTestSuite.cpp b/src/test/PythonIndexerTestSuite.cpp index c97d387b..b11c9975 100644 --- a/src/test/PythonIndexerTestSuite.cpp +++ b/src/test/PythonIndexerTestSuite.cpp @@ -56,16 +56,18 @@ std::shared_ptr parseCode(std::string code) const std::set includeFilters; const FilePath workingDirectory(L"."); - std::wstring args = L""; - args += L" --source-file-path=%{SOURCE_FILE_PATH}"; - args += L" --database-file-path=%{DATABASE_FILE_PATH}"; - args += L" --shallow"; + std::vector args; + args.push_back(L"index"); + args.push_back(L"--source-file-path=%{SOURCE_FILE_PATH}"); + args.push_back(L"--database-file-path=%{DATABASE_FILE_PATH}"); + args.push_back(L"--shallow"); std::shared_ptr indexerCommand = std::make_shared( INDEXER_COMMAND_PYTHON, L"\"" + FilePath("../app").getConcatenated(ResourcePaths::getPythonPath()).makeAbsolute().wstr() + - L"SourcetrailPythonIndexer\" index" + args, + L"SourcetrailPythonIndexer\"", + args, rootPath, tempDbPath, std::to_wstring(SqliteIndexStorage::getStorageVersion()), @@ -74,7 +76,12 @@ std::shared_ptr parseCode(std::string code) std::wstring errorMessage; const int result = utility::executeProcessAndGetExitCode( - indexerCommand->getCustomCommand(), {}, rootPath, -1, true, &errorMessage); + indexerCommand->getCommand(), + indexerCommand->getArguments(), + rootPath, + -1, + true, + &errorMessage); REQUIRE(result == 0); REQUIRE(errorMessage.empty()); diff --git a/src/test/SourceGroupTestSuite.cpp b/src/test/SourceGroupTestSuite.cpp index b5c5562a..6c64c25e 100644 --- a/src/test/SourceGroupTestSuite.cpp +++ b/src/test/SourceGroupTestSuite.cpp @@ -148,9 +148,15 @@ std::wstring indexerCommandCustomToString( std::shared_ptr indexerCommand, const FilePath& baseDirectory) { std::wstring result; - result += L"SourceFilePath: \"" + + result += L"IndexerCommandCustom\n"; + result += L"\tSourceFilePath: \"" + indexerCommand->getSourceFilePath().getRelativeTo(baseDirectory).wstr() + L"\"\n"; - result += L"\tCustom Command: \"" + indexerCommand->getCustomCommand() + L"\"\n"; + result += L"\tCustom Command: \"" + indexerCommand->getCommand() + L"\"\n"; + result += L"\tArguments:\n"; + for (const std::wstring& argument: indexerCommand->getArguments()) + { + result += L"\t\t\"" + argument + L"\"\n"; + } return result; }