Skip to content

Commit 7d9d72a

Browse files
jonathanpeppersjonpryor
authored andcommitted
[jdk] Don't require javac/jar in $PATH (#180)
Windows machines do not include Java in their path by default, so it is a better experience to not require it for the build. Changes: - `JdkInfo.props` will export `$(JavaCPath)` and `$(JarPath)` - We can customize `$(JavaCPath)` and `$(JarPath)` as needed on Windows - `jdk.mk` generates these values as `javac` and `jar` for existing platforms What will need to happen downstream in Xamarin.Android: - `Configuration.OperatingSystem.props` and `JdkInfo.props` will set `$(JavaCPath)` and `$(JarPath)` for Windows - Changes to `PrepareWindows.targets` will be needed - Cleaned up `JNIEnvGenPath` and places that hardcoded `Configuration`
1 parent 16be390 commit 7d9d72a

File tree

8 files changed

+26
-13
lines changed

8 files changed

+26
-13
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,9 @@ Overridable MSBuild properties include:
106106
[`java-interop`](src/java-interop) against. By default this is
107107
probed for from numerious locations within
108108
[`build-tools/scripts/jdk.mk`](build-tools/scripts/jdk.mk).
109+
* `$(JavaCPath)`: Path to the `javac` command-line tool, by default set to `javac`.
110+
* `$(JarPath)`: Path to the `jar` command-line tool, by default set to `jar`.
111+
* It may be desirable to override these on Windows, depending on your `PATH`.
109112
* `$(UtilityOutputFullPath)`: Directory to place various utilities such as
110113
[`class-parse`](tools/class-parse), [`generator`](tools/generator),
111114
and [`logcat-parse`](tools/logcat-parse). This value should be a full path.

build-tools/scripts/jdk.mk

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,4 +147,8 @@ bin/Build$(CONFIGURATION)/JdkInfo.props: $(JI_JDK_INCLUDE_PATHS) $(JI_JVM_PATH)
147147
echo ' </ItemGroup>' >> "$@"
148148
echo ' </When>' >> "$@"
149149
echo ' </Choose>' >> "$@"
150+
echo ' <PropertyGroup>' >> "$@"
151+
echo " <JavaCPath Condition=\" '\$$(JavaCPath)' == '' \">javac</JavaCPath>" >> "$@"
152+
echo " <JarPath Condition=\" '\$$(JarPath)' == '' \">jar</JarPath>" >> "$@"
153+
echo ' </PropertyGroup>' >> "$@"
150154
echo '</Project>' >> "$@"

src/Java.Interop.Export/Tests/Export-Tests.projitems

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
<PropertyGroup Label="Configuration">
99
<Import_RootNamespace>Java.Interop.ExportTests</Import_RootNamespace>
1010
</PropertyGroup>
11+
<Import Project="$(MSBuildThisFileDirectory)..\..\..\bin\Build$(Configuration)\JdkInfo.props" />
1112
<ItemGroup>
1213
<Compile Include="$(MSBuildThisFileDirectory)Java.Interop\ExportTest.cs" />
1314
<Compile Include="$(MSBuildThisFileDirectory)Java.Interop\MarshalMemberBuilderTest.cs" />
@@ -17,7 +18,7 @@
1718
</ItemGroup>
1819
<Target Name="BuildExportTestJar" Inputs="@(JavaExportTestJar)" Outputs="$(OutputPath)export-test.jar">
1920
<MakeDir Directories="$(IntermediateOutputPath)et-classes" />
20-
<Exec Command="javac -classpath &quot;$(OutputPath)..\$(Configuration)\java-interop.jar&quot; -source 1.5 -target 1.6 -d &quot;$(IntermediateOutputPath)et-classes&quot; @(JavaExportTestJar -&gt; '%(Identity)', ' ')" />
21-
<Exec Command="jar cf &quot;$(OutputPath)export-test.jar&quot; -C &quot;$(IntermediateOutputPath)et-classes&quot; ." />
21+
<Exec Command="&quot;$(JavaCPath)&quot; -classpath &quot;$(OutputPath)..\$(Configuration)\java-interop.jar&quot; -source 1.5 -target 1.6 -d &quot;$(IntermediateOutputPath)et-classes&quot; @(JavaExportTestJar -&gt; '%(Identity)', ' ')" />
22+
<Exec Command="&quot;$(JarPath)&quot; cf &quot;$(OutputPath)export-test.jar&quot; -C &quot;$(IntermediateOutputPath)et-classes&quot; ." />
2223
</Target>
2324
</Project>

