Skip to content

Commit

Permalink
Rework runtime pack version declaration
Browse files Browse the repository at this point in the history
  • Loading branch information
pjcollins committed Mar 18, 2021
1 parent e03fcc6 commit 199668b
Show file tree
Hide file tree
Showing 12 changed files with 84 additions and 54 deletions.
2 changes: 0 additions & 2 deletions Configuration.props
Expand Up @@ -75,8 +75,6 @@
<AndroidNdkDirectory Condition=" '$(AndroidNdkDirectory)' == '' ">$(AndroidToolchainDirectory)\ndk</AndroidNdkDirectory>
<DotNetPreviewPath Condition=" '$(DotNetPreviewPath)' == '' ">$(AndroidToolchainDirectory)\dotnet\</DotNetPreviewPath>
<DotNetPreviewTool Condition=" '$(DotNetPreviewTool)' == '' ">$(DotNetPreviewPath)dotnet</DotNetPreviewTool>
<!-- TODO: Calculate based on $(MicrosoftDotnetSdkInternalPackageVersion) -->
<DotNetPreviewVersionBand Condition=" '$(DotNetPreviewVersionBand)' == '' ">6.0.100</DotNetPreviewVersionBand>
<WixToolPath Condition=" '$(WixToolPath)' == '' ">$(AndroidToolchainDirectory)\wix\</WixToolPath>
<AndroidCmakeVersion Condition=" '$(AndroidCmakeVersion)' == '' ">3.18.1</AndroidCmakeVersion>
<AndroidCmakeUrlPrefix Condition=" '$(HostOS)' == 'Windows' And '$(AndroidCmakeUrlPrefix)' == '' ">7c386a739f915f5bd60051f2572c24782388e807.</AndroidCmakeUrlPrefix>
Expand Down
22 changes: 22 additions & 0 deletions build-tools/xaprepare/xaprepare/Application/Context.cs
Expand Up @@ -4,6 +4,7 @@
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;

namespace Xamarin.Android.Prepare
{
Expand Down Expand Up @@ -358,6 +359,27 @@ partial class Context : AppObject
}
}

string _bundledPreviewRuntimePackVersion;
public string BundledPreviewRuntimePackVersion {
get {
if (string.IsNullOrEmpty (_bundledPreviewRuntimePackVersion)) {
var dotnetPath = Properties.GetRequiredValue (KnownProperties.DotNetPreviewPath);
dotnetPath = dotnetPath.TrimEnd (new char [] { Path.DirectorySeparatorChar });
var dotnetPreviewVersion = Properties.GetRequiredValue (KnownProperties.MicrosoftDotnetSdkInternalPackageVersion);
var bundledVersionsPath = Path.Combine (dotnetPath, "sdk", dotnetPreviewVersion, "Microsoft.NETCoreSdk.BundledVersions.props");
if (!File.Exists (bundledVersionsPath))
throw new FileNotFoundException ("Could not find Microsoft.NETCoreSdk.BundledVersions.props.", bundledVersionsPath);

var version = XDocument.Load (bundledVersionsPath).Descendants ().FirstOrDefault (p => p.Name == "BundledNETCoreAppPackageVersion")?.Value ?? string.Empty;
if (string.IsNullOrEmpty (version))
throw new InvalidOperationException ($"Unable to locate $(BundledNETCoreAppPackageVersion) in {bundledVersionsPath}.");

_bundledPreviewRuntimePackVersion = version;
}
return _bundledPreviewRuntimePackVersion;
}
}

