Skip to content

Commit

Permalink
NH-3927 - Switch to SemVer version generation
Browse files Browse the repository at this point in the history
- SharedAssemblyInfo.?? are retired
  • Loading branch information
hazzik committed Aug 18, 2017
1 parent df34f46 commit 6d55031
Show file tree
Hide file tree
Showing 21 changed files with 83 additions and 309 deletions.
9 changes: 4 additions & 5 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,10 @@ The main GitHub repository is at <https://github.com/nhibernate/nhibernate-core>
## Setting up For Development

1. Install your favorite database and optionally set up a user capable of creating and dropping a database called **nhibernate**. There are some per-database instructions in the lib/teamcity/* folders, which you may find helpful. For SQL Server, you might be able to use the **localhost\sqlexpress** instance installed with Visual Studio. Often people already have databases set up, so you might not even need to do anything in this step.
2. Run the build menu and select the option A to create the AssemblyInfo.cs files.
3. Run the build menu and select option B to create a new test configuration. Notepad will pop up and you should edit the connection string information, saving it when you're done. These configurations will appear in the "available-test-configurations" folder.
4. Run the build menu and select option C to activate the test configuration you created. The appropriate configuration will be copied to the "current-test-configuration" folder.
5. (Optional) Run all the tests with option D and hopefully you will see no failing tests. The build may fail on certain databases; please ask on the mailing list if you are having trouble.
6. Before using the database for unit tests from Visual Studio, you'll need to create an empty database that matches your connection string. [NH-2866][2] will make this easier, but for now you just have to drop/create the database specified in your connection string yourself.
2. Run the build menu and select option B to create a new test configuration. Notepad will pop up and you should edit the connection string information, saving it when you're done. These configurations will appear in the "available-test-configurations" folder.
3. Run the build menu and select option C to activate the test configuration you created. The appropriate configuration will be copied to the "current-test-configuration" folder.
4. (Optional) Run all the tests with option D and hopefully you will see no failing tests. The build may fail on certain databases; please ask on the mailing list if you are having trouble.
5. Before using the database for unit tests from Visual Studio, you'll need to create an empty database that matches your connection string. [NH-2866][2] will make this easier, but for now you just have to drop/create the database specified in your connection string yourself.

## Creating a Test Case to Verify the Issue

Expand Down
26 changes: 9 additions & 17 deletions ShowBuildMenu.bat
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ set NUNIT="%~dp0Tools\NUnit.ConsoleRunner.3.6.0\tools\nunit3-console.exe"

:main-menu
echo ========================= NHIBERNATE BUILD MENU ==========================
echo --- SETUP ---
echo A. Set up for Visual Studio (creates AssemblyInfo.cs files).
echo.
echo --- TESTING ---
echo B. (Step 1) Set up a new test configuration for a particular database.
echo C. (Step 2) Activate a test configuration.
Expand All @@ -29,16 +26,15 @@ echo --- Exit ---
echo X. Make the beautiful build menu go away.
echo.

%BUILDTOOL% prompt ABCDEFGIX
if errorlevel 8 goto end
if errorlevel 7 goto teamcity-menu
if errorlevel 6 goto build-release-package
if errorlevel 5 goto build-release
if errorlevel 4 goto build-debug
if errorlevel 3 goto test-run
if errorlevel 2 goto test-activate
if errorlevel 1 goto test-setup-menu
if errorlevel 0 goto build-visual-studio
%BUILDTOOL% prompt BCDEFGIX
if errorlevel 7 goto end
if errorlevel 6 goto teamcity-menu
if errorlevel 5 goto build-release-package
if errorlevel 4 goto build-release
if errorlevel 3 goto build-debug
if errorlevel 2 goto test-run
if errorlevel 1 goto test-activate
if errorlevel 0 goto test-setup-menu

:test-setup-menu
echo A. Add a test configuration for SQL Server.
Expand Down Expand Up @@ -172,10 +168,6 @@ rem :build-test
rem %NANT% test
rem goto main-menu

:build-visual-studio
%NANT% visual-studio
goto main-menu

:build-debug
%NANT% clean build
echo.
Expand Down
16 changes: 16 additions & 0 deletions build-common/NHibernate.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<Project>
<PropertyGroup>
<VersionMajor Condition="'$(VersionMajor)' == ''">5</VersionMajor>
<VersionMinor Condition="'$(VersionMinor)' == ''">0</VersionMinor>
<VersionPatch Condition="'$(VersionPatch)' == ''">0</VersionPatch>
<VersionSuffix Condition="'$(VersionSuffix)' == ''">Alpha1</VersionSuffix>

<VersionPrefix>$(VersionMajor).$(VersionMinor).$(VersionPatch)</VersionPrefix>
<AssemblyVersion>$(VersionMajor).$(VersionMinor).0.0</AssemblyVersion>
<FileVersion>$(VersionPrefix).0</FileVersion>

<Product>NHibernate</Product>
<Company>NHibernate.info</Company>
<Copyright>Licensed under LGPL.</Copyright>
</PropertyGroup>
</Project>
41 changes: 1 addition & 40 deletions build-common/common-project.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@
- common.compile-all
compile a solution, generating the documentation file (.xml)
- common.generate-assemblyinfo
generate an AssemblyInfo.cs file from assembly.* NAnt properties.
- common.run-tests
run compiled NUnit tests.
Expand Down Expand Up @@ -58,7 +55,7 @@
</exec>
</target>

<target name="common.compile-all" depends="common.generate-assemblyinfo common.nuget-restore">
<target name="common.compile-all" depends="common.nuget-restore">
<!--property name="msbuild.cmd" value="${cmd.sln} ${cmd.out} ${cmd.platform} ${cmd.debug} ${cmd.optimize} ${cmd.doc} /t:Rebuild /v:q /m" /-->
<exec program="${path::combine(tools.dir, 'msbuild.cmd')}" verbose="true">
<arg value="${root.dir}/src/NHibernate.sln" />
Expand All @@ -72,42 +69,6 @@
<arg value="/m" />
</exec>
</target>

<target name="common.set-assembly-attribute-values">
<property overwrite="false" name="assembly.version" value="${project.default-assembly-version}" />
<property overwrite="false" name="assembly.version.informational" value="${project.version}" />
<property overwrite="false" name="assembly.version.file" value="${project.version.numeric}" />
</target>

<target name="common.generate-assemblyinfo"
depends="common.init common.set-assembly-attribute-values"
description="Generate SharedAssemblyInfo.* using assembly.* properties."
>
<asminfo output="${root.dir}/src/SharedAssemblyInfo.cs" language="CSharp">
<imports>
<import namespace="System" />
<import namespace="System.Reflection" />
<import namespace="System.Runtime.CompilerServices" />
</imports>
<attributes>
<attribute type="AssemblyVersionAttribute" value="${assembly.version}" />
<attribute type="AssemblyInformationalVersionAttribute" value="${assembly.version.informational}" />
<attribute type="AssemblyFileVersionAttribute" value="${assembly.version.file}" />
</attributes>
</asminfo>
<asminfo output="${root.dir}/src/SharedAssemblyInfo.vb" language="VB">
<imports>
<import namespace="System" />
<import namespace="System.Reflection" />
<import namespace="System.Runtime.CompilerServices" />
</imports>
<attributes>
<attribute type="AssemblyVersionAttribute" value="${assembly.version}" />
<attribute type="AssemblyInformationalVersionAttribute" value="${assembly.version.informational}" />
<attribute type="AssemblyFileVersionAttribute" value="${assembly.version.file}" />
</attributes>
</asminfo>
</target>

<target name="common.run-tests"
description="Run NUnit tests">
Expand Down
112 changes: 3 additions & 109 deletions build-common/common.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,116 +32,10 @@
<property name="lib.dir" value="lib" dynamic="true" />
<property name="lib.family.dir" value="${path::combine(lib.dir, framework::get-family(framework::get-target-framework()))}" dynamic="true" />
<property name="lib.framework.dir" value="${path::combine(lib.family.dir, version::to-string(framework::get-version()))}" dynamic="true" />

<!--
These are used to set the correct attributes in AssemblyInfo.cs.
-->
<property name="project.company" value="NHibernate.org" />

<!--
Version number computation
JBoss product versioning guidelines (http://wiki.jboss.org/wiki/Wiki.jsp?page=JBossProductVersioning)
say we are supposed to use version numbers formatted like major.minor.patch.qualifier, where
qualifier is alphanumeric (Alpha#, Beta#, CR#, GA, SP#), and the numeric part may be anything, e.g.
a time/date stamp, a SVN revision number and so on.
I'm only going to use simple sequential numbers for now and the script below is used to translate
the alphanumeric version into a numeric assembly version: x.y.z.qN is translated into x.y.z.(base+N)
where base is 1000 for Alpha, 2000 for Beta, 3000 for CR, and 4000 for both GA and SP (so GA is
effectively SP0).
-->

<property name="project.version" value="5.0.0.Alpha1" overwrite="false" />

<!-- This version number should be changed if, but only if, there are incompatible
changes compared to the previous version. -->
<property name="project.default-assembly-version" value="5.0.0.1001" overwrite="false" />

<!-- Compute short project version (major.minor) using a regex -->
<regex input="${project.version}" pattern="^(?'shortversion'\d+\.\d+)" />

<property name="project.version.short" value="${shortversion}" />

<!-- Compute and set project.version.numeric and project.version.nuget from project.version if it hasn't been set already -->
<if test="${not property::exists('project.version.numeric')}">

<script language="C#">
<references>
<include name="System.dll" />
</references>
<imports>
<import namespace="System.Text.RegularExpressions" />
</imports>
<code><![CDATA[
public const string VersionRegex = @"^(?<major>.+)\.{1}(?<minor>.+)\.{1}(?<build>.+)\.{1}(?<qualifier>Alpha|Beta|CR|GA|SP*)(?<qualifierNumber>\d*)$";
public static void ScriptMain(Project project)
{
string version = project.Properties["project.version"];
project.Properties["project.version.numeric"] = ToNumericVersion(version);
project.Properties["project.version.nuget"] = ToNuGetVersion(version);
}
public static string ToNuGetVersion(string version)
{
Match matches = Regex.Match(version, VersionRegex, RegexOptions.Singleline);
if (matches.Success == false) throw new BuildException("Unrecognised version number.");
if (matches.Groups.Count < 4) throw new BuildException("Unrecognised version number.");
string qualifier = matches.Groups["qualifier"].Value;
// For official releases we must use a completely numeric version.
// For pre-releases, the alphanumerics should be retained, to make Nuget
// understand it's a pre-release.
if (qualifier == "GA") return ToNumericVersion(version);
if (qualifier == "SP") return ToNumericVersion(version);
return String.Concat(
String.Join(".", new string[] { matches.Groups["major"].Value, matches.Groups["minor"].Value, matches.Groups["build"].Value }),
"-",
matches.Groups["qualifier"].Value,
matches.Groups["qualifierNumber"].Value);
}
public static string ToNumericVersion(string version)
{
const int BaseAlpha = 1000;
const int BaseBeta = 2000;
const int BaseCR = 3000;
const int BaseGA = 4000;
const int BaseSP = 4000; // SP is same as GA because GA has no number and SP's start with 1.
Match matches = Regex.Match(version, VersionRegex);
if (matches.Success == false) throw new BuildException("Unrecognised version number.");
if (matches.Groups.Count < 4) throw new BuildException("Unrecognised version number.");
string qualifier = matches.Groups["qualifier"].Value;
int qualifierNumber;
Int32.TryParse(matches.Groups["qualifierNumber"].Value, out qualifierNumber);
int revisionBase;
switch (qualifier)
{
case "Alpha": revisionBase = BaseAlpha; break;
case "Beta": revisionBase = BaseBeta; break;
case "CR": revisionBase = BaseCR; break;
case "GA": revisionBase = BaseGA; break;
case "SP": revisionBase = BaseSP; break;
default: throw new BuildException("Unknown version qualifier " + qualifier);
}
int revisionNumber = revisionBase + qualifierNumber;

return String.Join(".", new string[] {
matches.Groups["major"].Value,
matches.Groups["minor"].Value,
matches.Groups["build"].Value,
revisionNumber.ToString() });
}
]]></code>
</script>
</if>
<!-- This is used only for build folder -->
<!-- TODO: Either remove or refactor to use NHibernate.props -->
<property name="project.version" value="5.0.0-Alpha1" overwrite="false" />

<!-- debug|release -->
<property name="build.defines" value="" />
Expand Down
7 changes: 0 additions & 7 deletions default.build
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,6 @@
<exclude name="**/obj/**" />
</fileset>
</copy>

<!-- Generate AssemblyInfo.cs files for Visual Studio -->
<nant buildfile="${source.tmpdir}/default.build" target="visual-studio" />

</target>

<target name="sources-zip" depends="init sources">
Expand Down Expand Up @@ -224,9 +220,6 @@
<echo message="Created a '${project.config}' package in ${build.dir}" />
</target>

<target name="visual-studio" depends="init common.init common.generate-assemblyinfo" description="Generates SharedAssemblyInfo.cs files to work with Visual Studio">
</target>

<target name="cleanall" description="Deletes every build configuration">
<echo message="Deleting all builds from all configurations" />
<delete dir="build" failonerror="false" />
Expand Down
10 changes: 2 additions & 8 deletions src/NHibernate.DomainModel/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
using System;
using System.Reflection;

[assembly: CLSCompliantAttribute(false)]
[assembly: AssemblyTitleAttribute("NHibernate.DomainModel")]
[assembly: AssemblyDescriptionAttribute("The Domain Model used by the Unit Tests.")]
[assembly: AssemblyCompanyAttribute("NHibernate.info")]
[assembly: AssemblyProductAttribute("NHibernate.DomainModel")]
[assembly: AssemblyCopyrightAttribute("Licensed under LGPL.")]
[assembly: AssemblyDelaySignAttribute(false)]

[assembly: CLSCompliant(false)]
[assembly: AssemblyDelaySign(false)]
14 changes: 3 additions & 11 deletions src/NHibernate.DomainModel/NHibernate.DomainModel.csproj
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="../../build-common/NHibernate.props" />

<PropertyGroup>
<Description>The Domain Model used by the Unit Tests.</Description>

<TargetFramework>net461</TargetFramework>
<GenerateAssemblyTitleAttribute>False</GenerateAssemblyTitleAttribute>
<GenerateAssemblyProductAttribute>False</GenerateAssemblyProductAttribute>
<GenerateAssemblyCompanyAttribute>False</GenerateAssemblyCompanyAttribute>
<GenerateAssemblyDescriptionAttribute>False</GenerateAssemblyDescriptionAttribute>
<GenerateAssemblyVersionAttribute>False</GenerateAssemblyVersionAttribute>
<GenerateAssemblyFileVersionAttribute>False</GenerateAssemblyFileVersionAttribute>
<GenerateAssemblyInformationalVersionAttribute>False</GenerateAssemblyInformationalVersionAttribute>
<NoWarn>$(NoWarn);3001;3002;3003;3005</NoWarn>
</PropertyGroup>

Expand All @@ -25,10 +21,6 @@
<EmbeddedResource Include="**\*.hbm.xml" />
</ItemGroup>

<ItemGroup>
<Compile Include="..\SharedAssemblyInfo.cs" Link="SharedAssemblyInfo.cs" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Iesi.Collections" Version="4.0.2" />
</ItemGroup>
Expand Down
9 changes: 3 additions & 6 deletions src/NHibernate.Everything.sln
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ Microsoft Visual Studio Solution File, Format Version 12.00
VisualStudioVersion = 15.0.26730.3
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Support", "Support", "{9BDB5C84-14EC-4384-B423-9E319675B3CA}"
ProjectSection(SolutionItems) = preProject
..\build-common\NHibernate.props = ..\build-common\NHibernate.props
EndProjectSection
ProjectSection(FolderStartupServices) = postProject
{B4F97281-0DBD-4835-9ED8-7DFB966E87FF} = {B4F97281-0DBD-4835-9ED8-7DFB966E87FF}
EndProjectSection
Expand Down Expand Up @@ -68,11 +71,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NHibernate.Tool.HbmXsd", "N
EndProject
Project("{778DAE3C-4631-46EA-AA77-85C1314464D9}") = "NHibernate.Test.VisualBasic", "NHibernate.Test.VisualBasic\NHibernate.Test.VisualBasic.vbproj", "{7C2EF610-BCA0-4D1F-898A-DE9908E4970C}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "AssemblyInfo", "AssemblyInfo", "{00C03FBC-6720-4917-A203-DEA12FF3C7BF}"
ProjectSection(SolutionItems) = preProject
SharedAssemblyInfo.cs = SharedAssemblyInfo.cs
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NHibernate.Example.Web", "NHibernate.Example.Web\NHibernate.Example.Web.csproj", "{B291C1C1-599B-418E-8591-8A8CF1CAA188}"
EndProject
Global
Expand Down Expand Up @@ -161,7 +159,6 @@ Global
{7AEE5B37-C552-4E59-9B6F-88755BCB5070} = {094F74CD-2DD7-496F-BC48-A6D357BF33FD}
{446E148D-A9D5-4D7D-A706-BEDD45B2BC7D} = {92509065-DAEA-4457-8300-C7B64CD0E9F4}
{7C2EF610-BCA0-4D1F-898A-DE9908E4970C} = {094F74CD-2DD7-496F-BC48-A6D357BF33FD}
{00C03FBC-6720-4917-A203-DEA12FF3C7BF} = {9BDB5C84-14EC-4384-B423-9E319675B3CA}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {A41913C2-EDEB-440A-BBDE-0AEB56C1CBA6}
Expand Down
11 changes: 1 addition & 10 deletions src/NHibernate.Test.VisualBasic/AssemblyInfo.vb
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
Imports System
Imports System.Reflection
Imports System.Reflection
Imports NUnit.Framework

<Assembly: CLSCompliant(False)>
<Assembly: AssemblyTitle("NHibernate.Test.VisualBasic")>
<Assembly: AssemblyDescription("The Visual Basic Unit Tests for NHibernate.")>
<Assembly: AssemblyCompany("NHibernate.info")>
<Assembly: AssemblyProduct("NHibernate.Test.VisualBasic")>
<Assembly: AssemblyCopyright("Licensed under LGPL.")>
<Assembly: AssemblyTrademark("")>
<Assembly: AssemblyDelaySign(False)>

<Assembly: LevelOfParallelism(0)>

Loading

0 comments on commit 6d55031

Please sign in to comment.