Skip to content

Commit

Permalink
Xamarin.Android build preparation utility
Browse files Browse the repository at this point in the history
Testing:

 * Default mode: run `make prepare`
 * Verbose debug: run `make V=1 prepare`
 * CI mode: run `make PREPARE_CI=1 prepare`
 * Help: run `make prepare-help`
 * Logs: `bin/BuildDebug`

Supported operating systems:

 * macOS
 * Linux

Windows support is planned, present but not fully implemented or tested.

This commit implements a `make prepare` replacement that does not rely on shell
scripts or MSBuild. The idea is that a standalone C# program can perform all the
steps in a more streamlined, more clear way than the current solution. One of
the main goals is to make the process more approachable by external
contributors, but also by the core developers who may want to change some
aspects of XA build preparation (e.g. Android platforms, Mono version etc) but
are not familiar with the build system. Towards that goal, the codebase is
designed so that the minimum amount of searching around it is necessary to
figure out where to make the desired change. Main location serving this purpose
is the `build-tools/xabootstrap/xabootstrap/ConfigAndData` directory. It should
be the *only* location where one needs to look in order to change all and any
aspects of XA preparation.

[TBC]
  • Loading branch information
grendello committed May 7, 2019
1 parent 58be92e commit 973368b
Show file tree
Hide file tree
Showing 223 changed files with 14,586 additions and 2,510 deletions.
1 change: 1 addition & 0 deletions CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
/build-tools/manifest-attribute-codegen @jonpryor
/build-tools/scripts/PrepareWindows.targets @jonathanpeppers
/build-tools/timing @jonathanpeppers @radekdoulik
/build-tools/xaprepare @grendello

/src/OpenTK-1.0 @radekdoulik @jonpryor
/src/Mono.Android.Export @jonpryor
Expand Down
9 changes: 7 additions & 2 deletions Configuration.props
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,16 @@
<AndroidUseLatestPlatformSdk Condition=" '$(AndroidFrameworkVersion)' == '' And '$(_IsRunningNuGetRestore)' == 'True' ">True</AndroidUseLatestPlatformSdk>
<DebugType Condition=" '$(DebugType)' == '' ">portable</DebugType>
</PropertyGroup>
<PropertyGroup Condition=" '$(HostOS)' == '' ">
<HostOS Condition="$([MSBuild]::IsOSPlatform('windows'))">Windows</HostOS>
<HostOS Condition="$([MSBuild]::IsOSPlatform('linux'))">Linux</HostOS>
<HostOS Condition="$([MSBuild]::IsOSPlatform('osx'))">Darwin</HostOS>
</PropertyGroup>
<PropertyGroup>
<AutoProvision Condition=" '$(AutoProvision)' == '' ">False</AutoProvision>
<AutoProvisionUsesSudo Condition=" '$(AutoProvisionUsesSudo)' == '' ">False</AutoProvisionUsesSudo>
<XAInstallPrefix Condition=" '$(XAInstallPrefix)' == '' ">$(MSBuildThisFileDirectory)bin\$(Configuration)\lib\xamarin.android\</XAInstallPrefix>
<MingwDependenciesRootDirectory Condition=" '$(MingwDependenciesRootDirectory)' == '' ">$(MSBuildThisFileDirectory)\bin\Build$(Configuration)\mingw-deps</MingwDependenciesRootDirectory>
<HostOS Condition=" '$(HostOS)' == '' And '$(OS)' == 'Windows_NT' ">Windows</HostOS>
<HostCc Condition=" '$(HostCc)' == '' ">$(HostCc64)</HostCc>
<HostCxx Condition=" '$(HostCxx)' == '' ">$(HostCxx64)</HostCxx>
<HostCc Condition=" '$(HostCc)' == '' ">$(HostCc32)</HostCc>
Expand Down Expand Up @@ -171,7 +175,8 @@
<AndroidSupportedTargetAotAbisSplit>$(AndroidSupportedTargetAotAbis.Split(':'))</AndroidSupportedTargetAotAbisSplit>
</PropertyGroup>
<PropertyGroup>
<RemapAssemblyRefTool>$(ManagedRuntime) $(ManagedRuntimeArgs) &quot;$(MSBuildThisFileDirectory)bin\Build$(Configuration)\remap-assembly-ref.exe&quot;</RemapAssemblyRefTool>
<RemapAssemblyRefToolExecutable>$(MSBuildThisFileDirectory)bin\Build$(Configuration)\remap-assembly-ref.exe</RemapAssemblyRefToolExecutable>
<RemapAssemblyRefTool>$(ManagedRuntime) $(ManagedRuntimeArgs) &quot;$(RemapAssemblyRefToolExecutable)&quot;</RemapAssemblyRefTool>
</PropertyGroup>