/// <summary>
/// Do not install mingw-w64 with brew on MacOS, default false
/// </summary>
Expand Down
Expand Up @@ -22,7 +22,6 @@ static class KnownProperties
public const string CommandLineToolsFolder = nameof (CommandLineToolsFolder);
public const string DotNetPreviewPath = "DotNetPreviewPath";
public const string MicrosoftDotnetSdkInternalPackageVersion = "MicrosoftDotnetSdkInternalPackageVersion";
public const string MicrosoftNetCoreAppRuntimeandroidarm64PackageVersion = "MicrosoftNetCoreAppRuntimeandroidarm64PackageVersion";
public const string EmulatorVersion = "EmulatorVersion";
public const string EmulatorPkgRevision = "EmulatorPkgRevision";
public const string HostOS = "HostOS";
Expand Down
Expand Up @@ -26,7 +26,6 @@ namespace Xamarin.Android.Prepare
properties.Add (KnownProperties.CommandLineToolsVersion, StripQuotes ("@CommandLineToolsVersion@"));
properties.Add (KnownProperties.DotNetPreviewPath, StripQuotes (@"@DotNetPreviewPath@"));
properties.Add (KnownProperties.MicrosoftDotnetSdkInternalPackageVersion, StripQuotes ("@MicrosoftDotnetSdkInternalPackageVersion@"));
properties.Add (KnownProperties.MicrosoftNetCoreAppRuntimeandroidarm64PackageVersion, StripQuotes ("@MicrosoftNetCoreAppRuntimeandroidarm64PackageVersion@"));
properties.Add (KnownProperties.EmulatorVersion, StripQuotes ("@EmulatorVersion@"));
properties.Add (KnownProperties.EmulatorPkgRevision, StripQuotes ("@EmulatorPkgRevision@"));
properties.Add (KnownProperties.HostOS, StripQuotes ("@HostOS@"));
Expand Down
23 changes: 0 additions & 23 deletions build-tools/xaprepare/xaprepare/ConfigAndData/Configurables.cs
Expand Up @@ -367,12 +367,6 @@ public static partial class Paths
public static string MonoArchiveLocalPath => Path.Combine (ctx.Properties.GetRequiredValue (KnownProperties.AndroidToolchainCacheDirectory), MonoArchiveFileName);
public static string MonoArchiveWindowsLocalPath => Path.Combine (ctx.Properties.GetRequiredValue (KnownProperties.AndroidToolchainCacheDirectory), MonoArchiveWindowsFileName);

// .NET 6
public static string NetcoreAppRuntimeAndroidARM => GetCachedPath (ref netcoreAppRuntimeAndroidARM, () => GetNetcoreAppRuntimePath (ctx, "arm"));
public static string NetcoreAppRuntimeAndroidARM64 => GetCachedPath (ref netcoreAppRuntimeAndroidARM64, () => GetNetcoreAppRuntimePath (ctx, "arm64"));
public static string NetcoreAppRuntimeAndroidX86 => GetCachedPath (ref netcoreAppRuntimeAndroidX86, () => GetNetcoreAppRuntimePath (ctx, "x86"));
public static string NetcoreAppRuntimeAndroidX86_64 => GetCachedPath (ref netcoreAppRuntimeAndroidX86_64, () => GetNetcoreAppRuntimePath (ctx, "x64"));

// CMake
public static string CmakeMSBuildPropsName = "cmake-config.props";
public static string CmakeShellScriptsPropsName = "cmake-config.sh";
Expand All @@ -398,17 +392,6 @@ public static partial class Paths
return Directory.Exists (path) ? path : Path.Combine (MonoSdksTpnExternalPath, "llvm");
});

static string GetNetcoreAppRuntimePath (Context ctx, string androidTarget)
{
return Path.Combine (
XAPackagesDir,
$"microsoft.netcore.app.runtime.android-{androidTarget}",
ctx.Properties.GetRequiredValue (KnownProperties.MicrosoftNetCoreAppRuntimeandroidarm64PackageVersion),
"runtimes",
$"android-{androidTarget}"
);
}

