From 39408739432b4b969e6e9748d7fe0155de53f7d8 Mon Sep 17 00:00:00 2001 From: Kiran Challa Date: Tue, 11 Aug 2015 13:04:17 -0700 Subject: [PATCH] Enable pinning build scripts(build.cmd) --- makefile.shade | 20 +++++++++++++------- tools/PinVersion/Program.cs | 35 +++++++++++++++++++++++++++++++++-- 2 files changed, 46 insertions(+), 9 deletions(-) diff --git a/makefile.shade b/makefile.shade index bfee64a9c5..3cd847b878 100644 --- a/makefile.shade +++ b/makefile.shade @@ -192,6 +192,12 @@ var buildTarget = "compile" throw new Exception("COHERENCE_FEED not specified. Usually this is Packages-NoTimestamp directory of Coherence-Signed."); } + var korebuildVersion = Environment.GetEnvironmentVariable("KOREBUILD_VERSION"); + if (string.IsNullOrEmpty(korebuildVersion)) + { + throw new Exception("KOREBUILD_VERSION environment variable is not specified."); + } + var excludeReposForJson = new[] { "Coherence", @@ -216,7 +222,7 @@ var buildTarget = "compile" var repoPath = Path.Combine(Directory.GetCurrentDirectory(), repo); - Exec("dnx", string.Format(@".\tools\PinVersion run ""{0}"" ""{1}""", repo, coherenceFeed), string.Empty); + Exec("dnx", string.Format(@".\tools\PinVersion run ""{0}"" ""{1}"" ""{2}""", repo, coherenceFeed, korebuildVersion), string.Empty); // Build projects to produce project.lock.json Exec("build.cmd", "compile", repo); @@ -661,8 +667,8 @@ functions return true; } - - static IEnumerable GetRepositoriesToBuild() + + static IEnumerable GetRepositoriesToBuild() { IEnumerable reposToBuild = new HashSet(StringComparer.OrdinalIgnoreCase) { // The repos list is topologically sorted based on build order @@ -703,7 +709,7 @@ functions "CORS", "Entropy", }; - + var repositoryInclude = Environment.GetEnvironmentVariable("KOREBUILD_REPOSITORY_INCLUDE"); if (!string.IsNullOrEmpty(repositoryInclude)) { @@ -711,14 +717,14 @@ functions repositoryInclude.Split(new string[] {","}, StringSplitOptions.RemoveEmptyEntries), StringComparer.OrdinalIgnoreCase); } - + var repositoryExclude = Environment.GetEnvironmentVariable("KOREBUILD_REPOSITORY_EXCLUDE"); - if (!string.IsNullOrEmpty(repositoryExclude)) + if (!string.IsNullOrEmpty(repositoryExclude)) { var reposToExclude = repositoryExclude.Split(new string[] {","}, StringSplitOptions.RemoveEmptyEntries); reposToBuild = reposToBuild.Except(reposToExclude); } - + return reposToBuild.ToList(); } } diff --git a/tools/PinVersion/Program.cs b/tools/PinVersion/Program.cs index 5b2117b299..e8e2b8dcf8 100644 --- a/tools/PinVersion/Program.cs +++ b/tools/PinVersion/Program.cs @@ -14,16 +14,18 @@ namespace PinVersion { public void Main(string[] args) { - if (args.Length != 2) + if (args.Length != 3) { - Console.Error.WriteLine("Usage "); + Console.Error.WriteLine("Usage "); } var repositoryPath = args[0]; var packageSource = args[1]; + var korebuildVersion = args[2]; var packageRepository = PackageRepositoryFactory.Default.CreateRepository(packageSource); + // Pin project.json files foreach (var file in Directory.EnumerateFiles(repositoryPath, "project.json", SearchOption.AllDirectories)) { var projectJson = JObject.Parse(File.ReadAllText(file)); @@ -69,6 +71,35 @@ namespace PinVersion projectJson.WriteTo(fileWriter); } } + + // Pin the build scripts + //TODO: handle build.sh files too + var dnxPackageName = "dnx-clr-win-x86"; + var dnxPackage = packageRepository.FindPackage(dnxPackageName); + if (dnxPackage == null) + { + throw new InvalidOperationException( + $"Could not find the DNX package with name '{dnxPackageName}' to " + + "pin the build script"); + } + + var buildCmdFiles = Directory.GetFiles(repositoryPath, "build.cmd", SearchOption.TopDirectoryOnly); + if (buildCmdFiles == null || buildCmdFiles.Length == 0) + { + throw new InvalidOperationException($"No build.cmd files found at {repositoryPath}"); + } + + var buildCmdFile = buildCmdFiles[0]; + var buildCmdFileContent = File.ReadAllText(buildCmdFile); + buildCmdFileContent = buildCmdFileContent.Replace( + "SET BUILDCMD_KOREBUILD_VERSION=\"\"", + $"SET BUILDCMD_KOREBUILD_VERSION={korebuildVersion}"); + buildCmdFileContent = buildCmdFileContent.Replace( + "SET BUILDCMD_DNX_VERSION=\"\"", + $"SET BUILDCMD_DNX_VERSION={dnxPackage.Version.ToNormalizedString()}"); + + // Replace all content of the file + File.WriteAllText(buildCmdFile, buildCmdFileContent); } } }