From 9e1be97a513936935faea20804c2942b3b0fbba4 Mon Sep 17 00:00:00 2001 From: DominikDeak Date: Fri, 29 Jan 2021 17:21:44 +1100 Subject: [PATCH] Added options to checkout and build specific tags for Synergy-Core. --- Documentation/BuildingOnDarwin.md | 6 ++++ Documentation/BuildingOnLinux.md | 6 ++++ Documentation/BuildingOnWindows.md | 6 ++++ Scripts/Detail/Config.py | 45 +++++++++++++++++------------- Scripts/build.py | 5 ++++ Scripts/config.txt | 1 - Synergy-Core | 2 +- 7 files changed, 50 insertions(+), 21 deletions(-) diff --git a/Documentation/BuildingOnDarwin.md b/Documentation/BuildingOnDarwin.md index ac00899..77fd4cb 100644 --- a/Documentation/BuildingOnDarwin.md +++ b/Documentation/BuildingOnDarwin.md @@ -35,6 +35,12 @@ Build the project with the following Python script. Packages will be copied into ./Scripts/build.py ``` +To build a specific version of the product, supply the appropriate tag name (or commit hash) as an argument: + +```sh +./Scripts/build.py --checkout 1.13.1.3-snapshot +``` + Similarly, one can clean the project, which resets Git repositories to a clean state: ```sh diff --git a/Documentation/BuildingOnLinux.md b/Documentation/BuildingOnLinux.md index 1963ed8..d8f0478 100644 --- a/Documentation/BuildingOnLinux.md +++ b/Documentation/BuildingOnLinux.md @@ -28,6 +28,12 @@ Build the project with the following Python script. Packages will be copied into ./Scripts/build.py ``` +To build a specific version of the product, supply the appropriate tag name (or commit hash) as an argument: + +```sh +./Scripts/build.py --checkout 1.13.1.3-snapshot +``` + Similarly, one can clean the project, which resets Git repositories to a clean state: ```sh diff --git a/Documentation/BuildingOnWindows.md b/Documentation/BuildingOnWindows.md index 22acf66..b0029b7 100644 --- a/Documentation/BuildingOnWindows.md +++ b/Documentation/BuildingOnWindows.md @@ -42,6 +42,12 @@ Build the project with the following Python script. Packages will be copied into python.exe Scripts\build.py ``` +To build a specific version of the product, supply the appropriate tag name (or commit hash) as an argument: + +```sh +python.exe Scripts\build.py --checkout 1.13.1.3-snapshot +``` + Similarly, one can clean the project, which resets Git repositories to a clean state: ```bat diff --git a/Scripts/Detail/Config.py b/Scripts/Detail/Config.py index 52fc977..f5c658e 100644 --- a/Scripts/Detail/Config.py +++ b/Scripts/Detail/Config.py @@ -1,6 +1,6 @@ #!/bin/echo "This module must be imported by other Python scripts." -import configparser, os, platform, re, sys +import argparse, configparser, os, platform, re, sys import Detail.Utility as utility @@ -27,12 +27,23 @@ class Configuration(): productPackageName = "-".join( [ productName, productVersion, productStage ] ).lower() productRepoPath = "" productBuildPath = "" - productVersionPath = "" + productCheckout = "" # Constructor def __init__( self, configPath ): + def programOptions( self ): + + parser = argparse.ArgumentParser( description = + "This utility builds the Synergy-Core binaries. The product version is extracted from the most recent Git tag. One can also build older versions " + "by checking out specific git tags, see options below." ) + + parser.add_argument( "--checkout", dest = "productCheckout", help = "Checkout and build a specific Git tag (or commit hash) for the Synergy-Core submodule." ) + + for key, value in vars( parser.parse_args() ).items(): + setattr( self, key, value ) + def loadConfiguration( self, configPath ): utility.printItem( "configPath: ", configPath ) @@ -87,7 +98,6 @@ class Configuration(): resolvePath( self, "productRepoPath" ) resolvePath( self, "productBuildPath", mustExist = False ) - resolvePath( self, "productVersionPath", mustExist = False ) resolvePath( self, "binariesPath" ) resolvePath( self, "toolsPath" ) resolvePath( self, "libQtPath" ) @@ -116,6 +126,8 @@ class Configuration(): self.updateProductVersion() + programOptions( self ) + utility.printHeading( "Loading configuration..." ) loadConfiguration( self, configPath ) @@ -135,26 +147,19 @@ class Configuration(): def updateProductVersion( self ): - if not os.path.exists( self.productVersionPath ): + os.chdir( self.productRepoPath ) - utility.printWarning( "Unable to determine product version at this time; version file was missing:\n\t", self.productVersionPath ) + lastTag = utility.captureCommandOutput( "git describe --tags --abbrev=0" ) - else: + matches = re.search( "v?(\d+(?:\.\d+)+)-(\w+)", lastTag ) - versionFile = open( self.productVersionPath, "r" ) - versionData = versionFile.read() - versionFile.close() - - versionParts = re.findall( r'set \(SYNERGY_VERSION_\w+ "?(\w+)"?\)', versionData ) - - if len( versionParts ) == 0: - utility.printError( "Failed to extract version information." ) - raise SystemExit( 1 ) - - self.productVersion = ".".join( versionParts[ 0:-1 ] ) - self.productStage = versionParts[ -1 ] - self.productRevision = utility.captureCommandOutput( "git rev-parse --short=8 HEAD" ) + if not matches: + utility.printError( "Unable to extract version information from Git tags." ) + raise SystemExit( 1 ) + self.productVersion = matches.group( 1 ) + self.productStage = matches.group( 2 ) + self.productRevision = utility.captureCommandOutput( "git rev-parse --short=8 HEAD" ) self.productPackageName = "-".join( [ self.productName, self.productVersion, self.productStage, self.platformVersion ] ).lower() utility.printItem( "productVersion: ", self.productVersion ) @@ -162,6 +167,8 @@ class Configuration(): utility.printItem( "productRevision: ", self.productRevision ) utility.printItem( "productPackageName: ", self.productPackageName ) + os.chdir( self.toplevelPath ) + # Property list def propertyList( self ): diff --git a/Scripts/build.py b/Scripts/build.py index 90df47f..861754c 100755 --- a/Scripts/build.py +++ b/Scripts/build.py @@ -18,6 +18,11 @@ def configureSubmodules(): utility.runCommand( "git submodule update --init --remote --recursive" ) + if config.productCheckoutTag: + os.chdir( config.productRepoPath ) + utility.runCommand( "git checkout " + config.productCheckoutTag ) + os.chdir( config.toplevelPath ) + statusAfter = utility.captureCommandOutput( "git submodule status" ) print( statusAfter ) diff --git a/Scripts/config.txt b/Scripts/config.txt index f92823b..1ed2f1b 100644 --- a/Scripts/config.txt +++ b/Scripts/config.txt @@ -7,7 +7,6 @@ productName = Synergy productRepoPath = ./Synergy-Core productBuildPath = ./Synergy-Core/build - productVersionPath = ./Synergy-Core/cmake/Version.cmake [Windows] diff --git a/Synergy-Core b/Synergy-Core index ede2721..9c8a1c1 160000 --- a/Synergy-Core +++ b/Synergy-Core @@ -1 +1 @@ -Subproject commit ede272185d5acae6466bfd19edeb8efed95ac429 +Subproject commit 9c8a1c1e3d2c66ea535f6d91ce59f99c588ff2fc