mirror of
https://github.com/LizardByte/Sunshine.git
synced 2025-03-14 01:27:36 +00:00
build(docs): add cmake target for docs (#2748)
This commit is contained in:
parent
13f94f113a
commit
4683bcaf36
@ -63,6 +63,7 @@ sudo update-alternatives --install \
|
||||
mkdir -p build
|
||||
cd build || exit 1
|
||||
cmake \
|
||||
-DBUILD_DOCS=OFF \
|
||||
-DCMAKE_CUDA_COMPILER=/usr/local/cuda/bin/nvcc \
|
||||
-G "Unix Makefiles" \
|
||||
..
|
||||
|
@ -35,7 +35,9 @@ pacman -Syu --noconfirm --ignore=mingw-w64-ucrt-x86_64-curl \
|
||||
# build
|
||||
mkdir -p build
|
||||
cd build || exit 1
|
||||
cmake -G "MinGW Makefiles" ..
|
||||
cmake \
|
||||
-DBUILD_DOCS=OFF \
|
||||
-G "MinGW Makefiles" ..
|
||||
mingw32-make -j"$(nproc)"
|
||||
|
||||
# skip autobuild
|
||||
|
@ -15,6 +15,7 @@ mkdir -p build
|
||||
cd build || exit 1
|
||||
cmake \
|
||||
-DBOOST_USE_STATIC=OFF \
|
||||
-DBUILD_DOCS=OFF \
|
||||
-G "Unix Makefiles" ..
|
||||
make -j"$(sysctl -n hw.logicalcpu)"
|
||||
|
||||
|
13
.github/workflows/CI.yml
vendored
13
.github/workflows/CI.yml
vendored
@ -251,6 +251,8 @@ jobs:
|
||||
sudo apt-get install -y \
|
||||
build-essential \
|
||||
cmake \
|
||||
doxygen \
|
||||
graphviz \
|
||||
gcc-10 \
|
||||
g++-10 \
|
||||
libayatana-appindicator3-dev \
|
||||
@ -277,7 +279,8 @@ jobs:
|
||||
libxfixes-dev \
|
||||
libxrandr-dev \
|
||||
libxtst-dev \
|
||||
python3
|
||||
python3 \
|
||||
python3-venv
|
||||
|
||||
# clean apt cache
|
||||
sudo apt-get clean
|
||||
@ -414,9 +417,6 @@ jobs:
|
||||
run: |
|
||||
sudo apt-get update -y
|
||||
sudo apt-get install -y \
|
||||
doxygen \
|
||||
graphviz \
|
||||
python3-venv \
|
||||
x11-xserver-utils \
|
||||
xvfb
|
||||
|
||||
@ -803,9 +803,6 @@ jobs:
|
||||
working-directory:
|
||||
/opt/local/var/macports/build/_Users_runner_work_Sunshine_Sunshine_ports_multimedia_Sunshine/Sunshine/work/build/tests
|
||||
run: |
|
||||
sudo port install \
|
||||
doxygen \
|
||||
graphviz
|
||||
sudo ./test_sunshine --gtest_color=yes
|
||||
|
||||
- name: Generate gcov report
|
||||
@ -1038,8 +1035,8 @@ jobs:
|
||||
cmake \
|
||||
-DBUILD_WERROR=ON \
|
||||
-DCMAKE_BUILD_TYPE=RelWithDebInfo \
|
||||
-DPython_EXECUTABLE='${{ steps.python-path.outputs.python-path }}' \
|
||||
-DSUNSHINE_ASSETS_DIR=assets \
|
||||
-DTESTS_PYTHON_EXECUTABLE='${{ steps.python-path.outputs.python-path }}' \
|
||||
-DTESTS_SOFTWARE_ENCODER_UNAVAILABLE='skip' \
|
||||
-G "MinGW Makefiles" \
|
||||
..
|
||||
|
@ -1,3 +1,4 @@
|
||||
option(BUILD_DOCS "Build documentation" ON)
|
||||
option(BUILD_TESTS "Build tests" ON)
|
||||
option(TESTS_ENABLE_PYTHON_TESTS "Enable Python tests" ON)
|
||||
|
||||
|
@ -61,6 +61,11 @@ add_custom_target(web-ui ALL
|
||||
COMMAND_EXPAND_LISTS
|
||||
VERBATIM)
|
||||
|
||||
# docs
|
||||
if(BUILD_DOCS)
|
||||
add_subdirectory(docs)
|
||||
endif()
|
||||
|
||||
# tests
|
||||
if(BUILD_TESTS)
|
||||
add_subdirectory(tests)
|
||||
|
@ -32,7 +32,6 @@ apt-get update -y
|
||||
apt-get install -y --no-install-recommends \
|
||||
build-essential \
|
||||
ca-certificates \
|
||||
cmake=3.18.* \
|
||||
doxygen \
|
||||
git \
|
||||
graphviz \
|
||||
@ -67,6 +66,27 @@ apt-get clean
|
||||
rm -rf /var/lib/apt/lists/*
|
||||
_DEPS
|
||||
|
||||
# install cmake
|
||||
# sunshine requires cmake >= 3.19
|
||||
WORKDIR /build/cmake
|
||||
# https://cmake.org/download/
|
||||
ENV CMAKE_VERSION="3.29.6"
|
||||
# hadolint ignore=SC3010
|
||||
RUN <<_INSTALL_CMAKE
|
||||
#!/bin/bash
|
||||
cmake_prefix="https://github.com/Kitware/CMake/releases/download/v"
|
||||
if [[ "${TARGETPLATFORM}" == 'linux/amd64' ]]; then
|
||||
cmake_arch="x86_64"
|
||||
elif [[ "${TARGETPLATFORM}" == 'linux/arm64' ]]; then
|
||||
cmake_arch="aarch64"
|
||||
fi
|
||||
url="${cmake_prefix}${CMAKE_VERSION}/cmake-${CMAKE_VERSION}-linux-${cmake_arch}.sh"
|
||||
echo "cmake url: ${url}"
|
||||
wget "$url" --progress=bar:force:noscroll -q --show-progress -O ./cmake.sh
|
||||
sh ./cmake.sh --prefix=/usr/local --skip-license
|
||||
cmake --version
|
||||
_INSTALL_CMAKE
|
||||
|
||||
#Install Node
|
||||
# hadolint ignore=SC1091
|
||||
RUN <<_INSTALL_NODE
|
||||
|
@ -107,6 +107,7 @@ RUN <<_MAKE
|
||||
set -e
|
||||
cmake \
|
||||
-DCMAKE_CUDA_COMPILER:PATH=/build/cuda/bin/nvcc \
|
||||
-DBUILD_DOCS=OFF \
|
||||
-DBUILD_WERROR=ON \
|
||||
-DCMAKE_BUILD_TYPE=Release \
|
||||
-DCMAKE_INSTALL_PREFIX=/usr \
|
||||
@ -116,7 +117,6 @@ cmake \
|
||||
-DSUNSHINE_ENABLE_X11=ON \
|
||||
-DSUNSHINE_ENABLE_DRM=ON \
|
||||
-DSUNSHINE_ENABLE_CUDA=ON \
|
||||
-DTESTS_ENABLE_PYTHON_TESTS=OFF \
|
||||
/build/sunshine
|
||||
make -j "$(nproc)"
|
||||
cpack -G RPM
|
||||
|
114
docs/CMakeLists.txt
Normal file
114
docs/CMakeLists.txt
Normal file
@ -0,0 +1,114 @@
|
||||
cmake_minimum_required(VERSION 3.19)
|
||||
|
||||
# find doxygen and graphviz
|
||||
find_package(Doxygen
|
||||
REQUIRED dot)
|
||||
|
||||
if(POLICY CMP0094) # https://cmake.org/cmake/help/latest/policy/CMP0094.html
|
||||
cmake_policy(SET CMP0094 NEW) # FindPython should return the first matching Python
|
||||
endif()
|
||||
|
||||
# needed on GitHub Actions CI: actions/setup-python does not touch registry/frameworks on Windows/macOS
|
||||
# this mirrors PythonInterp behavior which did not consult registry/frameworks first
|
||||
if(NOT DEFINED Python_FIND_REGISTRY)
|
||||
set(Python_FIND_REGISTRY "LAST") # cmake-lint: disable=C0103
|
||||
endif()
|
||||
if(NOT DEFINED Python_FIND_FRAMEWORK)
|
||||
set(Python_FIND_FRAMEWORK "LAST") # cmake-lint: disable=C0103
|
||||
endif()
|
||||
|
||||
# find python
|
||||
if(NOT DEFINED Python_EXECUTABLE)
|
||||
find_package(Python3 3.9 REQUIRED COMPONENTS Interpreter)
|
||||
else()
|
||||
set(Python3_EXECUTABLE "${Python_EXECUTABLE}") # cmake-lint: disable=C0103
|
||||
message(STATUS "Using Python3_EXECUTABLE: ${Python3_EXECUTABLE}")
|
||||
endif()
|
||||
|
||||
# create venv in build dir
|
||||
set(VENV_DIR "${CMAKE_BINARY_DIR}/venv")
|
||||
|
||||
# create venv
|
||||
execute_process(
|
||||
COMMAND ${Python3_EXECUTABLE} -m venv ${VENV_DIR}
|
||||
COMMAND_ERROR_IS_FATAL LAST
|
||||
RESULT_VARIABLE VENV_RESULT
|
||||
)
|
||||
|
||||
# set Python3_EXECUTABLE to the python interpreter in the venv
|
||||
if(WIN32)
|
||||
set(Python3_EXECUTABLE "${VENV_DIR}/Scripts/python.exe") # cmake-lint: disable=C0103
|
||||
set(Python3_ROOT_DIR "${VENV_DIR}/Scripts") # cmake-lint: disable=C0103
|
||||
else()
|
||||
set(Python3_EXECUTABLE "${VENV_DIR}/bin/python") # cmake-lint: disable=C0103
|
||||
set(Python3_ROOT_DIR "${VENV_DIR}/bin") # cmake-lint: disable=C0103
|
||||
endif()
|
||||
|
||||
# print path
|
||||
message(STATUS "Python3_EXECUTABLE: ${Python3_EXECUTABLE}")
|
||||
|
||||
# call a simple python command
|
||||
execute_process(
|
||||
COMMAND ${Python3_EXECUTABLE} -c "print(' Testing Python3_EXECUTABLE')"
|
||||
COMMAND_ERROR_IS_FATAL ANY
|
||||
RESULT_VARIABLE PYTHON_RESULT
|
||||
)
|
||||
|
||||
# fail if the python command failed
|
||||
if(NOT PYTHON_RESULT EQUAL 0)
|
||||
message(FATAL_ERROR "Python3_EXECUTABLE failed")
|
||||
endif()
|
||||
|
||||
# install doc requirements
|
||||
execute_process(
|
||||
COMMAND ${Python3_EXECUTABLE} -m pip install -r ${CMAKE_CURRENT_SOURCE_DIR}/requirements.txt
|
||||
COMMAND_ERROR_IS_FATAL ANY
|
||||
RESULT_VARIABLE PIP_RESULT
|
||||
)
|
||||
|
||||
# rst check
|
||||
set(RST_PATTERNS
|
||||
${CMAKE_CURRENT_SOURCE_DIR}
|
||||
${CMAKE_SOURCE_DIR}/README.rst
|
||||
)
|
||||
|
||||
# check rst files
|
||||
foreach(pattern ${RST_PATTERNS})
|
||||
message(STATUS "Checking RST files: ${pattern}")
|
||||
execute_process(
|
||||
COMMAND "${Python3_ROOT_DIR}/rstcheck" -r "${pattern}"
|
||||
COMMAND_ERROR_IS_FATAL ANY
|
||||
RESULT_VARIABLE RST_RESULT
|
||||
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
|
||||
)
|
||||
endforeach()
|
||||
|
||||
# commands
|
||||
list(APPEND SPHINX_BUILD_HTML_COMMAND
|
||||
"${Python3_ROOT_DIR}/sphinx-build"
|
||||
"-M"
|
||||
"html"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/source"
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/build/html"
|
||||
"-W"
|
||||
"--keep-going"
|
||||
)
|
||||
|
||||
list(APPEND SPHINX_BUILD_EPUB_COMMAND
|
||||
"${Python3_ROOT_DIR}/sphinx-build"
|
||||
"-M"
|
||||
"epub"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/source"
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/build/epub"
|
||||
"-W"
|
||||
"--keep-going"
|
||||
)
|
||||
|
||||
# build docs
|
||||
add_custom_target(docs ALL
|
||||
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
|
||||
COMMENT "Building documentation"
|
||||
COMMAND ${SPHINX_BUILD_HTML_COMMAND}
|
||||
COMMAND ${SPHINX_BUILD_EPUB_COMMAND}
|
||||
VERBATIM
|
||||
)
|
@ -32,16 +32,16 @@ depends=('avahi'
|
||||
'numactl'
|
||||
'openssl'
|
||||
'opus'
|
||||
'python'
|
||||
'udev')
|
||||
checkdepends=('doxygen'
|
||||
'graphviz')
|
||||
makedepends=('cmake'
|
||||
'doxygen'
|
||||
"gcc${_gcc_version}"
|
||||
'graphviz'
|
||||
'git'
|
||||
'make'
|
||||
'nodejs'
|
||||
'npm')
|
||||
'npm'
|
||||
'python')
|
||||
optdepends=('cuda: Nvidia GPU encoding support'
|
||||
'libva-mesa-driver: AMD GPU encoding support'
|
||||
'xorg-server-xvfb: Virtual X server for headless testing')
|
||||
|
@ -274,6 +274,7 @@ modules:
|
||||
npm_config_nodedir: /usr/lib/sdk/node18
|
||||
NPM_CONFIG_LOGLEVEL: info
|
||||
config-opts:
|
||||
- -DBUILD_DOCS=OFF
|
||||
- -DBUILD_WERROR=ON
|
||||
- -DCMAKE_BUILD_TYPE=Release
|
||||
- -DCMAKE_INSTALL_PREFIX=/app
|
||||
@ -285,7 +286,6 @@ modules:
|
||||
- -DSUNSHINE_ENABLE_DRM=ON
|
||||
- -DSUNSHINE_ENABLE_CUDA=ON
|
||||
- -DSUNSHINE_BUILD_FLATPAK=ON
|
||||
- -DTESTS_ENABLE_PYTHON_TESTS=OFF
|
||||
sources:
|
||||
- type: git
|
||||
url: "@GITHUB_CLONE_URL@"
|
||||
|
@ -31,18 +31,17 @@ post-fetch {
|
||||
}
|
||||
|
||||
# https://guide.macports.org/chunked/reference.dependencies.html
|
||||
depends_build-append port:npm9 \
|
||||
port:pkgconfig
|
||||
depends_build-append port:doxygen \
|
||||
port:graphviz \
|
||||
port:npm9 \
|
||||
port:pkgconfig \
|
||||
port:python311 \
|
||||
port:py311-pip
|
||||
|
||||
depends_lib port:avahi \
|
||||
port:curl \
|
||||
port:libopus \
|
||||
port:miniupnpc \
|
||||
port:python311 \
|
||||
port:py311-pip
|
||||
|
||||
depends_test port:doxygen \
|
||||
port:graphviz
|
||||
port:miniupnpc
|
||||
|
||||
configure.args -DBOOST_USE_STATIC=ON \
|
||||
-DBUILD_WERROR=ON \
|
||||
|
@ -21,10 +21,13 @@ class @PROJECT_NAME@ < Formula
|
||||
end
|
||||
end
|
||||
|
||||
option "without-dynamic-boost", "Statically link Boost libraries" # default option
|
||||
option "with-docs-off", "Disable docs"
|
||||
option "with-dynamic-boost", "Dynamically link Boost libraries"
|
||||
option "without-dynamic-boost", "Statically link Boost libraries" # default option
|
||||
|
||||
depends_on "cmake" => :build
|
||||
depends_on "doxygen" => :build
|
||||
depends_on "graphviz" => :build
|
||||
depends_on "node" => :build
|
||||
depends_on "pkg-config" => :build
|
||||
depends_on "curl"
|
||||
@ -66,9 +69,16 @@ class @PROJECT_NAME@ < Formula
|
||||
-DSUNSHINE_ASSETS_DIR=sunshine/assets
|
||||
-DSUNSHINE_BUILD_HOMEBREW=ON
|
||||
-DSUNSHINE_ENABLE_TRAY=OFF
|
||||
-DTESTS_ENABLE_PYTHON_TESTS=OFF
|
||||
]
|
||||
|
||||
if build.with? "docs-off"
|
||||
ohai "Building docs: disabled"
|
||||
args << "-DBUILD_DOCS=OFF"
|
||||
else
|
||||
ohai "Building docs: enabled"
|
||||
args << "-DBUILD_DOCS=ON"
|
||||
end
|
||||
|
||||
if build.without? "dynamic-boost"
|
||||
args << "-DBOOST_USE_STATIC=ON"
|
||||
ohai "Statically linking Boost libraries"
|
||||
|
@ -3,9 +3,6 @@ cmake_minimum_required(VERSION 3.13)
|
||||
|
||||
project(test_sunshine)
|
||||
|
||||
set(PYTHON_PREFERRED_VERSION 3.11)
|
||||
set(PYTHON_MINIMUM_VERSION 3.9)
|
||||
|
||||
include_directories("${CMAKE_SOURCE_DIR}")
|
||||
|
||||
enable_testing()
|
||||
@ -38,55 +35,6 @@ endif ()
|
||||
|
||||
set(TEST_DEFINITIONS) # list will be appended as needed
|
||||
|
||||
# IF option TESTS_ENABLE_PYTHON_TESTS is ON, then we need to find python
|
||||
if (TESTS_ENABLE_PYTHON_TESTS)
|
||||
if (NOT DEFINED TESTS_PYTHON_EXECUTABLE)
|
||||
# python is required for doc tests
|
||||
|
||||
# https://github.com/actions/setup-python/issues/121#issuecomment-777748504
|
||||
if (POLICY CMP0094) # https://cmake.org/cmake/help/latest/policy/CMP0094.html
|
||||
cmake_policy(SET CMP0094 NEW) # FindPython should return the first matching Python
|
||||
endif ()
|
||||
|
||||
# needed on GitHub Actions CI: actions/setup-python does not touch registry/frameworks on Windows/macOS
|
||||
# this mirrors PythonInterp behavior which did not consult registry/frameworks first
|
||||
if (NOT DEFINED Python_FIND_REGISTRY)
|
||||
set(Python_FIND_REGISTRY "LAST") # cmake-lint: disable=C0103
|
||||
endif ()
|
||||
if (NOT DEFINED Python_FIND_FRAMEWORK)
|
||||
set(Python_FIND_FRAMEWORK "LAST") # cmake-lint: disable=C0103
|
||||
endif ()
|
||||
|
||||
# first, try to find preferred version of python
|
||||
find_package(Python ${PYTHON_PREFERRED_VERSION} EXACT COMPONENTS Interpreter)
|
||||
if (Python_FOUND)
|
||||
message(STATUS
|
||||
"Preferred Python ${PYTHON_PREFERRED_VERSION} found, tests dependent on Python will be enabled")
|
||||
else ()
|
||||
# fallback to minimum version
|
||||
find_package(Python ${PYTHON_MINIMUM_VERSION} COMPONENTS Interpreter)
|
||||
endif ()
|
||||
if (Python_FOUND)
|
||||
message(STATUS "Python found, tests dependent on Python will be enabled")
|
||||
list(APPEND TEST_DEFINITIONS TESTS_ENABLE_VENV_TESTS=1)
|
||||
list(APPEND TEST_DEFINITIONS TESTS_PYTHON_EXECUTABLE="${Python_EXECUTABLE}")
|
||||
else ()
|
||||
message(SEND_ERROR "Python not found, tests dependent on Python will be disabled")
|
||||
list(APPEND TEST_DEFINITIONS TESTS_ENABLE_VENV_TESTS=0)
|
||||
endif ()
|
||||
else()
|
||||
message(STATUS "Python executable is set to ${TESTS_PYTHON_EXECUTABLE}")
|
||||
list(APPEND TEST_DEFINITIONS TESTS_ENABLE_VENV_TESTS=1)
|
||||
list(APPEND TEST_DEFINITIONS TESTS_PYTHON_EXECUTABLE="${TESTS_PYTHON_EXECUTABLE}")
|
||||
endif()
|
||||
else ()
|
||||
message(STATUS "Python tests are disabled by 'TESTS_ENABLE_PYTHON_TESTS' option")
|
||||
list(APPEND TEST_DEFINITIONS TESTS_ENABLE_VENV_TESTS=0)
|
||||
endif ()
|
||||
|
||||
list(APPEND TEST_DEFINITIONS TESTS_SOURCE_DIR="${CMAKE_SOURCE_DIR}") # add source directory to TEST_DEFINITIONS
|
||||
list(APPEND TEST_DEFINITIONS TESTS_DOCS_DIR="${CMAKE_SOURCE_DIR}/docs") # add docs directory to TEST_DEFINITIONS
|
||||
|
||||
# make sure TESTS_SOFTWARE_ENCODER_UNAVAILABLE is set to "fail" or "skip"
|
||||
if (NOT (TESTS_SOFTWARE_ENCODER_UNAVAILABLE STREQUAL "fail" OR TESTS_SOFTWARE_ENCODER_UNAVAILABLE STREQUAL "skip"))
|
||||
set(TESTS_SOFTWARE_ENCODER_UNAVAILABLE "fail")
|
||||
|
@ -1,36 +0,0 @@
|
||||
#include <tests/conftest.cpp>
|
||||
|
||||
class DocsTests: public DocsTestFixture, public ::testing::WithParamInterface<std::tuple<const char *, const char *>> {};
|
||||
INSTANTIATE_TEST_SUITE_P(
|
||||
DocFormats,
|
||||
DocsTests,
|
||||
::testing::Values(
|
||||
std::make_tuple("html", "index.html"),
|
||||
std::make_tuple("epub", "Sunshine.epub")));
|
||||
TEST_P(DocsTests, MakeDocs) {
|
||||
auto params = GetParam();
|
||||
std::string format = std::get<0>(params);
|
||||
std::string expected_filename = std::get<1>(params);
|
||||
|
||||
std::filesystem::path expected_file = std::filesystem::current_path() / "build" / format / expected_filename;
|
||||
|
||||
std::string command = "make " + format;
|
||||
int status = BaseTest::exec(command.c_str());
|
||||
EXPECT_EQ(status, 0);
|
||||
|
||||
EXPECT_TRUE(std::filesystem::exists(expected_file));
|
||||
}
|
||||
|
||||
class DocsRstTests: public DocsPythonVenvTest, public ::testing::WithParamInterface<std::filesystem::path> {};
|
||||
INSTANTIATE_TEST_SUITE_P(
|
||||
RstFiles,
|
||||
DocsRstTests,
|
||||
::testing::Values(
|
||||
std::filesystem::path(TESTS_DOCS_DIR),
|
||||
std::filesystem::path(TESTS_SOURCE_DIR) / "README.rst"));
|
||||
TEST_P(DocsRstTests, RstCheckDocs) {
|
||||
std::filesystem::path docs_dir = GetParam();
|
||||
std::string command = "rstcheck -r " + docs_dir.string();
|
||||
int status = BaseTest::exec(command.c_str());
|
||||
EXPECT_EQ(status, 0);
|
||||
}
|
@ -194,204 +194,3 @@ protected:
|
||||
private:
|
||||
std::unique_ptr<platf::deinit_t> deinit_guard;
|
||||
};
|
||||
|
||||
class DocsPythonVenvBase: public virtual BaseTest {
|
||||
protected:
|
||||
void
|
||||
SetUp() override {
|
||||
#if defined TESTS_ENABLE_VENV_TESTS && TESTS_ENABLE_VENV_TESTS == 0
|
||||
GTEST_SKIP_("TESTS_ENABLE_VENV_TESTS is disabled by CMake");
|
||||
#else
|
||||
std::cout << "DocsPythonVenvTest:: starting Fixture SetUp" << std::endl;
|
||||
|
||||
std::string pythonBinDirArray[] = { "bin", "Scripts" };
|
||||
std::filesystem::path pythonPath = "python";
|
||||
std::string binPath;
|
||||
std::string command;
|
||||
int exit_code;
|
||||
|
||||
std::filesystem::path venvPath = ".venv";
|
||||
std::filesystem::path fullVenvPath = BaseTest::testBinaryDir / venvPath;
|
||||
|
||||
// check for existence of venv, and create it if necessary
|
||||
std::cout << "DocsPythonVenvTest:: checking for venv" << std::endl;
|
||||
if (!std::filesystem::exists(fullVenvPath)) {
|
||||
std::cout << "DocsPythonVenvTest:: venv not found" << std::endl;
|
||||
|
||||
// create the venv
|
||||
command = "\"" TESTS_PYTHON_EXECUTABLE "\" -m venv " + fullVenvPath.string();
|
||||
std::cout << "DocsPythonVenvTest:: trying to create venv with command: " << command << std::endl;
|
||||
exit_code = BaseTest::exec(command.c_str());
|
||||
if (exit_code != 0) {
|
||||
if (!std::filesystem::exists(fullVenvPath)) {
|
||||
FAIL() << "Command failed: " << command << " with exit code: " << exit_code;
|
||||
}
|
||||
else {
|
||||
// venv command will randomly complain that some files already exist...
|
||||
std::cout << "DocsPythonVenvTest:: exit code (" << exit_code << ") indicates venv creation failed, but venv exists" << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// determine if bin directory is `bin` (Unix) or `Scripts` (Windows)
|
||||
// cannot assume `Scripts` on Windows, as it could be `bin` if using MSYS2, cygwin, etc.
|
||||
std::cout << "DocsPythonVenvTest:: checking structure of venv" << std::endl;
|
||||
for (const std::string &binDir : pythonBinDirArray) {
|
||||
// check if bin directory exists
|
||||
if (std::filesystem::exists(fullVenvPath / binDir)) {
|
||||
binPath = binDir;
|
||||
std::cout << "DocsPythonVenvTest:: found binPath: " << binPath << std::endl;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (binPath.empty()) {
|
||||
FAIL() << "Python venv not found";
|
||||
}
|
||||
|
||||
// set fullPythonPath and fullPythonBinPath
|
||||
fullPythonPath = fullVenvPath / binPath / pythonPath;
|
||||
fullPythonBinPath = fullVenvPath / binPath;
|
||||
|
||||
std::cout << "DocsPythonVenvTest:: fullPythonPath: " << fullPythonPath << std::endl;
|
||||
std::cout << "DocsPythonVenvTest:: fullPythonBinPath: " << fullPythonBinPath << std::endl;
|
||||
|
||||
std::filesystem::path requirements_path = std::filesystem::path(TESTS_DOCS_DIR) / "requirements.txt";
|
||||
|
||||
// array of commands to run
|
||||
std::string CommandArray[] = {
|
||||
"\"" + fullPythonPath.string() + "\" -m pip install -r " + requirements_path.string(),
|
||||
};
|
||||
|
||||
for (const std::string &_command : CommandArray) {
|
||||
std::cout << "DocsPythonVenvTest:: running command: " << _command << std::endl;
|
||||
exit_code = BaseTest::exec(_command.c_str());
|
||||
if (exit_code != 0) {
|
||||
FAIL() << "Command failed: " << command << " with exit code: " << exit_code;
|
||||
}
|
||||
}
|
||||
|
||||
// Save the original PATH
|
||||
originalEnvPath = std::getenv("PATH") ? std::getenv("PATH") : "";
|
||||
std::cout << "DocsPythonVenvTest:: originalEnvPath: " << originalEnvPath << std::endl;
|
||||
|
||||
// Set the temporary PATH
|
||||
std::string tempPath;
|
||||
std::string envPathSep;
|
||||
|
||||
#ifdef _WIN32
|
||||
envPathSep = ";";
|
||||
#else
|
||||
envPathSep = ":";
|
||||
#endif
|
||||
tempPath = fullPythonBinPath.string() + envPathSep + originalEnvPath;
|
||||
std::cout << "DocsPythonVenvTest:: tempPath: " << tempPath << std::endl;
|
||||
setEnv("PATH", tempPath);
|
||||
|
||||
std::cout << "DocsPythonVenvTest:: finished Fixture SetUp" << std::endl;
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
TearDown() override {
|
||||
std::cout << "DocsPythonVenvTest:: starting Fixture TearDown" << std::endl;
|
||||
|
||||
// Restore the original PATH
|
||||
if (!originalEnvPath.empty()) {
|
||||
std::cout << "DocsPythonVenvTest:: restoring originalEnvPath: " << originalEnvPath << std::endl;
|
||||
setEnv("PATH", originalEnvPath);
|
||||
}
|
||||
|
||||
std::cout << "DocsPythonVenvTest:: finished Fixture TearDown" << std::endl;
|
||||
}
|
||||
|
||||
// functions and variables
|
||||
std::filesystem::path fullPythonPath;
|
||||
std::filesystem::path fullPythonBinPath;
|
||||
std::string originalEnvPath;
|
||||
};
|
||||
|
||||
class DocsPythonVenvTest: public virtual BaseTest, public DocsPythonVenvBase {
|
||||
protected:
|
||||
void
|
||||
SetUp() override {
|
||||
BaseTest::SetUp();
|
||||
DocsPythonVenvBase::SetUp();
|
||||
}
|
||||
|
||||
void
|
||||
TearDown() override {
|
||||
DocsPythonVenvBase::TearDown();
|
||||
BaseTest::TearDown();
|
||||
}
|
||||
};
|
||||
|
||||
class DocsWorkingDirectoryBase: public virtual BaseTest {
|
||||
protected:
|
||||
void
|
||||
SetUp() override {
|
||||
#if defined TESTS_ENABLE_VENV_TESTS && TESTS_ENABLE_VENV_TESTS == 1
|
||||
std::cout << "DocsWorkingDirectoryTest:: starting Fixture SetUp" << std::endl;
|
||||
|
||||
temp_dir = TESTS_DOCS_DIR;
|
||||
std::cout << "DocsWorkingDirectoryTest:: temp_dir: " << temp_dir << std::endl;
|
||||
|
||||
// change directory to `docs`
|
||||
original_dir = std::filesystem::current_path(); // save original directory
|
||||
std::cout << "DocsWorkingDirectoryTest:: original_dir: " << original_dir << std::endl;
|
||||
std::filesystem::current_path(temp_dir);
|
||||
std::cout << "DocsWorkingDirectoryTest:: working directory set to: " << std::filesystem::current_path() << std::endl;
|
||||
|
||||
std::cout << "DocsWorkingDirectoryTest:: finished Fixture SetUp" << std::endl;
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
TearDown() override {
|
||||
#if defined TESTS_ENABLE_VENV_TESTS && TESTS_ENABLE_VENV_TESTS == 1
|
||||
std::cout << "DocsWorkingDirectoryTest:: starting Fixture TearDown" << std::endl;
|
||||
|
||||
// change directory back to original
|
||||
std::filesystem::current_path(original_dir);
|
||||
std::cout << "DocsWorkingDirectoryTest:: working directory set to: " << std::filesystem::current_path() << std::endl;
|
||||
|
||||
std::cout << "DocsWorkingDirectoryTest:: finished Fixture TearDown" << std::endl;
|
||||
#endif
|
||||
}
|
||||
|
||||
// functions and variables
|
||||
std::filesystem::path original_dir;
|
||||
std::filesystem::path temp_dir;
|
||||
};
|
||||
|
||||
class DocsWorkingDirectoryTest: public virtual BaseTest, public DocsWorkingDirectoryBase {
|
||||
protected:
|
||||
void
|
||||
SetUp() override {
|
||||
BaseTest::SetUp();
|
||||
DocsWorkingDirectoryBase::SetUp();
|
||||
}
|
||||
|
||||
void
|
||||
TearDown() override {
|
||||
DocsWorkingDirectoryBase::TearDown();
|
||||
BaseTest::TearDown();
|
||||
}
|
||||
};
|
||||
|
||||
class DocsTestFixture: public virtual BaseTest, public DocsPythonVenvBase, public DocsWorkingDirectoryBase {
|
||||
protected:
|
||||
void
|
||||
SetUp() override {
|
||||
BaseTest::SetUp();
|
||||
DocsPythonVenvBase::SetUp();
|
||||
DocsWorkingDirectoryBase::SetUp();
|
||||
}
|
||||
|
||||
void
|
||||
TearDown() override {
|
||||
DocsWorkingDirectoryBase::TearDown();
|
||||
DocsPythonVenvBase::TearDown();
|
||||
BaseTest::TearDown();
|
||||
}
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user