Add the AndroidManifest.xml merger (#648)

This commit is contained in:
Matthew Leibowitz 2019-08-26 16:38:12 +02:00 коммит произвёл GitHub
Родитель 8b22847ad0
Коммит fec4fa56d2
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
37 изменённых файлов: 432 добавлений и 31 удалений

Просмотреть файл

@ -1,6 +1,6 @@
The MIT License (MIT)
Copyright (c) 2015 Xamarin
Copyright (c) .NET Foundation Contributors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal

Просмотреть файл

@ -0,0 +1 @@
All .jar files are under their own licenses.

Просмотреть файл

@ -0,0 +1,86 @@
using System.Xml.Linq;
var target = Argument("target", "Default");
var PACKAGE_VERSION = "1.0.0-preview02";
var TOOL_VERSION = "26.5.0";
var KXML_VERSION = "2.3.0";
var KOTLIN_VERSION = "1.3.41";
var GUAVA_VERSION = "27.0.1-jre";
Task("externals")
.Does(() =>
{
Download($"https://dl.google.com/dl/android/maven2/com/android/tools/build/manifest-merger/{TOOL_VERSION}/manifest-merger-{TOOL_VERSION}.jar", "manifest-merger.jar");
Download($"https://dl.google.com/dl/android/maven2/com/android/tools/common/{TOOL_VERSION}/common-{TOOL_VERSION}.jar", "common.jar");
Download($"https://dl.google.com/dl/android/maven2/com/android/tools/sdklib/{TOOL_VERSION}/sdklib-{TOOL_VERSION}.jar", "sdklib.jar");
Download($"https://dl.google.com/dl/android/maven2/com/android/tools/sdk-common/{TOOL_VERSION}/sdk-common-{TOOL_VERSION}.jar", "sdk-common.jar");
Download($"https://repo1.maven.org/maven2/net/sf/kxml/kxml2/{KXML_VERSION}/kxml2-{KXML_VERSION}.jar", "kxml2.jar");
Download($"https://repo1.maven.org/maven2/com/google/guava/guava/{GUAVA_VERSION}/guava-{GUAVA_VERSION}.jar", "guava.jar");
Download($"https://repo1.maven.org/maven2/org/jetbrains/kotlin/kotlin-stdlib-jdk8/{KOTLIN_VERSION}/kotlin-stdlib-jdk8-{KOTLIN_VERSION}.jar", "kotlin-stdlib-jdk8.jar");
Download($"https://repo1.maven.org/maven2/org/jetbrains/kotlin/kotlin-stdlib/{KOTLIN_VERSION}/kotlin-stdlib-{KOTLIN_VERSION}.jar", "kotlin-stdlib.jar");
void Download(string url, string filename)
{
var root = (DirectoryPath)"./externals/merger/";
EnsureDirectoryExists(root);
var dest = root.CombineWithFilePath(filename);
if (!FileExists(dest))
DownloadFile(url, dest);
}
});
Task("nuget")
.IsDependentOn("externals")
.Does(() =>
{
NuGetPack("./nuget/Xamarin.Android.ManifestMerger.nuspec", new NuGetPackSettings {
Version = PACKAGE_VERSION,
OutputDirectory = "./output"
});
});
Task("tests")
.IsDependentOn("nuget")
.Does(() =>
{
if (DirectoryExists("./externals/packages/xamarin.android.manifestmerger/"))
CleanDirectories("./externals/packages/xamarin.android.manifestmerger/");
var settings = new MSBuildSettings()
.SetConfiguration("Release")
.SetVerbosity(Verbosity.Minimal)
.WithRestore();
MSBuild("./samples/FancyMergingApp.sln", settings);
// TODO: actually create real tests that build the APK and test that as well
// as ensuring that the target is properly skipped on subsequent builds.
var android = (XNamespace)"http://schemas.android.com/apk/res/android";
var xdoc = XDocument.Load("./samples/FancyMergingApp/obj/Release/90/android/AndroidManifest.xml");
var serviceName = "com.google.firebase.components.ComponentDiscoveryService";
var services = xdoc
.Element("manifest")
.Element("application")
.Elements("service")
.Where(x => x.Attribute(android + "name")?.Value == serviceName);
if (services.Count() != 1)
throw new Exception("Manifests were not merged.");
var contents = services.Elements("meta-data");
if (contents.Count() != 3)
throw new Exception("Manifests were merged, but data was lost.");
});
Task("Default")
.IsDependentOn("externals")
.IsDependentOn("nuget")
.IsDependentOn("tests");
RunTarget(target);

Просмотреть файл

@ -0,0 +1,20 @@
<?xml version="1.0"?>
<package>
<metadata>
<id>Xamarin.Android.ManifestMerger</id>
<version>1.0.0</version>
<license type="expression">MIT</license>
<projectUrl>https://go.microsoft.com/fwlink/?linkid=2102130</projectUrl>
<description>A set of tools and MSBuild tasks to merge several AndroidManifest.xml files.</description>
<authors>Microsoft</authors>
<owners>Microsoft</owners>
<requireLicenseAcceptance>true</requireLicenseAcceptance>
<copyright>© Microsoft Corporation. All rights reserved.</copyright>
<tags>Xamarin Xamarin.Android</tags>
</metadata>
<files>
<file src="..\externals\merger\*.jar" target="build/monoandroid" />
<file src="..\source\*.targets" target="build/monoandroid" />
<file src="..\External-Dependency-Info.txt" target="THIRD-PARTY-NOTICES.txt" />
</files>
</package>

Просмотреть файл

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<RestoreNoCache>true</RestoreNoCache>
<RestorePackagesPath>$(MSBuildThisFileDirectory)..\externals\packages</RestorePackagesPath>
</PropertyGroup>
</Project>

Просмотреть файл

@ -0,0 +1,27 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.29124.190
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FancyMergingApp", "FancyMergingApp\FancyMergingApp.csproj", "{F2523D60-97F9-4687-9768-6861C0D69CA5}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{F2523D60-97F9-4687-9768-6861C0D69CA5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F2523D60-97F9-4687-9768-6861C0D69CA5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F2523D60-97F9-4687-9768-6861C0D69CA5}.Debug|Any CPU.Deploy.0 = Debug|Any CPU
{F2523D60-97F9-4687-9768-6861C0D69CA5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F2523D60-97F9-4687-9768-6861C0D69CA5}.Release|Any CPU.Build.0 = Release|Any CPU
{F2523D60-97F9-4687-9768-6861C0D69CA5}.Release|Any CPU.Deploy.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {0AE3E205-7E80-4FC0-B488-6AFE486E835B}
EndGlobalSection
EndGlobal

Просмотреть файл

@ -0,0 +1,106 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{F2523D60-97F9-4687-9768-6861C0D69CA5}</ProjectGuid>
<ProjectTypeGuids>{EFBA0AD7-5A72-4C68-AF49-83D382785DCF};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<TemplateGuid>{122416d6-6b49-4ee2-a1e8-b825f31c79fe}</TemplateGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>FancyMergingApp</RootNamespace>
<AssemblyName>FancyMergingApp</AssemblyName>
<FileAlignment>512</FileAlignment>
<AndroidApplication>True</AndroidApplication>
<AndroidResgenFile>Resources\Resource.designer.cs</AndroidResgenFile>
<AndroidResgenClass>Resource</AndroidResgenClass>
<GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
<AndroidUseLatestPlatformSdk>false</AndroidUseLatestPlatformSdk>
<TargetFrameworkVersion>v9.0</TargetFrameworkVersion>
<AndroidManifest>Properties\AndroidManifest.xml</AndroidManifest>
<MonoAndroidResourcePrefix>Resources</MonoAndroidResourcePrefix>
<MonoAndroidAssetsPrefix>Assets</MonoAndroidAssetsPrefix>
<AndroidEnableSGenConcurrent>true</AndroidEnableSGenConcurrent>
<AndroidUseAapt2>true</AndroidUseAapt2>
<AndroidHttpClientHandlerType>Xamarin.Android.Net.AndroidClientHandler</AndroidHttpClientHandlerType>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>True</DebugSymbols>
<DebugType>portable</DebugType>
<Optimize>False</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<AndroidUseSharedRuntime>True</AndroidUseSharedRuntime>
<AndroidLinkMode>None</AndroidLinkMode>
<EmbedAssembliesIntoApk>False</EmbedAssembliesIntoApk>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugSymbols>True</DebugSymbols>
<DebugType>portable</DebugType>
<Optimize>True</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<AndroidManagedSymbols>true</AndroidManagedSymbols>
<AndroidUseSharedRuntime>False</AndroidUseSharedRuntime>
<AndroidLinkMode>SdkOnly</AndroidLinkMode>
<EmbedAssembliesIntoApk>True</EmbedAssembliesIntoApk>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Xml" />
<Reference Include="System.Core" />
<Reference Include="Mono.Android" />
<Reference Include="System.Numerics" />
<Reference Include="System.Numerics.Vectors" />
</ItemGroup>
<ItemGroup>
<Compile Include="MainActivity.cs" />
<Compile Include="Resources\Resource.designer.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="Properties\AndroidManifest.xml" />
</ItemGroup>
<ItemGroup>
<AndroidResource Include="Resources\layout\activity_main.xml" />
<AndroidResource Include="Resources\values\colors.xml" />
<AndroidResource Include="Resources\values\ic_launcher_background.xml" />
<AndroidResource Include="Resources\values\strings.xml" />
<AndroidResource Include="Resources\values\styles.xml" />
<AndroidResource Include="Resources\mipmap-anydpi-v26\ic_launcher.xml" />
<AndroidResource Include="Resources\mipmap-anydpi-v26\ic_launcher_round.xml" />
<AndroidResource Include="Resources\mipmap-hdpi\ic_launcher.png" />
<AndroidResource Include="Resources\mipmap-hdpi\ic_launcher_foreground.png" />
<AndroidResource Include="Resources\mipmap-hdpi\ic_launcher_round.png" />
<AndroidResource Include="Resources\mipmap-mdpi\ic_launcher.png" />
<AndroidResource Include="Resources\mipmap-mdpi\ic_launcher_foreground.png" />
<AndroidResource Include="Resources\mipmap-mdpi\ic_launcher_round.png" />
<AndroidResource Include="Resources\mipmap-xhdpi\ic_launcher.png" />
<AndroidResource Include="Resources\mipmap-xhdpi\ic_launcher_foreground.png" />
<AndroidResource Include="Resources\mipmap-xhdpi\ic_launcher_round.png" />
<AndroidResource Include="Resources\mipmap-xxhdpi\ic_launcher.png" />
<AndroidResource Include="Resources\mipmap-xxhdpi\ic_launcher_foreground.png" />
<AndroidResource Include="Resources\mipmap-xxhdpi\ic_launcher_round.png" />
<AndroidResource Include="Resources\mipmap-xxxhdpi\ic_launcher.png" />
<AndroidResource Include="Resources\mipmap-xxxhdpi\ic_launcher_foreground.png" />
<AndroidResource Include="Resources\mipmap-xxxhdpi\ic_launcher_round.png" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Xamarin.Android.Support.Design" Version="28.0.0.1" />
<PackageReference Include="Xamarin.Android.Support.Core.Utils" Version="28.0.0.1" />
<PackageReference Include="Xamarin.Android.Support.CustomTabs" Version="28.0.0.1" />
<PackageReference Include="Xamarin.Essentials" Version="1.1.0" />
<PackageReference Include="Xamarin.Firebase.Measurement.Connector.Impl" Version="71.1705.0-preview6" />
<PackageReference Include="Xamarin.Firebase.Perf" Version="71.1620.0" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Xamarin.Android.ManifestMerger" Version="1.0.0-preview02" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Xamarin\Android\Xamarin.Android.CSharp.targets" />
</Project>

Просмотреть файл

@ -0,0 +1,27 @@
using Android.App;
using Android.OS;
using Android.Runtime;
using Android.Support.V7.App;
namespace FancyMergingApp
{
[Activity(Label = "@string/app_name", Theme = "@style/AppTheme", MainLauncher = true)]
public class MainActivity : AppCompatActivity
{
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
Xamarin.Essentials.Platform.Init(this, savedInstanceState);
// Set our view from the "main" layout resource
SetContentView(Resource.Layout.activity_main);
}
public override void OnRequestPermissionsResult(int requestCode, string[] permissions, [GeneratedEnum] Android.Content.PM.Permission[] grantResults)
{
Xamarin.Essentials.Platform.OnRequestPermissionsResult(requestCode, permissions, grantResults);
base.OnRequestPermissionsResult(requestCode, permissions, grantResults);
}
}
}

