Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Design]Use global.json and switch to netcoreapp2.2 #661

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ project.lock.json
.build
.vs/
.vscode/
global.json
launchSettings.json
korebuild-lock.txt
*.binlog
Expand Down
6 changes: 5 additions & 1 deletion Directory.Build.targets
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
<Project>
<PropertyGroup>
<RuntimeFrameworkVersion Condition=" '$(TargetFramework)' == 'netcoreapp2.0' ">$(MicrosoftNETCoreApp20PackageVersion)</RuntimeFrameworkVersion>
<RuntimeFrameworkVersion Condition=" '$(TargetFramework)' == 'netcoreapp2.1' ">$(MicrosoftNETCoreApp21PackageVersion)</RuntimeFrameworkVersion>
</PropertyGroup>

<!-- Don't police what version of NetCoreApp we use -->
<PropertyGroup>
<NETCoreAppMaximumVersion>99.9</NETCoreAppMaximumVersion>
</PropertyGroup>
</Project>
1 change: 0 additions & 1 deletion build/dependencies.props
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
<HtmlAgilityPackPackageVersion>1.5.1</HtmlAgilityPackPackageVersion>
<MicrosoftDotNetPlatformAbstractionsVersion>2.0.0</MicrosoftDotNetPlatformAbstractionsVersion>
<MicrosoftNETCoreApp20PackageVersion>2.0.0</MicrosoftNETCoreApp20PackageVersion>
<MicrosoftNETCoreApp21PackageVersion>2.1.0-rc1-26425-06</MicrosoftNETCoreApp21PackageVersion>
<MicrosoftNETTestSdkPackageVersion>15.6.1</MicrosoftNETTestSdkPackageVersion>
<MicrosoftWin32RegistryPackageVersion>4.4.0</MicrosoftWin32RegistryPackageVersion>
<MonoCecilPackageVersion>0.10.0-beta6</MonoCecilPackageVersion>
Expand Down
5 changes: 3 additions & 2 deletions files/KoreBuild/KoreBuild.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ invoke_korebuild_command(){
shift

if [ "$command" = "default-build" ]; then
__install_tools "$tools_source" "$dot_net_home"
__install_tools "$tools_source" "$dot_net_home" "$repo_path"
__invoke_repository_build "$repo_path" "$@"
elif [ "$command" = "msbuild" ]; then
__invoke_repository_build "$repo_path" "$@"
elif [ "$command" = "install-tools" ]; then
__install_tools "$tools_source" "$dot_net_home"
__install_tools "$tools_source" "$dot_net_home" "$repo_path"
else
__ensure_dotnet

Expand Down Expand Up @@ -80,6 +80,7 @@ __invoke_repository_build() {
__install_tools() {
local tools_source=$1
local install_dir=$2
local repo_path=$3
local tools_home="$install_dir/buildtools"
local netfx_version='4.6.1'

Expand Down
1 change: 0 additions & 1 deletion files/KoreBuild/config/sdk.version

This file was deleted.

18 changes: 3 additions & 15 deletions files/KoreBuild/scripts/KoreBuild.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ function Invoke-RepositoryBuild(
}
else {
[string[]]$repoTasksArgs = $MSBuildArgs | Where-Object { ($_ -like '-p:*') -or ($_ -like '/p:*') -or ($_ -like '-property:') -or ($_ -like '/property:') }
$repoTasksArgs += ,"@$msBuildLogRspFile"
$repoTasksArgs += , "@$msBuildLogRspFile"
__build_task_project $Path $repoTasksArgs
}

Expand Down Expand Up @@ -359,15 +359,6 @@ function Invoke-KoreBuildCommand(
throw "Set-KoreBuildSettings must be called before Invoke-KoreBuildCommand."
}

$sdkVersion = __get_dotnet_sdk_version
$korebuildVersion = Get-KoreBuildVersion
if ($sdkVersion -ne 'latest') {
"{ `"sdk`": { `n`"version`": `"$sdkVersion`" },`n`"msbuild-sdks`": {`n`"Microsoft.DotNet.GlobalTools.Sdk`": `"$korebuildVersion`"}`n }" | Out-File (Join-Path $global:KoreBuildSettings.RepoPath 'global.json') -Encoding ascii
}
else {
Write-Verbose "Skipping global.json generation because the `$sdkVersion = $sdkVersion"
}

if ($Command -eq "default-build") {
Install-Tools
Invoke-RepositoryBuild $global:KoreBuildSettings.RepoPath @Arguments
Expand Down Expand Up @@ -432,11 +423,8 @@ function __install_shared_runtime($installScript, $installDir, [string]$arch, [s
}

function __get_dotnet_sdk_version {
if ($env:KOREBUILD_DOTNET_VERSION) {
Write-Warning "dotnet SDK version overridden by KOREBUILD_DOTNET_VERSION"
return $env:KOREBUILD_DOTNET_VERSION
}
return Get-Content (Join-Paths $PSScriptRoot ('..', 'config', 'sdk.version'))
$globalObj = Get-Content(Join-Path $global:KoreBuildSettings.RepoPath "global.json") -Raw | ConvertFrom-Json
return $globalObj.sdk.version
}

function __build_task_project($RepoPath, [string[]]$msbuildArgs) {
Expand Down
30 changes: 25 additions & 5 deletions files/KoreBuild/scripts/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,34 @@ __ensure_macos_version() {
fi
}

__machine_has() {
hash "$1" > /dev/null 2>&1
return $?
}

__get_dotnet_sdk_version() {
local repo_path=$1
local src="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
version=$(< "$src/../config/sdk.version" head -1 | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')
# environment override
if [ ! -z "${KOREBUILD_DOTNET_VERSION:-}" ]; then
version=${KOREBUILD_DOTNET_VERSION:-}
__warn "Dotnet SDK version changed by KOREBUILD_DOTNET_VERSION"

local global_json="$repo_path/global.json"
local version

if __machine_has jq ; then
if jq '.' "$global_json" >/dev/null ; then
version="$(jq -r 'select(.sdk!=null) | .sdk.version' "$global_json")"
else
__warn "$global_json is invalid JSON. Its settings will be ignored."
fi
elif __machine_has python ; then
if python -c "import json,codecs;obj=json.load(codecs.open('$global_json', 'r', 'utf-8-sig'))" >/dev/null ; then
version="$(python -c "import json,codecs;obj=json.load(codecs.open('$global_json', 'r', 'utf-8-sig'));print(obj['sdk']['version'] if 'channel' in obj else '')")"
else
__warn "$config_file is invalid JSON. Its settings will be ignored."
fi
else
__warn 'Missing required command: jq or pyton. Could not parse the JSON file. Its settings will be ignored.'
fi

echo $version
}

Expand Down
2 changes: 1 addition & 1 deletion files/KoreBuild/scripts/get-dotnet.sh
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ if [ ! -z "${KOREBUILD_SKIP_RUNTIME_INSTALL:-}" ]; then
fi

channel='preview'
version=$(__get_dotnet_sdk_version)
version=$(__get_dotnet_sdk_version )
runtime_channel='master'
runtime_version=$(< "$__script_dir/../config/runtime.version" head -1 | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')

Expand Down
15 changes: 0 additions & 15 deletions files/KoreBuild/scripts/invoke-repository-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -58,21 +58,6 @@ fi
repo_path="$(cd "$repo_path" && pwd)"
__verbose "Building $repo_path"

sdk_version="$(__get_dotnet_sdk_version)"
korebuild_version="$(__get_korebuild_version)"
if [ "$sdk_version" != 'latest' ]; then
echo "{
\"sdk\": {
\"version\": \"${sdk_version}\"
},
\"msbuild-sdks\": {
\"Microsoft.DotNet.GlobalTools.Sdk\": \"${korebuild_version}\"
}
}" > "$repo_path/global.json"
else
__verbose "Skipping global.json generation because the \$sdk_version = $sdk_version"
fi

korebuild_proj="$__script_dir/../KoreBuild.proj"
msbuild_artifacts_dir="$repo_path/artifacts/logs"
msbuild_response_file="$msbuild_artifacts_dir/msbuild.rsp"
Expand Down
1 change: 1 addition & 0 deletions global.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{ "sdk": { "version": "2.1.300-rc1-008669" } }
96 changes: 91 additions & 5 deletions modules/KoreBuild.Tasks/UpgradeDependencies.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ public class UpgradeDependencies : Microsoft.Build.Utilities.Task, ICancelableTa
/// </summary>
public string LineupDependenciesFile { get; set; }

/// <summary>
/// The tools.props file to use versions from
/// </summary>
public string LineupToolsFile { get; set; }

/// <summary>
/// The NuGet feed containing the lineup package
/// </summary>
Expand All @@ -56,6 +61,12 @@ public class UpgradeDependencies : Microsoft.Build.Utilities.Task, ICancelableTa
[Required]
public string DependenciesFile { get; set; }

/// <summary>
/// The global.json file to update
/// </summary>
[Required]
public string GlobalJsonFile { get; set; }

public void Cancel()
{
_cts.Cancel();
Expand Down Expand Up @@ -85,13 +96,12 @@ public async Task<bool> ExecuteAsync()
return true;
}


var tmpNupkgPath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
var logger = new MSBuildLogger(Log);

try
{
var remoteDepsVersionFile = await TryDownloadLineupDepsFile() ?? await TryDownloadLineupPackage(logger, tmpNupkgPath);
var remoteDepsVersionFile = await TryDownloadLineupDepsFile() ?? (await TryDownloadLineupPackage(logger, tmpNupkgPath)).DepsFile;

if (remoteDepsVersionFile == null)
{
Expand All @@ -110,6 +120,21 @@ public async Task<bool> ExecuteAsync()
Log.LogMessage($"Versions in {DependenciesFile} are already up to date");
}

var remoteToolsVersionFile = await TryDownloadLineupToolsFile() ?? (await TryDownloadLineupPackage(logger, tmpNupkgPath)).ToolsFile;

var globalFile = new GlobalJsonFile(GlobalJsonFile);
var toolsCount = UpdateTools(globalFile, remoteToolsVersionFile);

if (toolsCount > 0)
{
Log.LogMessage($"Finished updating {toolsCount} sdks in {GlobalJsonFile}");
globalFile.Save();
}
else
{
Log.LogMessage($"Versions in {GlobalJsonFile} are already up to date");
}

return !Log.HasLoggedErrors;
}
finally
Expand All @@ -121,14 +146,64 @@ public async Task<bool> ExecuteAsync()
}
}

private const string CLIVersionVariableName = "DotNetCliVersion";

private int UpdateTools(GlobalJsonFile global, DependencyVersionsFile toolsFile)
{
var updateCount = 0;

foreach (var var in global.MSBuildSdks)
{
if (!toolsFile.VersionVariables.TryGetValue(var.Key, out string newValue))
{
Log.LogKoreBuildWarning(global.Path, KoreBuildErrors.PackageVersionNotFoundInLineup,
$"A new version variable for {var.Key} could not be found in {LineupPackageId}. This might be an unsupported external dependency.");
continue;
}

if (newValue != var.Value)
{
updateCount++;
global.MSBuildSdks[var.Key] = newValue;
}
}

if (toolsFile.VersionVariables.ContainsKey(CLIVersionVariableName))
{
global.SDKVersion = toolsFile.VersionVariables[CLIVersionVariableName];
updateCount++;
}
else
{
Log.LogKoreBuildWarning(global.Path, KoreBuildErrors.PackageVersionNotFoundInLineup,
$"A new version variable for DotNetCliVersion could not be found in {LineupPackageId}. This might mean the lineup is broken.");
}

return updateCount;
}

private async Task<DependencyVersionsFile> TryDownloadLineupDepsFile()
{
if (string.IsNullOrEmpty(LineupDependenciesFile))
{
return null;
}

var path = LineupDependenciesFile;
return await TryDownloadLineupFile(LineupDependenciesFile);
}

private async Task<DependencyVersionsFile> TryDownloadLineupToolsFile()
{
if (string.IsNullOrEmpty(LineupToolsFile))
{
return null;
}

return await TryDownloadLineupFile(LineupToolsFile);
}

private async Task<DependencyVersionsFile> TryDownloadLineupFile(string path)
{
string text;
if (path.StartsWith("http"))
{
Expand All @@ -151,7 +226,7 @@ private async Task<DependencyVersionsFile> TryDownloadLineupDepsFile()
}
}

private async Task<DependencyVersionsFile> TryDownloadLineupPackage(MSBuildLogger logger, string tmpNupkgPath)
private async Task<LineupPackage> TryDownloadLineupPackage(MSBuildLogger logger, string tmpNupkgPath)
{
VersionRange versionRange;

Expand Down Expand Up @@ -189,13 +264,24 @@ private async Task<DependencyVersionsFile> TryDownloadLineupPackage(MSBuildLogge
return null;
}

var lineupPackage = new LineupPackage();
using (var nupkgReader = new PackageArchiveReader(tmpNupkgPath))
using (var stream = nupkgReader.GetStream("build/dependencies.props"))
using (var reader = new XmlTextReader(stream))
{
var projectRoot = ProjectRootElement.Create(reader);
return DependencyVersionsFile.Load(projectRoot);
lineupPackage.DepsFile = DependencyVersionsFile.Load(projectRoot);
}

using (var nupkgReader = new PackageArchiveReader(tmpNupkgPath))
using (var stream = nupkgReader.GetStream("build/tools.props"))
using (var reader = new XmlTextReader(stream))
{
var projectRoot = ProjectRootElement.Create(reader);
lineupPackage.ToolsFile = DependencyVersionsFile.Load(projectRoot);
}

return lineupPackage;
}

private int UpdateDependencies(DependencyVersionsFile localVersionsFile, DependencyVersionsFile remoteDepsVersionFile)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ public static string GetVariableName(string packageId)
return sb.ToString();
}


public static DependencyVersionsFile Create(bool addOverrideImport, string[] additionalImports = null)
{
var projectRoot = ProjectRootElement.Create(NewProjectFileOptions.None);
Expand Down
Loading