Skip to content

Commit b91501e

Browse files
Update versioning in build scripts
1 parent ebe925f commit b91501e

File tree

10 files changed

+124
-74
lines changed

10 files changed

+124
-74
lines changed

build/Program.cs

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public class BuildContext : FrostingContext
3333
public string BuildConfiguration { get; set; }
3434
public bool SkipTests { get; set; }
3535
public bool SkipSlowTests { get; set; }
36+
public string TargetVersion { get; set; }
3637

3738
public DirectoryPath RootDirectory { get; }
3839
public DirectoryPath ArtifactsDirectory { get; }
@@ -45,8 +46,6 @@ public class BuildContext : FrostingContext
4546
public DirectoryPath ChangeLogGenDirectory { get; }
4647

4748
public DirectoryPath RedirectRootDirectory { get; }
48-
public DirectoryPath RedirectProjectDirectory { get; }
49-
public DirectoryPath RedirectSourceDirectory { get; }
5049
public DirectoryPath RedirectTargetDirectory { get; }
5150

5251
public FilePath SolutionFile { get; }
@@ -70,6 +69,7 @@ public BuildContext(ICakeContext context)
7069
BuildConfiguration = context.Argument("Configuration", "Release");
7170
SkipTests = context.Argument("SkipTests", false);
7271
SkipSlowTests = context.Argument("SkipSlowTests", false);
72+
TargetVersion = context.Argument("Version", "");
7373

7474
RootDirectory = new DirectoryPath(new DirectoryInfo(Directory.GetCurrentDirectory()).Parent.FullName);
7575
ArtifactsDirectory = RootDirectory.Combine("artifacts");
@@ -82,8 +82,6 @@ public BuildContext(ICakeContext context)
8282
ChangeLogGenDirectory = RootDirectory.Combine("docs").Combine("_changelog");
8383

8484
RedirectRootDirectory = RootDirectory.Combine("docs").Combine("_redirects");
85-
RedirectProjectDirectory = RedirectRootDirectory.Combine("RedirectGenerator");
86-
RedirectSourceDirectory = RedirectRootDirectory.Combine("redirects");
8785
RedirectTargetDirectory = RootDirectory.Combine("docs").Combine("_site");
8886

8987
SolutionFile = RootDirectory.CombineWithFilePath("BenchmarkDotNet.sln");
@@ -96,11 +94,16 @@ public BuildContext(ICakeContext context)
9694
AllPackableSrcProjects = new FilePathCollection(context.GetFiles(RootDirectory.FullPath + "/src/**/*.csproj")
9795
.Where(p => !p.FullPath.Contains("Disassembler")));
9896

99-
MsBuildSettings = new DotNetMSBuildSettings
97+
MsBuildSettings = new DotNetMSBuildSettings();
98+
if (IsCiBuild)
10099
{
101-
MaxCpuCount = 1
102-
};
103-
MsBuildSettings.WithProperty("UseSharedCompilation", "false");
100+
MsBuildSettings.MaxCpuCount = 1;
101+
MsBuildSettings.WithProperty("UseSharedCompilation", "false");
102+
System.Environment.SetEnvironmentVariable("BDN_CI_BUILD", "true");
103+
}
104+
105+
if (!string.IsNullOrEmpty(TargetVersion))
106+
MsBuildSettings.WithProperty("Version", TargetVersion);
104107