static string DetermineNugetPackagesDir (Context ctx)
{
return Path.GetFullPath (
Expand Down Expand Up @@ -466,8 +449,6 @@ static string GetCachedPath (ref string? variable, Func<string> creator)
static string? mingw64CmakeTemplatePath;
static string? monoRuntimesEnabledAbisCachePath;
static string? frameworkListInstallPath;
static string? correttoCacheDir;
static string? correttoInstallDir;
static string? profileAssembliesProjitemsPath;
static string? bclTestsSourceDir;
static string? installHostBCLDir;
Expand All @@ -487,10 +468,6 @@ static string GetCachedPath (ref string? variable, Func<string> creator)
static string? configurationPropsGeneratedPath;
static string? windowsBinutilsInstallDir;
static string? hostBinutilsInstallDir;
static string? netcoreAppRuntimeAndroidARM;
static string? netcoreAppRuntimeAndroidARM64;
static string? netcoreAppRuntimeAndroidX86;
static string? netcoreAppRuntimeAndroidX86_64;
static string? monodroidSourceDir;
}
}
Expand Down
20 changes: 16 additions & 4 deletions build-tools/xaprepare/xaprepare/Steps/Step_GenerateFiles.cs
Expand Up @@ -87,18 +87,30 @@ GeneratedFile Get_Cmake_XA_Build_Configuration (Context context)
{
const string OutputFileName = "xa_build_configuration.cmake";

var runtimePackVersion = context.BundledPreviewRuntimePackVersion;
var replacements = new Dictionary<string, string> (StringComparer.Ordinal) {
{ "@NETCORE_APP_RUNTIME_ANDROID_ARM@", Utilities.EscapePathSeparators (Configurables.Paths.NetcoreAppRuntimeAndroidARM) },
{ "@NETCORE_APP_RUNTIME_ANDROID_ARM64@", Utilities.EscapePathSeparators (Configurables.Paths.NetcoreAppRuntimeAndroidARM64) },
{ "@NETCORE_APP_RUNTIME_ANDROID_X86@", Utilities.EscapePathSeparators (Configurables.Paths.NetcoreAppRuntimeAndroidX86) },
{ "@NETCORE_APP_RUNTIME_ANDROID_X86_64@", Utilities.EscapePathSeparators (Configurables.Paths.NetcoreAppRuntimeAndroidX86_64) },
{ "@NETCORE_APP_RUNTIME_ANDROID_ARM@", Utilities.EscapePathSeparators (GetNetCoreAppRuntimePath ("arm", runtimePackVersion)) },
{ "@NETCORE_APP_RUNTIME_ANDROID_ARM64@", Utilities.EscapePathSeparators (GetNetCoreAppRuntimePath ("arm64", runtimePackVersion)) },
{ "@NETCORE_APP_RUNTIME_ANDROID_X86@", Utilities.EscapePathSeparators (GetNetCoreAppRuntimePath ("x86", runtimePackVersion)) },
{ "@NETCORE_APP_RUNTIME_ANDROID_X86_64@", Utilities.EscapePathSeparators (GetNetCoreAppRuntimePath ("x86_64", runtimePackVersion)) },
};

return new GeneratedPlaceholdersFile (
replacements,
Path.Combine (Configurables.Paths.BuildToolsScriptsDir, $"{OutputFileName}.in"),
Path.Combine (Configurables.Paths.BuildBinDir, OutputFileName)
);

string GetNetCoreAppRuntimePath (string androidTarget, string version)
{
return Path.Combine (
Configurables.Paths.XAPackagesDir,
$"microsoft.netcore.app.runtime.android-{androidTarget}",
version,
"runtimes",
$"android-{androidTarget}"
);
}
}

GeneratedFile Get_Configuration_Generated_Props (Context context)
Expand Down
15 changes: 10 additions & 5 deletions build-tools/xaprepare/xaprepare/Steps/Step_InstallDotNetPreview.cs
Expand Up @@ -17,6 +17,7 @@ protected override async Task<bool> Execute (Context context)
{
var dotnetPath = context.Properties.GetRequiredValue (KnownProperties.DotNetPreviewPath);
dotnetPath = dotnetPath.TrimEnd (new char [] { Path.DirectorySeparatorChar });
var dotnetTool = Path.Combine (dotnetPath, "dotnet");
var dotnetPreviewVersion = context.Properties.GetRequiredValue (KnownProperties.MicrosoftDotnetSdkInternalPackageVersion);
var dotnetTestRuntimeVersion = Configurables.Defaults.DotNetTestRuntimeVersion;

Expand All @@ -38,8 +39,8 @@ protected override async Task<bool> Execute (Context context)
}
}

