|
| 1 | +<Project> |
| 2 | + |
| 3 | + <ItemDefinitionGroup> |
| 4 | + <JavaCompile> |
| 5 | + <Bind>True</Bind> |
| 6 | + </JavaCompile> |
| 7 | + <JavaReference> |
| 8 | + <Bind>True</Bind> |
| 9 | + </JavaReference> |
| 10 | + </ItemDefinitionGroup> |
| 11 | + |
| 12 | + <PropertyGroup> |
| 13 | + <JavaOutputJar Condition=" '$(JavaOutputJar)' == '' ">$(OutputPath)$(AssemblyName).jar</JavaOutputJar> |
| 14 | + </PropertyGroup> |
| 15 | + |
| 16 | + <PropertyGroup> |
| 17 | + <JavaCreateManagedBindingsDependsOn> |
| 18 | + _BuildJavaCompileForManagedBinding; |
| 19 | + _GenerateApiDescription; |
| 20 | + _GenerateManagedBinding; |
| 21 | + _CleanupManagedBinding; |
| 22 | + </JavaCreateManagedBindingsDependsOn> |
| 23 | + <JavaCreateJavaCallableWrappersDependsOn> |
| 24 | + _JavaCreateJcws; |
| 25 | + _JavaCreateOutputJar; |
| 26 | + </JavaCreateJavaCallableWrappersDependsOn> |
| 27 | + </PropertyGroup> |
| 28 | + |
| 29 | + <Target Name="JavaCreateManagedBindings" |
| 30 | + BeforeTargets="CoreCompile" |
| 31 | + DependsOnTargets="$(JavaCreateManagedBindingsDependsOn)"> |
| 32 | + </Target> |
| 33 | + |
| 34 | + <Target Name="JavaCreateJavaCallableWrappers" |
| 35 | + AfterTargets="CoreCompile" |
| 36 | + DependsOnTargets="$(JavaCreateJavaCallableWrappersDependsOn)"> |
| 37 | + </Target> |
| 38 | + |
| 39 | + <PropertyGroup> |
| 40 | + <_GeneratorPath>$(UtilityOutputFullPath)generator.dll</_GeneratorPath> |
| 41 | + <_JavaIntermediateDir>$(IntermediateOutputPath)_ji\</_JavaIntermediateDir> |
| 42 | + <_JavaManagedBindingInput>$(_JavaIntermediateDir)o.jar</_JavaManagedBindingInput> |
| 43 | + <_JavaManagedBindingDir>$(_JavaIntermediateDir)mcw\</_JavaManagedBindingDir> |
| 44 | + <_JavaJcwClassesDir>$(_JavaIntermediateDir)classes\</_JavaJcwClassesDir> |
| 45 | + <_JavaJcwSourcesDir>$(_JavaIntermediateDir)java\</_JavaJcwSourcesDir> |
| 46 | + </PropertyGroup> |
| 47 | + |
| 48 | + <Target Name="_CollectJavaCompileForManagedBindingInputs"> |
| 49 | + <ItemGroup> |
| 50 | + <_JavaCompileForBindingInputs |
| 51 | + Condition=" '%(JavaCompile.Bind)' == 'True' " |
| 52 | + Include="@(JavaCompile)" |
| 53 | + /> |
| 54 | + </ItemGroup> |
| 55 | + </Target> |
| 56 | + |
| 57 | + <Target Name="_JavaCollectJavacRefs"> |
| 58 | + <ItemGroup> |
| 59 | + <_JavacRefs Include="$(ToolOutputFullPath)java-interop.jar" /> |
| 60 | + <_JavacRefs Include="@(JavaReference)" /> |
| 61 | + <_JavacRefsWithForwardSlash Include="@(_JavacRefs->Replace('%5c', '/'))" /> |
| 62 | + </ItemGroup> |
| 63 | + </Target> |
| 64 | + |
| 65 | + <Target Name="_BuildJavaCompileForManagedBinding" |
| 66 | + DependsOnTargets="_CollectJavaCompileForManagedBindingInputs;_JavaCollectJavacRefs" |
| 67 | + Inputs="@(_JavaCompileForBindingInputs)" |
| 68 | + Outputs="$(_JavaManagedBindingInput)"> |
| 69 | + <PropertyGroup> |
| 70 | + <_ClassesDir>$(_JavaIntermediateDir)\bound-classes</_ClassesDir> |
| 71 | + <_ResponseFile>$(_JavaIntermediateDir)r.txt</_ResponseFile> |
| 72 | + <_Classpath>@(_JavacRefsWithForwardSlash, '$(JavaPathSeparator)')</_Classpath> |
| 73 | + </PropertyGroup> |
| 74 | + <MakeDir Directories="$(_ClassesDir)" /> |
| 75 | + <ItemGroup> |
| 76 | + <_Response Include="-classpath" /> |
| 77 | + <_Response Include=""$(_Classpath)"" /> |
| 78 | + <_Response Include="@(_JavaCompileForBindingInputs->Replace('%5c', '/'))" /> |
| 79 | + </ItemGroup> |
| 80 | + <WriteLinesToFile |
| 81 | + File="$(_ResponseFile)" |
| 82 | + Lines="@(_Response)" |
| 83 | + Overwrite="True" |
| 84 | + /> |
| 85 | + <Message Text="`javac` response file contents:" Importance="Low" /> |
| 86 | + <Message Text="@(_Response, ' |
| 87 | +')" Importance="Low" /> |
| 88 | + <Exec Command=""$(JavaCPath)" $(_JavacSourceOptions) -d "$(_ClassesDir)" "@$(_ResponseFile)"" /> |
| 89 | + <Delete Files="$(_ResponseFile)" /> |
| 90 | + <Exec Command=""$(JarPath)" cf "$(_JavaManagedBindingInput)" -C "$(_ClassesDir)" ." /> |
| 91 | + </Target> |
| 92 | + |
| 93 | + <Target Name="_CollectClassParseInputs"> |
| 94 | + <ItemGroup> |
| 95 | + <_ClassParseInputs |
| 96 | + Condition=" Exists($(_JavaManagedBindingInput))" |
| 97 | + Include="$(_JavaManagedBindingInput)" |
| 98 | + /> |
| 99 | + <_ClassParseInputs |
| 100 | + Condition=" '%(JavaReference.Bind)' == 'True' " |
| 101 | + Include="@(JavaReference)" |
| 102 | + /> |
| 103 | + </ItemGroup> |
| 104 | + </Target> |
| 105 | + |
| 106 | + <Target Name="_GenerateApiDescription" |
| 107 | + DependsOnTargets="_CollectClassParseInputs" |
| 108 | + Inputs="@(_ClassParseInputs)" |
| 109 | + Outputs="$(_JavaManagedBindingDir)api.xml"> |
| 110 | + <MakeDir Directories="$(_JavaManagedBindingDir)" /> |
| 111 | + <PropertyGroup> |
| 112 | + <_ClassParse>"$(UtilityOutputFullPath)class-parse.dll"</_ClassParse> |
| 113 | + <_Inputs>@(_ClassParseInputs, ' ')</_Inputs> |
| 114 | + <_Output>"-o=$(_JavaManagedBindingDir)api.xml"</_Output> |
| 115 | + </PropertyGroup> |
| 116 | + <Exec |
| 117 | + Command="$(DotnetToolPath) $(_ClassParse) $(_Inputs) $(_Output)" |
| 118 | + /> |
| 119 | + </Target> |
| 120 | + |
| 121 | + <Target Name="_GenerateManagedBinding" |
| 122 | + DependsOnTargets="_GenerateApiDescription" |
| 123 | + Inputs="$(_JavaManagedBindingDir)api.xml" |
| 124 | + Outputs="$(_JavaManagedBindingDir)$(AssemblyName).projitems"> |
| 125 | + <MakeDir Directories="$(_JavaManagedBindingDir)" /> |
| 126 | + <PropertyGroup> |
| 127 | + <Generator>"$(_GeneratorPath)"</Generator> |
| 128 | + <_GenFlags>--public --global</_GenFlags> |
| 129 | + <_Out>-o "$(_JavaManagedBindingDir)"</_Out> |
| 130 | + <_Codegen>--codegen-target=JavaInterop1</_Codegen> |
| 131 | + <_Assembly>"--assembly=$(AssemblyName)"</_Assembly> |
| 132 | + <_TypeMap>--type-map-report=$(_JavaManagedBindingDir)type-mapping.txt</_TypeMap> |
| 133 | + <_Api>$(_JavaManagedBindingDir)api.xml</_Api> |
| 134 | + <_Dirs>--enumdir=$(_JavaManagedBindingDir)</_Dirs> |
| 135 | + <_FullIntermediateOutputPath>$([System.IO.Path]::GetFullPath('$(_JavaManagedBindingDir)'))</_FullIntermediateOutputPath> |
| 136 | + <_LangFeatures>--lang-features=nullable-reference-types,default-interface-methods,nested-interface-types,interface-constants</_LangFeatures> |
| 137 | + </PropertyGroup> |
| 138 | + <ItemGroup> |
| 139 | + <!-- I can't find a good way to trim the trailing `\`, so append with `.` so we can sanely quote for $(_Libpath) --> |
| 140 | + <_RefAsmDir Include="@(ReferencePathWithRefAssemblies->'%(RootDir)%(Directory).'->Distinct())" /> |
| 141 | + <_Lib Include="@(_RefAsmDir->'-L "%(Identity)"')" /> |
| 142 | + <_JavaBaseRef Include="@(ReferencePathWithRefAssemblies)" |
| 143 | + Condition=" '%(FileName)' == 'Java.Base' " |
| 144 | + /> |
| 145 | + <_Ref Include="@(_JavaBaseRef->'-r "%(FullPath)"')" /> |
| 146 | + </ItemGroup> |
| 147 | + <Exec |
| 148 | + Command="$(DotnetToolPath) $(Generator) $(_GenFlags) $(_ApiLevel) $(_Out) @(_Lib, ' ') @(_Ref, ' ') $(_Codegen) $(_Assembly) $(_TypeMap) $(_LangFeatures) $(_Dirs) $(_Api) $(_WithJavadocXml)" |
| 149 | + IgnoreStandardErrorWarningFormat="True" |
| 150 | + /> |
| 151 | + <ItemGroup> |
| 152 | + <Compile Include="$(_FullIntermediateOutputPath)\**\*.cs" KeepDuplicates="False" /> |
| 153 | + <FileWrites Include="$(_FullIntermediateOutputPath)\**\*.cs" /> |
| 154 | + </ItemGroup> |
| 155 | + <XmlPeek |
| 156 | + Namespaces="<Namespace Prefix='msbuild' Uri='http://schemas.microsoft.com/developer/msbuild/2003' />" |
| 157 | + XmlInputPath="$(_JavaManagedBindingDir)$(AssemblyName).projitems" |
| 158 | + Query="/msbuild:Project/msbuild:PropertyGroup/msbuild:DefineConstants/text()" > |
| 159 | + <Output TaskParameter="Result" PropertyName="_GeneratedDefineConstants" /> |
| 160 | + </XmlPeek> |
| 161 | + <PropertyGroup> |
| 162 | + <DefineConstants>$(DefineConstants);$([System.String]::Copy('$(_GeneratedDefineConstants)').Replace ('%24(DefineConstants);', ''))</DefineConstants> |
| 163 | + </PropertyGroup> |
| 164 | + </Target> |
| 165 | + |
| 166 | + <Target Name="_CleanupManagedBinding" /> |
| 167 | + |
| 168 | + <Target Name="_JavaCreateJcws" |
| 169 | + Condition=" '$(TargetPath)' != '' And Exists($(TargetPath))" |
| 170 | + Inputs="$(TargetPath)" |
| 171 | + Outputs="$(_JavaJcwSourcesDir).stamp"> |
| 172 | + <RemoveDir Directories="$(_JavaJcwSourcesDir)" /> |
| 173 | + <MakeDir Directories="$(_JavaJcwSourcesDir)" /> |
| 174 | + <ItemGroup> |
| 175 | + <!-- I can't find a good way to trim the trailing `\`, so append with `.` so we can sanely quote for $(_Libpath) --> |
| 176 | + <_RefAsmDirs Include="@(ReferencePathWithRefAssemblies->'%(RootDir)%(Directory).'->Distinct())" /> |
| 177 | + </ItemGroup> |
| 178 | + <PropertyGroup> |
| 179 | + <_JcwGen>"$(UtilityOutputFullPath)/jcw-gen.dll"</_JcwGen> |
| 180 | + <_Target>--codegen-target JavaInterop1</_Target> |
| 181 | + <_Output>-o "$(_JavaJcwSourcesDir)"</_Output> |
| 182 | + <_Libpath>@(_RefAsmDirs->'-L "%(Identity)"', ' ')</_Libpath> |
| 183 | + </PropertyGroup> |
| 184 | + <Exec Command="$(DotnetToolPath) $(_JcwGen) -v "$(TargetPath)" $(_Target) $(_Output) $(_Libpath)" /> |
| 185 | + <Touch Files="$(_JavaJcwSourcesDir).stamp" AlwaysCreate="True" /> |
| 186 | + </Target> |
| 187 | + |
| 188 | + <Target Name="_JavaCollectGeneratdJcwSource"> |
| 189 | + <ItemGroup> |
| 190 | + <_JavaGeneratedJcwSource Include="$(_JavaJcwSourcesDir)**\*.java" /> |
| 191 | + </ItemGroup> |
| 192 | + </Target> |
| 193 | + |
| 194 | + <Target Name="_JavaCreateOutputJar" |
| 195 | + DependsOnTargets="_JavaCollectGeneratdJcwSource;_JavaCollectJavacRefs" |
| 196 | + Inputs="@(_JavaGeneratedJcwSource)" |
| 197 | + Outputs="$(JavaOutputJar)"> |
| 198 | + <RemoveDir Directories="$(_JavaJcwClassesDir)" /> |
| 199 | + <MakeDir Directories="$(_JavaJcwClassesDir)" /> |
| 200 | + <PropertyGroup> |
| 201 | + <_ResponseFile>$(_JavaIntermediateDir)r.txt</_ResponseFile> |
| 202 | + <_Classpath>@(_JavacRefsWithForwardSlash, '$(JavaPathSeparator)')</_Classpath> |
| 203 | + </PropertyGroup> |
| 204 | + <ItemGroup> |
| 205 | + <_Source Include="@(JavaCompile->Replace('%5c', '/'))" /> |
| 206 | + <_Source Include="@(_JavaGeneratedJcwSource->Replace('%5c', '/'))" /> |
| 207 | + </ItemGroup> |
| 208 | + <WriteLinesToFile |
| 209 | + File="$(_JavaIntermediateDir)_java_sources.txt" |
| 210 | + Lines="@(_Source)" |
| 211 | + Overwrite="True" |
| 212 | + /> |
| 213 | + <Exec Command=""$(JavaCPath)" $(_JavacSourceOptions) -d "$(_JavaJcwClassesDir)" -classpath "$(_Classpath)" "@$(_JavaIntermediateDir)_java_sources.txt"" /> |
| 214 | + <Delete Files="$(_JavaIntermediateDir)_java_sources.txt" /> |
| 215 | + <Exec Command=""$(JarPath)" cf "$(JavaOutputJar)" -C "$(_JavaJcwClassesDir)" ." /> |
| 216 | + </Target> |
| 217 | + |
| 218 | +</Project> |
0 commit comments