<!-- Unit Test Properties -->
Expand Down
194 changes: 51 additions & 143 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,28 +1,57 @@
export OS_NAME := $(shell uname)
export OS_ARCH := $(shell uname -m)
export NO_SUDO ?= false
V ?= 0
prefix = /usr/local
CONFIGURATION = Debug
RUNTIME := $(shell which mono64 2> /dev/null && echo mono64 || echo mono) --debug=casts
SOLUTION = Xamarin.Android.sln
TEST_TARGETS = build-tools/scripts/RunTests.targets
API_LEVEL ?=
PREPARE_ARGS =
PREPARE_BUILD_LOG = bin/Build$(CONFIGURATION)/bootstrap-build.binlog
PREPARE_SOURCE_DIR = build-tools/xaprepare
PREPARE_SOLUTION = $(PREPARE_SOURCE_DIR)/xaprepare.sln
PREPARE_EXE = $(PREPARE_SOURCE_DIR)/xaprepare/bin/$(CONFIGURATION)/xaprepare.exe
PREPARE_MSBUILD_ARGS = /p:Configuration=$(CONFIGURATION) /binaryLogger:"$(PREPARE_BUILD_LOG)"
PREPARE_CI ?= 0

all:
$(call MSBUILD_BINLOG,all,$(_SLN_BUILD)) $(MSBUILD_FLAGS) $(SOLUTION)

ifeq ($(OS_NAME),Darwin)
export MACOSX_DEPLOYMENT_TARGET := 10.11
HOMEBREW_PREFIX ?= $(shell brew --prefix)
else
HOMEBREW_PREFIX := $prefix
-include bin/Build$(CONFIGURATION)/rules.mk

ifeq ($(OS_NAME),)
export OS_NAME := $(shell uname)
endif

ifeq ($(OS_ARCH),)
export OS_ARCH := $(shell uname -m)
endif

export NO_SUDO ?= false

ifneq ($(NO_SUDO),false)
PREPARE_ARGS += --no-sudo
endif

ifneq ($(V),0)
MONO_OPTIONS += --debug
NUGET_VERBOSITY = -Verbosity Detailed
PREPARE_ARGS += -v:d
endif

ifneq ($(PREPARE_CI),0)
PREPARE_ARGS += --no-sudo --no-emoji --run-mode=CI
endif

ifneq ($(MONO_OPTIONS),)
export MONO_OPTIONS
ifeq ($(OS_NAME),Darwin)
ifeq ($(HOMEBREW_PREFIX),)
HOMEBREW_PREFIX ?= $(shell brew --prefix)
endif
else
HOMEBREW_PREFIX := $prefix
endif

ifeq ($(wildcard Configuration.OperatingSystem.props),)
PREPARE_MSBUILD_ARGS += "/p:HostHomebrewPrefix=$(HOMEBREW_PREFIX)"
endif

include build-tools/scripts/msbuild.mk
Expand All @@ -37,9 +66,6 @@ ifneq ($(API_LEVEL),)
MSBUILD_FLAGS += /p:AndroidApiLevel=$(API_LEVEL) /p:AndroidFrameworkVersion=$(word $(API_LEVEL), $(ALL_FRAMEWORKS))
endif