Просмотреть файл

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
android:versionCode="6"
android:versionName="2.1"
package="com.companyname.fancymergingapp">
<uses-sdk android:minSdkVersion="21" android:targetSdkVersion="28" />
<application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/AppTheme">
</application>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
</manifest>

Просмотреть файл

@ -0,0 +1,30 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using Android.App;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("FancyMergingApp")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("FancyMergingApp")]
[assembly: AssemblyCopyright("Copyright © 2018")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

Просмотреть файл

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
</RelativeLayout>

Просмотреть файл

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@color/ic_launcher_background"/>
<foreground android:drawable="@mipmap/ic_launcher_foreground"/>
</adaptive-icon>

Просмотреть файл

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@color/ic_launcher_background"/>
<foreground android:drawable="@mipmap/ic_launcher_foreground"/>
</adaptive-icon>

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 1.6 KiB

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 1.4 KiB

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 3.5 KiB

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 1.3 KiB

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 958 B

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 2.4 KiB

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 2.3 KiB

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 2.0 KiB

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 4.7 KiB

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 3.8 KiB

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 3.3 KiB

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 7.8 KiB

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 4.9 KiB

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 4.8 KiB

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 11 KiB

Просмотреть файл

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#2c3e50</color>
<color name="colorPrimaryDark">#1B3147</color>
<color name="colorAccent">#3498db</color>
</resources>

Просмотреть файл

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="ic_launcher_background">#2C3E50</color>
</resources>

Просмотреть файл

@ -0,0 +1,4 @@
<resources>
<string name="app_name">FancyMergingApp</string>
<string name="action_settings">Settings</string>
</resources>

Просмотреть файл

@ -0,0 +1,11 @@
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
</resources>

Просмотреть файл

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="output-win" value="..\output" />
<add key="output-mac" value="../output" />
</packageSources>
</configuration>

Просмотреть файл

@ -0,0 +1,34 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="_Before_GenerateJavaStubs" BeforeTargets="_GenerateJavaStubs"
Condition="'$(SkipExternalGoogleManifestMerge)' != 'true'">
<ItemGroup>
<_Proxy_ExtractedManifestDocuments Include="@(ExtractedManifestDocuments)" />
<ExtractedManifestDocuments Remove="@(ExtractedManifestDocuments)" />
</ItemGroup>
</Target>
<Target Name="_After_GenerateJavaStubs" AfterTargets="_GenerateJavaStubs"
Inputs="$(IntermediateOutputPath)android\AndroidManifest.xml;@(_Proxy_ExtractedManifestDocuments)"
Outputs="$(_AndroidStampDirectory)_After_GenerateJavaStubs.stamp"
Condition="'$(SkipExternalGoogleManifestMerge)' != 'true'">
<PropertyGroup>
<_MergerJavaPath Condition="'$(_MergerJavaPath)' == '' and '$(OS)' == 'Unix'">$(JavaSdkDirectory)/bin/java</_MergerJavaPath>
<_MergerJavaPath Condition="'$(_MergerJavaPath)' == '' and '$(OS)' != 'Unix'">$(JavaSdkDirectory)\bin\java.exe</_MergerJavaPath>
</PropertyGroup>
<ItemGroup>
<_MergerJar Include="$(MSBuildThisFileDirectory)\*.jar" />
</ItemGroup>
<Exec Command="&quot;$(_MergerJavaPath)&quot; -cp &quot;@(_MergerJar)&quot; &quot;com.android.manifmerger.Merger&quot; --main &quot;$(IntermediateOutputPath)android\AndroidManifest.xml&quot; --libs &quot;@(_Proxy_ExtractedManifestDocuments)&quot; --out &quot;$(IntermediateOutputPath)android\AndroidManifest.xml&quot;" />
<Touch Files="$(_AndroidStampDirectory)_GenerateJavaStubs.stamp;@(_TypeMapAssemblySource);$(_AndroidStampDirectory)_After_GenerateJavaStubs.stamp" AlwaysCreate="True" />
</Target>
</Project>

Просмотреть файл

@ -5,11 +5,12 @@ trigger:
variables:
MONO_VERSION: 5_18_1
XCODE_VERSION: 10.2.1
XCODE_VERSION: 10.3
VERBOSITY: diagnostic
DOTNET_CORE_VERSION: 2.2.401
CAKE_VERSION: 0.34.1
API_TOOLS_VERSION: 1.0.2-preview.14
MASTER_BRANCH: master
resources:
repositories:
@ -28,50 +29,46 @@ jobs:
steps:
- checkout: none
- powershell: |
$branch = $env:BUILD_SOURCEBRANCHNAME
if ($env:SYSTEM_PULLREQUEST_TARGETBRANCH) {
$branch = $env:SYSTEM_PULLREQUEST_TARGETBRANCH
}
# determine the "master" branch
$masterBranch = "$(MASTER_BRANCH)"
$encodedBranch = [Uri]::EscapeDataString("refs/heads/$masterBranch")
Write-Host "Master branch: $masterBranch"
Write-Host "Branch: $branch"
# determine the "current" branch
$branch = if ("$(System.PullRequest.TargetBranch)") { "$(System.PullRequest.TargetBranch)" } else { "$(Build.SourceBranchName)" }
Write-Host "Current branch: $branch"
if ($branch -eq "master") {
if ($branch -eq $masterBranch) {
Write-Host "Branch is master, fetching last successful build commit..."
# Must check allow scripts to have oauth token access in devops
$url = "$env:SYSTEM_TEAMFOUNDATIONCOLLECTIONURI$env:SYSTEM_TEAMPROJECTID/_apis/build/builds/?definitions=$env:SYSTEM_DEFINITIONID&branchName=refs%2Fheads%2Fmaster&statusFilter=completed&resultFilter=succeeded&api-version=5.0"
Write-Host "URL: $url"
$url = "$(System.TeamFoundationCollectionUri)$(System.TeamProjectId)/_apis/build/builds/?definitions=$(System.DefinitionId)&branchName=$encodedBranch&statusFilter=completed&resultFilter=succeeded&api-version=5.0"
Write-Host "URL for last successful master build: $url"
$json = Invoke-RestMethod -Uri $url -Headers @{
Authorization = "Bearer $env:SYSTEM_ACCESSTOKEN"
Authorization = "Bearer $(System.AccessToken)"
}
Write-Host "JSON response:"
Write-Host "$json"
Try {
$lastSuccessfulBuildCommit = $json.value[0].sourceVersion;
}
Catch {
}
$lastSuccessfulBuildCommit = try { $json.value[0].sourceVersion; } catch { $null }
}
if ($lastSuccessfulBuildCommit) {
Write-Host "Last Successful Commit: $lastSuccessfulBuildCommit"
Write-Host "Last successful commit: $lastSuccessfulBuildCommit"
} else {
$lastSuccessfulBuildCommit = "origin/master"
Write-Host "No previously successful build found, using this commit: $lastSuccessfulBuildCommit"
$lastSuccessfulBuildCommit = $masterBranch
Write-Host "No previously successful build found, using this branch: $lastSuccessfulBuildCommit"
}
Write-Host "##vso[task.setvariable variable=GitLastSuccessfulCommit;isOutput=true]$lastSuccessfulBuildCommit"
name: lastSuccessful
env:
SYSTEM_ACCESSTOKEN: $(System.AccessToken)
displayName: 'Find last successful commit'
- job: build
strategy:
matrix:
macos:
imageName: 'Hosted Mac Internal Mojave'
imageName: 'Hosted macOS'
windows:
imageName: 'Hosted Windows 2019 with VS2019'
displayName: 'Build'
@ -98,10 +95,14 @@ jobs:
dotnet tool install -g api-tools --version $(API_TOOLS_VERSION)
dotnet tool install -g cake.tool --version $(CAKE_VERSION)
displayName: 'Install .NET Core global tools'
- powershell: |
$env:JavaSdkDirectory = $env:JAVA_HOME # https://github.com/xamarin/xamarin-android-tools/pull/74
dotnet-cake --target=build --gitpreviouscommit=$(GitLastSuccessfulCommit) --gitcommit=$(Build.SourceVersion) --forcebuild=$(ForceBuild) --names="$(BuildManifestNames)" --targets="$(BuildManifestTargets)" --copyoutputtoroot=true --verbosity=$(VERBOSITY)
- task: NuGetToolInstaller@1
inputs:
checkLatest: true
displayName: 'Download the latest nuget.exe'
- powershell: dotnet cake --target=build --gitpreviouscommit=$(GitLastSuccessfulCommit) --gitcommit=$(Build.SourceVersion) --forcebuild=$(ForceBuild) --names="$(BuildManifestNames)" --targets="$(BuildManifestTargets)" --copyoutputtoroot=true --verbosity=$(VERBOSITY)
displayName: 'Run build'
env:
JavaSdkDirectory: $(JAVA_HOME)
- powershell: |
if (Get-ChildItem artifacts -Filter *.nupkg) {
api-tools nuget-diff artifacts --latest --group-ids --output artifacts/api-diff --cache externals/package_cache

Просмотреть файл

@ -39,9 +39,6 @@ foreach (var ev in ENV_VARS)
CakeStealer.CakeContext = Context;
// From Cake.Xamarin.Build, dumps out versions of things
LogSystemInfo ();
// Print out git commit info
Information ("Git Path: {0}", GIT_PATH);
Information ("Git Previous Commit: {0}", GIT_PREVIOUS_COMMIT);
@ -141,10 +138,12 @@ Task ("build")
// Get all the changed files in this commit
IEnumerable<string> changedFiles = new List<string> ();
StartProcess (GIT_PATH, new ProcessSettings {
var exitCode = StartProcess (GIT_PATH, new ProcessSettings {
Arguments = gitArgs,
RedirectStandardOutput = true },
out changedFiles);
if (exitCode != 0)
throw new Exception($"git exited with error code {exitCode}.");
// Determine which group each file belongs to
Information ("Changed Files:");

Просмотреть файл

@ -591,6 +591,10 @@
BuildScript: ./Util/SamplePackager/build.cake
TriggerPaths: [ Util/SamplePackager ]
MacBuildTargets: [ nuget ]
- Name: AndroidManifestMerger
BuildScript: ./Util/AndroidManifestMerger/build.cake
TriggerPaths: [ Util/AndroidManifestMerger ]
WindowsBuildTargets: [ Default ]
- Name: Xamarin.AndroidBinderator
BuildScript: ./Util/Xamarin.AndroidBinderator/build.cake
TriggerPaths: [ Util/Xamarin.AndroidBinderator ]