From 6e3cc248f7a70d875f3cb9858de9197e681b06c4 Mon Sep 17 00:00:00 2001 From: Jared Parsons Date: Thu, 24 Aug 2017 16:08:36 -0700 Subject: [PATCH] Centralize tool version numbers This lets us avoid hard coding in version numbers for the core tools we use in our build. --- build/Targets/README.md | 9 +++++++ build/Targets/Settings.props | 6 ++++- build/Targets/Tools.props | 8 ++++++ build/scripts/build-utils.ps1 | 23 +++++++++++----- build/scripts/build-utils.sh | 49 ++++++++++++++++++++++++++++++++++ build/scripts/obtain_dotnet.sh | 4 ++- build/scripts/tests.sh | 17 ++---------- 7 files changed, 92 insertions(+), 24 deletions(-) create mode 100644 build/Targets/Tools.props create mode 100644 build/scripts/build-utils.sh diff --git a/build/Targets/README.md b/build/Targets/README.md index 019e4a9587b..4a140479a06 100644 --- a/build/Targets/README.md +++ b/build/Targets/README.md @@ -65,3 +65,12 @@ The general structure of this file is: - Import all of the external targets. - PropertyGroup to adjust properties set by the external projects. - Custom Targets for our build. + +### Version property files + +There are a number props files that just control version numbers: + +- Packages.props: version numbers for all of the NuGet packages we use. Versions here presumably will change as new packages are available. +- FixedPackages.props: similar to Packages.props but for packages that should never change versions. They are fixed and do not change when new packages are available. Typically used for producing SDKs for older VS / .NET versions. +- Tools.props: version numbers for non-Nuget assets. + diff --git a/build/Targets/Settings.props b/build/Targets/Settings.props index 5ed5905da86..ae49c197fbb 100644 --- a/build/Targets/Settings.props +++ b/build/Targets/Settings.props @@ -174,7 +174,11 @@ - + + + + 2.0.0-preview3-006923 + 4.1.0 + + diff --git a/build/scripts/build-utils.ps1 b/build/scripts/build-utils.ps1 index 7875d701be5..1d6d0afb9d3 100644 --- a/build/scripts/build-utils.ps1 +++ b/build/scripts/build-utils.ps1 @@ -110,7 +110,7 @@ function Exec-Script([string]$script, [string]$scriptArgs = "") { # Ensure that NuGet is installed and return the path to the # executable to use. function Ensure-NuGet() { - $nugetVersion = "4.1.0" + $nugetVersion = Get-ToolVersion "nugetExe" $toolsDir = Join-Path $binariesDir "Tools" Create-Directory $toolsDir @@ -136,7 +136,7 @@ function Ensure-NuGet() { # Ensure the proper SDK in installed in our %PATH%. This is how MSBuild locates the # SDK. function Ensure-SdkInPathAndData() { - $sdkVersion = "2.0.0-preview3-006923" + $sdkVersion = Get-ToolVersion "dotnetSdk" # Get the path to dotnet.exe. This is the first path on %PATH% that contains the # dotnet.exe instance. Many SDK tools use this to locate items like the SDK. @@ -245,13 +245,11 @@ function Create-Directory([string]$dir) { New-Item $dir -ItemType Directory -ErrorAction SilentlyContinue | Out-Null } -# Return the version of the NuGet package as used in this repo -function Get-PackageVersion([string]$name) { +function Get-VersionCore([string]$name, [string]$versionFile) { $name = $name.Replace(".", "") $name = $name.Replace("-", "") - $deps = Join-Path $repoDir "build\Targets\Packages.props" $nodeName = "$($name)Version" - $x = [xml](Get-Content -raw $deps) + $x = [xml](Get-Content -raw $versionFile) $node = $x.Project.PropertyGroup.FirstChild while ($node -ne $null) { if ($node.Name -eq $nodeName) { @@ -260,7 +258,18 @@ function Get-PackageVersion([string]$name) { $node = $node.NextSibling } - throw "Cannot find package $name in Packages.props" + throw "Cannot find package $name in $versionFile" + +} + +# Return the version of the NuGet package as used in this repo +function Get-PackageVersion([string]$name) { + return Get-VersionCore $name (Join-Path $repoDir "build\Targets\Packages.props") +} + +# Return the version of the specified tool +function Get-ToolVersion([string]$name) { + return Get-VersionCore $name (Join-Path $repoDir "build\Targets\Tools.props") } # Locate the directory where our NuGet packages will be deployed. Needs to be kept in sync diff --git a/build/scripts/build-utils.sh b/build/scripts/build-utils.sh new file mode 100644 index 00000000000..263311b5f62 --- /dev/null +++ b/build/scripts/build-utils.sh @@ -0,0 +1,49 @@ +#!/usr/bin/env bash +# Copyright (c) .NET Foundation and contributors. All rights reserved. +# Licensed under the MIT license. See LICENSE file in the project root for full license information. + +set -e +set -u + +get_repo_dir() +{ + local d=$(cd -P "$(dirname "${BASH_SOURCE[0]}")" && pwd) + pushd $d > /dev/null + cd .. + cd .. + local repoDir=$(pwd) + popd > /dev/null + echo $repoDir +} + +# This function will give you the current version number for the specified string in the +# specified version file. +get_version_core() +{ + local name=${1/./} + local name=${name/-/} + local version=$(awk -F'[<>]' "/<${name}Version>/{print \$3}" $2) + echo $version +} + +# This function will give you the current version number for a given nuget package +# based on the contents of Packages.props. +# +# Provide the package name in the format shown in the nuget gallery +# get_package_version dotnet-xunit +# get_package_version System.Console +get_package_version() +{ + local repoDir=$(get_repo_dir) + local version=$(get_version_core $1 ${repoDir}/build/Targets/Packages.props) + echo $version +} + +get_tool_version() +{ + local repoDir=$(get_repo_dir) + local version=$(get_version_core $1 ${repoDir}/build/Targets/Tools.props) + echo $version +} + + diff --git a/build/scripts/obtain_dotnet.sh b/build/scripts/obtain_dotnet.sh index bea78e3b655..4b7e5a34fd5 100755 --- a/build/scripts/obtain_dotnet.sh +++ b/build/scripts/obtain_dotnet.sh @@ -21,8 +21,10 @@ fi # This is a function to keep variable assignments out of the parent script (that is sourcing this file) install_dotnet () { # Download and install `dotnet` locally - local DOTNET_VERSION=2.0.0-preview3-006923 local THIS_DIR=$(cd -P "$(dirname "${BASH_SOURCE[0]}")" && pwd) + source ${THIS_DIR}/build-utils.sh + + local DOTNET_VERSION=$(get_tool_version dotnetSdk) local DOTNET_PATH=${THIS_DIR}/../../Binaries/dotnet-cli if [[ ! -x "${DOTNET_PATH}/dotnet" ]] diff --git a/build/scripts/tests.sh b/build/scripts/tests.sh index dad34e77dfd..7a6f0db4bac 100755 --- a/build/scripts/tests.sh +++ b/build/scripts/tests.sh @@ -5,23 +5,11 @@ set -e set -u -# This function will give you the current version number for a given nuget package -# based on the contents of Packages.props. -# -# Provide the package name in the format shown in the nuget gallery -# get_package_version dotnet-xunit -# get_package_version System.Console -get_package_version() -{ - local name=${1/./} - local name=${name/-/} - local version=$(awk -F'[<>]' "/<${name}Version>/{print \$3}" ${SRC_PATH}/build/Targets/Packages.props) - echo $version -} - BUILD_CONFIGURATION=${1:-Debug} THIS_DIR=$(cd -P "$(dirname "${BASH_SOURCE[0]}")" && pwd) +source ${THIS_DIR}/build-utils.sh + BINARIES_PATH=${THIS_DIR}/../../Binaries SRC_PATH=${THIS_DIR}/../.. UNITTEST_DIR=${BINARIES_PATH}/${BUILD_CONFIGURATION}/UnitTests @@ -38,7 +26,6 @@ echo Using $XUNIT_CONSOLE NEED_PUBLISH=( 'src\Compilers\CSharp\Test\Symbol\CSharpCompilerSymbolTest.csproj' ) -BUILD_ARGS="--no-restore -c ${BUILD_CONFIGURATION} -consoleloggerparameters:Verbosity=minimal;summary -p:RuntimeIdentifier=${RUNTIME_ID} -p:TargetFramework=${TARGET_FRAMEWORK}" for p in $NEED_PUBLISH do echo Publishing ${p} -- GitLab