all::
$(call MSBUILD_BINLOG,all,$(_SLN_BUILD)) $(MSBUILD_FLAGS) $(SOLUTION)

all-tests::
MSBUILD="$(MSBUILD)" $(call MSBUILD_BINLOG,all-tests,tools/scripts/xabuild) $(MSBUILD_FLAGS) Xamarin.Android-Tests.sln

Expand Down Expand Up @@ -70,87 +96,6 @@ uninstall::
rm -rf "$(prefix)/lib/mono/xbuild/Xamarin/Android"
rm -rf "$(prefix)/lib/mono/xbuild-frameworks/MonoAndroid"

ifeq ($(OS_NAME),Linux)
export LINUX_DISTRO := $(shell lsb_release -i -s || true)
export LINUX_DISTRO_RELEASE := $(shell lsb_release -r -s || true)
prepare:: linux-prepare
endif # $(OS_NAME)=Linux

prepare:: prepare-paths prepare-msbuild

linux-prepare::
BINFMT_MISC_TROUBLE="cli win" \
BINFMT_WARN=no ; \
for m in ${BINFMT_MISC_TROUBLE}; do \
if [ -f "/proc/sys/fs/binfmt_misc/$$m" ]; then \
BINFMT_WARN=yes ; \
fi ; \
done ; \
if [ "x${BINFMT_WARN}" = "xyes" ]; then \
cat Documentation/binfmt_misc-warning-Linux.txt ; \
fi; \
if [ -f build-tools/scripts/dependencies/linux-prepare-$(LINUX_DISTRO)-$(LINUX_DISTRO_RELEASE).sh ]; then \
sh build-tools/scripts/dependencies/linux-prepare-$(LINUX_DISTRO)-$(LINUX_DISTRO_RELEASE).sh $(LINUX_DISTRO_RELEASE); \
elif [ -f build-tools/scripts/dependencies/linux-prepare-$(LINUX_DISTRO).sh ]; then \
sh build-tools/scripts/dependencies/linux-prepare-$(LINUX_DISTRO).sh $(LINUX_DISTRO_RELEASE); \
fi

# $(call GetPath,path)
GetPath = $(shell $(MSBUILD) $(MSBUILD_FLAGS) /p:DoNotLoadOSProperties=True /nologo /v:minimal /t:Get$(1)FullPath build-tools/scripts/Paths.targets | tr -d '[[:space:]]' )

MSBUILD_PREPARE_PROJS = \
src/mono-runtimes/mono-runtimes.csproj \
src/Xamarin.Android.Build.Tasks/Xamarin.Android.Build.Tasks.csproj

prepare-deps: prepare-cmake-mingw-toolchain
git submodule update --init --recursive
./build-tools/scripts/generate-os-info Configuration.OperatingSystem.props
mkdir -p bin/Build$(CONFIGURATION)
$(call MSBUILD_BINLOG,prepare-deps) build-tools/dependencies/dependencies.csproj

#
# $(1): output file name
#
define create_cmake_toolchain
prepare-cmake-mingw-toolchain:: bin/Build$(CONFIGURATION)/$(1)

bin/Build$(CONFIGURATION)/$(1): build-tools/scripts/$(1).in
mkdir -p $$(dir $$@)
sed -e 's;@HOMEBREW_PREFIX@;$$(HOMEBREW_PREFIX);g' < $$< > $$@
endef

$(eval $(call create_cmake_toolchain,mingw-32.cmake))
$(eval $(call create_cmake_toolchain,mingw-64.cmake))

prepare-external: prepare-deps
nuget restore $(NUGET_VERBOSITY) $(SOLUTION)
nuget restore $(NUGET_VERBOSITY) Xamarin.Android-Tests.sln
(cd external/xamarin-android-tools && make prepare CONFIGURATION=$(CONFIGURATION))
(cd $(call GetPath,JavaInterop) && make prepare CONFIGURATION=$(CONFIGURATION) JI_MAX_JDK=8)
(cd $(call GetPath,JavaInterop) && make bin/Build$(CONFIGURATION)/JdkInfo.props CONFIGURATION=$(CONFIGURATION) JI_MAX_JDK=8)

