Skip to content

Commit

Permalink
[build] Use GitInfo to generate $(Version) (#865)
Browse files Browse the repository at this point in the history
[build] Use GitInfo to generate $(Version) (#865)

Context: http://github.com/xamarin/xamarin-android/commit/2d81740cc1c708cd0474c9eac8936cd7abfc72e3
Context: dotnet/android#5749

In order to better support building solutions which reference both
.NET 6 and legacy projects within Visual Studio, we have begun
strong-naming all the MSBuild-related assemblies; see also ff27142.
This allows loading two different version of the "same" assembly, e.g.
`Java.Interop.Tools.Diagnostics.dll`, from two different filesystem
locations in the same AppDomain/AssemblyLoadContext.

However, strong-naming is only part of the solution.  The other part
is that, for sanity and reliability, the "two different versions of
the 'same' assembly" should *also* have different assembly *versions*.
If they have the same assembly version, are they truly different?

Update the build system by adding a `Directory.Build.targets` and
`GitInfo.txt` file so that the the [`GitInfo`][0] [NuGet Package][1]
will be used to "fully" set the `$(Version)` MSBuild property,
consisting of the major and minor version numbers contained within
`GitInfo.txt`, along with a "computed" `$(GitSemVerPatch)` value
based on the "patch version" in `GitInfo.txt`, if present, added to
the number of commits which have occurred since `GitInfo.txt` changed.

Additionally, set the `$(InformationalVersion)` MSBuild property so
that it mirrors the behavior in [`Mono.Android.dll`][2]:

	[assembly: System.Reflection.AssemblyInformationalVersionAttribute("0.1.1; git-rev-head:2eb9ff2; git-branch:main")

Setting the `$(Version)` and `$(InformationalVersion)` MSBuild
properties also requires setting `$(GenerateAssemblyInfo)`=True.
Update `src/Java.Interop/Properties/AssemblyInfo.cs` to remove the
attributes that `$(GenerateAssemblyInfo)` will generate.

Other:

  * Centralize the `$(Company)` and `$(Copyright)` values.
  * Various whitespace changes due to `.editorconfig`.

[0]: https://github.com/devlooped/GitInfo
[1]: https://www.nuget.org/packages/GitInfo/2.1.2
[2]: dotnet/android@b620689
  • Loading branch information
dellis1972 authored Aug 19, 2021
1 parent 2eb9ff2 commit d16b1e5
Show file tree
Hide file tree
Showing 11 changed files with 34 additions and 32 deletions.
22 changes: 20 additions & 2 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<_OutputPath>$(MSBuildThisFileDirectory)bin\Build$(Configuration)\</_OutputPath>
<GenerateAssemblyInfo>true</GenerateAssemblyInfo>
</PropertyGroup>

<PropertyGroup>
<XlfLanguages>cs;de;es;fr;it;ja;ko;pl;pt-BR;ru;tr;zh-Hans;zh-Hant</XlfLanguages>
<UpdateXlfOnBuild Condition="'$(RunningOnCI)' != 'true'">true</UpdateXlfOnBuild>
Expand Down Expand Up @@ -75,7 +76,7 @@
<_RunJNIEnvGen Condition=" '$(JIBuildingForNetCoreApp)' == 'True' ">$(DotnetToolPath) "$(_JNIEnvGenPath)"</_RunJNIEnvGen>
<_RunJNIEnvGen Condition=" '$(JIBuildingForNetCoreApp)' != 'True' ">$(Runtime) "$(_JNIEnvGenPath)"</_RunJNIEnvGen>
</PropertyGroup>

<!-- Add Roslyn analyzers NuGet to all projects -->
<ItemGroup Condition=" '$(DisableRoslynAnalyzers)' != 'True' ">
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="3.3.0">
Expand All @@ -84,4 +85,21 @@
</PackageReference>
</ItemGroup>

<!-- GitInfo Package for Assembly Versioning -->
<ItemGroup>
<PackageReference Include="GitInfo" Version="2.1.2" PrivateAssets="all" />
</ItemGroup>
<PropertyGroup>
<GitDefaultBranch>main</GitDefaultBranch>
<GitThisAssembly>false</GitThisAssembly>
</PropertyGroup>

<Target Name="SetVersion" BeforeTargets="GetAssemblyVersion;GetPackageVersion" DependsOnTargets="GitVersion">
<PropertyGroup>
<Version>$(GitSemVerMajor).$(GitSemVerMinor).$(GitSemVerPatch)</Version>
<InformationalVersion>$(Version); git-rev-head:$(GitCommit); git-branch:$(GitBranch)</InformationalVersion>
<Company>Microsoft Corporation</Company>
<Copyright>Microsoft Corporation</Copyright>
</PropertyGroup>
</Target>
</Project>
1 change: 1 addition & 0 deletions GitInfo.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.1
18 changes: 9 additions & 9 deletions build-tools/automation/azure-pipelines.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ jobs:
solution: Java.Interop.sln
configuration: $(Build.Configuration)
msbuildArguments: /restore

- task: MSBuild@1
displayName: MSBuild RunNUnitTests.targets
inputs:
Expand Down Expand Up @@ -93,7 +93,7 @@ jobs:
runNativeDotnetTests: true

- template: templates\fail-on-issue.yaml

- job: mac_build
displayName: Mac - Mono
pool:
Expand All @@ -114,10 +114,10 @@ jobs:
- script: make prepare CONFIGURATION=$(Build.Configuration) JI_MAX_JDK=$(MaxJdkVersion)
displayName: make prepare

- script: make all CONFIGURATION=$(Build.Configuration) JI_MAX_JDK=$(MaxJdkVersion)
displayName: make all

- script: |
r=0
make run-all-tests CONFIGURATION=$(Build.Configuration) JI_MAX_JDK=$(MaxJdkVersion) || r=$?
Expand All @@ -139,7 +139,7 @@ jobs:
SourceFolder: $(System.DefaultWorkingDirectory)
Contents: |
xatb.jar
bin.zip
bin.zip
TargetFolder: $(Build.ArtifactStagingDirectory)
condition: succeededOrFailed()

Expand All @@ -148,7 +148,7 @@ jobs:
inputs:
ArtifactName: debug
condition: succeededOrFailed()

- job: mac_dotnet_build
displayName: Mac - .NET Core
pool:
Expand All @@ -161,12 +161,12 @@ jobs:
submodules: recursive

- template: templates\install-dependencies.yaml

- script: make prepare-core CONFIGURATION=$(Build.Configuration) JI_MAX_JDK=$(MaxJdkVersion)
displayName: make prepare-core

- template: templates\core-build.yaml

- template: templates\core-tests.yaml
parameters:
runNativeTests: true
Expand Down
3 changes: 0 additions & 3 deletions src/Java.Interop.Dynamic/Java.Interop.Dynamic.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>..\..\product.snk</AssemblyOriginatorKeyFile>
<AssemblyTitle>Java.Interop.Dynamic</AssemblyTitle>
<Company>Microsoft Corporation</Company>
<Copyright>Microsoft Corporation</Copyright>
<AssemblyVersion>0.1.0.0</AssemblyVersion>
</PropertyGroup>
<PropertyGroup>
<OutputPath>$(ToolOutputFullPath)</OutputPath>
Expand Down
3 changes: 0 additions & 3 deletions src/Java.Interop.Export/Java.Interop.Export.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>..\..\product.snk</AssemblyOriginatorKeyFile>
<AssemblyTitle>Java.Interop.Export</AssemblyTitle>
<Company>Microsoft Corporation</Company>
<Copyright>Microsoft Corporation</Copyright>
<AssemblyVersion>0.1.0.0</AssemblyVersion>
</PropertyGroup>
<PropertyGroup>
<OutputPath>$(ToolOutputFullPath)</OutputPath>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>..\..\product.snk</AssemblyOriginatorKeyFile>
<AssemblyTitle>Java.Interop.GenericMarshaler</AssemblyTitle>
<Company>Microsoft Corporation</Company>
<Copyright>Microsoft Corporation</Copyright>
<AssemblyVersion>0.1.0.0</AssemblyVersion>
</PropertyGroup>
<PropertyGroup>
<OutputPath>$(ToolOutputFullPath)</OutputPath>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
<DefineConstants>INTERNAL_NULLABLE_ATTRIBUTES</DefineConstants>
<ProjectGuid>{5C0B3562-8DA0-4726-9762-75B9709ED6B7}</ProjectGuid>
<AssemblyTitle>Java.Interop.Tools.JavaSource</AssemblyTitle>
<Company>Microsoft Corporation</Company>
<Copyright>Microsoft Corporation</Copyright>
<AssemblyVersion>0.1.0.0</AssemblyVersion>
</PropertyGroup>
<PropertyGroup>
<OutputPath>$(ToolOutputFullPath)</OutputPath>
Expand Down
1 change: 0 additions & 1 deletion src/Java.Interop/Java.Interop.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
<AssemblyOriginatorKeyFile>..\..\product.snk</AssemblyOriginatorKeyFile>
<DefineConstants>INTEROP;FEATURE_JNIENVIRONMENT_JI_PINVOKES;FEATURE_JNIOBJECTREFERENCE_INTPTRS;INTERNAL_NULLABLE_ATTRIBUTES;$(JavaInteropDefineConstants)</DefineConstants>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<IntermediateOutputPath>$(BaseIntermediateOutputPath)$(Configuration)\$(TargetFramework.ToLowerInvariant())\</IntermediateOutputPath>
<OutputPath>$(ToolOutputFullPath)</OutputPath>
<DocumentationFile>$(ToolOutputFullPath)Java.Interop.xml</DocumentationFile>
Expand Down
8 changes: 1 addition & 7 deletions src/Java.Interop/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,9 @@

[assembly: DefaultDllImportSearchPathsAttribute (DllImportSearchPath.SafeDirectories | DllImportSearchPath.AssemblyDirectory)]

[assembly: AssemblyTitle ("Java.Interop")]
[assembly: AssemblyDescription ("")]
[assembly: AssemblyCulture ("")]
[assembly: AssemblyConfiguration ("")]
[assembly: AssemblyCompany ("Microsoft Corporation")]
[assembly: AssemblyCopyright ("Microsoft Corporation")]
[assembly: AssemblyProduct ("")]
[assembly: AssemblyTrademark ("Microsoft Corporation")]
[assembly: AssemblyVersion ("0.1.0.0")]

[assembly: AssemblyMetadata ("IsTrimmable", "True")]

[assembly: InternalsVisibleTo (
Expand Down
2 changes: 2 additions & 0 deletions tests/Java.Interop-Tests/Java.Interop-Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
<TargetFrameworks>net472;net6.0</TargetFrameworks>
<IsPackable>false</IsPackable>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>..\..\product.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>

<PropertyGroup>
Expand Down
2 changes: 1 addition & 1 deletion tools/generator/generator.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<Link>utils\XmlExtensions.cs</Link>
</Compile>
</ItemGroup>

<Import Project="..\..\build-tools\scripts\cecil.projitems" />

<ItemGroup>
Expand Down

0 comments on commit d16b1e5

Please sign in to comment.