diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 000000000..5847fa2c0 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,195 @@ +name: CI + +on: + workflow_dispatch: + pull_request: + types: + - opened + - reopened + - synchronize + - ready_for_review + push: + branches: [master*, release*] + +env: + GIT_COMMIT: ${{ github.sha }} + +jobs: + windows-2022: + runs-on: windows-2022 + timeout-minutes: 20 + + env: + QT_BASE_DIR: ${{ github.workspace }}\deps\Qt + QT_VERSION: 5.15.2 + + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + submodules: "recursive" + + - name: Cache Qt + id: cache-qt + uses: actions/cache@v1 + with: + path: ${{ env.QT_BASE_DIR }} + key: ${{ runner.os }}-Qt_${{ env.QT_VERSION }} + + - name: Install Qt + if: steps.cache-qt.outputs.cache-hit != 'true' + run: python ./scripts/install_deps.py --only qt + + - name: Install dependencies + run: | + pip install pyyaml + python ./scripts/install_deps.py + + - name: Setup VC++ environment + uses: ilammy/msvc-dev-cmd@v1 + + - name: Configure + env: + CMAKE_PREFIX_PATH: "${{ env.QT_BASE_DIR }}\\${{ env.QT_VERSION }}\\msvc2019_64\\" + run: cmake -B build --preset=windows-release + + - name: Build + run: cmake --build build + + - name: Test + run: ./build/bin/unittests + + macos: + runs-on: ${{ matrix.runtime.os }} + timeout-minutes: ${{ matrix.runtime.timeout }} + name: ${{ matrix.runtime.name }} + + defaults: + run: + shell: ${{ matrix.runtime.shell }} + + strategy: + matrix: + runtime: + - name: "macos-10-intel" + timeout: 20 + os: "macos-14-large" + arch: x64 + target: "10.14" + shell: "bash" + + - name: "macos-11-m1" + timeout: 10 + os: "macos-14" + arch: arm64 + target: "11" + shell: "/usr/bin/arch -arch arm64e /bin/bash --noprofile --norc -eo pipefail {0}" + + steps: + - name: Setup PATH + run: | + case "$ARCH" in + "arm64") + echo "/opt/homebrew/bin" >> $GITHUB_PATH + ;; + esac + env: + ARCH: ${{ matrix.runtime.arch }} + + - name: Checkout + uses: actions/checkout@v4 + with: + submodules: "recursive" + + - name: Install dependencies + run: | + pip install pyyaml + python ./scripts/install_deps.py + + - name: Configure + env: + CMAKE_OSX_DEPLOYMENT_TARGET: ${{ matrix.runtime.target }} + run: cmake -B build --preset=macos-release -DCMAKE_PREFIX_PATH=$(brew --prefix qt@5) + + - name: Build + run: cmake --build build + + - name: Test + run: ./build/bin/unittests + + linux: + runs-on: ${{ matrix.distro.runs-on }} + timeout-minutes: 10 + name: linux-${{ matrix.distro.name }} + container: ${{ matrix.distro.container }} + + strategy: + matrix: + distro: + - name: centos-7.6 + container: symless/synergy-core:centos7.6 + runs-on: ubuntu-latest + legacy-cmake: true + + - name: centos-8 + container: symless/synergy-core:centos8 + runs-on: ubuntu-latest + legacy-cmake: true + + - name: debian-11 + container: symless/synergy-core:debian11 + runs-on: ubuntu-latest + legacy-cmake: true + + - name: debian-12 + container: symless/synergy-core:debiansid + runs-on: ubuntu-latest + + - name: fedora-37 + container: symless/synergy-core:fedora37 + runs-on: ubuntu-latest + legacy-cmake: true + + - name: fedora-38 + container: symless/synergy-core:fedora38 + runs-on: ubuntu-latest + legacy-cmake: true + + - name: ubuntu-20.04 + container: symless/synergy-core:ubuntu20.04 + runs-on: ubuntu-latest + legacy-cmake: true + + - name: ubuntu-22.04 + container: symless/synergy-core:ubuntu22.04 + runs-on: ubuntu-latest + + - name: ubuntu-24.04 + runs-on: ubuntu-24.04 + install-deps: true + + steps: + # Use @v3 since some older Linux distro versions don't support @v4 + - name: Checkout + uses: actions/checkout@v3 + with: + submodules: "recursive" + + - name: Install dependencies + if: ${{ matrix.distro.install-deps }} + run: python ./scripts/install_deps.py + + - name: Configure + if: ${{ !matrix.distro.legacy-cmake }} + run: cmake -B build --preset=linux-release + + # Some older Linux distro versions don't support modern CMake presets. + - name: Configure (legacy) + if: ${{ matrix.distro.legacy-cmake }} + run: cmake -B build -DCMAKE_BUILD_TYPE=Release + + - name: Build + run: cmake --build build + + - name: Test + run: ./build/bin/unittests diff --git a/.github/workflows/job-test-linux-centos.yml b/.github/workflows/job-test-linux-centos.yml deleted file mode 100644 index 7668506bd..000000000 --- a/.github/workflows/job-test-linux-centos.yml +++ /dev/null @@ -1,44 +0,0 @@ -name: Test CentOS - -on: - push: - branches: [master] - pull_request: - branches: [master] - -concurrency: - group: "${{ github.workflow }}-${{ github.ref || github.run_id }}" - cancel-in-progress: true - -jobs: - test-linux-centos: - name: ${{ matrix.distro }} - runs-on: ubuntu-latest - container: symless/synergy-core:${{ matrix.distro }} - timeout-minutes: 10 - - env: - GIT_COMMIT: ${{ github.sha }} - - strategy: - matrix: - distro: - - centos7.6 - - centos8 - - steps: - - name: Checkout git repo - uses: actions/checkout@v3 - with: - submodules: "recursive" - - - name: Build - run: | - mkdir build - cd build - cmake3 -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX:PATH=$(pwd)/rpm/BUILDROOT/usr .. - . ./version - make -j - - - name: Run unit test - run: ./build/bin/unittests diff --git a/.github/workflows/job-test-linux-debian.yml b/.github/workflows/job-test-linux-debian.yml deleted file mode 100644 index f61ddb4e0..000000000 --- a/.github/workflows/job-test-linux-debian.yml +++ /dev/null @@ -1,45 +0,0 @@ -name: Test Debian - -on: - push: - branches: [master] - pull_request: - branches: [master] - -concurrency: - group: "${{ github.workflow }}-${{ github.ref || github.run_id }}" - cancel-in-progress: true - -jobs: - test-linux-debian: - name: ${{ matrix.distro }} - runs-on: ubuntu-latest - container: symless/synergy-core:${{ matrix.distro }} - timeout-minutes: 10 - - env: - GIT_COMMIT: ${{ github.sha }} - - strategy: - matrix: - distro: - - debian9 - - debian10 - - debian11 - - steps: - - name: Checkout git repo - uses: actions/checkout@v3 - with: - submodules: "recursive" - - - name: Build - run: | - mkdir build - cd build - cmake -DCMAKE_BUILD_TYPE=Release .. - . ./version - make -j - - - name: Run unit test - run: ./build/bin/unittests diff --git a/.github/workflows/job-test-linux-fedora.yml b/.github/workflows/job-test-linux-fedora.yml deleted file mode 100644 index b41ae0b96..000000000 --- a/.github/workflows/job-test-linux-fedora.yml +++ /dev/null @@ -1,52 +0,0 @@ -name: Test Fedora - -on: - push: - branches: [master] - pull_request: - branches: [master] - -concurrency: - group: "${{ github.workflow }}-${{ github.ref || github.run_id }}" - cancel-in-progress: true - -jobs: - test-linux-fedora: - name: ${{ matrix.distro }} - runs-on: ubuntu-latest - container: symless/synergy-core:${{ matrix.distro }} - timeout-minutes: 10 - - env: - GIT_COMMIT: ${{ github.sha }} - - strategy: - matrix: - distro: - - fedora33 - - fedora34 - - fedora35 - - fedora36 - - fedora37 - - fedora38 - - steps: - - name: Checkout git repo - uses: actions/checkout@v3 - with: - submodules: "recursive" - - - name: Work around https://github.com/actions/checkout/issues/766 - run: | - git config --global --add safe.directory "$GITHUB_WORKSPACE" - - - name: Build - run: | - mkdir build - cd build - cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX:PATH=$(pwd)/rpm/BUILDROOT/usr .. - . ./version - make -j - - - name: Run unit test - run: ./build/bin/unittests diff --git a/.github/workflows/job-test-linux-ubuntu.yml b/.github/workflows/job-test-linux-ubuntu.yml deleted file mode 100644 index 3865fa389..000000000 --- a/.github/workflows/job-test-linux-ubuntu.yml +++ /dev/null @@ -1,50 +0,0 @@ -name: Test Ubuntu - -on: - push: - branches: [master] - pull_request: - branches: [master] - -concurrency: - group: "${{ github.workflow }}-${{ github.ref || github.run_id }}" - cancel-in-progress: true - -jobs: - test-linux-ubuntu: - name: ubuntu${{ matrix.distro }} - runs-on: ubuntu-latest - container: symless/synergy-core:ubuntu${{ matrix.distro }} - timeout-minutes: 10 - - env: - GIT_COMMIT: ${{ github.sha }} - - strategy: - matrix: - distro: - - "22.04" - - "20.04" - flag: - - "-j" - - steps: - - name: Checkout git repo - uses: actions/checkout@v3 - with: - submodules: "recursive" - - - name: Work around https://github.com/actions/checkout/issues/766 - run: | - git config --global --add safe.directory "$GITHUB_WORKSPACE" - - - name: Build - run: | - mkdir build - cd build - cmake -DCMAKE_BUILD_TYPE=Release .. - . ./version - make ${{ matrix.flag }} - - - name: Run unit test - run: ./build/bin/unittests diff --git a/.github/workflows/job-test-mac.yml b/.github/workflows/job-test-mac.yml deleted file mode 100644 index b4adfc424..000000000 --- a/.github/workflows/job-test-mac.yml +++ /dev/null @@ -1,71 +0,0 @@ -name: "Test macOS" - -on: - push: - branches: [master] - pull_request: - branches: [master] - -concurrency: - group: "${{ github.workflow }}-${{ github.ref || github.run_id }}" - cancel-in-progress: true - -jobs: - test-macos: - runs-on: ${{ matrix.runtime.os }} - timeout-minutes: 20 - - defaults: - run: - shell: ${{ matrix.runtime.shell }} - - strategy: - matrix: - runtime: - - name: "macos-10-intel" - os: "macos-14-large" - arch: x64 - target: "10.14" - shell: "bash" - - name: "macos-11-m1" - os: "macos-14" - arch: arm64 - target: "11" - shell: "/usr/bin/arch -arch arm64e /bin/bash --noprofile --norc -eo pipefail {0}" - - name: ${{ matrix.runtime.name }} - - env: - GIT_COMMIT: ${{ github.sha }} - - steps: - - name: Setup PATH - run: | - case "$ARCH" in - "arm64") - echo "/opt/homebrew/bin" >> $GITHUB_PATH - ;; - esac - env: - ARCH: ${{ matrix.runtime.arch }} - - - name: Checkout git repo - uses: actions/checkout@v3 - with: - submodules: "recursive" - - - name: Install dependencies - run: | - pip install pyyaml - python ./scripts/install_deps.py - - - name: Configure - env: - CMAKE_OSX_DEPLOYMENT_TARGET: ${{ matrix.runtime.target }} - run: cmake -B build --preset=macos-release -DCMAKE_PREFIX_PATH=$(brew --prefix qt@5) - - - name: Build - run: cmake --build build - - - name: Run unit test - run: ./build/bin/unittests diff --git a/.github/workflows/job-test-windows.yml b/.github/workflows/job-test-windows.yml deleted file mode 100644 index 36529e94b..000000000 --- a/.github/workflows/job-test-windows.yml +++ /dev/null @@ -1,75 +0,0 @@ -name: "Test Windows" - -on: - push: - branches: [master] - pull_request: - branches: [master] - -concurrency: - group: "${{ github.workflow }}-${{ github.ref || github.run_id }}" - cancel-in-progress: true - -jobs: - test-windows: - runs-on: windows-latest - timeout-minutes: 20 - - env: - GIT_COMMIT: ${{ github.sha }} - BONJOUR_BASE_DIR: ${{ github.workspace }}\deps\bonjour - QT_BASE_DIR: ${{ github.workspace }}\deps\Qt - QT_VERSION: 5.15.2 - - steps: - - name: Checkout git repo - uses: actions/checkout@v3 - with: - submodules: "recursive" - - - name: Cache Qt - id: cache-qt - uses: actions/cache@v1 - with: - path: ${{ env.QT_BASE_DIR }} - key: ${{ runner.os }}-Qt_${{ env.QT_VERSION }} - - - name: Install Qt - if: steps.cache-qt.outputs.cache-hit != 'true' - run: python ./scripts/install_deps.py --only qt - - - name: Cache Bonjour - id: cache-bonjour - uses: actions/cache@v1 - with: - path: ${{ env.BONJOUR_BASE_DIR }} - key: ${{ runner.os }}-Bonjour - - - name: Install Bonjour SDK - if: steps.cache-bonjour.outputs.cache-hit != 'true' - run: | - New-Item -Force -ItemType Directory -Path "$env:BONJOUR_BASE_DIR" - $client = new-object System.Net.WebClient - $client.DownloadFile("https://binaries.symless.com/bonjour/BonjourSDK.zip",".\bonjoursdk.zip") - [System.IO.Compression.ZipFile]::ExtractToDirectory(".\bonjoursdk.zip", "$env:BONJOUR_BASE_DIR") - - - name: Install dependencies - run: | - pip install pyyaml - python ./scripts/install_deps.py - - - name: Add msbuild to PATH - uses: microsoft/setup-msbuild@v1.0.2 - - - name: Build - env: - CMAKE_PREFIX_PATH: "${{ env.QT_BASE_DIR }}\\${{ env.QT_VERSION }}\\msvc2019_64\\" - run: | - mkdir build - cd build - cmake -DCMAKE_BUILD_TYPE=Release .. - . ./version - msbuild synergy-core.sln /p:Configuration=Release - - - name: Run unit test - run: .\build\bin\Release\unittests.exe diff --git a/CMakeLists.txt b/CMakeLists.txt index 5688283b4..eeb8cc655 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -26,12 +26,12 @@ set(CMAKE_C_RESPONSE_FILE_LINK_FLAG "@") set(CMAKE_CXX_RESPONSE_FILE_LINK_FLAG "@") set(CMAKE_NINJA_FORCE_RESPONSE_FILE 1 CACHE INTERNAL "") -if (DEFINED ENV{SYNERGY_NO_LEGACY}) - option (SYNERGY_BUILD_LEGACY_GUI "Build the legacy GUI" OFF) - option (SYNERGY_BUILD_LEGACY_INSTALLER "Build the legacy installer" OFF) +if (DEFINED ENV{SYNERGY_BUILD_MINIMAL}) + option (SYNERGY_BUILD_GUI "Build the GUI" OFF) + option (SYNERGY_BUILD_INSTALLER "Build the installer" OFF) else() - option (SYNERGY_BUILD_LEGACY_GUI "Build the legacy GUI" ON) - option (SYNERGY_BUILD_LEGACY_INSTALLER "Build the legacy installer" ON) + option (SYNERGY_BUILD_GUI "Build the GUI" ON) + option (SYNERGY_BUILD_INSTALLER "Build the installer" ON) endif() if (DEFINED ENV{SYNERGY_NO_TESTS}) @@ -435,7 +435,7 @@ endmacro(generate_versionfile) generate_versionfile() -if (${SYNERGY_BUILD_LEGACY_INSTALLER}) +if (${SYNERGY_BUILD_INSTALLER}) # # macOS app Bundle # diff --git a/CMakePresets.json b/CMakePresets.json index 6d981a83c..856784a8a 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -13,7 +13,7 @@ "name": "minimal", "hidden": true, "environment": { - "SYNERGY_NO_LEGACY": "ON" + "SYNERGY_BUILD_MINIMAL": "ON" } }, { diff --git a/ChangeLog b/ChangeLog index ed43cd8d9..0efc54147 100644 --- a/ChangeLog +++ b/ChangeLog @@ -32,6 +32,7 @@ Enhancements: - #7335 Clickable debug source paths and new launch target - #7336 Add C++ and LLDB to VS Code recommendations - #7351 Use deps script to make life easier for contribs +- #7352 Combine GitHub workflows to reduce config duplication # 1.14.6 diff --git a/Chocolatey.config b/Chocolatey.config index b03282198..f5584b659 100644 --- a/Chocolatey.config +++ b/Chocolatey.config @@ -8,4 +8,7 @@ + + \ No newline at end of file diff --git a/deps.yml b/deps.yml index 9da4a8d43..6f1489232 100644 --- a/deps.yml +++ b/deps.yml @@ -5,6 +5,12 @@ dependencies: version: 5.15.2 mirror: https://qt.mirror.constant.com/ install-dir: C:\Qt + ci: + skip: + edit-config: Chocolatey.config + packages: + - cmake + - visualstudio2022buildtools mac: command: brew bundle --file=Brewfile @@ -15,6 +21,7 @@ dependencies: packages: - cmake - make + - g++ - xorg-dev - libx11-dev - libxtst-dev @@ -38,11 +45,13 @@ dependencies: - cmake - make - gcc-c++ + - openssl-devel - libXtst-devel - glib2-devel - gdk-pixbuf2-devel - libnotify-devel - qt5-qtbase-devel + - qt5-qttools-devel - libxkbfile-devel - gtk3-devel - rpm-build diff --git a/scripts/buildCoreLinux.sh b/scripts/buildCoreLinux.sh deleted file mode 100755 index b9a2cdca5..000000000 --- a/scripts/buildCoreLinux.sh +++ /dev/null @@ -1,12 +0,0 @@ -#! /bin/bash - -export SYNERGY_NO_LEGACY=1 -CMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE:-Release} -mkdir -p build -pushd build -cmake -DCMAKE_BUILD_TYPE=$CMAKE_BUILD_TYPE .. -make synergyc synergys -zip synergy-core-linux-x64.zip bin/* -echo "::set-output name=location::build/synergy-core-linux-x64.zip" -echo "::set-output name=name::synergy-core-linux-x64.zip" -popd diff --git a/scripts/buildCoreMacos.sh b/scripts/buildCoreMacos.sh deleted file mode 100755 index 989a67697..000000000 --- a/scripts/buildCoreMacos.sh +++ /dev/null @@ -1,17 +0,0 @@ -#! /bin/zsh - -export SYNERGY_NO_LEGACY=1 -CMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE:-Release} -mkdir -p build -pushd build -cmake -DOPENSSL_ROOT_DIR=/usr/local/opt/openssl \ - -DOPENSSL_LIBRARIES=/usr/local/opt/openssl/lib \ - -DCMAKE_OSX_DEPLOYMENT_TARGET=10.13 \ - -DCMAKE_OSX_ARCHITECTURES=x86_64 \ - -DCMAKE_BUILD_TYPE=$CMAKE_BUILD_TYPE \ - .. -make synergyc synergys -zip synergy-core-macos-x64.zip bin/* -echo "::set-output name=location::build/synergy-core-macos-x64.zip" -echo "::set-output name=name::synergy-core-macos-x64.zip" -popd diff --git a/scripts/buildCoreWindows.ps1 b/scripts/buildCoreWindows.ps1 deleted file mode 100644 index e858785dc..000000000 --- a/scripts/buildCoreWindows.ps1 +++ /dev/null @@ -1,115 +0,0 @@ -# -# Tests to see if command exists -# -Function Test-CommandExists { - Param ($command) - Try { - if (Get-Command $command) { - RETURN $true - } - } - Catch { - RETURN $false - } -} - - -# -# Check prerequisites -# -If (-not (Test-CommandExists "cmake" -ErrorAction SilentlyContinue)) { - Write-Error "Cmake not found. Aborting." -ErrorAction Stop -} - - -# https://patrickwbarnes.com/articles/using-msbuild-with-powershell/ -# -# Find vswhere (installed with recent Visual Studio versions). -# -If ($vsWhere = Get-Command "vswhere.exe" -ErrorAction SilentlyContinue) { - $vsWhere = $vsWhere.Path -} -ElseIf (Test-Path "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe") { - $vsWhere = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe" -} -Else { - Write-Error "vswhere not found. Aborting." -ErrorAction Stop -} - - -# -# Get path to Visual Studio installation using vswhere. -# -$vsPath = &$vsWhere ` - -latest ` - -products * ` - -version "[16.0,17.0)" ` - -requires Microsoft.Component.MSBuild ` - -property installationPath -If ([string]::IsNullOrEmpty("$vsPath")) { - Write-Error "Failed to find Visual Studio 2019 installation. Aborting." -ErrorAction Stop -} - - -# -# Make sure the Visual Studio Command Prompt variables are set. -# -If (-not (Test-Path env:LIBPATH)) { - # Load VC vars - Push-Location "${vsPath}\VC\Auxiliary\Build" - Try { - cmd /c "vcvarsall.bat x64&set" | - ForEach-Object { - If ($_ -match "=") { - $v = $_.split("=") - Set-Item -Force -Path "ENV:\$($v[0])" -Value "$($v[1])" - } - } - } - Finally { - Pop-Location - } -} - - -# -# Set undefined environment variables -# -$env:SYNERGY_NO_LEGACY = 1 -If (-not (Test-Path env:SYNERGY_BUILD_TYPE)) { - $env:SYNERGY_BUILD_TYPE = "Release" -} -If (-not (Test-Path env:SYNERGY_BUILD_DIRECTORY)) { - $env:SYNERGY_BUILD_DIRECTORY = '.\build' -} - - -# -# Create build folder and make builds -# -New-Item ` - -Path . ` - -Name $env:SYNERGY_BUILD_DIRECTORY ` - -ItemType "directory" ` - -ErrorAction SilentlyContinue | Out-Null -Push-Location $env:SYNERGY_BUILD_DIRECTORY -Try { - cmake ` - -DCMAKE_BUILD_TYPE=$env:SYNERGY_BUILD_TYPE ` - .. - . ./version - msbuild synergy-core.sln ` - /p:Configuration=$env:SYNERGY_BUILD_TYPE ` - /p:Platform="x64" ` - /m - - Remove-Item -Force -Path "synergy-core-win-x64.zip" -ErrorAction SilentlyContinue - Compress-Archive ` - -Path ".\bin\${env:SYNERGY_BUILD_TYPE}\*" ` - -DestinationPath "synergy-core-win-x64.zip" - Write-Output "::set-output name=location::build\synergy-core-win-x64.zip" - Write-Output "::set-output name=name::synergy-core-win-x64.zip" -} -Finally { - Pop-Location -} diff --git a/scripts/install_deps.py b/scripts/install_deps.py old mode 100644 new mode 100755 index 9f498c624..0f5b0bad1 --- a/scripts/install_deps.py +++ b/scripts/install_deps.py @@ -1,6 +1,7 @@ +#!/usr/bin/env python3 + import os -from lib import windows -import subprocess +from lib import windows, cmd_utils import sys import argparse import traceback @@ -8,10 +9,6 @@ import traceback config_file = "deps.yml" -class EnvError(Exception): - pass - - class YamlError(Exception): pass @@ -55,22 +52,6 @@ def main(): input("Press enter to continue...") -def run(command, check=True): - """Runs a shell command and by default asserts that the return code is 0.""" - - command_str = command - if isinstance(command, list): - command_str = " ".join(command) - - print(f"Running: {command_str}") - - try: - subprocess.run(command, shell=True, check=check) - except subprocess.CalledProcessError as e: - print(f"Command failed: {command_str}", file=sys.stderr) - raise e - - def get_os(): """Detects the operating system.""" if sys.platform == "win32": @@ -178,7 +159,7 @@ class Dependencies: # for ci, skip qt; we install qt separately so we can cache it. if not ci_env or only_qt: - qt = WindowsQt(self.config.get_qt_config()) + qt = windows.WindowsQt(self.config.get_qt_config(), config_file) qt_install_dir = qt.get_install_dir() if qt_install_dir: print(f"Skipping Qt, already installed at: {qt_install_dir}") @@ -188,16 +169,19 @@ class Dependencies: if only_qt: return - # use winget instead of choco to install the vc++ deps, since in choco there is no way - # to load a choco config file but skip a specific package (i.e. to skip vc++ for ci) - if not ci_env: - winget = WindowsWinGet() - winget.install_visual_studio() - - choco = WindowsChoco() + choco = windows.WindowsChoco() if ci_env: choco.config_ci_cache() + try: + ci_skip = self.config.os["ci"]["skip"] + choco_config_file = ci_skip["edit-config"] + remove_packages = ci_skip["packages"] + except KeyError: + raise YamlError(f"Bad mapping in {config_file} on Windows for: ci") + + choco.remove_from_config(choco_config_file, remove_packages) + try: command = self.config.os["command"] except KeyError: @@ -212,7 +196,7 @@ class Dependencies: except KeyError: raise YamlError(f"Nothing found in {config_file} on Mac for: command") - run(command) + cmd_utils.run(command) def linux(self): """Installs dependencies on Linux.""" @@ -222,115 +206,8 @@ class Dependencies: raise PlatformError("Unable to detect Linux distro") command = self.config.get_linux_package_command(distro) - run(command) + cmd_utils.run(command) -class WindowsWinGet: - """WinGet for Windows.""" - - def install_visual_studio(self): - """Installs packages using WinGet.""" - - override = [ - "--quiet", - "--wait", - "--includeRecommended", - "--add Microsoft.VisualStudio.Workload.MSBuildTools", - "--add Microsoft.VisualStudio.Workload.VCTools", - ] - - args = [ - "winget", - "install", - "--silent", - "--id", - "Microsoft.VisualStudio.2022.BuildTools", - "--override", - f'"{" ".join(override)}"', - ] - - run( - " ".join(args), - check=False, - ) - - -class WindowsChoco: - """Chocolatey for Windows.""" - - def install(self, command, ci_env): - """Installs packages using Chocolatey.""" - if ci_env: - # don't show noisy choco progress bars in ci env - run(f"{command} --no-progress") - else: - run(command) - - def config_ci_cache(self): - """Configures Chocolatey cache for CI.""" - - runner_temp_key = "RUNNER_TEMP" - runner_temp = os.environ.get(runner_temp_key) - if runner_temp: - # sets the choco cache dir, which should match the dir in the ci cache action. - key_arg = '--name="cacheLocation"' - value_arg = f'--value="{runner_temp}/choco"' - run(["choco", "config", "set", key_arg, value_arg]) - else: - print(f"Warning: CI environment variable {runner_temp_key} not set") - - -class WindowsQt: - """Qt for Windows.""" - - def __init__(self, config): - self.config = config - - self.version = os.environ.get("QT_VERSION") - if not self.version: - try: - default_version = config["version"] - except KeyError: - raise EnvError(f"Qt version not set in {config_file}") - - print(f"QT_VERSION not set, using: {default_version}") - self.version = default_version - - self.base_dir = os.environ.get("QT_BASE_DIR") - if not self.base_dir: - try: - default_base_dir = config["install-dir"] - except KeyError: - raise EnvError(f"Qt install-dir not set in {config_file}") - - print(f"QT_BASE_DIR not set, using: {default_base_dir}") - self.base_dir = default_base_dir - - self.install_dir = f"{self.base_dir}\\{self.version}" - - def get_install_dir(self): - if os.path.isdir(self.install_dir): - return self.install_dir - - def install(self): - """Installs Qt on Windows.""" - - run(["pip", "install", "aqtinstall"]) - - try: - mirror_url = self.config["mirror"] - except KeyError: - raise EnvError(f"Qt mirror not set in {config_file}") - - args = ["python", "-m", "aqt", "install-qt"] - args.extend(["--outputdir", self.base_dir]) - args.extend(["--base", mirror_url]) - args.extend(["windows", "desktop", self.version, "win64_msvc2019_64"]) - run(args) - - install_dir = self.get_install_dir() - if not install_dir: - raise EnvError(f"Qt not installed, path not found: {install_dir}") - - -main() +if __name__ == "__main__": + main() diff --git a/scripts/lib/cmd_utils.py b/scripts/lib/cmd_utils.py new file mode 100644 index 000000000..a923877c7 --- /dev/null +++ b/scripts/lib/cmd_utils.py @@ -0,0 +1,19 @@ +import subprocess +import sys + + +def run(command, check=True): + """Runs a shell command and by default asserts that the return code is 0.""" + + command_str = command + if isinstance(command, list): + command_str = " ".join(command) + + print(f"Running: {command_str}") + sys.stdout.flush() + + try: + subprocess.run(command, shell=True, check=check) + except subprocess.CalledProcessError as e: + print(f"Command failed: {command_str}", file=sys.stderr) + raise e diff --git a/scripts/lib/windows.py b/scripts/lib/windows.py index be88e9b3a..4d7aa1d46 100644 --- a/scripts/lib/windows.py +++ b/scripts/lib/windows.py @@ -1,11 +1,20 @@ import ctypes import sys +import os +import xml.etree.ElementTree as ET +from lib import cmd_utils + + +class EnvError(Exception): + pass + def relaunch_as_admin(script): - args = ' '.join(sys.argv[1:]) - command = f'{script} --pause-on-exit {args}' - print(f'Re-launching script as admin: {command}') - ctypes.windll.shell32.ShellExecuteW(None, 'runas', sys.executable, command, None, 1) + args = " ".join(sys.argv[1:]) + command = f"{script} --pause-on-exit {args}" + print(f"Re-launching script as admin: {command}") + ctypes.windll.shell32.ShellExecuteW(None, "runas", sys.executable, command, None, 1) + def is_admin(): """Returns True if the current process has admin privileges.""" @@ -13,3 +22,95 @@ def is_admin(): return ctypes.windll.shell32.IsUserAnAdmin() except ctypes.WinError: return False + + +class WindowsChoco: + """Chocolatey for Windows.""" + + def install(self, command, ci_env): + """Installs packages using Chocolatey.""" + if ci_env: + # don't show noisy choco progress bars in ci env + cmd_utils.run(f"{command} --no-progress") + else: + cmd_utils.run(command) + + def config_ci_cache(self): + """Configures Chocolatey cache for CI.""" + + runner_temp_key = "RUNNER_TEMP" + runner_temp = os.environ.get(runner_temp_key) + if runner_temp: + # sets the choco cache dir, which should match the dir in the ci cache action. + key_arg = '--name="cacheLocation"' + value_arg = f'--value="{runner_temp}/choco"' + cmd_utils.run(["choco", "config", "set", key_arg, value_arg]) + else: + print(f"Warning: CI environment variable {runner_temp_key} not set") + + def remove_from_config(self, config_file, remove_packages): + """Removes a package from the Chocolatey configuration.""" + + tree = ET.parse(config_file) + root = tree.getroot() + for remove in remove_packages: + for package in root.findall("package"): + if package.get("id") == remove: + root.remove(package) + print(f"Removed package from choco config: {remove}") + + tree.write(config_file) + + +class WindowsQt: + """Qt for Windows.""" + + def __init__(self, config, config_file): + self.config = config + self.config_file = config_file + + self.version = os.environ.get("QT_VERSION") + if not self.version: + try: + default_version = config["version"] + except KeyError: + raise EnvError(f"Qt version not set in {config_file}") + + print(f"QT_VERSION not set, using: {default_version}") + self.version = default_version + + self.base_dir = os.environ.get("QT_BASE_DIR") + if not self.base_dir: + try: + default_base_dir = config["install-dir"] + except KeyError: + raise EnvError(f"Qt install-dir not set in {config_file}") + + print(f"QT_BASE_DIR not set, using: {default_base_dir}") + self.base_dir = default_base_dir + + self.install_dir = f"{self.base_dir}\\{self.version}" + + def get_install_dir(self): + if os.path.isdir(self.install_dir): + return self.install_dir + + def install(self): + """Installs Qt on Windows.""" + + cmd_utils.run(["pip", "install", "aqtinstall"]) + + try: + mirror_url = self.config["mirror"] + except KeyError: + raise EnvError(f"Qt mirror not set in {self.config_file}") + + args = ["python", "-m", "aqt", "install-qt"] + args.extend(["--outputdir", self.base_dir]) + args.extend(["--base", mirror_url]) + args.extend(["windows", "desktop", self.version, "win64_msvc2019_64"]) + cmd_utils.run(args) + + install_dir = self.get_install_dir() + if not install_dir: + raise EnvError(f"Qt not installed, path not found: {install_dir}") diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 28bf317bb..a58af85c0 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -19,9 +19,9 @@ include_directories (${CMAKE_CURRENT_BINARY_DIR}/lib) add_subdirectory(lib) add_subdirectory(cmd) -if (SYNERGY_BUILD_LEGACY_GUI) +if (SYNERGY_BUILD_GUI) add_subdirectory(gui) -endif (SYNERGY_BUILD_LEGACY_GUI) +endif (SYNERGY_BUILD_GUI) if (BUILD_TESTS) add_subdirectory(test)