Skip to content

Commit b6431ac

Browse files
jonpryorradical
authored andcommitted
[build] Add support for Configuration.Override.props (#45)
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]: #41
1 parent 2f68f98 commit b6431ac

File tree

9 files changed

+104
-15
lines changed

9 files changed

+104
-15
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
bin
2+
Configuration.Override.props
23
obj
34
JavaDeveloper-2013005_dp__11m4609.pkg
45
LocalJDK

Configuration.Override.props.in

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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+
<JdkJvmPath>/Library/Java/JavaVirtualMachines/jdk1.8.0_77.jdk/Contents/Home/jre/lib/server/libjvm.dylib</JdkJvmPath>
5+
<MonoFrameworkPath>/Library/Frameworks/Mono.framework/Libraries/libmonosgen-2.0.1.dylib</MonoFrameworkPath>
6+
<UtilityOutputFullPath>$(MSBuildThisFileDirectory)bin\$(Configuration)\</UtilityOutputFullPath>
7+
</PropertyGroup>
8+
<ItemGroup>
9+
<!-- JDK C `include` directories -->
10+
<JdkIncludePath Include="/Library/Java/JavaVirtualMachines/jdk1.8.0_77.jdk/Contents/Home/include" />
11+
<JdkIncludePath Include="/Library/Java/JavaVirtualMachines/jdk1.8.0_77.jdk/Contents/Home/include/darwin" />
12+
</ItemGroup>
13+
<ItemGroup>
14+
<!-- Mono C `include` directories -->
15+
<MonoIncludePath Include="/Library/Frameworks/Mono.framework/Headers/mono-2.0" />
16+
</ItemGroup>
17+
</Project>

Configuration.props

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<!-- Note: MUST be imported *after* $(Configuration) is set! -->
4+
<Import
5+
Project="$(MSBuildThisFileDirectory)Configuration.Override.props"
6+
Condition="Exists('$(MSBuildThisFileDirectory)Configuration.Override.props')"
7+
/>
8+
<Import
9+
Project="$(MSBuildThisFileDirectory)bin\Build$(Configuration)\JdkInfo.props"
10+
Condition="Exists('$(MSBuildThisFileDirectory)bin\Build$(Configuration)\JdkInfo.props')"
11+
/>
12+
<Import
13+
Project="$(MSBuildThisFileDirectory)bin\Build$(Configuration)\MonoInfo.props"
14+
Condition="Exists('$(MSBuildThisFileDirectory)bin\Build$(Configuration)\MonoInfo.props')"
15+
/>
16+
<PropertyGroup>
17+
<UtilityOutputFullPath Condition=" '$(UtilityOutputFullPath)' == '' ">$(MSBuildThisFileDirectory)bin\$(Configuration)\</UtilityOutputFullPath>
18+
</PropertyGroup>
19+
</Project>

README.md

Lines changed: 53 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@
22

