|
| 1 | +<Project> |
| 2 | + |
| 3 | + <PropertyGroup> |
| 4 | + <DotnetToolPath>"$(DOTNET_HOST_PATH)"</DotnetToolPath> |
| 5 | + </PropertyGroup> |
| 6 | + |
| 7 | + <Target Name="_CreateJavaCallableWrappers" |
| 8 | + Condition=" '$(TargetPath)' != '' " |
| 9 | + BeforeTargets="BuildNativeAOTFromJNIJar" |
| 10 | + Inputs="$(TargetPath)" |
| 11 | + Outputs="$(IntermediateOutputPath)java\.stamp"> |
| 12 | + <RemoveDir Directories="$(IntermediateOutputPath)java" /> |
| 13 | + <MakeDir Directories="$(IntermediateOutputPath)java" /> |
| 14 | + <ItemGroup> |
| 15 | + <!-- I can't find a good way to trim the trailing `\`, so append with `.` so we can sanely quote for $(_Libpath) --> |
| 16 | + <_JcwGenRefAsmDirs Include="@(ReferencePathWithRefAssemblies->'%(RootDir)%(Directory).'->Distinct())" /> |
| 17 | + </ItemGroup> |
| 18 | + <PropertyGroup> |
| 19 | + <_JcwGen>"$(UtilityOutputFullPath)/jcw-gen.dll"</_JcwGen> |
| 20 | + <_Target>--codegen-target JavaInterop1</_Target> |
| 21 | + <_Output>-o "$(IntermediateOutputPath)/java"</_Output> |
| 22 | + <_Libpath>@(_JcwGenRefAsmDirs->'-L "%(Identity)"', ' ')</_Libpath> |
| 23 | + </PropertyGroup> |
| 24 | + <Exec Command="$(DotnetToolPath) $(_JcwGen) "$(TargetPath)" $(_Target) $(_Output) $(_Libpath)" /> |
| 25 | + <Touch Files="$(IntermediateOutputPath)java\.stamp" AlwaysCreate="True" /> |
| 26 | + </Target> |
| 27 | + |
| 28 | + <Target Name="_AddMarshalMethods" |
| 29 | + Condition=" '$(TargetPath)' != '' " |
| 30 | + Inputs="$(TargetPath)" |
| 31 | + Outputs="$(IntermediateOutputPath).added-marshal-methods" |
| 32 | + AfterTargets="_CreateJavaCallableWrappers"> |
| 33 | + <ItemGroup> |
| 34 | + <!-- I can't find a good way to trim the trailing `\`, so append with `.` so we can sanely quote for $(_Libpath) --> |
| 35 | + <_JnimmRefAsmDirs Include="@(RuntimePackAsset->'%(RootDir)%(Directory).'->Distinct())" /> |
| 36 | + </ItemGroup> |
| 37 | + <PropertyGroup> |
| 38 | + <_JnimarshalmethodGen>"$(UtilityOutputFullPath)/jnimarshalmethod-gen.dll"</_JnimarshalmethodGen> |
| 39 | + <_Verbosity>-v -v --keeptemp</_Verbosity> |
| 40 | + <_Libpath>-L "$(TargetDir)" @(_JnimmRefAsmDirs->'-L "%(Identity)"', ' ')</_Libpath> |
| 41 | + <!-- <_Output>-o "$(IntermediateOutputPath)/jonp"</_Output> --> |
| 42 | + </PropertyGroup> |
| 43 | + |
| 44 | + <Exec Command="$(DotnetToolPath) $(_JnimarshalmethodGen) "$(TargetPath)" $(_Verbosity) $(_Libpath)" /> |
| 45 | + |
| 46 | + <!-- the IlcCompile target uses files from `$(IntermediateOutputPath)`, not `$(TargetPath)`, so… update both? --> |
| 47 | + <Copy SourceFiles="$(TargetPath)" DestinationFolder="$(IntermediateOutputPath)" /> |
| 48 | + |
| 49 | + <Touch Files="$(IntermediateOutputPath).added-marshal-methods" AlwaysCreate="True" /> |
| 50 | + </Target> |
| 51 | + |
| 52 | + <Target Name="BuildNativeAOTFromJNIJar" |
| 53 | + AfterTargets="Build" |
| 54 | + Inputs="@(HelloNativeAOTFromJNIJar)" |
| 55 | + Outputs="$(OutputPath)hello-from-java.jar"> |
| 56 | + <MakeDir Directories="$(IntermediateOutputPath)h-classes" /> |
| 57 | + <ItemGroup> |
| 58 | + <_JcwSource Include="$(IntermediateOutputPath)java\**\*.java" /> |
| 59 | + </ItemGroup> |
| 60 | + <ItemGroup> |
| 61 | + <_Source Include="@(_JcwSource->Replace('%5c', '/'))" /> |
| 62 | + <_Source Include="@(HelloNativeAOTFromJNIJar->Replace('%5c', '/'))" /> |
| 63 | + </ItemGroup> |
| 64 | + <WriteLinesToFile |
| 65 | + File="$(IntermediateOutputPath)_java_sources.txt" |
| 66 | + Lines="@(_Source)" |
| 67 | + Overwrite="True" |
| 68 | + /> |
| 69 | + <ItemGroup> |
| 70 | + <_JavacOpt Include="$(_JavacSourceOptions)" /> |
| 71 | + <_JavacOpt Include="-d "$(IntermediateOutputPath)h-classes" " /> |
| 72 | + <_JavacOpt Include="-classpath "$(OutputPath)java-interop.jar" " /> |
| 73 | + <_JavacOpt Include=""@$(IntermediateOutputPath)_java_sources.txt"" /> |
| 74 | + <_JavacOpt Include="-h "$(IntermediateOutputPath)h-classes" " /> |
| 75 | + </ItemGroup> |
| 76 | + <Exec Command=""$(JavaCPath)" @(_JavacOpt, ' ')" /> |
| 77 | + <Delete Files="$(IntermediateOutputPath)_java_sources.txt" /> |
| 78 | + <Exec Command=""$(JarPath)" cf "$(OutputPath)hello-from-java.jar" -C "$(IntermediateOutputPath)h-classes" ." /> |
| 79 | + </Target> |
| 80 | + |
| 81 | + <Target Name="_NativeLibRequiresLibPrefix" |
| 82 | + AfterTargets="Publish"> |
| 83 | + <Copy |
| 84 | + Condition=" '$(OS)' != 'Windows_NT' " |
| 85 | + SourceFiles="$(PublishDir)$(AssemblyName).dylib" |
| 86 | + DestinationFiles="$(PublishDir)lib$(AssemblyName).dylib" |
| 87 | + /> |
| 88 | + <Copy SourceFiles="$(OutputPath)hello-from-java.jar" DestinationFolder="$(PublishDir)" /> |
| 89 | + </Target> |
| 90 | + |
| 91 | + <Target Name="RunJavaSample"> |
| 92 | + <ItemGroup> |
| 93 | + <_Classpath Include="hello-from-java.jar" /> |
| 94 | + <_Classpath Include="java-interop.jar" /> |
| 95 | + </ItemGroup> |
| 96 | + <PropertyGroup> |
| 97 | + <_CPSep Condition=" '$(OS)' == 'Windows_NT' ">;</_CPSep> |
| 98 | + <_CPSep Condition=" '$(_CPSep)' == '' ">:</_CPSep> |
| 99 | + <_CP>@(_Classpath, '$(_CPSep)')</_CP> |
| 100 | + </PropertyGroup> |
| 101 | + <Exec |
| 102 | + Command=""$(JavaPath)" -classpath "$(_CP)" net/dot/jni/hello/App" |
| 103 | + WorkingDirectory="$(MSBuildThisFileDirectory)$(PublishDir)" |
| 104 | + /> |
| 105 | + </Target> |
| 106 | +</Project> |
0 commit comments