Compare commits

...
Author SHA1 Message Date
mlangkabel 70092378c2 test 2021-02-01 18:01:15 +01:00
mlangkabel f76c1773ae test 2021-02-01 17:12:51 +01:00
mlangkabel 997a0ff1e7 test 2021-02-01 15:22:47 +01:00
mlangkabel f0a143a85e test 2021-02-01 14:28:43 +01:00
mlangkabel 7b7c6f4794 add more logging 2021-02-01 13:56:43 +01:00
mlangkabel 9ad9fd8980 Revert "test"
This reverts commit 6ad1b1ce52.
2021-02-01 13:56:34 +01:00
mlangkabel 6ad1b1ce52 test 2021-01-27 22:25:54 +01:00
mlangkabel 4750791a6a test 2021-01-27 22:01:37 +01:00
mlangkabel 6894f9b608 test for ninja 2021-01-27 21:26:45 +01:00
mlangkabel c23dbfb9f9 test 2021-01-26 08:03:22 +01:00
mlangkabel 47fd6af759 install swig for building SourcetrailDB python bindings 2021-01-25 22:24:19 +01:00
mlangkabel 351399ee9e fetch submodule of submodule in appveyor script 2021-01-25 22:06:02 +01:00
mlangkabel 86b5efbd76 fetch submodules in appveyor script 2021-01-25 22:00:42 +01:00
mlangkabel b0c43ce94f remove download_python_indexer call from appveyor script 2021-01-25 21:48:15 +01:00
mlangkabel c28260a0fa update SourcetrailPythonIndexer submodule 2021-01-25 21:19:29 +01:00
mlangkabel b6a92d0825 fix python indexer call in tests 2021-01-25 21:18:08 +01:00
mlangkabel cd0f4e8fc0 fix cmake to copy correct files for python indexer 2021-01-25 20:43:50 +01:00
mlangkabel 146487b760 update SourcetrailPythonIndexer submodule 2021-01-25 20:43:21 +01:00
mlangkabel 197e127035 update usage of python indexer to call run.py 2021-01-25 20:43:00 +01:00
mlangkabel ecfa1b7920 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.
2021-01-25 20:36:42 +01:00
mlangkabel 093261232c create python environment instead of using pyinstaller 2021-01-25 18:45:27 +01:00
mlangkabel fd05f0fbc5 add SourcetrailPythonIndexer as submodule 2021-01-25 13:47:22 +01:00
26 changed files with 375 additions and 206 deletions
+1
View File
@@ -26,6 +26,7 @@ build-*
.DS_Store .DS_Store
.idea .idea
.vscode .vscode
__pycache__
/ide_plugins/vs/vs2015/SourcetrailPlugin/SourcetrailExtension/bin /ide_plugins/vs/vs2015/SourcetrailPlugin/SourcetrailExtension/bin
/ide_plugins/vs/vs2015/SourcetrailPlugin/SourcetrailExtension/obj /ide_plugins/vs/vs2015/SourcetrailPlugin/SourcetrailExtension/obj
+3
View File
@@ -0,0 +1,3 @@
[submodule "submodules/SourcetrailPythonIndexer"]
path = submodules/SourcetrailPythonIndexer
url = https://github.com/CoatiSoftware/SourcetrailPythonIndexer.git
+44 -6
View File
@@ -482,10 +482,39 @@ else()
endif() endif()
string(REGEX REPLACE "/" "\\\\" BACKSLASHED_CMAKE_BINARY_DIR ${CMAKE_BINARY_DIR})
string(REGEX REPLACE "/" "\\\\" BACKSLASHED_CMAKE_SOURCE_DIR ${CMAKE_SOURCE_DIR})
# Lib Python --------------------------------------------------------------------- # Lib Python ---------------------------------------------------------------------
if (BUILD_PYTHON_LANGUAGE_PACKAGE) if (BUILD_PYTHON_LANGUAGE_PACKAGE)
file (STRINGS "${CMAKE_SOURCE_DIR}/submodules/SourcetrailPythonIndexer/SourcetrailDB/version.txt" VERSION_STRING)
string(REGEX REPLACE "v([0-9]+)\\..*" "\\1" INTERFACE_VERSION "${VERSION_STRING}")
string(REGEX REPLACE "v[0-9]+\\.db([0-9]+)\\..*" "\\1" DATABASE_VERSION "${VERSION_STRING}")
string(REGEX REPLACE "v[0-9]+\\.db[0-9]+\\.p([0-9]+).*" "\\1" PATCH_VERSION "${VERSION_STRING}")
set(VERSION_STRING_UNDERSCORE "v${INTERFACE_VERSION}_db${DATABASE_VERSION}_p${PATCH_VERSION}")
message(STATUS "SourcetrailDB Version: ${VERSION_STRING}")
message(STATUS "Interface Version: ${INTERFACE_VERSION}")
message(STATUS "Database Version: ${DATABASE_VERSION}")
message(STATUS "Patch Version: ${PATCH_VERSION}")
set(LIB_CORE_TARGET_NAME "SourcetrailDB_core_lib")
add_subdirectory(
"${CMAKE_SOURCE_DIR}/submodules/SourcetrailPythonIndexer/SourcetrailDB/core"
"${CMAKE_BINARY_DIR}/SourcetrailPythonIndexer/SourcetrailDB/core")
set(PYTHON_BINDING_TARGET_NAME "bindings_python")
set(PYTHON_BINDING_OUTPUT_DIR "")
add_subdirectory(
"${CMAKE_SOURCE_DIR}/submodules/SourcetrailPythonIndexer/SourcetrailDB/bindings_python"
"${CMAKE_BINARY_DIR}/SourcetrailPythonIndexer/SourcetrailDB/bindings_python")
add_library(${LIB_PYTHON_PROJECT_NAME} ${LIB_PYTHON_FILES}) add_library(${LIB_PYTHON_PROJECT_NAME} ${LIB_PYTHON_FILES})
create_source_groups(${LIB_PYTHON_FILES}) create_source_groups(${LIB_PYTHON_FILES})
@@ -502,12 +531,24 @@ if (BUILD_PYTHON_LANGUAGE_PACKAGE)
#link_directories(${Boost_LIBRARY_DIRS}) #link_directories(${Boost_LIBRARY_DIRS})
target_link_libraries(${LIB_PYTHON_PROJECT_NAME} ${LIB_UTILITY_PROJECT_NAME} ${LIB_PROJECT_NAME}) target_link_libraries(${LIB_PYTHON_PROJECT_NAME} ${LIB_UTILITY_PROJECT_NAME} ${LIB_PROJECT_NAME})
add_dependencies(${LIB_PYTHON_PROJECT_NAME} _${PYTHON_BINDING_TARGET_NAME})
string(REGEX REPLACE "\\\\" "/" FORWARDSLASHED_PYTHON_INCLUDE_DIR ${PYTHON_INCLUDE_DIR})
set(PYTHON_ENVIRONMENT_DIR "${BACKSLASHED_CMAKE_SOURCE_DIR}\\bin\\app\\data\\python\\environment")
set(PYTHON_INDEXER_DIR "${BACKSLASHED_CMAKE_SOURCE_DIR}\\bin\\app\\data\\python\\indexer")
execute_process(
COMMAND "cmd.exe" "/k" "rmdir" "/s" "/q" "${PYTHON_ENVIRONMENT_DIR}" & "${PYTHON_INCLUDE_DIR}/../python.exe" "-m" "venv" "--clear" "--copies" "${PYTHON_ENVIRONMENT_DIR}" & "${PYTHON_ENVIRONMENT_DIR}/Scripts/pip" "install" "-r" "${CMAKE_SOURCE_DIR}/submodules/SourcetrailPythonIndexer/requirements.txt" & exit
)
execute_process(
COMMAND "cmd.exe" "/k" "rmdir" "/s" "/q" "${PYTHON_INDEXER_DIR}" & exit
)
add_custom_command( add_custom_command(
TARGET ${LIB_PYTHON_PROJECT_NAME} TARGET ${LIB_PYTHON_PROJECT_NAME}
PRE_BUILD PRE_BUILD
COMMAND ${PROJECT_SOURCE_DIR}/script/download_python_indexer.sh COMMAND ${PROJECT_SOURCE_DIR}/script/update_python_indexer.sh
COMMENT "download python indexer" COMMENT "updating python indexer scripts"
) )
else() else()
@@ -695,9 +736,6 @@ if (WIN32)
TARGET ${APP_PROJECT_NAME} TARGET ${APP_PROJECT_NAME}
PROPERTY VS_DEBUGGER_WORKING_DIRECTORY PROPERTY VS_DEBUGGER_WORKING_DIRECTORY
"${CMAKE_SOURCE_DIR}/bin/app") "${CMAKE_SOURCE_DIR}/bin/app")
string(REGEX REPLACE "/" "\\\\" BACKSLASHED_CMAKE_BINARY_DIR ${CMAKE_BINARY_DIR})
string(REGEX REPLACE "/" "\\\\" BACKSLASHED_CMAKE_SOURCE_DIR ${CMAKE_SOURCE_DIR})
else () else ()
add_executable(${APP_PROJECT_NAME} ${APP_FILES}) add_executable(${APP_PROJECT_NAME} ${APP_FILES})
endif () endif ()
@@ -864,7 +902,7 @@ if (UNIX)
COMMAND "${CMAKE_COMMAND}" "-E" "create_symlink" "${CMAKE_SOURCE_DIR}/bin/app/user" "${CMAKE_BINARY_DIR}/app/user" COMMAND "${CMAKE_COMMAND}" "-E" "create_symlink" "${CMAKE_SOURCE_DIR}/bin/app/user" "${CMAKE_BINARY_DIR}/app/user"
COMMAND "${CMAKE_COMMAND}" "-E" "create_symlink" "${CMAKE_SOURCE_DIR}/bin/test/data" "${CMAKE_BINARY_DIR}/test/data" COMMAND "${CMAKE_COMMAND}" "-E" "create_symlink" "${CMAKE_SOURCE_DIR}/bin/test/data" "${CMAKE_BINARY_DIR}/test/data"
) )
elseif(WIN32) elseif (WIN32)
foreach(OUTPUTCONFIG ${CMAKE_CONFIGURATION_TYPES}) foreach(OUTPUTCONFIG ${CMAKE_CONFIGURATION_TYPES})
if (EXISTS "${BACKSLASHED_CMAKE_BINARY_DIR}\\${OUTPUTCONFIG}") if (EXISTS "${BACKSLASHED_CMAKE_BINARY_DIR}\\${OUTPUTCONFIG}")
execute_process( execute_process(
+16 -9
View File
@@ -10,16 +10,19 @@ install:
- 7z x ninja.zip -oC:\projects\deps\ninja > nul - 7z x ninja.zip -oC:\projects\deps\ninja > nul
- set PATH=C:\projects\deps\ninja;%PATH% - set PATH=C:\projects\deps\ninja;%PATH%
- ninja --version - ninja --version
# Install SWIG by Choco
- ps: choco install -y --no-progress swig --version 4.0.1
before_build: before_build:
- git submodule init
- git submodule update
- cd submodules/SourcetrailPythonIndexer
- git submodule init
- git submodule update
- cd ../..
- mkdir build - mkdir build
- cd build - cd build
- mkdir temp - mkdir temp
- cd ../
- cd script
- cmd: "\"C:/Program Files/Git/usr/bin/bash.exe\" download_python_indexer.sh"
- cd ../
- cd build
- mkdir win64 - mkdir win64
- cd win64 - cd win64
- call "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvarsall.bat" amd64 - call "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvarsall.bat" amd64
@@ -31,7 +34,11 @@ build_script:
- ninja - ninja
- cd ../../ - cd ../../
test_script: artifacts:
- cd bin/test - path: bin
- ..\..\build\win64\Release\test\Sourcetrail_test.exe name: bin
- cd ../../ type: zip
- path: build
name: build
type: zip
@@ -1,6 +1,15 @@
SourceFilePath: "src/a.txt" IndexerCommandCustom
Custom Command: "echo "Hello World"" SourceFilePath: "src/a.txt"
SourceFilePath: "src/b.txt" Custom Command: "echo"
Custom Command: "echo "Hello World"" Arguments:
SourceFilePath: "src/included/a.txt" "Hello World"
Custom Command: "echo "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"
-101
View File
@@ -1,101 +0,0 @@
#!/bin/bash
SOURCETRAIL_PYTHON_INDEXER_VERSION="v1_db25_p5"
# Determine current platform
PLATFORM='unknown'
if [ "$(uname)" == "Darwin" ]; then
PLATFORM='osx'
elif [ "$(expr substr $(uname -s) 1 5)" == "Linux" ]; then
PLATFORM='linux'
elif [ "$(expr substr $(uname -s) 1 10)" == "MINGW32_NT" ]; then
PLATFORM='windows'
elif [ "$(expr substr $(uname -s) 1 10)" == "MINGW64_NT" ]; then
PLATFORM='windows'
elif [ "$OSTYPE" == "msys" ]; then
PLATFORM='windows'
fi
PACKAGE_NAME="SourcetrailPythonIndexer_${SOURCETRAIL_PYTHON_INDEXER_VERSION}-${PLATFORM}"
PACKAGE_FILE_NAME="${PACKAGE_NAME}.zip"
PACKAGE_URL="https://github.com/CoatiSoftware/SourcetrailPythonIndexer/releases/download/${SOURCETRAIL_PYTHON_INDEXER_VERSION}/${PACKAGE_FILE_NAME}"
TEMP_PATH="build/temp"
TARGET_PATH="bin/app/data/python"
ABORT="\033[31mAbort:\033[00m"
SUCCESS="\033[32mSuccess:\033[00m"
INFO="\033[33mInfo:\033[00m"
if [ $PLATFORM == "windows" ]; then
SCRIPT=`realpath $0`
if [ "$SCRIPT" == "" ]; then
ORIGINAL_PATH_TO_SCRIPT="${0}"
CLEANED_PATH_TO_SCRIPT="${ORIGINAL_PATH_TO_SCRIPT//\\//}"
SCRIPT_DIR=${CLEANED_PATH_TO_SCRIPT%/*}
else
ORIGINAL_PATH_TO_SCRIPT=`dirname $SCRIPT`
SCRIPT_DIR="${ORIGINAL_PATH_TO_SCRIPT//\\//}"
fi
else
SCRIPT_DIR="$( cd "$( dirname "$0" )" && pwd )"
fi
echo "This script is running in: $SCRIPT_DIR"
# Enter main directory
cd $SCRIPT_DIR/
cd ..
BINARY_PATH="$TARGET_PATH/SourcetrailPythonIndexer"
if [ $PLATFORM == "windows" ]; then
BINARY_PATH="${BINARY_PATH}.exe"
fi
if [ -e "${BINARY_PATH}" ]; then
echo -e $INFO "SourcetrailPythonIndexer already exists, checking version..."
INSTALLED_VERSION="$(${BINARY_PATH} --version)"
INSTALLED_VERSION=${INSTALLED_VERSION#* }
INSTALLED_VERSION="${INSTALLED_VERSION//./$'_'}"
if [ "$INSTALLED_VERSION" == "$SOURCETRAIL_PYTHON_INDEXER_VERSION" ]; then
echo -e $INFO "Nothing to update. Target version of SourcetrailPythonIndexer is already installed."
exit
fi
fi
mkdir -p $TEMP_PATH
echo -e $INFO "starting to download $PACKAGE_FILE_NAME"
if [ $PLATFORM == "linux" ]; then
wget -O $TEMP_PATH/$PACKAGE_FILE_NAME $PACKAGE_URL
elif [ $PLATFORM == "osx" ]; then
wget -O $TEMP_PATH/$PACKAGE_FILE_NAME $PACKAGE_URL
elif [ $PLATFORM == "windows" ]; then
certutil.exe -urlcache -split -f $PACKAGE_URL $TEMP_PATH/$PACKAGE_FILE_NAME
fi
echo -e $INFO "finished downloading $PACKAGE_FILE_NAME"
if [ $PLATFORM == "linux" ]; then
unzip -d $TEMP_PATH $TEMP_PATH/$PACKAGE_FILE_NAME
elif [ $PLATFORM == "osx" ]; then
unzip -d $TEMP_PATH $TEMP_PATH/$PACKAGE_FILE_NAME
elif [ $PLATFORM == "windows" ]; then
7z x $TEMP_PATH/$PACKAGE_FILE_NAME -o$TEMP_PATH
fi
echo -e $INFO "clearing $TARGET_PATH"
rm -rf $TARGET_PATH
mkdir -p $TARGET_PATH
cp -r $TEMP_PATH/$PACKAGE_NAME/* $TARGET_PATH
echo -e $INFO "clearing temporary data at $TEMP_PATH"
rm -rf $TEMP_PATH
+70
View File
@@ -0,0 +1,70 @@
#!/bin/bash
# Determine current platform
PLATFORM='unknown'
if [ "$(uname)" == "Darwin" ]; then
PLATFORM='osx'
elif [ "$(expr substr $(uname -s) 1 5)" == "Linux" ]; then
PLATFORM='linux'
elif [ "$(expr substr $(uname -s) 1 10)" == "MINGW32_NT" ]; then
PLATFORM='windows'
elif [ "$(expr substr $(uname -s) 1 10)" == "MINGW64_NT" ]; then
PLATFORM='windows'
elif [ "$OSTYPE" == "msys" ]; then
PLATFORM='windows'
fi
INPUT_DIR="submodules/SourcetrailPythonIndexer"
OUTPUT_DIR="bin/app/data/python/indexer"
ABORT="\033[31mAbort:\033[00m"
SUCCESS="\033[32mSuccess:\033[00m"
INFO="\033[33mInfo:\033[00m"
if [ $PLATFORM == "windows" ]; then
SCRIPT=`realpath $0`
if [ "$SCRIPT" == "" ]; then
ORIGINAL_PATH_TO_SCRIPT="${0}"
CLEANED_PATH_TO_SCRIPT="${ORIGINAL_PATH_TO_SCRIPT//\\//}"
SCRIPT_DIR=${CLEANED_PATH_TO_SCRIPT%/*}
else
ORIGINAL_PATH_TO_SCRIPT=`dirname $SCRIPT`
SCRIPT_DIR="${ORIGINAL_PATH_TO_SCRIPT//\\//}"
fi
else
SCRIPT_DIR="$( cd "$( dirname "$0" )" && pwd )"
fi
echo "This script is running in: $SCRIPT_DIR"
# Enter main directory
cd $SCRIPT_DIR/
cd ..
echo "create $OUTPUT_DIR"
if [ $PLATFORM == "windows" ]; then
mkdir "$OUTPUT_DIR"
dir
mkdir bin
cd bin
mkdir app
cd app
mkdir data
cd data
mkdir python
cd python
dir
mkdir indexer
cd ../../../../
else
mkdir -p $OUTPUT_DIR
fi
echo "Copy python indexer files to $OUTPUT_DIR"
cp $INPUT_DIR/_version.py $OUTPUT_DIR
cp $INPUT_DIR/run.py $OUTPUT_DIR
cp $INPUT_DIR/indexer.py $OUTPUT_DIR
cp $INPUT_DIR/shallow_indexer.py $OUTPUT_DIR
echo "Done updating Python indexer"
+12 -2
View File
@@ -37,12 +37,22 @@ FilePath ResourcePaths::getJavaPath()
return AppPath::getSharedDataPath().concatenate(L"data/java/"); return AppPath::getSharedDataPath().concatenate(L"data/java/");
} }
FilePath ResourcePaths::getPythonPath() FilePath ResourcePaths::getPythonEnvironmentFilePath()
{ {
return AppPath::getSharedDataPath().concatenate(L"data/python/"); return ResourcePaths::getPythonPath().concatenate(L"environment/Scripts/python");
}
FilePath ResourcePaths::getPythonIndexerFilePath()
{
return ResourcePaths::getPythonPath().concatenate(L"indexer/run.py");
} }
FilePath ResourcePaths::getCxxCompilerHeaderPath() FilePath ResourcePaths::getCxxCompilerHeaderPath()
{ {
return AppPath::getSharedDataPath().concatenate(L"data/cxx/include/").getCanonical(); return AppPath::getSharedDataPath().concatenate(L"data/cxx/include/").getCanonical();
} }
FilePath ResourcePaths::getPythonPath()
{
return AppPath::getSharedDataPath().concatenate(L"data/python/");
}
+5 -1
View File
@@ -15,8 +15,12 @@ public:
static FilePath getGuiPath(); static FilePath getGuiPath();
static FilePath getLicensePath(); static FilePath getLicensePath();
static FilePath getJavaPath(); static FilePath getJavaPath();
static FilePath getPythonPath(); static FilePath getPythonEnvironmentFilePath();
static FilePath getPythonIndexerFilePath();
static FilePath getCxxCompilerHeaderPath(); static FilePath getCxxCompilerHeaderPath();
private:
static FilePath getPythonPath();
}; };
#endif // RESOURCE_PATHS_H #endif // RESOURCE_PATHS_H
+37 -16
View File
@@ -11,7 +11,8 @@ IndexerCommandType IndexerCommandCustom::getStaticIndexerCommandType()
} }
IndexerCommandCustom::IndexerCommandCustom( IndexerCommandCustom::IndexerCommandCustom(
const std::wstring& customCommand, const std::wstring& command,
const std::vector<std::wstring>& arguments,
const FilePath& projectFilePath, const FilePath& projectFilePath,
const FilePath& databaseFilePath, const FilePath& databaseFilePath,
const std::wstring& databaseVersion, const std::wstring& databaseVersion,
@@ -19,7 +20,8 @@ IndexerCommandCustom::IndexerCommandCustom(
bool runInParallel) bool runInParallel)
: IndexerCommand(sourceFilePath) : IndexerCommand(sourceFilePath)
, m_type(getStaticIndexerCommandType()) , m_type(getStaticIndexerCommandType())
, m_customCommand(customCommand) , m_command(command)
, m_arguments(arguments)
, m_projectFilePath(projectFilePath) , m_projectFilePath(projectFilePath)
, m_databaseFilePath(databaseFilePath) , m_databaseFilePath(databaseFilePath)
, m_databaseVersion(databaseVersion) , m_databaseVersion(databaseVersion)
@@ -29,7 +31,8 @@ IndexerCommandCustom::IndexerCommandCustom(
IndexerCommandCustom::IndexerCommandCustom( IndexerCommandCustom::IndexerCommandCustom(
IndexerCommandType type, IndexerCommandType type,
const std::wstring& customCommand, const std::wstring& command,
const std::vector<std::wstring>& arguments,
const FilePath& projectFilePath, const FilePath& projectFilePath,
const FilePath& databaseFilePath, const FilePath& databaseFilePath,
const std::wstring& databaseVersion, const std::wstring& databaseVersion,
@@ -37,7 +40,8 @@ IndexerCommandCustom::IndexerCommandCustom(
bool runInParallel) bool runInParallel)
: IndexerCommand(sourceFilePath) : IndexerCommand(sourceFilePath)
, m_type(type) , m_type(type)
, m_customCommand(customCommand) , m_command(command)
, m_arguments(arguments)
, m_projectFilePath(projectFilePath) , m_projectFilePath(projectFilePath)
, m_databaseFilePath(databaseFilePath) , m_databaseFilePath(databaseFilePath)
, m_databaseVersion(databaseVersion) , m_databaseVersion(databaseVersion)
@@ -67,19 +71,19 @@ void IndexerCommandCustom::setDatabaseFilePath(const FilePath& databaseFilePath)
m_databaseFilePath = 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( std::vector<std::wstring> IndexerCommandCustom::getArguments() const
command, L"%{PROJECT_FILE_PATH}", L'\"' + m_projectFilePath.wstr() + L'\"'); {
command = utility::replace( std::vector<std::wstring> args;
command, L"%{DATABASE_FILE_PATH}", L'\"' + m_databaseFilePath.wstr() + L'\"'); for (const std::wstring& argument: m_arguments)
command = utility::replace(command, L"%{DATABASE_VERSION}", L'\"' + m_databaseVersion + L'\"'); {
command = utility::replace( args.push_back(replaceVariables(argument));
command, L"%{SOURCE_FILE_PATH}", L'\"' + getSourceFilePath().wstr() + L'\"'); }
return args;
return command;
} }
bool IndexerCommandCustom::getRunInParallel() const bool IndexerCommandCustom::getRunInParallel() const
@@ -92,7 +96,15 @@ QJsonObject IndexerCommandCustom::doSerialize() const
QJsonObject jsonObject = IndexerCommand::doSerialize(); 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; jsonObject["run_in_parallel"] = m_runInParallel;
@@ -100,3 +112,12 @@ QJsonObject IndexerCommandCustom::doSerialize() const
return jsonObject; 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;
}
+10 -4
View File
@@ -12,7 +12,8 @@ public:
static IndexerCommandType getStaticIndexerCommandType(); static IndexerCommandType getStaticIndexerCommandType();
IndexerCommandCustom( IndexerCommandCustom(
const std::wstring& customCommand, const std::wstring& command,
const std::vector<std::wstring>& arguments,
const FilePath& projectFilePath, const FilePath& projectFilePath,
const FilePath& databaseFilePath, const FilePath& databaseFilePath,
const std::wstring& databaseVersion, const std::wstring& databaseVersion,
@@ -21,7 +22,8 @@ public:
IndexerCommandCustom( IndexerCommandCustom(
IndexerCommandType type, IndexerCommandType type,
const std::wstring& customCommand, const std::wstring& command,
const std::vector<std::wstring>& arguments,
const FilePath& projectFilePath, const FilePath& projectFilePath,
const FilePath& databaseFilePath, const FilePath& databaseFilePath,
const std::wstring& databaseVersion, const std::wstring& databaseVersion,
@@ -34,15 +36,19 @@ public:
FilePath getDatabaseFilePath() const; FilePath getDatabaseFilePath() const;
void setDatabaseFilePath(const FilePath& databaseFilePath); void setDatabaseFilePath(const FilePath& databaseFilePath);
std::wstring getCustomCommand() const; std::wstring getCommand() const;
std::vector<std::wstring> getArguments() const;
bool getRunInParallel() const; bool getRunInParallel() const;
protected: protected:
QJsonObject doSerialize() const override; QJsonObject doSerialize() const override;
private: private:
std::wstring replaceVariables(std::wstring s) const;
IndexerCommandType m_type; IndexerCommandType m_type;
std::wstring m_customCommand; std::wstring m_command;
std::vector<std::wstring> m_arguments;
FilePath m_projectFilePath; FilePath m_projectFilePath;
FilePath m_databaseFilePath; FilePath m_databaseFilePath;
std::wstring m_databaseVersion; std::wstring m_databaseVersion;
@@ -465,9 +465,12 @@ void TaskExecuteCustomCommands::runIndexerCommand(
indexedSourceFileCount + 1, indexedSourceFileCount, m_indexerCommandCount, {sourcePath}); indexedSourceFileCount + 1, indexedSourceFileCount, m_indexerCommandCount, {sourcePath});
MessageIndexingStatus(true, indexedSourceFileCount * 100 / m_indexerCommandCount).dispatch(); MessageIndexingStatus(true, indexedSourceFileCount * 100 / m_indexerCommandCount).dispatch();
const std::wstring command = indexerCommand->getCustomCommand(); const std::wstring command = indexerCommand->getCommand();
const std::vector<std::wstring> 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() const ErrorCountInfo previousErrorCount = storage ? storage->getErrorCount()
: ErrorCountInfo(); : ErrorCountInfo();
@@ -475,7 +478,7 @@ void TaskExecuteCustomCommands::runIndexerCommand(
LOG_INFO("Starting to index"); LOG_INFO("Starting to index");
std::wstring errorMessage; std::wstring errorMessage;
const int result = utility::executeProcessAndGetExitCode( const int result = utility::executeProcessAndGetExitCode(
command, {}, m_projectDirectory, -1, true, &errorMessage); command, arguments, m_projectDirectory, -1, true, &errorMessage);
LOG_INFO("Finished indexing"); LOG_INFO("Finished indexing");
if (storage) if (storage)
@@ -508,8 +511,9 @@ void TaskExecuteCustomCommands::runIndexerCommand(
} }
else else
{ {
std::wstring statusText = L"command \"" + indexerCommand->getCustomCommand() + std::wstring statusText = L"command \"" + indexerCommand->getCommand() + L" " +
L"\" returned"; utility::join(arguments, L" ") + L"\" returned";
if (result != 0) if (result != 0)
{ {
statusText += L" code \"" + std::to_wstring(result) + L"\""; statusText += L" code \"" + std::to_wstring(result) + L"\"";
+62 -1
View File
@@ -42,7 +42,67 @@ std::set<FilePath> SourceGroupCustomCommand::getAllSourceFilePaths() const
std::vector<std::shared_ptr<IndexerCommand>> SourceGroupCustomCommand::getIndexerCommands( std::vector<std::shared_ptr<IndexerCommand>> SourceGroupCustomCommand::getIndexerCommands(
const RefreshInfo& info) const const RefreshInfo& info) const
{ {
std::vector<std::wstring> parts;
{
const std::wstring customCommand = m_settings->getCustomCommand(); 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<std::wstring> args;
for (size_t i = 1; i < parts.size(); i++)
{
args.push_back(parts[i]);
}
const bool runInParallel = m_settings->getRunInParallel(); const bool runInParallel = m_settings->getRunInParallel();
std::vector<std::shared_ptr<IndexerCommand>> indexerCommands; std::vector<std::shared_ptr<IndexerCommand>> indexerCommands;
@@ -51,7 +111,8 @@ std::vector<std::shared_ptr<IndexerCommand>> SourceGroupCustomCommand::getIndexe
if (info.filesToIndex.find(sourcePath) != info.filesToIndex.end()) if (info.filesToIndex.find(sourcePath) != info.filesToIndex.end())
{ {
indexerCommands.push_back(std::make_shared<IndexerCommandCustom>( indexerCommands.push_back(std::make_shared<IndexerCommandCustom>(
customCommand, command,
args,
m_settings->getProjectSettings()->getProjectFilePath(), m_settings->getProjectSettings()->getProjectFilePath(),
m_settings->getProjectSettings()->getTempDBFilePath(), m_settings->getProjectSettings()->getTempDBFilePath(),
std::to_wstring(SqliteIndexStorage::getStorageVersion()), std::to_wstring(SqliteIndexStorage::getStorageVersion()),
@@ -25,8 +25,9 @@ void QtProjectWizardContentSelect::populate(QGridLayout* layout, int& row)
std::string pythonIndexerVersion = " "; std::string pythonIndexerVersion = " ";
{ {
std::string str = utility::executeProcess( std::string str = utility::executeProcess(
ResourcePaths::getPythonPath().wstr().append(L"SourcetrailPythonIndexer"), ResourcePaths::getPythonEnvironmentFilePath().wstr(),
std::vector<std::wstring>{L"--version"}, std::vector<std::wstring> {
ResourcePaths::getPythonIndexerFilePath().wstr(), L"--version"},
FilePath(), FilePath(),
5000) 5000)
.second; .second;
@@ -63,13 +63,14 @@ void QtProjectWizardContentPathPythonEnvironment::onTextChanged(const QString& t
m_resultLabel->setText("Checking validity of Python environment..."); m_resultLabel->setText("Checking validity of Python environment...");
std::thread([=]() { std::thread([=]() {
std::pair<int, std::string> out = utility::executeProcess( std::pair<int, std::string> out = utility::executeProcess(
ResourcePaths::getPythonPath().wstr().append(L"SourcetrailPythonIndexer"), ResourcePaths::getPythonEnvironmentFilePath().wstr(),
std::vector<std::wstring>{ std::vector<std::wstring> {
ResourcePaths::getPythonIndexerFilePath().wstr(),
L"check-environment", L"check-environment",
L"--environment-path " + utility::getExpandedAndAbsolutePath( L"--environment-path " +
utility::getExpandedAndAbsolutePath(
FilePath(text.toStdWString()), m_settings->getProjectDirectoryPath()) FilePath(text.toStdWString()), m_settings->getProjectDirectoryPath())
.wstr() .wstr()},
},
FilePath(), FilePath(),
5000); 5000);
m_onQtThread([=]() { m_onQtThread([=]() {
@@ -20,9 +20,11 @@ std::vector<FilePath> CxxVs15HeaderPathDetector::doGetPaths() const
.expandEnvironmentVariables(); .expandEnvironmentVariables();
if (!expandedPaths.empty()) if (!expandedPaths.empty())
{ {
const std::string output = const std::string output = utility::executeProcess(
utility::executeProcess( expandedPaths[0].wstr(),
expandedPaths[0].wstr(), std::vector<std::wstring> {L"-latest", L"-property installationPath"}, FilePath(), 10000) {L"-latest", L"-property installationPath"},
FilePath(),
10000)
.second; .second;
const FilePath vsInstallPath(output); const FilePath vsInstallPath(output);
@@ -14,7 +14,7 @@ std::vector<std::string> getCxxHeaderPaths(const std::string& compilerName)
std::string command = compilerName + " -x c++ -v -E /dev/null"; std::string command = compilerName + " -x c++ -v -E /dev/null";
std::string clangOutput = utility::executeProcess( std::string clangOutput = utility::executeProcess(
utility::decodeFromUtf8(compilerName), utility::decodeFromUtf8(compilerName),
std::vector<std::wstring> {L"-x c++", L"-v", L"-E /dev/null"}) {L"-x c++", L"-v", L"-E /dev/null"})
.second; .second;
std::string standardHeaders = utility::substrBetween<std::string>( std::string standardHeaders = utility::substrBetween<std::string>(
clangOutput, "#include <...> search starts here:\n", "\nEnd of search list"); clangOutput, "#include <...> search starts here:\n", "\nEnd of search list");
@@ -54,7 +54,7 @@ std::vector<FilePath> JavaPathDetectorLinux::doGetPaths() const
FilePath JavaPathDetectorLinux::getJavaInPath() const FilePath JavaPathDetectorLinux::getJavaInPath() const
{ {
std::string output = utility::executeProcess(L"which", std::vector<std::wstring>{L"java"}).second; std::string output = utility::executeProcess(L"which", {L"java"}).second;
if (!output.empty()) if (!output.empty())
{ {
@@ -72,7 +72,7 @@ FilePath JavaPathDetectorLinux::getJavaInPath() const
FilePath JavaPathDetectorLinux::readLink(const FilePath& path) const FilePath JavaPathDetectorLinux::readLink(const FilePath& path) const
{ {
FilePath javaPath(utility::executeProcess(L"readlink", std::vector<std::wstring>{L"-f " + path.wstr()}).second); FilePath javaPath(utility::executeProcess(L"readlink", {L"-f " + path.wstr()}).second);
if (!javaPath.empty()) if (!javaPath.empty())
{ {
return javaPath; return javaPath;
@@ -113,7 +113,7 @@ FilePath JavaPathDetectorLinux::getJavaInJavaHome() const
bool JavaPathDetectorLinux::checkVersion(const FilePath& path) const bool JavaPathDetectorLinux::checkVersion(const FilePath& path) const
{ {
std::string output = utility::executeProcess(path.wstr(), std::vector<std::wstring>{L"-version"}).second; std::string output = utility::executeProcess(path.wstr(), {L"-version"}).second;
return output.find(m_javaVersion) != std::string::npos; return output.find(m_javaVersion) != std::string::npos;
} }
@@ -14,7 +14,7 @@ std::vector<FilePath> JavaPathDetectorMac::doGetPaths() const
std::vector<FilePath> paths; std::vector<FilePath> paths;
FilePath javaPath; FilePath javaPath;
std::string output = utility::executeProcess(L"/usr/libexec/java_home", std::vector<std::wstring>{}).second; const std::string output = utility::executeProcess(L"/usr/libexec/java_home", {}).second;
if (!output.empty()) if (!output.empty())
{ {
@@ -7,7 +7,7 @@ MavenPathDetectorUnix::MavenPathDetectorUnix(): PathDetector("Maven for Unix") {
std::vector<FilePath> MavenPathDetectorUnix::doGetPaths() const std::vector<FilePath> MavenPathDetectorUnix::doGetPaths() const
{ {
FilePath mavenPath(utility::executeProcess(L"which", std::vector<std::wstring>{L"mvn"}).second); FilePath mavenPath(utility::executeProcess(L"which", {L"mvn"}).second);
std::vector<FilePath> paths; std::vector<FilePath> paths;
if (mavenPath.exists()) if (mavenPath.exists())
@@ -7,9 +7,7 @@ MavenPathDetectorWindows::MavenPathDetectorWindows(): PathDetector("Maven for Wi
std::vector<FilePath> MavenPathDetectorWindows::doGetPaths() const std::vector<FilePath> MavenPathDetectorWindows::doGetPaths() const
{ {
FilePath mavenPath( FilePath mavenPath(utility::executeProcess(L"cmd", {L"\"/c where mvn.cmd && exit\""}).second);
utility::executeProcess(L"cmd", std::vector<std::wstring> {L"\"/c where mvn.cmd && exit\""})
.second);
std::vector<FilePath> paths; std::vector<FilePath> paths;
if (mavenPath.exists()) if (mavenPath.exists())
+13 -2
View File
@@ -208,13 +208,24 @@ int utility::executeProcessAndGetExitCode(
*errorMessage = L"An unknown error occurred while executing process."; *errorMessage = L"An unknown error occurred while executing process.";
break; break;
} }
}; }
}); });
QObject::connect( QObject::connect(
&process, &process,
static_cast<void (QProcess::*)(int, QProcess::ExitStatus)>(&QProcess::finished), static_cast<void (QProcess::*)(int, QProcess::ExitStatus)>(&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()) if (!workingDirectory.empty())
@@ -49,25 +49,27 @@ std::set<FilePath> SourceGroupPythonEmpty::getAllSourceFilePaths() const
std::vector<std::shared_ptr<IndexerCommand>> SourceGroupPythonEmpty::getIndexerCommands( std::vector<std::shared_ptr<IndexerCommand>> SourceGroupPythonEmpty::getIndexerCommands(
const RefreshInfo& info) const const RefreshInfo& info) const
{ {
std::wstring args = L""; std::vector<std::wstring> args;
args.push_back(L"index");
args += L" --source-file-path=%{SOURCE_FILE_PATH}"; args.push_back(L"--source-file-path=%{SOURCE_FILE_PATH}");
args += L" --database-file-path=%{DATABASE_FILE_PATH}"; args.push_back(L"--database-file-path=%{DATABASE_FILE_PATH}");
if (!m_settings->getEnvironmentPath().empty()) if (!m_settings->getEnvironmentPath().empty())
{ {
args += L" --environment-path=\"" + args.push_back(
m_settings->getEnvironmentPathExpandedAndAbsolute().wstr() + L"\""; L"--environment-path=\"" + m_settings->getEnvironmentPathExpandedAndAbsolute().wstr() +
L"\"");
} }
if (ApplicationSettings::getInstance()->getVerboseIndexerLoggingEnabled()) if (ApplicationSettings::getInstance()->getVerboseIndexerLoggingEnabled())
{ {
args += L" --verbose"; args.push_back(L"--verbose");
} }
if (info.shallow) if (info.shallow)
{ {
args += L" --shallow"; args.push_back(L"--shallow");
} }
std::vector<std::shared_ptr<IndexerCommand>> indexerCommands; std::vector<std::shared_ptr<IndexerCommand>> indexerCommands;
@@ -77,8 +79,9 @@ std::vector<std::shared_ptr<IndexerCommand>> SourceGroupPythonEmpty::getIndexerC
{ {
indexerCommands.push_back(std::make_shared<IndexerCommandCustom>( indexerCommands.push_back(std::make_shared<IndexerCommandCustom>(
INDEXER_COMMAND_PYTHON, INDEXER_COMMAND_PYTHON,
L"\"" + ResourcePaths::getPythonPath().wstr() + L"\"" + ResourcePaths::getPythonEnvironmentFilePath().wstr() + L"\" \"" +
L"SourcetrailPythonIndexer\" index" + args, ResourcePaths::getPythonIndexerFilePath().wstr() + L"\"",
args,
m_settings->getProjectSettings()->getProjectFilePath(), m_settings->getProjectSettings()->getProjectFilePath(),
m_settings->getProjectSettings()->getTempDBFilePath(), m_settings->getProjectSettings()->getTempDBFilePath(),
std::to_wstring(SqliteIndexStorage::getStorageVersion()), std::to_wstring(SqliteIndexStorage::getStorageVersion()),
+22 -9
View File
@@ -56,16 +56,24 @@ std::shared_ptr<TestStorage> parseCode(std::string code)
const std::set<FilePathFilter> includeFilters; const std::set<FilePathFilter> includeFilters;
const FilePath workingDirectory(L"."); const FilePath workingDirectory(L".");
std::wstring args = L""; std::vector<std::wstring> args;
args += L" --source-file-path=%{SOURCE_FILE_PATH}"; args.push_back(FilePath("../app")
args += L" --database-file-path=%{DATABASE_FILE_PATH}"; .getConcatenated(ResourcePaths::getPythonIndexerFilePath())
args += L" --shallow"; .makeAbsolute()
.wstr());
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<IndexerCommandCustom> indexerCommand = std::make_shared<IndexerCommandCustom>( std::shared_ptr<IndexerCommandCustom> indexerCommand = std::make_shared<IndexerCommandCustom>(
INDEXER_COMMAND_PYTHON, INDEXER_COMMAND_PYTHON,
L"\"" +
FilePath("../app").getConcatenated(ResourcePaths::getPythonPath()).makeAbsolute().wstr() + FilePath("../app")
L"SourcetrailPythonIndexer\" index" + args, .getConcatenated(ResourcePaths::getPythonEnvironmentFilePath())
.makeAbsolute()
.wstr(),
args,
rootPath, rootPath,
tempDbPath, tempDbPath,
std::to_wstring(SqliteIndexStorage::getStorageVersion()), std::to_wstring(SqliteIndexStorage::getStorageVersion()),
@@ -74,10 +82,15 @@ std::shared_ptr<TestStorage> parseCode(std::string code)
std::wstring errorMessage; std::wstring errorMessage;
const int result = utility::executeProcessAndGetExitCode( 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()); REQUIRE(errorMessage.empty());
REQUIRE(result == 0);
} }
std::shared_ptr<TestStorage> testStorage; std::shared_ptr<TestStorage> testStorage;
+8 -2
View File
@@ -148,9 +148,15 @@ std::wstring indexerCommandCustomToString(
std::shared_ptr<const IndexerCommandCustom> indexerCommand, const FilePath& baseDirectory) std::shared_ptr<const IndexerCommandCustom> indexerCommand, const FilePath& baseDirectory)
{ {
std::wstring result; std::wstring result;
result += L"SourceFilePath: \"" + result += L"IndexerCommandCustom\n";
result += L"\tSourceFilePath: \"" +
indexerCommand->getSourceFilePath().getRelativeTo(baseDirectory).wstr() + L"\"\n"; 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; return result;
} }