if (Directory.Exists (dotnetPath)) {
if (!TestDotNetSdk (dotnetPath)) {
if (File.Exists (dotnetTool)) {
if (!TestDotNetSdk (dotnetTool)) {
Log.WarningLine ($"Attempt to run `dotnet --version` failed, reinstalling the SDK.");
Utilities.DeleteDirectory (dotnetPath);
}
Expand All @@ -55,7 +56,11 @@ protected override async Task<bool> Execute (Context context)
return false;
}

return true;
// Install runtime packs associated with the SDK previously installed.
var packageDownloadProj = Path.Combine (BuildPaths.XamarinAndroidSourceRoot, "build-tools", "xaprepare", "xaprepare", "package-download.proj");
var logPath = Path.Combine (Configurables.Paths.BuildBinDir, $"msbuild-{context.BuildTimeStamp}-download-runtime-packs.binlog");
return Utilities.RunCommand (dotnetTool, new string [] { "restore", $"-p:DotNetRuntimePacksVersion={context.BundledPreviewRuntimePackVersion}",
ProcessRunner.QuoteArgument (packageDownloadProj), ProcessRunner.QuoteArgument ($"-bl:{logPath}") });
}

async Task<bool> InstallDotNetAsync (Context context, string dotnetPath, string version, bool runtimeOnly = false)
Expand Down Expand Up @@ -122,9 +127,9 @@ async Task<bool> InstallDotNetAsync (Context context, string dotnetPath, string
}
}

bool TestDotNetSdk (string dotnetPath)
bool TestDotNetSdk (string dotnetTool)
{
return Utilities.RunCommand (Path.Combine (dotnetPath, "dotnet"), new string [] { "--version" });
return Utilities.RunCommand (dotnetTool, new string [] { "--version" });
}

}
Expand Down
25 changes: 25 additions & 0 deletions build-tools/xaprepare/xaprepare/package-download.proj
@@ -0,0 +1,25 @@
<!--
***********************************************************************************************
package-download.proj
Downloads .NET runtime packs using the version specified in $(DotNetRuntimePacksVersion) if set.
Otherwise, the $(BundledNETCoreAppPackageVersion) version specified in the Microsoft.NET.Sdk that
is building/restoring this project will be used. $(BundledNETCoreAppPackageVersion) is set in
dotnet\sdk\$(MicrosoftDotnetSdkInternalPackageVersion)\Microsoft.NETCoreSdk.BundledVersions.props
***********************************************************************************************
-->
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<DotNetRuntimePacksVersion Condition=" '$(DotNetRuntimePacksVersion)' == '' " >$(BundledNETCoreAppPackageVersion)</DotNetRuntimePacksVersion>
</PropertyGroup>

<ItemGroup>
<PackageDownload Include="Microsoft.NETCore.App.Runtime.android-arm" Version="[$(DotNetRuntimePacksVersion)]" />
<PackageDownload Include="Microsoft.NETCore.App.Runtime.android-arm64" Version="[$(DotNetRuntimePacksVersion)]" />
<PackageDownload Include="Microsoft.NETCore.App.Runtime.android-x86" Version="[$(DotNetRuntimePacksVersion)]" />
<PackageDownload Include="Microsoft.NETCore.App.Runtime.android-x64" Version="[$(DotNetRuntimePacksVersion)]" />
</ItemGroup>

</Project>
7 changes: 1 addition & 6 deletions build-tools/xaprepare/xaprepare/xaprepare.csproj
Expand Up @@ -60,10 +60,5 @@
</ItemGroup>

<Import Project="xaprepare.targets" Condition=" $(MSBuildToolsPath.IndexOf('omnisharp')) &lt; 0 " />
<ItemGroup Condition=" '$(TargetFramework)' == 'netcoreapp3.1' ">
<PackageDownload Include="Microsoft.NETCore.App.Runtime.android-arm64" Version="[$(MicrosoftNetCoreAppRuntimeandroidarm64PackageVersion)]" />
<PackageDownload Include="Microsoft.NETCore.App.Runtime.android-x64" Version="[$(MicrosoftNetCoreAppRuntimeandroidarm64PackageVersion)]" />
<PackageDownload Include="Microsoft.NETCore.App.Runtime.android-arm" Version="[$(MicrosoftNetCoreAppRuntimeandroidarm64PackageVersion)]" />
<PackageDownload Include="Microsoft.NETCore.App.Runtime.android-x86" Version="[$(MicrosoftNetCoreAppRuntimeandroidarm64PackageVersion)]" />
</ItemGroup>

