diff --git a/.gitignore b/.gitignore index f40c4348..f9cdc5a9 100644 --- a/.gitignore +++ b/.gitignore @@ -37,7 +37,9 @@ deps/lua/src/liblua.a *.exe *.sdf *.suo -msvs/ReleasePackagingTool +msvs/ReleasePackagingTool/bin/ +msvs/ReleasePackagingTool/obj/ +msvs/ReleasePackagingTool/packages/ msvs/ipch msvs/RedisServer.opensdf !msvs/RedisWaInst/bin/* diff --git a/msvs/ReleasePackagingTool/CmdLineOptions.cs b/msvs/ReleasePackagingTool/CmdLineOptions.cs new file mode 100644 index 00000000..179615f7 --- /dev/null +++ b/msvs/ReleasePackagingTool/CmdLineOptions.cs @@ -0,0 +1,16 @@ +using CommandLine; + +namespace ReleasePackagingTool +{ + class CmdLineOptions + { + [Option('n', "new-version", HelpText = "Prepares new version")] + public string PrepareNewVersion { get; set; } + + [Option('p', "root-path", HelpText = "Root path to project folder")] + public string RootPath { get; set; } + + [Option('s', "skip-package", HelpText = "When true skips preparing the package")] + public bool SkipPackage { get; set; } + } +} diff --git a/msvs/ReleasePackagingTool/Program.cs b/msvs/ReleasePackagingTool/Program.cs index 3ab8b6e8..019139b6 100644 --- a/msvs/ReleasePackagingTool/Program.cs +++ b/msvs/ReleasePackagingTool/Program.cs @@ -1,8 +1,10 @@ -using System; +using CommandLine; +using System; using System.Collections.Generic; using System.IO; using System.IO.Compression; using System.Reflection; +using System.Text.RegularExpressions; namespace ReleasePackagingTool { @@ -10,8 +12,13 @@ namespace ReleasePackagingTool { #region Private Fields - private static string rootPath; - private static string versionReplacementText = "CurrentRedisVersion"; + private readonly string rootPath; + private const string versionReplacementText = "CurrentRedisVersion"; + + public Program(string rootPath) + { + this.rootPath = rootPath; + } #endregion Private Fields @@ -21,18 +28,33 @@ namespace ReleasePackagingTool { try { - Program p = new Program(); + Parser.Default.ParseArguments(args).WithParsed(cmdLineOptions => + { + string assemblyDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); + var rootPath = cmdLineOptions.RootPath ?? Path.GetFullPath(Path.Combine(assemblyDirectory, @"..\..\..\..\..\")); - string assemblyDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); - rootPath = Path.GetFullPath(Path.Combine(assemblyDirectory, @"..\..\..\..\..\")); + Program p = new Program(rootPath); - string version; - version = p.GetRedisVersion(); - p.UpdateNuSpecFiles(version); - p.BuildReleasePackage(version, "x64"); + if (!string.IsNullOrWhiteSpace(cmdLineOptions.PrepareNewVersion)) + { + p.PrepareNewVersion(cmdLineOptions.PrepareNewVersion); + } - Console.Write("Release packaging complete."); - Environment.ExitCode = 0; + if (!cmdLineOptions.SkipPackage) + { + var version = p.GetRedisVersion(); + p.UpdateNuSpecFiles(version); + p.BuildReleasePackage(version, "x64"); + + Console.Write("Release packaging complete."); + } + else + { + Console.WriteLine("Creation of release package skipped."); + } + + Environment.ExitCode = 0; + }); } catch (Exception ex) { @@ -43,16 +65,16 @@ namespace ReleasePackagingTool private void BuildReleasePackage(string version, string platform) { - string releasePackageDir = Path.Combine(rootPath, @"msvs\BuildRelease\Redis-" + version + @"\"); + string releasePackageDir = GetTargetPath(@"msvs\BuildRelease\Redis-" + version + @"\"); if (Directory.Exists(releasePackageDir) == false) { Directory.CreateDirectory(releasePackageDir); } - string releasePackagePath = Path.Combine(rootPath, releasePackageDir + "Redis-" + platform + "-" + version + ".zip"); + string releasePackagePath = GetTargetPath(releasePackageDir + "Redis-" + platform + "-" + version + ".zip"); ForceFileErase(releasePackagePath); - string executablesRoot = Path.Combine(rootPath, @"msvs\" + platform + @"\Release"); + string executablesRoot = GetTargetPath(@"msvs\" + platform + @"\Release"); List> executableNames = new List>() { Tuple.Create("redis-benchmark.exe", "redis-benchmark.exe"), @@ -73,7 +95,7 @@ namespace ReleasePackagingTool { "EventLog.dll" }; - string documentsRoot = Path.Combine(rootPath, @"msvs\setups\documentation"); + string documentsRoot = GetTargetPath(@"msvs\setups\documentation"); List documentNames = new List() { "redis.windows.conf", @@ -127,9 +149,19 @@ namespace ReleasePackagingTool } } + private string GetTargetPath(string filePath) + { + if (Path.IsPathRooted(filePath)) + { + return filePath; + } + + return Path.Combine(rootPath, filePath); + } + private string GetRedisVersion() { - TextReader tr = File.OpenText(Path.Combine(rootPath, @"src\version.h")); + TextReader tr = File.OpenText(GetTargetPath(@"src\version.h")); string line = tr.ReadLine(); int start = line.IndexOf('\"'); int last = line.LastIndexOf('\"'); @@ -138,15 +170,46 @@ namespace ReleasePackagingTool private void UpdateNuSpecFiles(string version) { - string chocTemplate = Path.Combine(rootPath, @"msvs\setups\chocolatey\template\redis.nuspec.template"); - string chocDocument = Path.Combine(rootPath, @"msvs\setups\chocolatey\redis.nuspec"); + string chocTemplate = GetTargetPath(@"msvs\setups\chocolatey\template\redis.nuspec.template"); + string chocDocument = GetTargetPath(@"msvs\setups\chocolatey\redis.nuspec"); CreateTextFileFromTemplate(chocTemplate, chocDocument, versionReplacementText, version); - string nugetTemplate = Path.Combine(rootPath, @"msvs\setups\nuget\template\redis.nuspec.template"); - string nugetDocument = Path.Combine(rootPath, @"msvs\setups\nuget\redis.nuspec"); + string nugetTemplate = GetTargetPath(@"msvs\setups\nuget\template\redis.nuspec.template"); + string nugetDocument = GetTargetPath(@"msvs\setups\nuget\redis.nuspec"); CreateTextFileFromTemplate(nugetTemplate, nugetDocument, versionReplacementText, version); } + /// + /// Updates some source files that keep track of current Redis for Windows version + /// with newly provided . + /// + /// New version + private void PrepareNewVersion(string prepareNewVersion) + { + Console.WriteLine("Preparing new version: " + prepareNewVersion); + + //update src/version.h + File.WriteAllText(GetTargetPath(@"src\version.h"), $"#define REDIS_VERSION \"{prepareNewVersion}\"\r\n", System.Text.Encoding.ASCII); + + //update msvs/RedisForWindows.rc + var rcFilePath = GetTargetPath(@"msvs\RedisForWindows.rc"); + var rcLines = File.ReadAllLines(rcFilePath); + var versionWithCommas = prepareNewVersion.Replace('.', ','); + + for (int i = 0, j = rcLines.Length; i < j; i++) + { + var line = rcLines[i]; + + if (line.IndexOf("FILEVERSION", StringComparison.InvariantCultureIgnoreCase) > -1 + || line.IndexOf("PRODUCTVERSION", StringComparison.InvariantCultureIgnoreCase) > -1) { + rcLines[i] = Regex.Replace(line, @"(?FILEVERSION|PRODUCTVERSION)\s+[1-9][0-9,]+", "${optname} " + versionWithCommas); + rcLines[i] = Regex.Replace(rcLines[i], @"VALUE ""(?FileVersion|ProductVersion)"", ""[1-9]+[0-9.]+""", "VALUE \"${optname}\", \"" + prepareNewVersion + "\""); + } + } + + File.WriteAllLines(rcFilePath, rcLines, System.Text.Encoding.ASCII); + } + #endregion Private Methods } } \ No newline at end of file diff --git a/msvs/ReleasePackagingTool/ReleasePackagingTool.csproj b/msvs/ReleasePackagingTool/ReleasePackagingTool.csproj index 8d42cbe3..af635bd1 100644 --- a/msvs/ReleasePackagingTool/ReleasePackagingTool.csproj +++ b/msvs/ReleasePackagingTool/ReleasePackagingTool.csproj @@ -55,6 +55,9 @@ ReleasePackagingTool.Program + + packages\CommandLineParser.2.7.82\lib\net45\CommandLine.dll + @@ -66,11 +69,13 @@ + + diff --git a/msvs/ReleasePackagingTool/packages.config b/msvs/ReleasePackagingTool/packages.config new file mode 100644 index 00000000..ace26f7a --- /dev/null +++ b/msvs/ReleasePackagingTool/packages.config @@ -0,0 +1,4 @@ + + + + \ No newline at end of file