From b4ed684a4bbbb585341fa9859914e48018ba22f6 Mon Sep 17 00:00:00 2001 From: Jonathan Pryor Date: Wed, 8 Jun 2016 15:12:44 -0400 Subject: [PATCH] [build] Add support for `Configuration.Override.props` For proper use, the [xamarin-android][xa] build needs to place various Java.Interop utilities such as class-parse.exe and generator.exe into `$prefix/lib/mandroid`, so that Xamarin.Android.Build.Tasks.dll will properly verify the installation environment. There are three ways this could be accomplished: 1. The `xamarin-android` Makefile could explicitly build these utilities and override `$(OutputPath)`: xbuild external/Java.Interop/tools/class-parse /p:OutputPath=`pwd`/bin/$(CONFIGURATION)/lib/mandroid The problem with this is that we want to have the xamarin-android build system rely on MSBuild as much as possible, and this approach, while workable, runs counter to those desires. 2. We could add additional project configurations to control where the output directory should be. This was suggested by [@atsushieno][pr41]. My concern with this approach is that it's not easily extensible: it's not just a few projects that need to place files into `$prefix/lib/mandroid`, but all of their dependencies as well. Such an approach would thus require adding lots of new configurations to lots of projects. 3. Java.Interop could adopt a `xamarin-android`-style `Configuration.props` system. This would allow xamarin-android to *generate* a `Configuration.Override.props` file to specify the correct output path for those utilities. (3) is the chosen solution. It allows adding e.g. `external/Java.Interop/tools/generator/generator.csproj` to `Xamarin.Android.sln`, allowing it to be built "normally" from the `xamarin-android` build system, while causing the built files to be placed into e.g. `xamarin-android/bin/Debug/lib/mandroid` instead of the less useful `xamarin-android/external/Java.Interop/bin/Debug`. [xa]: https://github.com/xamarin/xamarin-android/ [pr41]: https://github.com/xamarin/java.interop/pull/41 --- .gitignore | 1 + Configuration.Override.props.in | 17 ++++++++ Configuration.props | 19 +++++++++ README.md | 57 ++++++++++++++++++++++++-- build-tools/scripts/jdk.mk | 4 +- build-tools/scripts/mono.mk | 6 +-- tools/class-parse/class-parse.csproj | 5 ++- tools/generator/generator.csproj | 5 ++- tools/logcat-parse/logcat-parse.csproj | 5 ++- 9 files changed, 104 insertions(+), 15 deletions(-) create mode 100644 Configuration.Override.props.in create mode 100644 Configuration.props diff --git a/.gitignore b/.gitignore index 246ab4580..479deabb9 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ bin +Configuration.Override.props obj JavaDeveloper-2013005_dp__11m4609.pkg LocalJDK diff --git a/Configuration.Override.props.in b/Configuration.Override.props.in new file mode 100644 index 000000000..e1da01c3c --- /dev/null +++ b/Configuration.Override.props.in @@ -0,0 +1,17 @@ + + + + /Library/Java/JavaVirtualMachines/jdk1.8.0_77.jdk/Contents/Home/jre/lib/server/libjvm.dylib + /Library/Frameworks/Mono.framework/Libraries/libmonosgen-2.0.1.dylib + $(MSBuildThisFileDirectory)bin\$(Configuration)\ + + + + + + + + + + + diff --git a/Configuration.props b/Configuration.props new file mode 100644 index 000000000..36fce7812 --- /dev/null +++ b/Configuration.props @@ -0,0 +1,19 @@ + + + + + + + + $(MSBuildThisFileDirectory)bin\$(Configuration)\ + + diff --git a/README.md b/README.md index 9da8b3a24..f2f464ca5 100644 --- a/README.md +++ b/README.md @@ -2,10 +2,13 @@ [![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/xamarin/xamarin-android?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) -**Java.Interop** is a brain-delusional [Second System Syndrome][sss] rebuild - of the monodroid/Xamarin.Android core, intended to fix some of the shortcomings - and design mistakes I've made over the years. +**Java.Interop** is a binding of the [Java Native Interface][jni] for use from +managed languages such as C#, and an associated set of code generators to +allow Java code to invoke managed code. It is *also* a brain-delusional +[Second System Syndrome][sss] rebuild of the monodroid/Xamarin.Android core, +intended to fix some of the shortcomings and design mistakes I've made over the years. +[jni]: http://docs.oracle.com/javase/8/docs/technotes/guides/jni/spec/jniTOC.html [sss]: http://en.wikipedia.org/wiki/Second-system_effect In particular, it attempts to fix the following issues: @@ -27,7 +30,7 @@ which returns a global reference while most other methods return a local ref. The `JNIEnv` API is also huge, unwieldy, and terrible. -## Requirements +## Build Requirements The current Oracle JDK7 installer only provides 64-bit binaries, while Mono for OS X is currently a 32-bit binary. These don't work together. :-( @@ -63,6 +66,52 @@ then run the `osx-setup` target: $ make osx-setup JDK=JavaDeveloper.pkg +## Build Configuration + +The Java.Interop build can be configured by overriding **make**(1) variables +on the command line or by specifying MSBuild properties to control behavior. + +### **make**(1) variables + +The following **make**(1) variables may be specified: + +* `$(CONFIGURATION)`: The product configuration to build, and corresponds + to the `$(Configuration)` MSBuild property when running `$(XBUILD)`. + Valid values are `Debug` and `Release`. Default value is `Debug`. +* `$(RUNTIME)`: The managed runtime to use to execute utilities, tests. + Default value is `mono64` if present in `$PATH`, otherwise `mono`. +* `$(TESTS)`: Which unit tests to execute. Useful in conjunction with the + `make run-tests` target: + + make run-tests TESTS=bin/Debug/Java.Interop.Dynamic-Tests.dll + +* `$(V)`: If set to a non-empty string, adds `/v:diag` to `$(XBUILD)` + invocations. +* `$(XBUILD)`: The MSBuild build tool to execute for builds. + Default value is `xbuild`. + + +### MSBuild Properties + +MSbuild properties may be placed into the file `Configuration.Override.props`, +which can be copied from +[`Configuration.Override.props.in`](Configuration.Override.props.in). +The `Configuration.Override.props` file is ``ed by +[`Configuration.props`](Configuration.props); there is no need to `` +it within other project files. + +Overridable MSBuild properties include: + +* `$(JdkJvmPath)`: Full path name to the JVM native library to link + [`java-interop`](src/java-interop) against. By default this is + probed for from numerious locations within + [`build-tools/scripts/jdk.mk`](build-tools/scripts/jdk.mk). +* `$(UtilityOutputFullPath)`: Directory to place various utilities such as + [`class-parse`](tools/class-parse), [`generator`](tools/generator), + and [`logcat-parse`](tools/logcat-parse). This value should be a full path. + By default this is `$(MSBuildThisFileDirectory)bin/$(Configuration)`. + + ## Type Safety The start of the reboot was to use strongly typed [`SafeHandle`][SafeHandle] diff --git a/build-tools/scripts/jdk.mk b/build-tools/scripts/jdk.mk index ab041f2c0..1a876e006 100644 --- a/build-tools/scripts/jdk.mk +++ b/build-tools/scripts/jdk.mk @@ -116,11 +116,11 @@ bin/Build$(CONFIGURATION)/JdkInfo.props: $(JI_JDK_INCLUDE_PATHS) $(JI_JVM_PATH) -rm "$@" echo '' > "$@" echo ' ' >> "$@" - echo " $(JI_JVM_PATH)" >> "$@" + echo " $(JI_JVM_PATH)" >> "$@" echo ' ' >> "$@" echo ' ' >> "$@" for p in $(JI_JDK_INCLUDE_PATHS); do \ - echo " " >> "$@"; \ + echo " " >> "$@"; \ done echo ' ' >> "$@" echo '' >> "$@" diff --git a/build-tools/scripts/mono.mk b/build-tools/scripts/mono.mk index 5e53ea468..0dac4088e 100644 --- a/build-tools/scripts/mono.mk +++ b/build-tools/scripts/mono.mk @@ -21,12 +21,12 @@ bin/Build$(CONFIGURATION)/MonoInfo.props: $(JI_MONO_INCLUDE_PATHS) $(JI_MONO_FRA -rm "$@" echo '' > "$@" echo ' ' >> "$@" - echo " $(JI_MONO_FRAMEWORK_PATH)" >> "$@" - echo ' $(JI_MONO_LIBS)' + echo " $(JI_MONO_FRAMEWORK_PATH)" >> "$@" + echo " $(JI_MONO_LIBS)" >> "$@" echo ' ' >> "$@" echo ' ' >> "$@" for p in $(JI_MONO_INCLUDE_PATHS); do \ - echo " " >> "$@"; \ + echo " " >> "$@"; \ done echo ' ' >> "$@" echo '' >> "$@" diff --git a/tools/class-parse/class-parse.csproj b/tools/class-parse/class-parse.csproj index e13176a40..d28b458fd 100644 --- a/tools/class-parse/class-parse.csproj +++ b/tools/class-parse/class-parse.csproj @@ -12,11 +12,12 @@ 8.0.30703 2.0 + true full false - ..\..\bin\Debug + $(UtilityOutputFullPath) DEBUG; prompt 4 @@ -26,7 +27,7 @@ full true - ..\..\bin\Release + $(UtilityOutputFullPath) prompt 4 true diff --git a/tools/generator/generator.csproj b/tools/generator/generator.csproj index e9b36829b..4c8cd2936 100644 --- a/tools/generator/generator.csproj +++ b/tools/generator/generator.csproj @@ -17,11 +17,12 @@ v4.5 + True full False - ..\..\bin\Debug + $(UtilityOutputFullPath) DEBUG;GENERATOR;USE_CECIL;JCW_ONLY_TYPE_NAMES prompt 4 @@ -30,7 +31,7 @@ none False - ..\..\bin\Release + $(UtilityOutputFullPath) prompt 4 True diff --git a/tools/logcat-parse/logcat-parse.csproj b/tools/logcat-parse/logcat-parse.csproj index 53eedd290..67fe5b425 100644 --- a/tools/logcat-parse/logcat-parse.csproj +++ b/tools/logcat-parse/logcat-parse.csproj @@ -12,11 +12,12 @@ v4.5 Xamarin.Android.Tools.LogcatParse.Program + true full false - ..\..\bin\Debug + $(UtilityOutputFullPath) DEBUG;TRACE prompt 4 @@ -26,7 +27,7 @@ full true - ..\..\bin\Release + $(UtilityOutputFullPath) TRACE prompt 4