Skip to content

Commit 49663cf

Browse files
committed
[Java.Interop] $(Version) depends on TargetFramework
Context: 2d5431f Context: 88d6093 Context: #936 Context: https://github.com/jonpryor/java.interop/commits/jonp-registration-scope Versioning is hard. Way back in 3e6a623 we tried to use the `GitInfo` NuGet package so that *all* assemblies would have a version number which contained the number of commits since `GitInfo.txt` changed. This turned out to have unanticipated breakage, and was largely reverted in 2d5431f for "core" libs like `Java.Interop.dll`. This still presents a problem, though: the *point* to assembly versioning is to prevent accidental breaking of referencing assemblies. If we add a new member to `Java.Interop.dll` but *fail to update the version*, then that *permits* a scenario in which an app/lib depends on the new member, but is built against a version missing that member. This result in runtime exceptions. The whole reason this hasn't been a problem so far is because `Java.Interop.dll` has barely changed in *years*. (Plus, most usage is hidden behind other layers and libs…) However, *I want this to change*: #936 and jonpryor/java.interop/jonp-registration-scope both *add* new public API to `Java.Interop.dll`, and there are other features and optimizations we're considering that would also require API changes. A policy of "no changes" isn't tenable. Thus, the first priority: allow `Java.Interop.dll` built for .NET 6 to have a different `$(Version)` than the one built for .NET Standard 2.0. Fixing this was unexpectedly problematic, as commit 88d6093: > Update[d] `Java.Interop.BootstrapTasks.csproj` to *no longer* `<Import/>` > `VersionInfo.targets`, as this causes a circular dependency > (`VersionInfo.targets` uses tasks from > `Java.Interop.BootstrapTasks.dll`). This is fine, as > `Java.Interop.BootstrapTasks.dll` doesn't need to be versioned. `Java.Interop.BootstrapTasks.dll` doesn't need to be versioned, but *other libraries **do***, and this change change meant that `VersionInfo.targets` was *never* used, which in turn meant that e.g. `bin/BuildDebug/Version.props` was never created. Re-introduce `VersionInfo.targets` by "moving" it into `build-tools/VersionInfo/VersionInfo.csproj`, and adding `VersionInfo.csproj` to `Java.Interop.BootstrapTasks.sln`. This allows the `Prepare` target to create `bin/Build$(Configuration)/Version.props`. Next, update `Java.Interop.csproj` so that `$(Version)` is *conditional* on `$(TargetFramework)`. This allows it to continue using version 0.1.0.0 for .NET Standard 2.0, and begin using 6.0.0.* for .NET 6+ builds. Finally -- and most of the "noise" in this commit -- "cleanup and unify" the disparate build systems. `make prepare all` is one world, while `dotnet` is a different and overlapping world. Clean this up: the `dotnet`-based MSBuild environment is now our Source Of Truth, and the `make` targets are updated to rely on the `Prepare` target instead of duplicating most of the logic. While cleaning up `Makefile`, remove other cruft such as the explicit `gcc` calls to build the `NativeTiming` lib (we have a `.csproj` as of 5c756b1; use it!), and rationalize `Java.Runtime.Environment.dll.config` generation.
1 parent 32635fd commit 49663cf

File tree

15 files changed

+105
-162
lines changed

15 files changed

+105
-162
lines changed

GitInfo.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.1
1+
6.0

Makefile

Lines changed: 9 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,6 @@ NATIVE_EXT = .so
1212
DLLMAP_OS_NAME = linux
1313
endif
1414

15-
PREPARE_EXTERNAL_FILES = \
16-
external/xamarin-android-tools/src/Xamarin.Android.Tools.AndroidSdk/Xamarin.Android.Tools.AndroidSdk.csproj
17-
18-
DEPENDENCIES = \
19-
bin/Test$(CONFIGURATION)/libNativeTiming$(NATIVE_EXT)
20-
2115
TESTS = \
2216
bin/Test$(CONFIGURATION)/Java.Interop-Tests.dll \
2317
bin/Test$(CONFIGURATION)/Java.Interop.Dynamic-Tests.dll \
@@ -38,9 +32,10 @@ PTESTS = \
3832
ATESTS = \
3933
bin/Test$(CONFIGURATION)/Android.Interop-Tests.dll
4034

