Skip to content

Commit 39f47b2

Browse files
committed
[build] Add make prepare-image-dependencies target.
We are investigating building Xamarin.Android atop Visual Studio Team System (VSTS) in addition to our current Jenkins setup, and one of the issues we're running into is "bootstrapping": VSTS is configured to create a "fresh" VM for each build. **Pro**: It should allow builds to be more reliable, as previous build artifacts won't be present, and thus won't cause/hide errors. **Con**: *Previous build artifacts are not present*. Previous build artifacts such as *downloading and extracting* the Android NDK & SDK, using `brew` to install dependencies, building MXE... Ensuring that the dependencies are installed through `make prepare` can be quite time consuming. What we want is a way to ensure that the "build image" -- *what's already installed* when the VM boots -- contains all of our desired dependencies. Furthermore, we *don't* want to have the responsible parties checkout and build xamarin-android in order to determine what the dependencies should be. Attempt to square this circle by adding a new `make prepare-image-dependencies` target, which processes `@(AndroidSdkItem)`, `@(AndroidNdkItem)`, `@(AntItem)`, and `@(RequiredProgram)` to create a `prepare-image-dependencies.sh` script which will download and install the required dependencies. The generated shell script does *not* take the state of the machine running `make prepare-image-dependencies` into consideration. This allows the target to be executed on one machine, and the output run on another. $ make prepare-image-dependencies # creates `prepare-image-dependencies.sh` *Note*: `make prepare-image-dependencies` does not currently deal with MXE. (Building MXE on the VSTS VM is *very* time consuming, so it's something we need to take care of. It is not *yet* dealt with.)
1 parent 1645e7b commit 39f47b2

File tree

3 files changed

+125
-0
lines changed

3 files changed

+125
-0
lines changed

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,10 @@ ifeq ($(USE_MSBUILD),1)
115115
done
116116
endif # msbuild
117117

118+
prepare-image-dependencies:
119+
$(MSBUILD) $(MSBUILD_FLAGS) build-tools/scripts/PrepareImageDependencies.targets /t:PrepareImageDependencies \
120+
/p:AndroidSupportedHostJitAbis=mxe-Win32:mxe-Win64
121+
118122
include build-tools/scripts/BuildEverything.mk
119123
include tests/api-compatibility/api-compatibility.mk
120124

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
2+
<PropertyGroup>
3+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
4+
</PropertyGroup>
5+
<UsingTask AssemblyFile="..\..\bin\Build$(Configuration)\xa-prep-tasks.dll" TaskName="Xamarin.Android.BuildTools.PrepTasks.ReplaceFileContents" />
6+
<Import Project="..\..\Configuration.props" />
7+
<Import Project="..\android-toolchain\android-toolchain.projitems" />
8+
<Import Project="..\dependencies\dependencies.projitems" />
9+
<Target Name="PrepareImageDependencies">
10+
<ItemGroup>
11+
<_Dir Include="sdk" />
12+
<_Dir Include="ndk" />
13+
<_Dir Include="ant" />
14+
</ItemGroup>
15+
<ItemGroup>
16+
<_Package
17+
Condition=" '%(HostOS)' == '$(HostOS)' Or '%(HostOS)' == '' "
18+
Include="@(AndroidSdkItem->'$(AndroidUri)/%(RelUrl)%(Identity) sdk/%(DestDir)')"
19+
/>
20+
<_Package
21+
Condition=" '%(HostOS)' == '$(HostOS)' Or '%(HostOS)' == '' "
22+
Include="@(AndroidNdkItem->'$(AndroidUri)/%(RelUrl)%(Identity) ndk/%(DestDir)')"
23+
/>
24+
<_Package
25+
Condition=" '%(HostOS)' == '$(HostOS)' Or '%(HostOS)' == '' "
26+
Include="@(AntItem->'$(AntUri)/%(RelUrl)%(Identity) ant/%(DestDir)')"
27+
/>
28+
</ItemGroup>
29+
<ItemGroup>
30+
<_Brew
31+
Condition=" '$(HostOS)' == 'Darwin' And '%(RequiredProgram.Homebrew)' != '' "
32+
Include="@(RequiredProgram->'%(Homebrew)')"
33+
/>
34+
</ItemGroup>
35+
<PropertyGroup>
36+
<_Packages>@(_Package->'%(Identity)', '
37+
')</_Packages>
38+
<_Dirs>@(_Dir->'%(Identity)', '
39+
')</_Dirs>
40+
<_Brews>@(_Brew->'%(Identity)', '
41+
')</_Brews>
42+
</PropertyGroup>
43+
<ReplaceFileContents
44+
SourceFile="$(MSBuildThisFileDirectory)prepare-image-dependencies.sh.in"
45+
DestinationFile="$(MSBuildThisFileDirectory)\..\..\prepare-image-dependencies.sh"
46+
Replacements="@TOOLCHAIN_DIRS@=$(_Dirs);@PACKAGES@=$(_Packages);@BREWS@=$(_Brews)">
47+
</ReplaceFileContents>
48+
</Target>
49+
</Project>
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
#!/bin/bash -e
2+
set -o xtrace
3+
4+
ARCHIVE_PATH="$HOME/android-archives"
5+
TOOLCHAIN_PATH="$HOME/android-toolchain"
6+
7+
TOOLCHAIN_DIRS="
8+
@TOOLCHAIN_DIRS@
9+
"
10+
11+
# format: URL path/under/$TOOLCHAIN_PATH
12+
PACKAGES="
13+
@PACKAGES@
14+
"
15+
16+
BREW_PACKAGES="
17+
@BREWS@
18+
"
19+
20+
function Download ()
21+
{
22+
local url="$1"
23+
local archive="$ARCHIVE_PATH/`basename "$url"`"
24+
if [ -f "$archive" ]; then
25+
return
26+
fi
27+
curl -o "$archive" "$url"
28+
}
29+
30+
function Install ()
31+
{
32+
local url="$1"
33+
local subdir="$2"
34+
35+
local file=`basename "$url"`
36+
local archive="$ARCHIVE_PATH/$file"
37+
local targetdir="$TOOLCHAIN_PATH/$subdir"
38+
39+
local flagdir="$TOOLCHAIN_PATH/$(echo $subdir | sed 's#/.*$##g')"
40+
local flagfile="$flagdir/.$file"
41+
42+
mkdir -p "$targetdir"
43+
if [ ! -f "$flagfile" ]; then
44+
local extractdir=`mktemp -d`
45+
unzip -d "$extractdir" "$ARCHIVE_PATH/$file"
46+
mv "$extractdir"/*/* "$targetdir"
47+
touch "$flagfile"
48+
rm -Rf "$extractdir"
49+
fi
50+
}
51+
52+
echo "$TOOLCHAIN_DIRS" | while read line ; do
53+
if [ -z "$line" ]; then
54+
continue
55+
fi
56+
rm -Rf "$TOOLCHAIN_PATH/$line"
57+
done
58+
59+
echo "$PACKAGES" | while read line ; do
60+
if [ -z "$line" ]; then
61+
continue
62+
fi
63+
Download $line
64+
Install $line
65+
done
66+
67+
echo "$BREW_PACKAGES" | while read line ; do
68+
if [ -z "$line" ]; then
69+
continue
70+
fi
71+
brew install $line
72+
done

0 commit comments

Comments
 (0)