prepare-bundle: prepare-external
$(call MSBUILD_BINLOG,prepare-bundle) build-tools/download-bundle/download-bundle.csproj
$(call MSBUILD_BINLOG,prepare-restore) $(MSBUILD_FLAGS) tests/Xamarin.Forms-Performance-Integration/Xamarin.Forms.Performance.Integration.csproj /t:Restore

prepare-props: prepare-bundle
cp $(call GetPath,JavaInterop)/external/Mono.Cecil* "$(call GetPath,MonoSource)/external"
cp "$(call GetPath,JavaInterop)/product.snk" "$(call GetPath,MonoSource)"
cp build-tools/scripts/Configuration.Java.Interop.Override.props external/Java.Interop/Configuration.Override.props
cp $(call GetPath,MonoSource)/mcs/class/msfinal.pub .

prepare-msbuild: prepare-props
ifeq ($(USE_MSBUILD),1)
for proj in $(MSBUILD_PREPARE_PROJS); do \
$(call MSBUILD_BINLOG,prepare-msbuild) "$$proj" || exit 1; \
done
endif # msbuild

prepare-image-dependencies:
$(call MSBUILD_BINLOG,prepare-image-deps) build-tools/scripts/PrepareImageDependencies.targets /t:PrepareImageDependencies \
/p:AndroidSupportedHostJitAbis=mxe-Win32:mxe-Win64
cat bin/Build$(CONFIGURATION)/prepare-image-dependencies.sh | tr -d '\r' > prepare-image-dependencies.sh

include build-tools/scripts/BuildEverything.mk

# Must be after BuildEverything.mk - it uses variables defined there
Expand All @@ -159,59 +104,10 @@ include tests/api-compatibility/api-compatibility.mk

topdir := $(shell pwd)


XA_BUILD_PATHS_OUT = bin/Test$(CONFIGURATION)/XABuildPaths.cs

prepare-paths: $(XA_BUILD_PATHS_OUT)

$(XA_BUILD_PATHS_OUT): bin/Test%/XABuildPaths.cs: build-tools/scripts/XABuildPaths.cs.in
mkdir -p $(shell dirname $@)
sed -e 's;@CONFIGURATION@;$*;g' \
-e 's;@TOP_DIRECTORY@;$(topdir);g' < $< > $@
cat $@


# Usage: $(call CALL_CREATE_THIRD_PARTY_NOTICES,path,licenseType,includeExternalDeps,includeBuildDeps)
define CREATE_THIRD_PARTY_NOTICES
$(call MSBUILD_BINLOG,create-tpn,$(MSBUILD)) $(_MSBUILD_ARGS) \
$(topdir)/build-tools/ThirdPartyNotices/ThirdPartyNotices.csproj \
/p:Configuration=$(CONFIGURATION) \
/p:ThirdPartyNoticeFile=$(topdir)/$(1) \
/p:ThirdPartyNoticeLicenseType=$(2) \
/p:TpnIncludeExternalDependencies=$(3) \
/p:TpnIncludeBuildDependencies=$(4)
endef # CREATE_THIRD_PARTY_NOTICES

prepare:: prepare-tpn

