Skip to content

Commit 54a7a02

Browse files
jonpryorgrendello
authored andcommitted
[build] Auto-Provision Dependencies (#447)
The #runtime team is requesting that Xamarin.Android support "auto-provisioning": the ability to track dependency *versions*, and if there is a "version mismatch", *install* a dependency that satisfies the minimum. The primary use case is Mono itself: there is a desire to build xamarin-android *itself* against mono/master, to see what breaks. (Does the C# compiler break things? Does the JIT hang? etc.) Extend the existing `@(RequiredProgram)` infrastructure to attempt to support this: * `%(RequiredProgram.MinimumVersion)`: The minimum program version that is supported. * `%(RequiredProgram.MaximumVersion)`: The maximum program version that is supported. * `%(RequiredProgram.CurrentVersionCommand)`: A command to execute to obtain the current program version. Defaults to `%(RequiredProgram.Identity) --version`. * `%(RequiredProgram.MinimumUrl)`: URL to download "something" to use to obtain a version of the program that satisfies `%(MinimumVersion)`. * `%(RequiredProgram.Install)`: Command to execute which installs the minimum version of the program. `%(RequiredProgram.CurrentVersionCommand)`, `%(RequiredProgram.MinimumUrl)`, and `%(RequiredProgram.Install)` can all be "overridden" for platform-specific values by prefixing the value with `$(HostOSName)` and/or `$(HostOS)`. Thus, macOS-specific values can be stored into e.g. `%(RequiredProgram.DarwinMinimumUrl)` and `%(RequiredProgram.DarwinInstall)`. Auto-Provisioning is controlled by the new `$(AutoProvision)` property, which can be provided in `Configuration.Override.props`. It defaults to `False`. If the `$(AutoProvisionUsesSudo)` MSBuild property is True, then `sudo` is used to invoke all install commands.
1 parent fb9dbce commit 54a7a02

18 files changed

Lines changed: 374 additions & 56 deletions

Configuration.props

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
/>
1414
<PropertyGroup>
1515
<ProductVersion>7.1.99</ProductVersion>
16+
<AutoProvision Condition=" '$(AutoProvision)' == '' ">False</AutoProvision>
17+
<AutoProvisionUsesSudo Condition=" '$(AutoProvisionUsesSudo)' == '' ">False</AutoProvisionUsesSudo>
1618
<HostOS Condition=" '$(HostOS)' == '' And '$(OS)' == 'Windows_NT' ">Windows</HostOS>
1719
<HostCc Condition=" '$(HostCc)' == '' ">$(HostCc64)</HostCc>
1820
<HostCxx Condition=" '$(HostCxx)' == '' ">$(HostCxx64)</HostCxx>

Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ all::
2626
all-tests::
2727
MSBUILD="$(MSBUILD)" tools/scripts/xabuild $(MSBUILD_FLAGS) Xamarin.Android-Tests.sln
2828

29-
prepare:: prepare-external prepare-props prepare-msbuild
29+
prepare:: prepare-external prepare-props prepare-deps prepare-msbuild
3030

3131
# $(call GetPath,path)
3232
GetPath = $(shell $(MSBUILD) $(MSBUILD_FLAGS) /p:DoNotLoadOSProperties=True /nologo /v:minimal /t:Get$(1)FullPath build-tools/scripts/Paths.targets | tr -d '[[:space:]]' )
@@ -46,6 +46,9 @@ prepare-props:
4646
./build-tools/scripts/generate-os-info Configuration.OperatingSystem.props
4747
cp `$(MSBUILD) $(MSBUILD_FLAGS) /nologo /v:minimal /t:GetMonoSourceFullPath build-tools/scripts/Paths.targets`/mcs/class/msfinal.pub .
4848

49+
prepare-deps:
50+
$(MSBUILD) $(MSBUILD_FLAGS) build-tools/dependencies/dependencies.mdproj
51+
4952
prepare-msbuild:
5053
ifeq ($(MSBUILD),msbuild)
5154
for proj in $(MSBUILD_PREPARE_PROJS); do \

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ and will override any default values specified in `Configuration.props`.
5454

5555
Overridable MSBuild properties include:
5656

57+
* `$(AutoProvision)`: Automatically install required dependencies, if possible.
58+
* `$(AutoProvisionUsesSudo)`: Use `sudo` when installing dependencies.
5759
* `$(AndroidApiLevel)`: The Android API level to bind in `src/Mono.Android`.
5860
This is an integer value, e.g. `15` for
5961
[API-15 (Android 4.0.3)](http://developer.android.com/about/versions/android-4.0.3.html).
@@ -114,6 +116,18 @@ Building Xamarin.Android requires:
114116
* [`xxd`](#xxd)
115117
* [The Android SDK and NDK](#ndk)
116118

119+
The `make prepare` build step will check that all required dependencies
120+
are present. If you would like `make prepare` to automatically install
121+
required dependencies, set the `$(AutoProvision)` MSBuild property to True
122+
and (if necessary) set the `$(AutoProvisionUsesSudo)` property to True.
123+
(This is not supported on all operating systems.)
124+
125+
If `$(AutoProvision)` is False (the default) and a dependency is missing,
126+
then the build will fail and an error message will be displayed attempting
127+
to provide install instructions to obtain the missing dependency, e.g.:
128+
129+
error : Could not find required program '7za'. Please run: brew install 'p7zip'.
130+
117131
<a name="mono-sdk" />
118132
## Mono MDK
119133

Xamarin.Android.sln

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Xamarin.Android.Cecil", "ex
9797
EndProject
9898
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Xamarin.Android.Cecil.Mdb", "external\Java.Interop\src\Xamarin.Android.Cecil\Xamarin.Android.Cecil.Mdb.csproj", "{C0487169-8F81-497F-919E-EB42B1D0243F}"
9999
EndProject
100+
Project("{9344BDBB-3E7F-41FC-A0DD-8665D75EE146}") = "dependencies", "build-tools\dependencies\dependencies.mdproj", "{C845ECC0-2ED3-498E-8EA8-02EF7AC6E9AD}"
101+
EndProject
100102
Global
101103
GlobalSection(SolutionConfigurationPlatforms) = preSolution
102104
Debug|AnyCPU = Debug|AnyCPU
@@ -447,6 +449,14 @@ Global
447449
{C876DA71-8573-4CEF-9149-716D72455ED4}.XAIntegrationDebug|AnyCPU.Build.0 = Debug|Any CPU
448450
{C876DA71-8573-4CEF-9149-716D72455ED4}.XAIntegrationRelease|AnyCPU.ActiveCfg = Debug|Any CPU
449451
{C876DA71-8573-4CEF-9149-716D72455ED4}.XAIntegrationRelease|AnyCPU.Build.0 = Debug|Any CPU
452+
{C845ECC0-2ED3-498E-8EA8-02EF7AC6E9AD}.Debug|AnyCPU.ActiveCfg = Debug|Any CPU
453+
{C845ECC0-2ED3-498E-8EA8-02EF7AC6E9AD}.Debug|AnyCPU.Build.0 = Debug|Any CPU
454+
{C845ECC0-2ED3-498E-8EA8-02EF7AC6E9AD}.Release|AnyCPU.ActiveCfg = Release|Any CPU
455+
{C845ECC0-2ED3-498E-8EA8-02EF7AC6E9AD}.Release|AnyCPU.Build.0 = Release|Any CPU
456+
{C845ECC0-2ED3-498E-8EA8-02EF7AC6E9AD}.XAIntegrationDebug|AnyCPU.ActiveCfg = Debug|Any CPU
457+
{C845ECC0-2ED3-498E-8EA8-02EF7AC6E9AD}.XAIntegrationDebug|AnyCPU.Build.0 = Debug|Any CPU
458+
{C845ECC0-2ED3-498E-8EA8-02EF7AC6E9AD}.XAIntegrationRelease|AnyCPU.ActiveCfg = Debug|Any CPU
459+
{C845ECC0-2ED3-498E-8EA8-02EF7AC6E9AD}.XAIntegrationRelease|AnyCPU.Build.0 = Debug|Any CPU
450460
EndGlobalSection
451461
GlobalSection(NestedProjects) = preSolution
452462
{8FF78EB6-6FC8-46A7-8A15-EBBA9045C5FA} = {E351F97D-EA4F-4E7F-AAA0-8EBB1F2A4A62}
@@ -493,6 +503,7 @@ Global
493503
{15945D4B-FF56-4BCC-B598-2718D199DD08} = {864062D3-A415-4A6F-9324-5820237BA058}
494504
{C0487169-8F81-497F-919E-EB42B1D0243F} = {864062D3-A415-4A6F-9324-5820237BA058}
495505
{C876DA71-8573-4CEF-9149-716D72455ED4} = {E351F97D-EA4F-4E7F-AAA0-8EBB1F2A4A62}
506+
{C845ECC0-2ED3-498E-8EA8-02EF7AC6E9AD} = {E351F97D-EA4F-4E7F-AAA0-8EBB1F2A4A62}
496507
EndGlobalSection
497508
GlobalSection(MonoDevelopProperties) = preSolution
498509
Policies = $0

build-tools/android-toolchain/android-toolchain.mdproj

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
<BuildDependsOn>
1919
ResolveReferences;
2020
_CopyBootstrapTasksAssembly;
21-
CheckForRequiredPrograms;
2221
_DownloadItems;
2322
_UnzipFiles;
2423
_CreateNdkToolchains;
@@ -31,6 +30,11 @@
3130
<Name>xa-prep-tasks</Name>
3231
<ReferenceOutputAssembly>False</ReferenceOutputAssembly>
3332
</ProjectReference>
33+
<ProjectReference Include="..\dependencies\dependencies.mdproj">
34+
<Project>{C845ECC0-2ED3-498E-8EA8-02EF7AC6E9AD}</Project>
35+
<Name>dependencies</Name>
36+
<ReferenceOutputAssembly>False</ReferenceOutputAssembly>
37+
</ProjectReference>
3438
<ProjectReference Include="..\..\src\Xamarin.Android.Tools.BootstrapTasks\Xamarin.Android.Tools.BootstrapTasks.csproj">
3539
<Project>{E8492EFB-D14A-4F32-AA28-88848322ECEA}</Project>
3640
<Name>Xamarin.Android.Tools.BootstrapTasks</Name>

build-tools/android-toolchain/android-toolchain.projitems

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -119,42 +119,4 @@
119119
<HostOS></HostOS>
120120
</AntItem>
121121
</ItemGroup>
122-
<ItemGroup>
123-
<RequiredProgram Include="$(ManagedRuntime)" Condition=" '$(ManagedRuntime)' != '' " />
124-
<RequiredProgram Include="$(HostCcName)" />
125-
<RequiredProgram Include="$(HostCxxName)" />
126-
<RequiredProgram Include="7za" Condition=" '$(NeedMxe)' == 'true' And $(AndroidSupportedHostJitAbisForConditionalChecks.Contains (':mxe-Win64:'))">
127-
<Homebrew>p7zip</Homebrew>
128-
</RequiredProgram>
129-
<RequiredProgram Include="autoconf" />
130-
<RequiredProgram Include="automake" />
131-
<RequiredProgram Include="cmake" Condition=" '$(NeedMxe)' == 'true' And $(AndroidSupportedHostJitAbisForConditionalChecks.Contains (':mxe-Win64:'))" />
132-
<RequiredProgram Include="gdk-pixbuf-csource" Condition=" '$(NeedMxe)' == 'true' And $(AndroidSupportedHostJitAbisForConditionalChecks.Contains (':mxe-Win64:'))">
133-
<Homebrew>gdk-pixbuf</Homebrew>
134-
</RequiredProgram>
135-
<RequiredProgram Include="gettext" Condition=" '$(NeedMxe)' == 'true' And $(AndroidSupportedHostJitAbisForConditionalChecks.Contains (':mxe-Win64:'))" />
136-
<RequiredProgram Include="glibtool" Condition=" '$(NeedMxe)' == 'true' And $(AndroidSupportedHostJitAbisForConditionalChecks.Contains (':mxe-Win64:'))">
137-
<Homebrew>libtool</Homebrew>
138-
</RequiredProgram>
139-
<RequiredProgram Include="gsed" Condition=" '$(NeedMxe)' == 'true' And $(AndroidSupportedHostJitAbisForConditionalChecks.Contains (':mxe-Win64:'))">
140-
<Homebrew>gnu-sed</Homebrew>
141-
</RequiredProgram>
142-
<RequiredProgram Include="intltoolize" Condition=" '$(NeedMxe)' == 'true' And $(AndroidSupportedHostJitAbisForConditionalChecks.Contains (':mxe-Win64:'))">
143-
<Homebrew>intltool</Homebrew>
144-
</RequiredProgram>
145-
<RequiredProgram Include="make" />
146-
<RequiredProgram Include="pkg-config" Condition=" '$(NeedMxe)' == 'true' And $(AndroidSupportedHostJitAbisForConditionalChecks.Contains (':mxe-Win64:'))">
147-
<Homebrew>pkg-config</Homebrew>
148-
</RequiredProgram>
149-
<RequiredProgram Include="ruby" Condition=" '$(NeedMxe)' == 'true' And $(AndroidSupportedHostJitAbisForConditionalChecks.Contains (':mxe-Win64:'))" />
150-
<RequiredProgram Include="scons" Condition=" '$(NeedMxe)' == 'true' And $(AndroidSupportedHostJitAbisForConditionalChecks.Contains (':mxe-Win64:'))">
151-
<Homebrew>scons</Homebrew>
152-
</RequiredProgram>
153-
<RequiredProgram Include="wget" Condition=" '$(NeedMxe)' == 'true' And $(AndroidSupportedHostJitAbisForConditionalChecks.Contains (':mxe-Win64:'))">
154-
<Homebrew>wget</Homebrew>
155-
</RequiredProgram>
156-
<RequiredProgram Include="xz" Condition=" '$(NeedMxe)' == 'true' And $(AndroidSupportedHostJitAbisForConditionalChecks.Contains (':mxe-Win64:'))">
157-
<Homebrew>xz</Homebrew>
158-
</RequiredProgram>
159-
</ItemGroup>
160122
</Project>

build-tools/android-toolchain/android-toolchain.targets

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
Properties="OutputPath=$(AndroidToolchainDirectory)\"
1111
/>
1212
</Target>
13-
<UsingTask AssemblyFile="..\..\bin\Build$(Configuration)\xa-prep-tasks.dll" TaskName="Xamarin.Android.BuildTools.PrepTasks.DownloadUri" />
1413
<UsingTask AssemblyFile="..\..\bin\Build$(Configuration)\Xamarin.Android.Tools.BootstrapTasks.dll" TaskName="Xamarin.Android.Tools.BootstrapTasks.UnzipDirectoryChildren" />
1514
<Target Name="_DetermineItems">
1615
<CreateItem
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
5+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
6+
<ItemType>GenericProject</ItemType>
7+
<ProjectGuid>{C845ECC0-2ED3-498E-8EA8-02EF7AC6E9AD}</ProjectGuid>
8+
</PropertyGroup>
9+
<Import Project="..\..\Configuration.props" />
10+
<Import Project="dependencies.targets" />
11+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
12+
<OutputPath>.\</OutputPath>
13+
</PropertyGroup>
14+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
15+
<OutputPath>.\</OutputPath>
16+
</PropertyGroup>
17+
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
18+
<PropertyGroup>
19+
<BuildDependsOn>
20+
ResolveReferences;
21+
CheckForRequiredPrograms;
22+
</BuildDependsOn>
23+
</PropertyGroup>
24+
<ItemGroup>
25+
<ProjectReference Include="..\xa-prep-tasks\xa-prep-tasks.csproj">
26+
<Project>{7CE69551-BD73-4726-ACAA-AAF89C84BAF8}</Project>
27+
<Name>xa-prep-tasks</Name>
28+
<ReferenceOutputAssembly>False</ReferenceOutputAssembly>
29+
</ProjectReference>
30+
</ItemGroup>
31+
</Project>
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<_DarwinMonoFramework>MonoFramework-MDK-4.8.0.489.macos10.xamarin.universal.pkg</_DarwinMonoFramework>
5+
<_AptGetInstall>apt-get -f -u install</_AptGetInstall>
6+
</PropertyGroup>
7+
<ItemGroup>
8+
<RequiredProgram Include="$(HostCcName)" />
9+
<RequiredProgram Include="$(HostCxxName)" />
10+
<RequiredProgram Include="7za" Condition=" '$(NeedMxe)' == 'true' And $(AndroidSupportedHostJitAbisForConditionalChecks.Contains (':mxe-Win64:'))">
11+
<Homebrew>p7zip</Homebrew>
12+
</RequiredProgram>
13+
<RequiredProgram Include="autoconf">
14+
<Homebrew>autoconf</Homebrew>
15+
</RequiredProgram>
16+
<RequiredProgram Include="automake">
17+
<Homebrew>automake</Homebrew>
18+
</RequiredProgram>
19+
<RequiredProgram Include="cmake" Condition=" '$(NeedMxe)' == 'true' And $(AndroidSupportedHostJitAbisForConditionalChecks.Contains (':mxe-Win64:'))">
20+
<Homebrew>cmake</Homebrew>
21+
</RequiredProgram>
22+
<RequiredProgram Include="gdk-pixbuf-csource" Condition=" '$(NeedMxe)' == 'true' And $(AndroidSupportedHostJitAbisForConditionalChecks.Contains (':mxe-Win64:'))">
23+
<Homebrew>gdk-pixbuf</Homebrew>
24+
</RequiredProgram>
25+
<RequiredProgram Include="gettext" Condition=" '$(NeedMxe)' == 'true' And $(AndroidSupportedHostJitAbisForConditionalChecks.Contains (':mxe-Win64:'))">
26+
<Homebrew>gettext</Homebrew>
27+
</RequiredProgram>
28+
<RequiredProgram Include="glibtool" Condition=" '$(NeedMxe)' == 'true' And $(AndroidSupportedHostJitAbisForConditionalChecks.Contains (':mxe-Win64:'))">
29+
<Homebrew>libtool</Homebrew>
30+
</RequiredProgram>
31+
<RequiredProgram Include="gsed" Condition=" '$(NeedMxe)' == 'true' And $(AndroidSupportedHostJitAbisForConditionalChecks.Contains (':mxe-Win64:'))">
32+
<Homebrew>gnu-sed</Homebrew>
33+
</RequiredProgram>
34+
<RequiredProgram Include="intltoolize" Condition=" '$(NeedMxe)' == 'true' And $(AndroidSupportedHostJitAbisForConditionalChecks.Contains (':mxe-Win64:'))">
35+
<Homebrew>intltool</Homebrew>
36+
</RequiredProgram>
37+
<RequiredProgram Include="javac">
38+
<MinimumVersion>1.8</MinimumVersion>
39+
<CurrentVersionCommand>$(MSBuildThisFileDirectory)..\scripts\javac-version</CurrentVersionCommand>
40+
<UbuntuInstall>$(_AptGetInstall) openjdk-8-jdk</UbuntuInstall>
41+
</RequiredProgram>
42+
<RequiredProgram Include="make" />
43+
<RequiredProgram Include="pkg-config" Condition=" '$(NeedMxe)' == 'true' And $(AndroidSupportedHostJitAbisForConditionalChecks.Contains (':mxe-Win64:'))">
44+
<Homebrew>pkg-config</Homebrew>
45+
</RequiredProgram>
46+
<RequiredProgram Include="ruby" Condition=" '$(NeedMxe)' == 'true' And $(AndroidSupportedHostJitAbisForConditionalChecks.Contains (':mxe-Win64:'))" />
47+
<RequiredProgram Include="scons" Condition=" '$(NeedMxe)' == 'true' And $(AndroidSupportedHostJitAbisForConditionalChecks.Contains (':mxe-Win64:'))">
48+
<Homebrew>scons</Homebrew>
49+
</RequiredProgram>
50+
<RequiredProgram Include="wget" Condition=" '$(NeedMxe)' == 'true' And $(AndroidSupportedHostJitAbisForConditionalChecks.Contains (':mxe-Win64:'))">
51+
<Homebrew>wget</Homebrew>
52+
</RequiredProgram>
53+
<RequiredProgram Include="xz" Condition=" '$(NeedMxe)' == 'true' And $(AndroidSupportedHostJitAbisForConditionalChecks.Contains (':mxe-Win64:'))">
54+
<Homebrew>xz</Homebrew>
55+
</RequiredProgram>
56+
<RequiredProgram Include="xxd">
57+
<UbuntuInstall>$(_AptGetInstall) vim-common</UbuntuInstall>
58+
</RequiredProgram>
59+
<RequiredProgram Include="$(ManagedRuntime)" Condition=" '$(ManagedRuntime)' != '' ">
60+
<MinimumVersion>4.4.0</MinimumVersion>
61+
<MaximumVersion>4.8.99</MaximumVersion>
62+
<CurrentVersionCommand>$(MSBuildThisFileDirectory)..\scripts\mono-version</CurrentVersionCommand>
63+
<DarwinMinimumUrl>https://bosstoragemirror.blob.core.windows.net/wrench/mono-4.8.0/9a/9ac5bf2f0235ab75d2cc6be0866d6ca3ed302977/$(_DarwinMonoFramework)</DarwinMinimumUrl>
64+
<DarwinInstall>installer -pkg "$(AndroidToolchainCacheDirectory)\$(_DarwinMonoFramework)" -target /</DarwinInstall>
65+
</RequiredProgram>
66+
</ItemGroup>
67+
</Project>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="dependencies.projitems" />
4+
<Import Project="..\scripts\RequiredPrograms.targets" />
5+
</Project>

0 commit comments

Comments
 (0)