Skip to content

Commit

Permalink
PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanbrandenburg committed May 3, 2018
1 parent df1eddb commit 4a9f641
Show file tree
Hide file tree
Showing 53 changed files with 246 additions and 97 deletions.
2 changes: 1 addition & 1 deletion Directory.Build.targets
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project>
<PropertyGroup>
<RuntimeFrameworkVersion Condition=" '$(TargetFramework)' == 'netcoreapp2.2' ">$(MicrosoftNETCoreApp22PackageVersion)</RuntimeFrameworkVersion>
<RuntimeFrameworkVersion Condition=" '$(TargetFramework)' == 'netcoreapp2.0' ">$(MicrosoftNETCoreApp20PackageVersion)</RuntimeFrameworkVersion>
</PropertyGroup>

<!-- Don't police what version of NetCoreApp we use -->
Expand Down
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
2 changes: 1 addition & 1 deletion build/tasks/RepoTasks.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<Import Project="$(RepoTasksSdkPath)\Sdk.props" Condition="'$(RepoTasksSdkPath)' != '' "/>

<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
<TargetFramework>netcoreapp2.0</TargetFramework>
<DefineConstants>$(DefineConstants);BuildTools</DefineConstants>
<NoWarn>$(NoWarn);NU1603</NoWarn>
</PropertyGroup>
Expand Down
7 changes: 4 additions & 3 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 All @@ -97,7 +98,7 @@ __install_tools() {

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

# Set environment variables
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<GenerateFullPaths Condition="'$(VSCODE_PID)' != ''">true</GenerateFullPaths>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>

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

<!--
Expand Down
5 changes: 0 additions & 5 deletions files/KoreBuild/scripts/KoreBuild.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -423,11 +423,6 @@ 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
}

$globalObj = Get-Content(Join-Path $global:KoreBuildSettings.RepoPath "global.json") -Raw | ConvertFrom-Json
return $globalObj.sdk.version
}
Expand Down
29 changes: 24 additions & 5 deletions files/KoreBuild/scripts/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +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/../../../global.json" head -1 | grep -Po '"version":.*?[^\\]",' global.json)
# 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
2 changes: 1 addition & 1 deletion modules/BuildTools.Tasks/BuildTools.Tasks.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<DefineConstants>$(DefineConstants);BuildTools</DefineConstants>
<Description>MSBuild tasks. This package is intended for Microsoft use only</Description>
<TargetFramework>netcoreapp2.2</TargetFramework>
<TargetFramework>0</TargetFramework>
<RootNamespace>Microsoft.AspNetCore.BuildTools</RootNamespace>
<AssemblyName>Internal.AspNetCore.BuildTools.Tasks</AssemblyName>
</PropertyGroup>
Expand Down
2 changes: 1 addition & 1 deletion modules/BuildTools.Tasks/FindUnusedReferences.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

#if NETCOREAPP2_2
#if NETCOREAPP2_0
using System;
using System.Collections.Generic;
using System.IO;
Expand Down
2 changes: 1 addition & 1 deletion modules/BuildTools.Tasks/GetDotNetHost.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

#if NETCOREAPP2_2
#if NETCOREAPP2_0

using System.IO;
using Microsoft.AspNetCore.BuildTools.Utilities;
Expand Down
2 changes: 1 addition & 1 deletion modules/BuildTools.Tasks/GetOSPlatform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public override bool Execute()
#if NET46
// MSBuild.exe only runs on Windows. This task doesn't support xbuild, only dotnet-msbuild and MSBuild.exe.
PlatformName = "Windows";
#elif NETCOREAPP2_2
#elif NETCOREAPP2_0
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
PlatformName = "Windows";
Expand Down
2 changes: 1 addition & 1 deletion modules/BuildTools.Tasks/ZipArchive.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public override bool Execute()

var entry = zip.CreateEntryFromFile(file.ItemSpec, entryName);
#if NET46
#elif NETCOREAPP2_2
#elif NETCOREAPP2_0
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
// This isn't required when creating a zip on Windows. unzip will check which
Expand Down
2 changes: 1 addition & 1 deletion modules/KoreBuild.Tasks/KoreBuild.Tasks.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
<TargetFramework>netcoreapp2.0</TargetFramework>
<AssemblyName>Internal.AspNetCore.KoreBuild.Tasks</AssemblyName>
</PropertyGroup>

Expand Down
95 changes: 85 additions & 10 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 Down Expand Up @@ -96,7 +101,7 @@ public async Task<bool> ExecuteAsync()

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

if (remoteDepsVersionFile == null)
{
Expand All @@ -115,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 @@ -126,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 @@ -156,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 @@ -194,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 All @@ -215,12 +296,6 @@ private int UpdateDependencies(DependencyVersionsFile localVersionsFile, Depende
newValue = KoreBuildVersion.Current;
Log.LogMessage(MessageImportance.Low, "Setting InternalAspNetCoreSdkPackageVersion to the current version of KoreBuild");
}
else if (var.Key == "SdkPackageVersion")
{
var globalFile = new GlobalJsonFile(GlobalJsonFile);
globalFile.SetSdkVersion(var.Value);
continue;
}
else if (!remoteDepsVersionFile.VersionVariables.TryGetValue(var.Key, out newValue))
{
Log.LogKoreBuildWarning(
Expand Down
Loading

0 comments on commit 4a9f641

Please sign in to comment.