Skip to content

Commit 4a9f641

Browse files
PR feedback
1 parent df1eddb commit 4a9f641

File tree

53 files changed

+246
-97
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+246
-97
lines changed

Directory.Build.targets

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Project>
22
<PropertyGroup>
3-
<RuntimeFrameworkVersion Condition=" '$(TargetFramework)' == 'netcoreapp2.2' ">$(MicrosoftNETCoreApp22PackageVersion)</RuntimeFrameworkVersion>
3+
<RuntimeFrameworkVersion Condition=" '$(TargetFramework)' == 'netcoreapp2.0' ">$(MicrosoftNETCoreApp20PackageVersion)</RuntimeFrameworkVersion>
44
</PropertyGroup>
55

66
<!-- Don't police what version of NetCoreApp we use -->

build/dependencies.props

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
<HtmlAgilityPackPackageVersion>1.5.1</HtmlAgilityPackPackageVersion>
44
<MicrosoftDotNetPlatformAbstractionsVersion>2.0.0</MicrosoftDotNetPlatformAbstractionsVersion>
55
<MicrosoftNETCoreApp20PackageVersion>2.0.0</MicrosoftNETCoreApp20PackageVersion>
6-
<MicrosoftNETCoreApp21PackageVersion>2.1.0-rc1-26425-06</MicrosoftNETCoreApp21PackageVersion>
76
<MicrosoftNETTestSdkPackageVersion>15.6.1</MicrosoftNETTestSdkPackageVersion>
87
<MicrosoftWin32RegistryPackageVersion>4.4.0</MicrosoftWin32RegistryPackageVersion>
98
<MonoCecilPackageVersion>0.10.0-beta6</MonoCecilPackageVersion>

build/tasks/RepoTasks.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<Import Project="$(RepoTasksSdkPath)\Sdk.props" Condition="'$(RepoTasksSdkPath)' != '' "/>
33

44
<PropertyGroup>
5-
<TargetFramework>netcoreapp2.2</TargetFramework>
5+
<TargetFramework>netcoreapp2.0</TargetFramework>
66
<DefineConstants>$(DefineConstants);BuildTools</DefineConstants>
77
<NoWarn>$(NoWarn);NU1603</NoWarn>
88
</PropertyGroup>

