From 090aaf8ee3911751e2a0fb8ce5f50d5459689881 Mon Sep 17 00:00:00 2001 From: Xavier Michelon Date: Fri, 19 Aug 2022 18:37:39 +0200 Subject: [PATCH] Other: grab version number from top-level Makefile. Other: PowerShell script uses $MyInvocation.MyCommand.Path instead of $PSScriptRoot --- .../frontend/bridge-gui/BridgeSetup.cmake | 31 ++++++++++++++++--- internal/frontend/bridge-gui/CMakeLists.txt | 4 +-- .../bridge-gui-tester/CMakeLists.txt | 2 +- .../bridge-gui/bridge-gui/CMakeLists.txt | 4 +-- .../bridge-gui/bridge-gui/Config.h.in | 24 -------------- .../frontend/bridge-gui/bridge-gui/build.ps1 | 15 +++++---- .../frontend/bridge-gui/bridge-gui/build.sh | 5 +-- .../bridge-gui/bridgepp/CMakeLists.txt | 4 ++- utils/bridge_app_version.ps1 | 2 ++ utils/bridge_app_version.sh | 2 ++ 10 files changed, 50 insertions(+), 43 deletions(-) delete mode 100644 internal/frontend/bridge-gui/bridge-gui/Config.h.in create mode 100644 utils/bridge_app_version.ps1 create mode 100755 utils/bridge_app_version.sh diff --git a/internal/frontend/bridge-gui/BridgeSetup.cmake b/internal/frontend/bridge-gui/BridgeSetup.cmake index 5054e15b..31d5a98d 100644 --- a/internal/frontend/bridge-gui/BridgeSetup.cmake +++ b/internal/frontend/bridge-gui/BridgeSetup.cmake @@ -19,16 +19,39 @@ include_guard() +if (NOT DEFINED BRIDGE_REPO_ROOT) + message(FATAL_ERROR "BRIDGE_REPO_ROOT is not defined.") +endif() +message(STATUS "BRIDGE_REPO_ROOT is ${BRIDGE_REPO_ROOT}") + +#***************************************************************************************************************************************************** +# Bridge version +#***************************************************************************************************************************************************** +if (NOT DEFINED BRIDGE_APP_VERSION) + if (WIN32) + find_program(POWERSHELL_EXE powershell.exe) + if (NOT POWERSHELL_EXE) + message(FATAL_ERROR "PowerShell could not be found.") + endif() + execute_process(COMMAND "${POWERSHELL_EXE}" -ExecutionPolicy Bypass "${BRIDGE_REPO_ROOT}/utils/bridge_app_version.ps1" + OUTPUT_VARIABLE BRIDGE_APP_VERSION OUTPUT_STRIP_TRAILING_WHITESPACE COMMAND_ERROR_IS_FATAL ANY) + else() + execute_process(COMMAND "${BRIDGE_REPO_ROOT}/utils/bridge_app_version.sh" + OUTPUT_VARIABLE BRIDGE_APP_VERSION OUTPUT_STRIP_TRAILING_WHITESPACE COMMAND_ERROR_IS_FATAL ANY) + endif() + if (NOT BRIDGE_APP_VERSION) + message(FATAL_ERROR "Could not determine BRIDGE_APP_VERSION.") + endif() +endif() + + #**************************************************************************************************************************************************** # vcpkg, toolchain, and architecture #**************************************************************************************************************************************************** # We rely on vcpkg for to get gRPC / Protobuf # run build.sh / build.ps1 to get gRPC / Protobuf and dependencies installed. -if (NOT DEFINED VCPKG_ROOT) - message(FATAL_ERROR "VCPKG_ROOT is not defined.") -endif() - +set(VCPKG_ROOT "${BRIDGE_REPO_ROOT}/extern/vcpkg") message(STATUS "VCPKG_ROOT is ${VCPKG_ROOT}") if (WIN32) find_program(VCPKG_EXE "${VCPKG_ROOT}/vcpkg.exe") diff --git a/internal/frontend/bridge-gui/CMakeLists.txt b/internal/frontend/bridge-gui/CMakeLists.txt index cca7559d..f3270c37 100644 --- a/internal/frontend/bridge-gui/CMakeLists.txt +++ b/internal/frontend/bridge-gui/CMakeLists.txt @@ -22,9 +22,7 @@ cmake_minimum_required(VERSION 3.22) #***************************************************************************************************************************************************** # Project #***************************************************************************************************************************************************** - - -set(VCPKG_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/../../../extern/vcpkg") +set(BRIDGE_REPO_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/../../..") include("BridgeSetup.cmake") project(frontend) diff --git a/internal/frontend/bridge-gui/bridge-gui-tester/CMakeLists.txt b/internal/frontend/bridge-gui/bridge-gui-tester/CMakeLists.txt index 325ada4c..705d0c8c 100644 --- a/internal/frontend/bridge-gui/bridge-gui-tester/CMakeLists.txt +++ b/internal/frontend/bridge-gui/bridge-gui-tester/CMakeLists.txt @@ -19,7 +19,7 @@ cmake_minimum_required(VERSION 3.22) -set(VCPKG_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/../../../../extern/vcpkg") +set(BRIDGE_REPO_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/../../../..") include(../BridgeSetup.cmake) diff --git a/internal/frontend/bridge-gui/bridge-gui/CMakeLists.txt b/internal/frontend/bridge-gui/bridge-gui/CMakeLists.txt index 75bbc62b..eafdf0ef 100644 --- a/internal/frontend/bridge-gui/bridge-gui/CMakeLists.txt +++ b/internal/frontend/bridge-gui/bridge-gui/CMakeLists.txt @@ -17,7 +17,7 @@ cmake_minimum_required(VERSION 3.22) -set(VCPKG_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/../../../../extern/vcpkg") +set(BRIDGE_REPO_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/../../../..") include(../BridgeSetup.cmake) @@ -61,7 +61,7 @@ set(CMAKE_PREFIX_PATH $ENV{QT6DIR} ${CMAKE_PREFIX_PATH}) if (DEFINED ENV{BRIDGE_INSTALL_PATH}) set(CMAKE_INSTALL_PREFIX "$ENV{BRIDGE_INSTALL_PATH}") else(DEFINED ENV{BRIDGE_INSTALL_PATH}) - message(status "Using Default install path (${CMAKE_INSTALL_PREFIX}), export BRIDGE_INSTALL_PATH to change it.") + message(STATUS "Using Default install path (${CMAKE_INSTALL_PREFIX}), export BRIDGE_INSTALL_PATH to change it.") endif(DEFINED ENV{BRIDGE_INSTALL_PATH}) if(NOT UNIX) diff --git a/internal/frontend/bridge-gui/bridge-gui/Config.h.in b/internal/frontend/bridge-gui/bridge-gui/Config.h.in deleted file mode 100644 index db360297..00000000 --- a/internal/frontend/bridge-gui/bridge-gui/Config.h.in +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright (c) 2022 Proton AG -// -// This file is part of Proton Mail Bridge. -// -// Proton Mail Bridge is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// Proton Mail Bridge is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Proton Mail Bridge. If not, see . - - -#ifndef BRIDGE_GUI_CONFIG_H -#define BRIDGE_GUI_CONFIG_H - -#cmakedefine ATTACH_MODE @ATTACH_MODE@ - -#endif // BRIDGE_GUI_CONFIG_H diff --git a/internal/frontend/bridge-gui/bridge-gui/build.ps1 b/internal/frontend/bridge-gui/bridge-gui/build.ps1 index a9559f0e..3eeb662f 100644 --- a/internal/frontend/bridge-gui/bridge-gui/build.ps1 +++ b/internal/frontend/bridge-gui/bridge-gui/build.ps1 @@ -18,9 +18,11 @@ #!/bin/bash $scriptpath = $MyInvocation.MyCommand.Path -$dir = Split-Path $scriptpath -Write-host "Bridge-gui directory is $dir" -Push-Location $dir +$scriptDir = Split-Path $scriptpath +$bridgeRepoRootDir = Join-Path $scriptDir "../../../.." -Resolve +Write-host "Bridge-gui directory is $scriptDir" +Write-host "Bridge repos root dir $bridgeRepoRootDir" +Push-Location $scriptDir $ErrorActionPreference = "Stop" @@ -29,10 +31,11 @@ if ($null -eq $cmakeExe) { $cmakeExe = "C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.exe" # Hardcoded for now. } + $bridgeVersion = ($env:BRIDGE_APP_VERSION) if ($null -eq $bridgeVersion) { - $bridgeVersion = "2.2.1+" + $bridgeVersion = . (Join-Path $bridgeRepoRootDir "utils/bridge_app_version.ps1") } $buildConfig = ($env:BRIDGE_GUI_BUILD_CONFIG) if ($null -eq $buildConfig) @@ -40,8 +43,8 @@ if ($null -eq $buildConfig) $buildConfig = "Debug" } -$buildDir=(Join-Path $PSScriptRoot "cmake-build-$buildConfig".ToLower()) -$vcpkgRoot = (Join-Path $PSScriptRoot "../../../../extern/vcpkg" -Resolve) +$buildDir=(Join-Path $scriptDir "cmake-build-$buildConfig".ToLower()) +$vcpkgRoot = (Join-Path $bridgeRepoRootDir "extern/vcpkg" -Resolve) $vcpkgExe = (Join-Path $vcpkgRoot "vcpkg.exe") $vcpkgBootstrap = (Join-Path $vcpkgRoot "bootstrap-vcpkg.bat") diff --git a/internal/frontend/bridge-gui/bridge-gui/build.sh b/internal/frontend/bridge-gui/bridge-gui/build.sh index fb74105b..7398f82f 100755 --- a/internal/frontend/bridge-gui/bridge-gui/build.sh +++ b/internal/frontend/bridge-gui/bridge-gui/build.sh @@ -22,8 +22,9 @@ if [[ "$OSTYPE" == "msys" ]] || [[ "$OSTYPE" == "win32" ]] ; then fi +BRIDGE_REPO_ROOT="../../../.." BRIDGE_INSTALL_PATH=${BRIDGE_INSTALL_PATH:-deploy} -BRIDGE_APP_VERSION=${BRIDGE_APP_VERSION:-2.2.1+git} +BRIDGE_APP_VERSION=${BRIDGE_APP_VERSION:-$("${BRIDGE_REPO_ROOT}/utils/bridge_app_version.sh")} BUILD_CONFIG=${BRIDGE_GUI_BUILD_CONFIG:-Debug} BUILD_DIR=$(echo "./cmake-build-${BUILD_CONFIG}" | tr '[:upper:]' '[:lower:]') @@ -51,7 +52,7 @@ check_exit() { fi } -VCPKG_ROOT="../../../../extern/vcpkg" +VCPKG_ROOT="${BRIDGE_REPO_ROOT}/extern/vcpkg" git submodule update --init --recursive ${VCPKG_ROOT} check_exit "Failed to initialize vcpkg as a submodule." diff --git a/internal/frontend/bridge-gui/bridgepp/CMakeLists.txt b/internal/frontend/bridge-gui/bridgepp/CMakeLists.txt index 3b76a796..792b4fdc 100644 --- a/internal/frontend/bridge-gui/bridgepp/CMakeLists.txt +++ b/internal/frontend/bridge-gui/bridgepp/CMakeLists.txt @@ -17,7 +17,8 @@ cmake_minimum_required(VERSION 3.22) -set(VCPKG_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/../../../../extern/vcpkg") + +set(BRIDGE_REPO_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/../../../..") include(../BridgeSetup.cmake) @@ -46,6 +47,7 @@ set(CMAKE_PREFIX_PATH $ENV{QT6DIR} ${CMAKE_PREFIX_PATH}) find_package(Qt6 COMPONENTS Core REQUIRED) qt_standard_project_setup() + #**************************************************************************************************************************************************** # gRPC / Protobuf #**************************************************************************************************************************************************** diff --git a/utils/bridge_app_version.ps1 b/utils/bridge_app_version.ps1 new file mode 100644 index 00000000..a5910fc5 --- /dev/null +++ b/utils/bridge_app_version.ps1 @@ -0,0 +1,2 @@ +Select-String -Path (Join-Path $PSScriptRoot "../Makefile") -Pattern "^BRIDGE_APP_VERSION\?=(\S*)" | + ForEach-Object {$_.Matches} | ForEach-Object { $_.Groups[1].Value } \ No newline at end of file diff --git a/utils/bridge_app_version.sh b/utils/bridge_app_version.sh new file mode 100755 index 00000000..9a9f960f --- /dev/null +++ b/utils/bridge_app_version.sh @@ -0,0 +1,2 @@ +#!/bin/sh +sed -n "s/BRIDGE_APP_VERSION?=\(\S*\)/\1/p" "$(dirname $0)/../Makefile"