105108
// NativeAOT build requires VS C++ tools to be added to $path via vcvars64.bat
106109
// but once we do that, dotnet restore fails with:
@@ -325,6 +328,7 @@ public class BuildTask : FrostingTask<BuildContext>
325328
{
326329
public override void Run(BuildContext context)
327330
{
331+
context.Information("BuildSystemProvider: " + context.BuildSystem().Provider);
328332
context.DotNetBuild(context.SolutionFile.FullPath, new DotNetBuildSettings
329333
{
330334
Configuration = context.BuildConfiguration,
@@ -410,17 +414,20 @@ public override void Run(BuildContext context)
410414
Configuration = context.BuildConfiguration,
411415
OutputDirectory = context.ArtifactsDirectory.FullPath,
412416
ArgumentCustomization = args => args.Append("--include-symbols").Append("-p:SymbolPackageFormat=snupkg"),
413-
MSBuildSettings = context.MsBuildSettings
417+
MSBuildSettings = context.MsBuildSettings,
418+
NoBuild = true,
419+
NoRestore = true
414420
};
421+
422+
foreach (var project in context.AllPackableSrcProjects)
423+
context.DotNetPack(project.FullPath, settingsSrc);
424+
415425
var settingsTemplate = new DotNetPackSettings
416426
{
417427
Configuration = context.BuildConfiguration,
418428
OutputDirectory = context.ArtifactsDirectory.FullPath,
419429
MSBuildSettings = context.MsBuildSettings
420430
};
421-
422-
foreach (var project in context.AllPackableSrcProjects)
423-
context.DotNetPack(project.FullPath, settingsSrc);
424431
context.DotNetPack(context.TemplatesTestsProjectFile.FullPath, settingsTemplate);
425432
}
426433
}

build/common.props

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -23,47 +23,41 @@
2323
</PropertyGroup>
2424

2525
<ItemGroup>
26-
<None Include="$(MSBuildThisFileDirectory)package-icon.png" Pack="True" PackagePath="" />
26+
<None Include="$(MSBuildThisFileDirectory)package-icon.png" Pack="True" PackagePath=""/>
2727
</ItemGroup>
2828

2929
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
3030
<AssemblyOriginatorKeyFile>$(MSBuildThisFileDirectory)strongNameKey.snk</AssemblyOriginatorKeyFile>
3131
<SignAssembly>true</SignAssembly>
3232
<GenerateDocumentationFile>true</GenerateDocumentationFile>
3333
</PropertyGroup>
34-
34+
3535
<PropertyGroup Condition=" '$(IsVisualBasic)' != 'true' AND '$(IsFsharp)' != 'true' ">
3636
<LangVersion>9.0</LangVersion>
37-
38-
<Major>0</Major>
39-
<Minor>13</Minor>
40-
<Revision>5</Revision>
41-
42-
<BuildNumber Condition=" '$(APPVEYOR_BUILD_NUMBER)' != '' ">$(APPVEYOR_BUILD_NUMBER)</BuildNumber>
43-
<BuildNumber Condition=" '$(BuildNumber)' == '' ">0</BuildNumber>
37+
</PropertyGroup>
4438

45-
<PrereleaseLabel>-develop</PrereleaseLabel>
46-
<PrereleaseLabel Condition=" '$(APPVEYOR_BUILD_NUMBER)' != '' "></PrereleaseLabel>
47-
<!-- <PrereleaseLabel></PrereleaseLabel> --> <!-- For release versions only -->
39+
<PropertyGroup Condition=" '$(VersionPrefix)' == '' ">
40+
<VersionPrefix>0.13.5</VersionPrefix>
41+
<VersionPrefix Condition=" '$(APPVEYOR_BUILD_NUMBER)' != '' ">$(VersionPrefix).$(APPVEYOR_BUILD_NUMBER)</VersionPrefix>
42+
</PropertyGroup>
4843

49-
<PrereleaseLabelConstants></PrereleaseLabelConstants>
50-
<PrereleaseLabelConstants Condition=" '$(PrereleaseLabel)' == '-develop' ">PRERELEASE_DEVELOP</PrereleaseLabelConstants>
51-
<PrereleaseLabelConstants Condition=" '$(APPVEYOR_BUILD_NUMBER)' != '' ">PRERELEASE_NIGHTLY</PrereleaseLabelConstants>
52-
<DefineConstants>$(DefineConstants);$(PrereleaseLabelConstants)</DefineConstants>
44+
<PropertyGroup Condition=" '$(VersionSuffix)' == '' ">
45+
<VersionSuffix>develop</VersionSuffix>
46+
<VersionSuffix Condition=" '$(APPVEYOR_BUILD_NUMBER)' == '' AND '$(BDN_CI_BUILD)' != '' ">ci</VersionSuffix>
47+
</PropertyGroup>
5348

54-
<AssemblyVersion>$(Major).$(Minor).$(Revision).$(BuildNumber)</AssemblyVersion>
55-
<AssemblyFileVersion>$(Major).$(Minor).$(Revision).$(BuildNumber)</AssemblyFileVersion>
56-
<InformationalVersion>$(Major).$(Minor).$(Revision).$(BuildNumber)$(PrereleaseLabel)</InformationalVersion>
57-
<PackageVersion>$(Major).$(Minor).$(Revision).$(BuildNumber)$(PrereleaseLabel)</PackageVersion>
49+
<PropertyGroup>
50+
<AssemblyVersion>$(VersionPrefix)</AssemblyVersion>
51+
<AssemblyFileVersion>$(VersionPrefix)</AssemblyFileVersion>
52+
<InformationalVersion>$(Version)</InformationalVersion>
53+
<PackageVersion>$(Version)</PackageVersion>
5854
</PropertyGroup>
55+
5956
<ItemGroup>
6057
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.2">
6158
<PrivateAssets>all</PrivateAssets>
6259
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
6360
</PackageReference>
64-
</ItemGroup>
65-
66-
<ItemGroup >
6761
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118">
6862
<PrivateAssets>all</PrivateAssets>
6963
</PackageReference>

src/BenchmarkDotNet/Disassemblers/WindowsDisassembler.cs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,15 +86,18 @@ private static string GetDisassemblerPath(string architectureName)
8686
var dir = new FileInfo(assemblyWithDisassemblersInResources.Location).Directory ?? throw new DirectoryNotFoundException();
8787
string disassemblerPath = Path.Combine(
8888
dir.FullName,
89-
FolderNameHelper.ToFolderName(BenchmarkDotNetInfo.FullVersion), // possible update
89+
FolderNameHelper.ToFolderName(BenchmarkDotNetInfo.Instance.FullVersion), // possible update
9090
exeName); // separate process per architecture!!
9191

9292
Path.GetDirectoryName(disassemblerPath).CreateIfNotExists();
9393

94-
#if !PRERELEASE_DEVELOP // for development we always want to copy the file to not omit any dev changes (Properties.BenchmarkDotNetInfo.FullVersion in file name is not enough)
95-
if (File.Exists(disassemblerPath))
96-
return disassemblerPath;
97-
#endif
94+
// for development we always want to copy the file to not omit any dev changes
95+
if (!BenchmarkDotNetInfo.Instance.IsDevelop)
96+
{
97+
if (File.Exists(disassemblerPath))
98+
return disassemblerPath;
99+
}
100+
98101
// the disassembler has not been yet retrieved from the resources
99102
CopyFromResources(
100103
assemblyWithDisassemblersInResources,

src/BenchmarkDotNet/Environments/BenchmarkEnvironmentInfo.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using BenchmarkDotNet.Jobs;
88
using BenchmarkDotNet.Portability;
99
using BenchmarkDotNet.Portability.Cpu;
10+
using BenchmarkDotNet.Properties;
1011
using BenchmarkDotNet.Validators;
1112
using JetBrains.Annotations;
1213

@@ -51,6 +52,7 @@ protected BenchmarkEnvironmentInfo()
5152
public virtual IEnumerable<string> ToFormattedString()
5253
{
5354
yield return "Benchmark Process Environment Information:";
55+
yield return $"{BenchmarkDotNetInfo.Instance.BrandTitle}";
5456
yield return $"{RuntimeInfoPrefix}{GetRuntimeInfo()}";
5557
yield return $"{GcInfoPrefix}{GetGcConcurrentFlag()} {GetGcServerFlag()}";
5658
yield return $"{HardwareIntrinsicsPrefix}{HardwareIntrinsics.GetFullInfo(RuntimeInformation.GetCurrentPlatform())} {HardwareIntrinsics.GetVectorSize()}";

src/BenchmarkDotNet/Environments/HostEnvironmentInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public class HostEnvironmentInfo : BenchmarkEnvironmentInfo
6767

6868
protected HostEnvironmentInfo()
6969
{
70-
BenchmarkDotNetVersion = BenchmarkDotNetInfo.FullVersion;
70+
BenchmarkDotNetVersion = BenchmarkDotNetInfo.Instance.BrandVersion;
7171
OsVersion = new Lazy<string>(RuntimeInformation.GetOsVersion);
7272
CpuInfo = new Lazy<CpuInfo>(RuntimeInformation.GetCpuInfo);
7373
ChronometerFrequency = Chronometer.Frequency;

src/BenchmarkDotNet/Exporters/RPlotExporter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public IEnumerable<string> ExportToFiles(Summary summary, ILogger consoleLogger)
3636
string logFullPath = Path.Combine(summary.ResultsDirectoryPath, logFileName);
3737
string script = ResourceHelper.
3838
LoadTemplate(scriptFileName).
39-
Replace("$BenchmarkDotNetVersion$", BenchmarkDotNetInfo.FullTitle).
39+
Replace("$BenchmarkDotNetVersion$", BenchmarkDotNetInfo.Instance.BrandTitle).
4040
Replace("$CsvSeparator$", CsvMeasurementsExporter.Default.Separator);
4141
lock (BuildScriptLock)
4242
File.WriteAllText(scriptFullPath, script);

src/BenchmarkDotNet/Properties/BenchmarkDotNetInfo.cs

Lines changed: 39 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,53 @@
11
using System;
2-
using System.Diagnostics.CodeAnalysis;
32
using System.Reflection;
3+
using BenchmarkDotNet.Extensions;
44

55
namespace BenchmarkDotNet.Properties
66
{
7-
[SuppressMessage("ReSharper", "MemberCanBePrivate.Global")]
8-
public static class BenchmarkDotNetInfo
7+
public class BenchmarkDotNetInfo
98
{
10-
#if PRERELEASE_NIGHTLY
11-
public const string PrereleaseLabel = "-nightly";
12-
#elif PRERELEASE_DEVELOP
13-
public const string PrereleaseLabel = "-develop";
14-
#else
15-
public const string PrereleaseLabel = "";
16-
#endif
17-
18-
// ReSharper disable once ConditionIsAlwaysTrueOrFalse
19-
[SuppressMessage("ReSharper", "RedundantLogicalConditionalExpressionOperand")]
20-
private static readonly Lazy<string> FullVersionLazy = new Lazy<string>(() =>
9+
private static readonly Lazy<BenchmarkDotNetInfo> LazyInstance = new (() =>
2110
{
22-
string version = typeof(BenchmarkDotNetInfo).GetTypeInfo().Assembly.GetName().Version.ToString();
23-
#pragma warning disable 162
24-
if (version.EndsWith(".0") && PrereleaseLabel == "")
25-
version = version.Substring(0, version.Length - 2);
26-
if (version.EndsWith(".0") && PrereleaseLabel == "-develop")
27-
version = version.Substring(0, version.Length - 1) + DateTime.Now.ToString("yyyyMMdd");
28-
#pragma warning restore 162
29-
return version + PrereleaseLabel;
11+
var assembly = typeof(BenchmarkDotNetInfo).GetTypeInfo().Assembly;
12+
var assemblyVersion = assembly.GetName().Version;
13+
string informationVersion = assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>().InformationalVersion ?? "";
14+
return new BenchmarkDotNetInfo(assemblyVersion, informationVersion);
3015
});
3116

32-
private static readonly Lazy<string> FullTitleLazy = new Lazy<string>(() => "BenchmarkDotNet v" + FullVersionLazy.Value);
17+
public static BenchmarkDotNetInfo Instance { get; } = LazyInstance.Value;
3318

34-
public static string FullVersion => FullVersionLazy.Value;
19+
public Version AssemblyVersion { get; }
20+
public string FullVersion { get; }
3521

36-
public static string FullTitle => FullTitleLazy.Value;
22+
public bool IsDevelop { get; }
23+
public bool IsNightly { get; }
24+
public bool IsRelease { get; }
25+
26+
public string BrandTitle { get; }
27+
public string BrandVersion { get; }
28+
29+
public BenchmarkDotNetInfo(Version assemblyVersion, string fullVersion)
30+
{
31+
AssemblyVersion = assemblyVersion;
32+
FullVersion = fullVersion;
33+
34+
string versionPrefix = AssemblyVersion.Revision > 0
35+
? AssemblyVersion.ToString()
36+
: AssemblyVersion.ToString(3);
37+
if (!FullVersion.StartsWith(versionPrefix))
38+
throw new ArgumentException($"Inconsistent versions: '{assemblyVersion}' and '{fullVersion}'");
39+
string versionSuffix = FullVersion.Substring(versionPrefix.Length).TrimStart('-');
40+
41+
IsDevelop = versionSuffix.StartsWith("develop");
42+
IsNightly = AssemblyVersion.Revision > 0;
43+
IsRelease = versionSuffix.IsEmpty() && AssemblyVersion.Revision <= 0;
44+
45+
string brandVersionSuffix = IsDevelop
46+
? " (" + DateTime.Now.ToString("yyyy-MM-dd") + ")"
47+
: "";
48+
BrandVersion = FullVersion + brandVersionSuffix;
49+
BrandTitle = "BenchmarkDotNet v" + BrandVersion;
50+
}
3751

3852
internal const string PublicKey =
3953
"00240000048000009400000006020000002400005253413100040000010001002970bbdfca4d12" +

src/BenchmarkDotNet/Running/BenchmarkRunnerClean.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,8 @@ internal static Summary[] Run(BenchmarkRunInfo[] benchmarkRunInfos)
145145
}
146146

147147
compositeLogger.WriteLineHeader("// * Artifacts cleanup *");
148-
Cleanup(new HashSet<string>(artifactsToCleanup.Distinct()));
148+
Cleanup(compositeLogger, new HashSet<string>(artifactsToCleanup.Distinct()));
149+
compositeLogger.WriteLineInfo("Artifacts cleanup is finished");
149150
compositeLogger.Flush();
150151
}
151152
}
@@ -639,10 +640,11 @@ void AddLogger(ILogger logger)
639640
return new CompositeLogger(loggers.Values.ToImmutableHashSet());
640641
}
641642

642-
private static void Cleanup(HashSet<string> artifactsToCleanup)
643+
private static void Cleanup(ILogger logger, HashSet<string> artifactsToCleanup)
643644
{
644645
foreach (string path in artifactsToCleanup)
645646
{
647+
logger.WriteLineInfo($"Trying to delete '{path}'");
646648
try
647649
{
648650
if (Directory.Exists(path))
@@ -653,9 +655,11 @@ private static void Cleanup(HashSet<string> artifactsToCleanup)
653655
{
654656
File.Delete(path);
655657
}
658+
logger.WriteLineInfo($"Successfully deleted '{path}'");
656659
}
657-
catch
660+
catch (Exception e)
658661
{
662+
logger.WriteLineInfo($"Failed to delete '{path}' because of the following exception: {e}");
659663
// sth is locking our auto-generated files
660664
// there is very little we can do about it
661665
}

src/BenchmarkDotNet/Toolchains/InProcess/Emit/Implementation/Emitters/RunnableEmitter.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
using BenchmarkDotNet.Helpers.Reflection.Emit;
1313
using BenchmarkDotNet.Jobs;
1414
using BenchmarkDotNet.Loggers;
15+
using BenchmarkDotNet.Properties;
1516
using BenchmarkDotNet.Running;
1617
using BenchmarkDotNet.Toolchains.Results;
1718
using JetBrains.Annotations;
@@ -78,11 +79,13 @@ public static Assembly EmitPartitionAssembly(
7879

7980
private static bool ShouldSaveToDisk(IConfig config)
8081
{
81-
#if PRERELEASE_DEVELOP || PRERELEASE_NIGHTLY // we never want to do that in our official NuGet.org package, it's a hack
82-
return config.Options.IsSet(ConfigOptions.KeepBenchmarkFiles) && Portability.RuntimeInformation.IsFullFramework;
83-
#else
82+
if (!BenchmarkDotNetInfo.Instance.IsRelease)
83+
{
84+
// we never want to do that in our official NuGet.org package, it's a hack
85+
return config.Options.IsSet(ConfigOptions.KeepBenchmarkFiles) && Portability.RuntimeInformation.IsFullFramework;
86+
}
87+
8488
return false;
85-
#endif
8689
}
8790

8891
private static string GetRunnableTypeName(BenchmarkBuildInfo benchmark)
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using System;
2+
using BenchmarkDotNet.Properties;
3+
using Xunit;
4+
5+
namespace BenchmarkDotNet.Tests
6+
{
7+
public class BenchmarkDotNetInfoTests
8+
{
9+
[Theory]
10+
[InlineData("1.0.0", "1.0.0", false, false, true)]
11+
[InlineData("1.0.0", "1.0.0-develop", true, false, false)]
12+
[InlineData("1.0.0", "1.0.0-develop123", true, false, false)]
13+
[InlineData("1.2.3.4", "1.2.3.4", false, true, false)]
14+
public void BenchmarkDotNetInfoTest(string assemblyVersion, string fullVersion, bool expectedIsDevelop, bool expectedIsNightly,
15+
bool expectedIsRelease)
16+
{
17+
var info = new BenchmarkDotNetInfo(Version.Parse(assemblyVersion), fullVersion);
18+
Assert.Equal(expectedIsDevelop, info.IsDevelop);
19+
Assert.Equal(expectedIsNightly, info.IsNightly);
20+
Assert.Equal(expectedIsRelease, info.IsRelease);
21+
}
22+
}
23+
}

0 commit comments

Comments
 (0)