files/KoreBuild/KoreBuild.sh

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,12 @@ invoke_korebuild_command(){
4040
shift
4141

4242
if [ "$command" = "default-build" ]; then
43-
__install_tools "$tools_source" "$dot_net_home"
43+
__install_tools "$tools_source" "$dot_net_home" "$repo_path"
4444
__invoke_repository_build "$repo_path" "$@"
4545
elif [ "$command" = "msbuild" ]; then
4646
__invoke_repository_build "$repo_path" "$@"
4747
elif [ "$command" = "install-tools" ]; then
48-
__install_tools "$tools_source" "$dot_net_home"
48+
__install_tools "$tools_source" "$dot_net_home" "$repo_path"
4949
else
5050
__ensure_dotnet
5151

@@ -80,6 +80,7 @@ __invoke_repository_build() {
8080
__install_tools() {
8181
local tools_source=$1
8282
local install_dir=$2
83+
local repo_path=$3
8384
local tools_home="$install_dir/buildtools"
8485
local netfx_version='4.6.1'
8586

@@ -97,7 +98,7 @@ __install_tools() {
9798

9899
# Call "sync" between "chmod" and execution to prevent "text file busy" error in Docker (aufs)
99100
chmod +x "$__korebuild_dir/scripts/get-dotnet.sh"; sync
100-
"$__korebuild_dir/scripts/get-dotnet.sh" $verbose_flag "$install_dir" \
101+
"$__korebuild_dir/scripts/get-dotnet.sh" $verbose_flag "$install_dir" "$repo_path"\
101102
|| return 1
102103

103104
# Set environment variables

files/KoreBuild/msbuild/KoreBuild.RepoTasks.Sdk/Sdk/Sdk.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<GenerateFullPaths Condition="'$(VSCODE_PID)' != ''">true</GenerateFullPaths>
66
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
77

8-
<!-- Set explicitly to make it clear that this is not a console app, even though it targets netcoreapp2.2 -->
8+
<!-- Set explicitly to make it clear that this is not a console app, even though it targets netcoreapp2.0 -->
99
<OutputType>library</OutputType>
1010

1111
<!--

files/KoreBuild/scripts/KoreBuild.psm1

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -423,11 +423,6 @@ function __install_shared_runtime($installScript, $installDir, [string]$arch, [s
423423
}
424424

425425
function __get_dotnet_sdk_version {
426-
if ($env:KOREBUILD_DOTNET_VERSION) {
427-
Write-Warning "dotnet SDK version overridden by KOREBUILD_DOTNET_VERSION"
428-
return $env:KOREBUILD_DOTNET_VERSION
429-
}
430-
431426
$globalObj = Get-Content(Join-Path $global:KoreBuildSettings.RepoPath "global.json") -Raw | ConvertFrom-Json
432427
return $globalObj.sdk.version
433428
}

files/KoreBuild/scripts/common.sh

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,34 @@ __ensure_macos_version() {
5959
fi
6060
}
6161

62+
__machine_has() {
63+
hash "$1" > /dev/null 2>&1
64+
return $?
65+
}
66+
6267
__get_dotnet_sdk_version() {
68+
local repo_path=$1
6369
local src="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
6470

65-
version=$(< "$src/../../../global.json" head -1 | grep -Po '"version":.*?[^\\]",' global.json)
66-
# environment override
67-
if [ ! -z "${KOREBUILD_DOTNET_VERSION:-}" ]; then
68-
version=${KOREBUILD_DOTNET_VERSION:-}
69-
__warn "Dotnet SDK version changed by KOREBUILD_DOTNET_VERSION"
71+
local global_json="$repo_path/global.json"
72+
local version
73+
74+
if __machine_has jq ; then
75+
if jq '.' "$global_json" >/dev/null ; then
76+
version="$(jq -r 'select(.sdk!=null) | .sdk.version' "$global_json")"
77+
else
78+
__warn "$global_json is invalid JSON. Its settings will be ignored."
79+
fi
80+
elif __machine_has python ; then
81+
if python -c "import json,codecs;obj=json.load(codecs.open('$global_json', 'r', 'utf-8-sig'))" >/dev/null ; then
82+
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 '')")"
83+
else
84+
__warn "$config_file is invalid JSON. Its settings will be ignored."
85+
fi
86+
else
87+
__warn 'Missing required command: jq or pyton. Could not parse the JSON file. Its settings will be ignored.'
7088
fi
89+
7190
echo $version
7291
}
7392

files/KoreBuild/scripts/get-dotnet.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ if [ ! -z "${KOREBUILD_SKIP_RUNTIME_INSTALL:-}" ]; then
6565
fi
6666

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

modules/BuildTools.Tasks/BuildTools.Tasks.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<PropertyGroup>
44
<DefineConstants>$(DefineConstants);BuildTools</DefineConstants>
55
<Description>MSBuild tasks. This package is intended for Microsoft use only</Description>
6-
<TargetFramework>netcoreapp2.2</TargetFramework>
6+
<TargetFramework>0</TargetFramework>
77
<RootNamespace>Microsoft.AspNetCore.BuildTools</RootNamespace>
88
<AssemblyName>Internal.AspNetCore.BuildTools.Tasks</AssemblyName>
99
</PropertyGroup>

modules/BuildTools.Tasks/FindUnusedReferences.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

4-
#if NETCOREAPP2_2
4+
#if NETCOREAPP2_0
55
using System;
66
using System.Collections.Generic;
77
using System.IO;

modules/BuildTools.Tasks/GetDotNetHost.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

4-
#if NETCOREAPP2_2
4+
#if NETCOREAPP2_0
55

66
using System.IO;
77
using Microsoft.AspNetCore.BuildTools.Utilities;

modules/BuildTools.Tasks/GetOSPlatform.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public override bool Execute()
2525
#if NET46
2626
// MSBuild.exe only runs on Windows. This task doesn't support xbuild, only dotnet-msbuild and MSBuild.exe.
2727
PlatformName = "Windows";
28-
#elif NETCOREAPP2_2
28+
#elif NETCOREAPP2_0
2929
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
3030
{
3131
PlatformName = "Windows";

modules/BuildTools.Tasks/ZipArchive.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public override bool Execute()
8989

9090
var entry = zip.CreateEntryFromFile(file.ItemSpec, entryName);
9191
#if NET46
92-
#elif NETCOREAPP2_2
92+
#elif NETCOREAPP2_0
9393
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
9494
{
9595
// This isn't required when creating a zip on Windows. unzip will check which

modules/KoreBuild.Tasks/KoreBuild.Tasks.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>netcoreapp2.2</TargetFramework>
4+
<TargetFramework>netcoreapp2.0</TargetFramework>
55
<AssemblyName>Internal.AspNetCore.KoreBuild.Tasks</AssemblyName>
66
</PropertyGroup>
77

modules/KoreBuild.Tasks/UpgradeDependencies.cs

Lines changed: 85 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ public class UpgradeDependencies : Microsoft.Build.Utilities.Task, ICancelableTa
4444
/// </summary>
4545
public string LineupDependenciesFile { get; set; }
4646

47+
/// <summary>
48+
/// The tools.props file to use versions from
49+
/// </summary>
50+
public string LineupToolsFile { get; set; }
51+
4752
/// <summary>
4853
/// The NuGet feed containing the lineup package
4954
/// </summary>
@@ -96,7 +101,7 @@ public async Task<bool> ExecuteAsync()
96101

97102
try
98103
{
99-
var remoteDepsVersionFile = await TryDownloadLineupDepsFile() ?? await TryDownloadLineupPackage(logger, tmpNupkgPath);
104+
var remoteDepsVersionFile = await TryDownloadLineupDepsFile() ?? (await TryDownloadLineupPackage(logger, tmpNupkgPath)).DepsFile;
100105

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

123+
var remoteToolsVersionFile = await TryDownloadLineupToolsFile() ?? (await TryDownloadLineupPackage(logger, tmpNupkgPath)).ToolsFile;
124+
125+
var globalFile = new GlobalJsonFile(GlobalJsonFile);
126+
var toolsCount = UpdateTools(globalFile, remoteToolsVersionFile);
127+
128+
if(toolsCount > 0)
129+
{
130+
Log.LogMessage($"Finished updating {toolsCount} sdks in {GlobalJsonFile}");
131+
globalFile.Save();
132+
}
133+
else
134+
{
135+
Log.LogMessage($"Versions in {GlobalJsonFile} are already up to date");
136+
}
137+
118138
return !Log.HasLoggedErrors;
119139
}
120140
finally
@@ -126,14 +146,64 @@ public async Task<bool> ExecuteAsync()
126146
}
127147
}
128148

149+
private const string CLIVersionVariableName = "DotNetCliVersion";
150+
151+
private int UpdateTools(GlobalJsonFile global, DependencyVersionsFile toolsFile)
152+
{
153+
var updateCount = 0;
154+
155+
foreach (var var in global.MSBuildSdks)
156+
{
157+
if(!toolsFile.VersionVariables.TryGetValue(var.Key, out string newValue))
158+
{
159+
Log.LogKoreBuildWarning(global.Path, KoreBuildErrors.PackageVersionNotFoundInLineup,
160+
$"A new version variable for {var.Key} could not be found in {LineupPackageId}. This might be an unsupported external dependency.");
161+
continue;
162+
}
163+
164+
if(newValue != var.Value)
165+
{
166+
updateCount++;
167+
global.MSBuildSdks[var.Key] = newValue;
168+
}
169+
}
170+
171+
if(toolsFile.VersionVariables.ContainsKey(CLIVersionVariableName))
172+
{
173+
global.SDKVersion = toolsFile.VersionVariables[CLIVersionVariableName];
174+
updateCount++;
175+
}
176+
else
177+
{
178+
Log.LogKoreBuildWarning(global.Path, KoreBuildErrors.PackageVersionNotFoundInLineup,
179+
$"A new version variable for DotNetCliVersion could not be found in {LineupPackageId}. This might mean the lineup is broken.");
180+
}
181+
182+
return updateCount;
183+
}
184+
129185
private async Task<DependencyVersionsFile> TryDownloadLineupDepsFile()
130186
{
131187
if (string.IsNullOrEmpty(LineupDependenciesFile))
132188
{
133189
return null;
134190
}
135191

136-
var path = LineupDependenciesFile;
192+
return await TryDownloadLineupFile(LineupDependenciesFile);
193+
}
194+
195+
private async Task<DependencyVersionsFile> TryDownloadLineupToolsFile()
196+
{
197+
if (string.IsNullOrEmpty(LineupToolsFile))
198+
{
199+
return null;
200+
}
201+
202+
return await TryDownloadLineupFile(LineupToolsFile);
203+
}
204+
205+
private async Task<DependencyVersionsFile> TryDownloadLineupFile(string path)
206+
{
137207
string text;
138208
if (path.StartsWith("http"))
139209
{
@@ -156,7 +226,7 @@ private async Task<DependencyVersionsFile> TryDownloadLineupDepsFile()
156226
}
157227
}
158228

159-
private async Task<DependencyVersionsFile> TryDownloadLineupPackage(MSBuildLogger logger, string tmpNupkgPath)
229+
private async Task<LineupPackage> TryDownloadLineupPackage(MSBuildLogger logger, string tmpNupkgPath)
160230
{
161231
VersionRange versionRange;
162232

@@ -194,13 +264,24 @@ private async Task<DependencyVersionsFile> TryDownloadLineupPackage(MSBuildLogge
194264
return null;
195265
}
196266

267+
var lineupPackage = new LineupPackage();
197268
using (var nupkgReader = new PackageArchiveReader(tmpNupkgPath))
198269
using (var stream = nupkgReader.GetStream("build/dependencies.props"))
199270
using (var reader = new XmlTextReader(stream))
200271
{
201272
var projectRoot = ProjectRootElement.Create(reader);
202-
return DependencyVersionsFile.Load(projectRoot);
273+
lineupPackage.DepsFile = DependencyVersionsFile.Load(projectRoot);
203274
}
275+
276+
using (var nupkgReader = new PackageArchiveReader(tmpNupkgPath))
277+
using (var stream = nupkgReader.GetStream("build/tools.props"))
278+
using (var reader = new XmlTextReader(stream))
279+
{
280+
var projectRoot = ProjectRootElement.Create(reader);
281+
lineupPackage.ToolsFile = DependencyVersionsFile.Load(projectRoot);
282+
}
283+
284+
return lineupPackage;
204285
}
205286

206287
private int UpdateDependencies(DependencyVersionsFile localVersionsFile, DependencyVersionsFile remoteDepsVersionFile)
@@ -215,12 +296,6 @@ private int UpdateDependencies(DependencyVersionsFile localVersionsFile, Depende
215296
newValue = KoreBuildVersion.Current;
216297
Log.LogMessage(MessageImportance.Low, "Setting InternalAspNetCoreSdkPackageVersion to the current version of KoreBuild");
217298
}
218-
else if (var.Key == "SdkPackageVersion")
219-
{
220-
var globalFile = new GlobalJsonFile(GlobalJsonFile);
221-
globalFile.SetSdkVersion(var.Value);
222-
continue;
223-
}
224299
else if (!remoteDepsVersionFile.VersionVariables.TryGetValue(var.Key, out newValue))
225300
{
226301
Log.LogKoreBuildWarning(

0 commit comments

Comments
 (0)