src/Java.Interop/Java.Interop.csproj

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
<ConsolePause>false</ConsolePause>
2828
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
2929
<DocumentationFile>..\..\bin\Debug\Java.Interop.xml</DocumentationFile>
30+
<JNIEnvGenPath>..\..\bin\BuildDebug</JNIEnvGenPath>
3031
</PropertyGroup>
3132
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
3233
<DebugType>full</DebugType>
@@ -38,6 +39,7 @@
3839
<DefineConstants>INTEROP;FEATURE_JNIENVIRONMENT_JI_PINVOKES;FEATURE_JNIOBJECTREFERENCE_INTPTRS</DefineConstants>
3940
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
4041
<DocumentationFile>..\..\bin\Release\Java.Interop.xml</DocumentationFile>
42+
<JNIEnvGenPath>..\..\bin\BuildRelease</JNIEnvGenPath>
4143
</PropertyGroup>
4244
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'XAIntegrationDebug|AnyCPU' ">
4345
<DebugSymbols>true</DebugSymbols>
@@ -59,7 +61,7 @@
5961
<WarningLevel>4</WarningLevel>
6062
<ConsolePause>false</ConsolePause>
6163
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
62-
<JNIEnvGenPath>..\..\bin\BuildDebug</JNIEnvGenPath>
64+
<JNIEnvGenPath>..\..\bin\BuildRelease</JNIEnvGenPath>
6365
</PropertyGroup>
6466
<ItemGroup>
6567
<Compile Include="Properties\AssemblyInfo.cs" />

src/Java.Interop/Java.Interop.targets

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,28 @@
33
<PropertyGroup>
44
<Runtime Condition="'$(OS)' != 'Windows_NT'">mono</Runtime>
55
</PropertyGroup>
6+
<Import Project="$(JNIEnvGenPath)\JdkInfo.props" />
67
<Target Name="BuildJnienvGen"
78
Inputs="..\..\build-tools\jnienv-gen\jnienv-gen.csproj"
8-
Outputs="..\..\bin\BuildDebug\jnienv-gen.exe">
9+
Outputs="$(JNIEnvGenPath)\jnienv-gen.exe">
910
<MSBuild
1011
Projects="..\..\build-tools\jnienv-gen\jnienv-gen.csproj"
11-
Properties="Configuration=Debug"
12+
Properties="Configuration=$(Configuration.Replace('XAIntegration', ''))"
1213
/>
1314
</Target>
1415
<Target Name="BuildJniEnvironment_g_cs"
1516
Inputs="$(JNIEnvGenPath)\jnienv-gen.exe"
1617
Outputs="Java.Interop\JniEnvironment.g.cs;$(IntermediateOutputPath)\jni.c">
1718
<MakeDir Directories="$(IntermediateOutputPath)" />
1819
<Exec
19-
Command="$(Runtime) &quot;..\..\bin\BuildDebug\jnienv-gen.exe&quot; Java.Interop\JniEnvironment.g.cs $(IntermediateOutputPath)\jni.c"
20+
Command="$(Runtime) &quot;$(JNIEnvGenPath)\jnienv-gen.exe&quot; Java.Interop\JniEnvironment.g.cs $(IntermediateOutputPath)\jni.c"
2021
/>
2122
</Target>
2223
<Target Name="BuildInteropJar"
2324
Inputs="@(CompileJavaInteropJar)"
2425
Outputs="$(OutputPath)java-interop.jar">
2526
<MakeDir Directories="$(OutputPath);$(IntermediateOutputPath)ji-classes" />
26-
<Exec Command="javac -source 1.5 -target 1.6 -d &quot;$(IntermediateOutputPath)ji-classes&quot; @(CompileJavaInteropJar -&gt; '%(Identity)', ' ')" />
27-
<Exec Command="jar cf &quot;$(OutputPath)java-interop.jar&quot; -C &quot;$(IntermediateOutputPath)ji-classes&quot; ." />
27+
<Exec Command="&quot;$(JavaCPath)&quot; -source 1.5 -target 1.6 -d &quot;$(IntermediateOutputPath)ji-classes&quot; @(CompileJavaInteropJar -&gt; '%(Identity)', ' ')" />
28+
<Exec Command="&quot;$(JarPath)&quot; cf &quot;$(OutputPath)java-interop.jar&quot; -C &quot;$(IntermediateOutputPath)ji-classes&quot; ." />
2829
</Target>
2930
</Project>