TPN_LICENSE_FILES = $(shell grep -h '<LicenseFile>' external/*.tpnitems src/*.tpnitems \
| sed -E 's,<LicenseFile>(.*)</LicenseFile>,\1,g;s,.\(MSBuildThisFileDirectory\),$(topdir)/external/,g' \
| tr \\ / )

# Usage: $(call CREATE_THIRD_PARTY_NOTICES_RULE,path,licenseType,includeExternalDeps,includeBuildDeps)
define CREATE_THIRD_PARTY_NOTICES_RULE
prepare-tpn:: $(1)

$(1) $(topdir)/$(1): build-tools/ThirdPartyNotices/ThirdPartyNotices.csproj \
$(wildcard external/*.tpnitems src/*.tpnitems build-tools/*.tpnitems) \
$(TPN_LICENSE_FILES)
$(call CREATE_THIRD_PARTY_NOTICES,$(1),$(2),$(3),$(4))
endef # CREATE_THIRD_PARTY_NOTICES_RULE

THIRD_PARTY_NOTICE_LICENSE_TYPE = microsoft-oss

$(eval $(call CREATE_THIRD_PARTY_NOTICES_RULE,ThirdPartyNotices.txt,foundation,False,False))
$(eval $(call CREATE_THIRD_PARTY_NOTICES_RULE,bin/$(CONFIGURATION)/lib/xamarin.android/ThirdPartyNotices.txt,$(THIRD_PARTY_NOTICE_LICENSE_TYPE),True,False))

# Used by External XA Build
EXTERNAL_XA_PATH=$(topdir)
EXTERNAL_GIT_PATH=$(topdir)/external

prepare-external-git-dependencies:
$(call MSBUILD_BINLOG,prep-external-tasks) build-tools/xa-prep-tasks/xa-prep-tasks.csproj
$(call MSBUILD_BINLOG,prep-external-checkout) build-tools/xa-prep-tasks/xa-prep-tasks.csproj \
/t:CheckoutExternalGitSources /p:ExternalSourceDependencyDirectory='$(EXTERNAL_GIT_PATH)'

-include $(EXTERNAL_GIT_PATH)/monodroid/xa-integration.mk

run-all-tests:
Expand Down Expand Up @@ -257,3 +153,15 @@ list-nunit-tests:
$(MSBUILD) $(MSBUILD_FLAGS) $(TEST_TARGETS) /t:ListNUnitTests

include build-tools/scripts/runtime-helpers.mk

.PHONY: bootstrap-build
prepare-build:
mkdir -p $(dir $(PREPARE_BUILD_LOG))
nuget restore $(NUGET_VERBOSITY) $(PREPARE_SOLUTION)
msbuild $(PREPARE_MSBUILD_ARGS) $(PREPARE_SOLUTION)

prepare: prepare-build
mono --debug $(PREPARE_EXE) $(PREPARE_ARGS)

prepare-help: prepare-build
mono --debug $(PREPARE_EXE) -h
25 changes: 14 additions & 11 deletions ThirdPartyNotices.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@ The attached notices are provided for information only.
3. nunit/nunitlite (https://github.com/nunit/nunitlite/)
4. zLibDll/minizip (http://www.winimage.com/zLibDll/minizip.html)


%% bazelbuild/bazel NOTICES AND INFORMATION BEGIN HERE
=========================================
======================================================

Apache License
Version 2.0, January 2004
Expand Down Expand Up @@ -221,11 +220,12 @@ The attached notices are provided for information only.
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
=========================================

======================================================
END OF bazelbuild/bazel NOTICES AND INFORMATION

%% google/desugar NOTICES AND INFORMATION BEGIN HERE
=========================================
====================================================

Apache License
Version 2.0, January 2004
Expand Down Expand Up @@ -428,12 +428,12 @@ END OF bazelbuild/bazel NOTICES AND INFORMATION
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
=========================================

====================================================
END OF google/desugar NOTICES AND INFORMATION

%% nunit/nunitlite NOTICES AND INFORMATION BEGIN HERE
=========================================

=====================================================
Copyright (c) 2004-2013 Charlie Poole

Permission is hereby granted, free of charge, to any person obtaining a copy
Expand All @@ -454,12 +454,13 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

=========================================


=====================================================
END OF nunit/nunitlite NOTICES AND INFORMATION

%% zLibDll/minizip NOTICES AND INFORMATION BEGIN HERE
=========================================

=====================================================
Copyright (C) 1998-2005 Gilles Vollant

This software is provided 'as-is', without any express or implied
Expand All @@ -478,5 +479,7 @@ appreciated but is not required.
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.

=========================================

=====================================================
END OF zLibDll/minizip NOTICES AND INFORMATION

Loading

0 comments on commit 973368b

Please sign in to comment.