41-
BUILD_PROPS = bin/Build$(CONFIGURATION)/JdkInfo.props bin/Build$(CONFIGURATION)/MonoInfo.props
35+
BUILD_PROPS = bin/Build$(CONFIGURATION)/MonoInfo.props
4236

43-
all: $(DEPENDENCIES) $(TESTS)
37+
all:
38+
msbuild Java.Interop.sln /p:Configuration=$(CONFIGURATION)
4439

4540
run-all-tests:
4641
r=0; \
@@ -52,50 +47,19 @@ run-all-tests:
5247

5348
include build-tools/scripts/msbuild.mk
5449

55-
prepare:: $(BUILD_PROPS) src/Java.Runtime.Environment/Java.Runtime.Environment.dll.config
56-
57-
prepare:: prepare-bootstrap
58-
$(MSBUILD) $(MSBUILD_FLAGS) /t:Restore Java.Interop.sln
59-
60-
prepare-bootstrap: prepare-external bin/Build$(CONFIGURATION)/Java.Interop.BootstrapTasks.dll
61-
62-
bin/Build$(CONFIGURATION)/Java.Interop.BootstrapTasks.dll: build-tools/Java.Interop.BootstrapTasks/Java.Interop.BootstrapTasks.csproj \
63-
external/xamarin-android-tools/src/Xamarin.Android.Tools.AndroidSdk/Xamarin.Android.Tools.AndroidSdk.csproj \
64-
$(wildcard build-tools/Java.Interop.BootstrapTasks/Java.Interop.BootstrapTasks/*.cs)
65-
$(MSBUILD) $(MSBUILD_FLAGS) /restore "$<"
66-
67-
prepare-external $(PREPARE_EXTERNAL_FILES):
68-
git submodule update --init --recursive
69-
(cd external/xamarin-android-tools && $(MAKE) prepare)
70-
nuget restore
50+
prepare:: $(BUILD_PROPS)
51+
dotnet build Java.Interop.sln -c $(CONFIGURATION) -target:Prepare -p:MaxJdkVersion=$(JI_MAX_JDK)
7152

72-
prepare-core: bin/Build$(CONFIGURATION)/MonoInfo.props src/Java.Runtime.Environment/Java.Runtime.Environment.dll.config
53+
prepare-core: bin/Build$(CONFIGURATION)/MonoInfo.props
7354

7455
clean:
7556
-$(MSBUILD) $(MSBUILD_FLAGS) /t:Clean
7657
-rm -Rf bin/$(CONFIGURATION) bin/Build$(CONFIGURATION) bin/Test$(CONFIGURATION)
77-
-rm src/Java.Runtime.Environment/Java.Runtime.Environment.dll.config
7858

7959
include build-tools/scripts/mono.mk
80-
include build-tools/scripts/jdk.mk
81-
82-
JAVA_RUNTIME_ENVIRONMENT_DLLMAP_OVERRIDE = Java.Runtime.Environment.Override.dllmap
83-
ifeq ($(wildcard $(JAVA_RUNTIME_ENVIRONMENT_DLLMAP_OVERRIDE)),)
84-
JAVA_RUNTIME_ENVIRONMENT_DLLMAP_OVERRIDE_CMD = '/@JAVA_RUNTIME_ENVIRONMENT_DLLMAP@/d'
85-
else
86-
JAVA_RUNTIME_ENVIRONMENT_DLLMAP_OVERRIDE_CMD = '/@JAVA_RUNTIME_ENVIRONMENT_DLLMAP@/ {' -e 'r $(JAVA_RUNTIME_ENVIRONMENT_DLLMAP_OVERRIDE)' -e 'd' -e '}'
87-
endif
88-
89-
src/Java.Runtime.Environment/Java.Runtime.Environment.dll.config: src/Java.Runtime.Environment/Java.Runtime.Environment.dll.config.in \
90-
bin/Build$(CONFIGURATION)/JdkInfo.props
91-
sed -e 's#@JI_JVM_PATH@#$(JI_JVM_PATH)#g' -e 's#@OS_NAME@#$(DLLMAP_OS_NAME)#g' -e $(JAVA_RUNTIME_ENVIRONMENT_DLLMAP_OVERRIDE_CMD) < $< > $@
60+
-include bin/Build$(CONFIGURATION)/JdkInfo.mk
9261

9362
JAVA_INTEROP_LIB = libjava-interop$(NATIVE_EXT)
94-
NATIVE_TIMING_LIB = libNativeTiming$(NATIVE_EXT)
95-
96-
bin/Test$(CONFIGURATION)/$(NATIVE_TIMING_LIB): tests/NativeTiming/timing.c $(wildcard $(JI_JDK_INCLUDE_PATHS)/jni.h)
97-
mkdir -p `dirname "$@"`
98-
gcc -g -shared -m64 -fPIC -o $@ $< $(JI_JDK_INCLUDE_PATHS:%=-I%)
9963

10064
# Usage: $(call TestAssemblyTemplate,assembly-basename)
10165
define TestAssemblyTemplate
@@ -109,7 +73,7 @@ $(eval $(call TestAssemblyTemplate,Java.Interop.Dynamic))
10973
$(eval $(call TestAssemblyTemplate,Java.Interop.Export))
11074
$(eval $(call TestAssemblyTemplate,Java.Interop.Tools.JavaCallableWrappers))
11175

112-
bin/Test$(CONFIGURATION)/Java.Interop-PerformanceTests.dll: $(wildcard tests/Java.Interop-PerformanceTests/*.cs) bin/Test$(CONFIGURATION)/$(NATIVE_TIMING_LIB)
76+
bin/Test$(CONFIGURATION)/Java.Interop-PerformanceTests.dll: $(wildcard tests/Java.Interop-PerformanceTests/*.cs)
11377
$(MSBUILD) $(MSBUILD_FLAGS)
11478
touch $@
11579

@@ -153,17 +117,12 @@ run-java-source-utils-tests:
153117
bin/Test$(CONFIGURATION)/$(JAVA_INTEROP_LIB): bin/$(CONFIGURATION)/$(JAVA_INTEROP_LIB)
154118
cp $< $@
155119

156-
JRE_DLL_CONFIG=bin/$(CONFIGURATION)/Java.Runtime.Environment.dll.config
157-
158-
$(JRE_DLL_CONFIG): src/Java.Runtime.Environment/Java.Runtime.Environment.csproj
159-
$(MSBUILD) $(MSBUILD_FLAGS) $<
160-
161120
define run-jnimarshalmethod-gen
162121
MONO_TRACE_LISTENER=Console.Out \
163122
$(RUNTIME) bin/$(CONFIGURATION)/jnimarshalmethod-gen.exe -v --jvm "$(JI_JVM_PATH)" -L "$(JI_MONO_LIB_PATH)mono/4.5" -L "$(JI_MONO_LIB_PATH)mono/4.5/Facades" $(2) $(1)
164123
endef
165124

166-
run-test-jnimarshal: bin/Test$(CONFIGURATION)/Java.Interop.Export-Tests.dll bin/Test$(CONFIGURATION)/$(JAVA_INTEROP_LIB) $(JRE_DLL_CONFIG)
125+
run-test-jnimarshal: bin/Test$(CONFIGURATION)/Java.Interop.Export-Tests.dll bin/Test$(CONFIGURATION)/$(JAVA_INTEROP_LIB)
167126
mkdir -p test-jni-output
168127
$(call run-jnimarshalmethod-gen,"$<",-f -o test-jni-output --keeptemp)
169128
(test -f test-jni-output/$(notdir $<) && test -f test-jni-output/Java.Interop.Export-Tests-JniMarshalMethods.dll) || { echo "jnimarshalmethod-gen did not create the expected assemblies in the test-jni-output directory"; exit 1; }
Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@ Microsoft Visual Studio Solution File, Format Version 12.00
33
# Visual Studio Version 17
44
VisualStudioVersion = 17.1.32104.313
55
MinimumVisualStudioVersion = 10.0.40219.1
6-
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Java.Interop.BootstrapTasks", "Java.Interop.BootstrapTasks.csproj", "{47C54705-71BA-455D-9F72-780487DE861C}"
6+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Java.Interop.BootstrapTasks", "Java.Interop.BootstrapTasks\Java.Interop.BootstrapTasks.csproj", "{47C54705-71BA-455D-9F72-780487DE861C}"
77
EndProject
8-
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Xamarin.Android.Tools.AndroidSdk", "..\..\external\xamarin-android-tools\src\Xamarin.Android.Tools.AndroidSdk\Xamarin.Android.Tools.AndroidSdk.csproj", "{2F8744CF-C265-440A-B976-DEC021324A3E}"
8+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Xamarin.Android.Tools.AndroidSdk", "..\external\xamarin-android-tools\src\Xamarin.Android.Tools.AndroidSdk\Xamarin.Android.Tools.AndroidSdk.csproj", "{2F8744CF-C265-440A-B976-DEC021324A3E}"
9+
EndProject
10+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VersionInfo", "VersionInfo\VersionInfo.csproj", "{D5E50EDC-6CE3-4E8D-85A6-6920DF74E44C}"
911
EndProject
1012
Global
1113
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -21,6 +23,10 @@ Global
2123
{2F8744CF-C265-440A-B976-DEC021324A3E}.Debug|Any CPU.Build.0 = Debug|Any CPU
2224
{2F8744CF-C265-440A-B976-DEC021324A3E}.Release|Any CPU.ActiveCfg = Release|Any CPU
2325
{2F8744CF-C265-440A-B976-DEC021324A3E}.Release|Any CPU.Build.0 = Release|Any CPU
26+
{D5E50EDC-6CE3-4E8D-85A6-6920DF74E44C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
27+
{D5E50EDC-6CE3-4E8D-85A6-6920DF74E44C}.Debug|Any CPU.Build.0 = Debug|Any CPU
28+
{D5E50EDC-6CE3-4E8D-85A6-6920DF74E44C}.Release|Any CPU.ActiveCfg = Release|Any CPU
29+
{D5E50EDC-6CE3-4E8D-85A6-6920DF74E44C}.Release|Any CPU.Build.0 = Release|Any CPU
2430
EndGlobalSection
2531
GlobalSection(SolutionProperties) = preSolution
2632
HideSolutionNode = FALSE
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,16 @@
77

88
namespace Java.Interop.BootstrapTasks
99
{
10-
public class GenerateVersionFile : Task
10+
public class ReplaceFileContents : Task
1111
{
12-
public ITaskItem InputFile { get; set; }
12+
public ITaskItem TemplateFile { get; set; }
1313
public ITaskItem OutputFile { get; set; }
1414

1515
public ITaskItem [] Replacements { get; set; }
16+
1617
public override bool Execute ()
1718
{
18-
string text = File.ReadAllText (InputFile.ItemSpec);
19+
string text = File.ReadAllText (TemplateFile.ItemSpec);
1920
foreach (var replacement in Replacements)
2021
{
2122
text = text.Replace (replacement.ItemSpec, replacement.GetMetadata ("Replacement"));
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<Project Sdk="Microsoft.Build.NoTargets">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>netstandard2.0</TargetFramework>
6+
<GitDefaultBranch>main</GitDefaultBranch>
7+
<GitThisAssembly>false</GitThisAssembly>
8+
</PropertyGroup>
9+
10+
<UsingTask AssemblyFile="$(MSBuildThisFileDirectory)..\..\bin\Build$(Configuration)\Java.Interop.BootstrapTasks.dll"
11+
TaskName="Java.Interop.BootstrapTasks.ReplaceFileContents" />
12+
13+
<ItemGroup>
14+
<ProjectReference Include="..\Java.Interop.BootstrapTasks\Java.Interop.BootstrapTasks.csproj" ReferenceOutputAssembly="False" />
15+
</ItemGroup>
16+
17+
<ItemGroup>
18+
<PackageReference Include="GitInfo" PrivateAssets="all" />
19+
</ItemGroup>
20+
21+
<Import Project="VersionInfo.targets" />
22+
23+
</Project>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<Project Sdk="Microsoft.Build.NoTargets">
2+
3+
<Target Name="GenerateVersionInfo"
4+
AfterTargets="Build"
5+
DependsOnTargets="GitVersion"
6+
Inputs="$(MSBuildThisFileDirectory)..\scripts\Version.props.in;$(MSBuildThisFileFullPath)"
7+
Outputs="$(MSBuildThisFileDirectory)..\..\bin\Build$(Configuration)\Version.props">
8+
<ItemGroup>
9+
<Replacements Include="@VERSION@" Replacement="$(GitSemVerMajor).$(GitSemVerMinor).0.$(GitSemVerPatch)"/>
10+
<Replacements Include="@COMMIT@" Replacement="$(GitCommit)"/>
11+
<Replacements Include="@BRANCH@" Replacement="$(GitBranch)"/>
12+
</ItemGroup>
13+
<ReplaceFileContents
14+
TemplateFile="$(MSBuildThisFileDirectory)..\scripts\Version.props.in;"
15+
OutputFile="$(MSBuildThisFileDirectory)..\..\bin\Build$(Configuration)\Version.props"
16+
Replacements="@(Replacements)"
17+
/>
18+
</Target>
19+
20+
</Project>

build-tools/scripts/Prepare.targets

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,21 @@
66
<UsingTask AssemblyFile="$(_TopDir)\bin\Build$(Configuration)\Java.Interop.BootstrapTasks.dll" TaskName="Java.Interop.BootstrapTasks.JdkInfo" />
77
<Target Name="Prepare">
88
<Exec Command="git submodule update --init --recursive" WorkingDirectory="$(_TopDir)" />
9-
<MSBuild Projects="$(MSBuildThisFileDirectory)..\..\build-tools\Java.Interop.BootstrapTasks\Java.Interop.BootstrapTasks.sln"
9+
<MSBuild Projects="$(MSBuildThisFileDirectory)..\..\build-tools\Java.Interop.BootstrapTasks.sln"
1010
Targets="Restore"
1111
/>
12-
<MSBuild Projects="$(MSBuildThisFileDirectory)..\..\build-tools\Java.Interop.BootstrapTasks\Java.Interop.BootstrapTasks.sln"
12+
<MSBuild Projects="$(MSBuildThisFileDirectory)..\..\build-tools\Java.Interop.BootstrapTasks.sln"
1313
Targets="Build"
1414
/>
1515
<PropertyGroup>
1616
<_MaxJdk>$(MaxJdkVersion)</_MaxJdk>
1717
<_MaxJdk Condition=" '$(_MaxJdk)' == '' ">$(JI_MAX_JDK)</_MaxJdk>
1818
<Jdks8Root Condition=" '$(Jdks8Root)' == '' And '$(JAVA_HOME_8_X64)' != '' And Exists($(JAVA_HOME_8_X64)) ">$(JAVA_HOME_8_X64)</Jdks8Root>
19+
<Jdks8Root Condition=" '$(Jdks8Root)' == '' And Exists('/Library/Java/JavaVirtualMachines') ">/Library/Java/JavaVirtualMachines</Jdks8Root>
20+
<Jdks8Root Condition=" '$(Jdks8Root)' == '' And Exists('/usr/lib/jvm') ">/usr/lib/jvm</Jdks8Root>
21+
<Jdks11Root Condition=" '$(Jdks11Root)' == '' And '$(JAVA_HOME_11_X64)' != '' And Exists($(JAVA_HOME_11_X64)) ">$(JAVA_HOME_11_X64)</Jdks11Root>
22+
<Jdks11Root Condition=" '$(Jdks11Root)' == '' And Exists('/Library/Java/JavaVirtualMachines') ">/Library/Java/JavaVirtualMachines</Jdks11Root>
23+
<Jdks11Root Condition=" '$(Jdks11Root)' == '' And Exists('/usr/lib/jvm') ">/usr/lib/jvm</Jdks11Root>
1924
</PropertyGroup>
2025
<JdkInfo
2126
JdksRoot="$(Jdks8Root)"

build-tools/scripts/VersionInfo.targets

Lines changed: 0 additions & 29 deletions
This file was deleted.

build-tools/scripts/jdk.mk

Lines changed: 0 additions & 49 deletions
This file was deleted.

build-tools/scripts/jdk.targets

Lines changed: 0 additions & 22 deletions
This file was deleted.

0 commit comments

Comments
 (0)