src/Java.Interop/Tests/Interop-Tests.projitems

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
<PropertyGroup Label="Configuration">
99
<Import_RootNamespace>Java.InteropTests</Import_RootNamespace>
1010
</PropertyGroup>
11+
<Import Project="$(MSBuildThisFileDirectory)..\..\..\bin\Build$(Configuration)\JdkInfo.props" />
1112
<ItemGroup>
1213
<Compile Include="$(MSBuildThisFileDirectory)Cadenza.Collections\CollectionContract.cs" />
1314
<Compile Include="$(MSBuildThisFileDirectory)Cadenza.Collections\EnumerableContract.cs" />
@@ -64,7 +65,7 @@
6465
</ItemGroup>
6566
<Target Name="BuildInteropTestJar" Inputs="@(JavaInteropTestJar)" Outputs="$(OutputPath)interop-test.jar">
6667
<MakeDir Directories="$(IntermediateOutputPath)it-classes" />
67-
<Exec Command="javac -source 1.5 -target 1.6 -d &quot;$(IntermediateOutputPath)it-classes&quot; -classpath &quot;$(OutputPath)..\$(Configuration)\java-interop.jar&quot; @(JavaInteropTestJar -&gt; '%(Identity)', ' ')" />
68-
<Exec Command="jar cf &quot;$(OutputPath)interop-test.jar&quot; -C &quot;$(IntermediateOutputPath)it-classes&quot; ." />
68+
<Exec Command="&quot;$(JavaCPath)&quot; -source 1.5 -target 1.6 -d &quot;$(IntermediateOutputPath)it-classes&quot; -classpath &quot;$(OutputPath)..\$(Configuration)\java-interop.jar&quot; @(JavaInteropTestJar -&gt; '%(Identity)', ' ')" />
69+
<Exec Command="&quot;$(JarPath)&quot; cf &quot;$(OutputPath)interop-test.jar&quot; -C &quot;$(IntermediateOutputPath)it-classes&quot; ." />
6970
</Target>
7071
</Project>

src/java-interop/java-interop.mdproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
<DefineSymbols>JI_DLL_EXPORT MONODEVELOP MONO_DLL_EXPORT</DefineSymbols>
2727
<SourceDirectory>.</SourceDirectory>
2828
</PropertyGroup>
29-
<Import Project="$(JNIEnvGenPath)\JdkInfo.props" Condition="Exists('$(JNIEnvGenPath)\JdkInfo.props')" />
29+
<Import Project="$(JNIEnvGenPath)\JdkInfo.props" />
3030
<Import Project="$(JNIEnvGenPath)\MonoInfo.props" Condition="Exists('$(JNIEnvGenPath)\MonoInfo.props')" />
3131
<ItemGroup>
3232
<None Include="java-interop.h" />

tests/PerformanceTests/PerformanceTests.projitems

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
<HasSharedItems>true</HasSharedItems>
66
<SharedGUID>{0FBECD2A-7C91-41AB-A4B4-B781E8EC8479}</SharedGUID>
77
</PropertyGroup>
8+
<Import Project="$(MSBuildThisFileDirectory)..\..\bin\Build$(Configuration)\JdkInfo.props" />
89
<PropertyGroup Label="Configuration">
910
<Import_RootNamespace>Java.Interop.PerformanceTests</Import_RootNamespace>
1011
</PropertyGroup>
@@ -17,7 +18,7 @@
1718
</ItemGroup>
1819
<Target Name="BuildPerformanceTestJar" Inputs="@(JavaPerformanceTestJar)" Outputs="$(OutputPath)performance-test.jar">
1920
<MakeDir Directories="$(IntermediateOutputPath)pt-classes" />
20-
<Exec Command="javac -source 1.5 -target 1.6 -d &quot;$(IntermediateOutputPath)pt-classes&quot; @(JavaPerformanceTestJar -&gt; '%(Identity)', ' ')" />
21-
<Exec Command="jar cf &quot;$(OutputPath)performance-test.jar&quot; -C &quot;$(IntermediateOutputPath)pt-classes&quot; ." />
21+
<Exec Command="&quot;$(JavaCPath)&quot; -source 1.5 -target 1.6 -d &quot;$(IntermediateOutputPath)pt-classes&quot; @(JavaPerformanceTestJar -&gt; '%(Identity)', ' ')" />
22+
<Exec Command="&quot;$(JarPath)&quot; cf &quot;$(OutputPath)performance-test.jar&quot; -C &quot;$(IntermediateOutputPath)pt-classes&quot; ." />
2223
</Target>
2324
</Project>

0 commit comments

Comments
 (0)