33
[![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)
44

5-
**Java.Interop** is a brain-delusional [Second System Syndrome][sss] rebuild
6-
of the monodroid/Xamarin.Android core, intended to fix some of the shortcomings
7-
and design mistakes I've made over the years.
5+
**Java.Interop** is a binding of the [Java Native Interface][jni] for use from
6+
managed languages such as C#, and an associated set of code generators to
7+
allow Java code to invoke managed code. It is *also* a brain-delusional
8+
[Second System Syndrome][sss] rebuild of the monodroid/Xamarin.Android core,
9+
intended to fix some of the shortcomings and design mistakes I've made over the years.
810

11+
[jni]: http://docs.oracle.com/javase/8/docs/technotes/guides/jni/spec/jniTOC.html
912
[sss]: http://en.wikipedia.org/wiki/Second-system_effect
1013

1114
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.
2730

2831
The `JNIEnv` API is also huge, unwieldy, and terrible.
2932

30-
## Requirements
33+
## Build Requirements
3134

3235
The current Oracle JDK7 installer only provides 64-bit binaries, while
3336
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:
6366
$ make osx-setup JDK=JavaDeveloper.pkg
6467

6568

69+
## Build Configuration
70+
71+
The Java.Interop build can be configured by overriding **make**(1) variables
72+
on the command line or by specifying MSBuild properties to control behavior.
73+
74+
### **make**(1) variables
75+
76+
The following **make**(1) variables may be specified:
77+
78+
* `$(CONFIGURATION)`: The product configuration to build, and corresponds
79+
to the `$(Configuration)` MSBuild property when running `$(XBUILD)`.
80+
Valid values are `Debug` and `Release`. Default value is `Debug`.
81+
* `$(RUNTIME)`: The managed runtime to use to execute utilities, tests.
82+
Default value is `mono64` if present in `$PATH`, otherwise `mono`.
83+
* `$(TESTS)`: Which unit tests to execute. Useful in conjunction with the
84+
`make run-tests` target:
85+
86+
make run-tests TESTS=bin/Debug/Java.Interop.Dynamic-Tests.dll
87+
88+
* `$(V)`: If set to a non-empty string, adds `/v:diag` to `$(XBUILD)`
89+
invocations.
90+
* `$(XBUILD)`: The MSBuild build tool to execute for builds.
91+
Default value is `xbuild`.
92+
93+
94+
### MSBuild Properties
95+
96+
MSbuild properties may be placed into the file `Configuration.Override.props`,
97+
which can be copied from
98+
[`Configuration.Override.props.in`](Configuration.Override.props.in).
99+
The `Configuration.Override.props` file is `<Import/>`ed by
100+
[`Configuration.props`](Configuration.props); there is no need to `<Import/>`
101+
it within other project files.
102+
103+
Overridable MSBuild properties include:
104+
105+
* `$(JdkJvmPath)`: Full path name to the JVM native library to link
106+
[`java-interop`](src/java-interop) against. By default this is
107+
probed for from numerious locations within
108+
[`build-tools/scripts/jdk.mk`](build-tools/scripts/jdk.mk).
109+
* `$(UtilityOutputFullPath)`: Directory to place various utilities such as
110+
[`class-parse`](tools/class-parse), [`generator`](tools/generator),
111+
and [`logcat-parse`](tools/logcat-parse). This value should be a full path.
112+
By default this is `$(MSBuildThisFileDirectory)bin/$(Configuration)`.
113+
114+
66115
## Type Safety
67116

68117
The start of the reboot was to use strongly typed [`SafeHandle`][SafeHandle]

build-tools/scripts/jdk.mk

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,11 @@ bin/Build$(CONFIGURATION)/JdkInfo.props: $(JI_JDK_INCLUDE_PATHS) $(JI_JVM_PATH)
116116
-rm "$@"
117117
echo '<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">' > "$@"
118118
echo ' <PropertyGroup>' >> "$@"
119-
echo " <JdkJvmPath>$(JI_JVM_PATH)</JdkJvmPath>" >> "$@"
119+
echo " <JdkJvmPath Condition=\" '\$$(JdkJvmPath)' == '' \">$(JI_JVM_PATH)</JdkJvmPath>" >> "$@"
120120
echo ' </PropertyGroup>' >> "$@"
121121
echo ' <ItemGroup>' >> "$@"
122122
for p in $(JI_JDK_INCLUDE_PATHS); do \
123-
echo " <JdkIncludePath Include=\"$$p\" />" >> "$@"; \
123+
echo " <JdkIncludePath Condition=\" '\$$(JdkJvmPath)' == '' \" Include=\"$$p\" />" >> "$@"; \
124124
done
125125
echo ' </ItemGroup>' >> "$@"
126126
echo '</Project>' >> "$@"

build-tools/scripts/mono.mk

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ bin/Build$(CONFIGURATION)/MonoInfo.props: $(JI_MONO_INCLUDE_PATHS) $(JI_MONO_FRA
2121
-rm "$@"
2222
echo '<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">' > "$@"
2323
echo ' <PropertyGroup>' >> "$@"
24-
echo " <MonoFrameworkPath>$(JI_MONO_FRAMEWORK_PATH)</MonoFrameworkPath>" >> "$@"
25-
echo ' <MonoLibs>$(JI_MONO_LIBS)</MonoLibs>'
24+
echo " <MonoFrameworkPath Condition=\" '\$$(MonoFrameworkPath)' == '' \">$(JI_MONO_FRAMEWORK_PATH)</MonoFrameworkPath>" >> "$@"
25+
echo " <MonoLibs Condition=\" '\$$(MonoLibs)' == '' \">$(JI_MONO_LIBS)</MonoLibs>" >> "$@"
2626
echo ' </PropertyGroup>' >> "$@"
2727
echo ' <ItemGroup>' >> "$@"
2828
for p in $(JI_MONO_INCLUDE_PATHS); do \
29-
echo " <MonoIncludePath Include=\"$$p\" />" >> "$@"; \
29+
echo " <MonoIncludePath Condition=\" '\$$(MonoFrameworkPath)' == '' \" Include=\"$$p\" />" >> "$@"; \
3030
done
3131
echo ' </ItemGroup>' >> "$@"
3232
echo '</Project>' >> "$@"

tools/class-parse/class-parse.csproj

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,12 @@
1212
<ProductVersion>8.0.30703</ProductVersion>
1313
<SchemaVersion>2.0</SchemaVersion>
1414
</PropertyGroup>
15+
<Import Project="..\..\Configuration.props" />
1516
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
1617
<DebugSymbols>true</DebugSymbols>
1718
<DebugType>full</DebugType>
1819
<Optimize>false</Optimize>
19-
<OutputPath>..\..\bin\Debug</OutputPath>
20+
<OutputPath>$(UtilityOutputFullPath)</OutputPath>
2021
<DefineConstants>DEBUG;</DefineConstants>
2122
<ErrorReport>prompt</ErrorReport>
2223
<WarningLevel>4</WarningLevel>
@@ -26,7 +27,7 @@
2627
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
2728
<DebugType>full</DebugType>
2829
<Optimize>true</Optimize>
29-
<OutputPath>..\..\bin\Release</OutputPath>
30+
<OutputPath>$(UtilityOutputFullPath)</OutputPath>
3031
<ErrorReport>prompt</ErrorReport>
3132
<WarningLevel>4</WarningLevel>
3233
<Externalconsole>true</Externalconsole>

tools/generator/generator.csproj

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,12 @@
1717
</EnvironmentVariables>
1818
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
1919
</PropertyGroup>
20+
<Import Project="..\..\Configuration.props" />
2021
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
2122
<DebugSymbols>True</DebugSymbols>
2223
<DebugType>full</DebugType>
2324
<Optimize>False</Optimize>
24-
<OutputPath>..\..\bin\Debug</OutputPath>
25+
<OutputPath>$(UtilityOutputFullPath)</OutputPath>
2526
<DefineConstants>DEBUG;GENERATOR;USE_CECIL;JCW_ONLY_TYPE_NAMES</DefineConstants>
2627
<ErrorReport>prompt</ErrorReport>
2728
<WarningLevel>4</WarningLevel>
@@ -30,7 +31,7 @@
3031
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
3132
<DebugType>none</DebugType>
3233
<Optimize>False</Optimize>
33-
<OutputPath>..\..\bin\Release</OutputPath>
34+
<OutputPath>$(UtilityOutputFullPath)</OutputPath>
3435
<ErrorReport>prompt</ErrorReport>
3536
<WarningLevel>4</WarningLevel>
3637
<Externalconsole>True</Externalconsole>

tools/logcat-parse/logcat-parse.csproj

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,12 @@
1212
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
1313
<StartupObject>Xamarin.Android.Tools.LogcatParse.Program</StartupObject>
1414
</PropertyGroup>
15+
<Import Project="..\..\Configuration.props" />
1516
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
1617
<DebugSymbols>true</DebugSymbols>
1718
<DebugType>full</DebugType>
1819
<Optimize>false</Optimize>
19-
<OutputPath>..\..\bin\Debug</OutputPath>
20+
<OutputPath>$(UtilityOutputFullPath)</OutputPath>
2021
<DefineConstants>DEBUG;TRACE</DefineConstants>
2122
<ErrorReport>prompt</ErrorReport>
2223
<WarningLevel>4</WarningLevel>
@@ -26,7 +27,7 @@
2627
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
2728
<DebugType>full</DebugType>
2829
<Optimize>true</Optimize>
29-
<OutputPath>..\..\bin\Release</OutputPath>
30+
<OutputPath>$(UtilityOutputFullPath)</OutputPath>
3031
<DefineConstants>TRACE</DefineConstants>
3132
<ErrorReport>prompt</ErrorReport>
3233
<WarningLevel>4</WarningLevel>

0 commit comments

Comments
 (0)