</Project>
1 change: 0 additions & 1 deletion build-tools/xaprepare/xaprepare/xaprepare.targets
Expand Up @@ -60,7 +60,6 @@
<Replacement Include="@CommandLineToolsVersion@=$(CommandLineToolsVersion)" />
<Replacement Include="@DotNetPreviewPath@=$(DotNetPreviewPath)" />
<Replacement Include="@MicrosoftDotnetSdkInternalPackageVersion@=$(MicrosoftDotnetSdkInternalPackageVersion)" />
<Replacement Include="@MicrosoftNetCoreAppRuntimeandroidarm64PackageVersion@=$(MicrosoftNetCoreAppRuntimeandroidarm64PackageVersion)" />
<Replacement Include="@EmulatorVersion@=$(EmulatorVersion)" />
<Replacement Include="@EmulatorPkgRevision@=$(EmulatorPkgRevision)" />
<Replacement Include="@HostOS@=$(HostOS)" />
Expand Down
12 changes: 4 additions & 8 deletions eng/Version.Details.xml
@@ -1,16 +1,12 @@
<Dependencies>
<ProductDependencies>
<Dependency Name="Microsoft.Dotnet.Sdk.Internal" Version="6.0.100-preview.3.21160.15">
<Dependency Name="Microsoft.Dotnet.Sdk.Internal" Version="6.0.100-preview.3.21167.10">
<Uri>https://github.com/dotnet/installer</Uri>
<Sha>a28ceebdcd4601c69f86d4ec1341ad95295f5020</Sha>
<Sha>18a633b84588c419939a55ee9504727eeb2e9714</Sha>
</Dependency>
<Dependency Name="Microsoft.NETCore.App.Runtime.android-arm64" Version="6.0.0-preview.3.21160.15">
<Uri>https://github.com/dotnet/runtime</Uri>
<Sha>b38ea6a4f067b571a007b2ac69f3e4431cb100e7</Sha>
</Dependency>
<Dependency Name="Microsoft.NET.ILLink" Version="6.0.100-preview.2.21160.1">
<Dependency Name="Microsoft.NET.ILLink" Version="6.0.100-preview.2.21167.4">
<Uri>https://github.com/mono/linker</Uri>
<Sha>bb923d296a0aa9afa499ffe29dcf71e66ee54352</Sha>
<Sha>75b1c3003bc12139c3a918705da5a4c12e7cb37b</Sha>
</Dependency>
</ProductDependencies>
</Dependencies>
9 changes: 6 additions & 3 deletions eng/Versions.props
@@ -1,8 +1,11 @@
<Project>
<!--Package versions-->
<PropertyGroup>
<MicrosoftDotnetSdkInternalPackageVersion>6.0.100-preview.3.21160.15</MicrosoftDotnetSdkInternalPackageVersion>
<MicrosoftNETCoreAppRuntimeandroidarm64PackageVersion>6.0.0-preview.3.21160.15</MicrosoftNETCoreAppRuntimeandroidarm64PackageVersion>
<MicrosoftNETILLinkPackageVersion>6.0.100-preview.2.21160.1</MicrosoftNETILLinkPackageVersion>
<MicrosoftDotnetSdkInternalPackageVersion>6.0.100-preview.3.21167.10</MicrosoftDotnetSdkInternalPackageVersion>
<MicrosoftNETILLinkPackageVersion>6.0.100-preview.2.21167.4</MicrosoftNETILLinkPackageVersion>
</PropertyGroup>
<PropertyGroup>
<!-- Trim all characters after first `-` or `+` is encountered. -->
<DotNetPreviewVersionBand Condition=" '$(DotNetPreviewVersionBand)' == '' ">$([System.Text.RegularExpressions.Regex]::Replace($(MicrosoftDotnetSdkInternalPackageVersion), `[-+].*$`, ""))</DotNetPreviewVersionBand>
</PropertyGroup>
</Project>

0 comments on commit 199668b

Please sign in to comment.