Enable pinning build scripts(build.cmd)

This commit is contained in:
Kiran Challa 2015-08-11 13:04:17 -07:00
parent 7b0f6e7c2a
commit 3940873943
2 changed files with 46 additions and 9 deletions

View File

@ -192,6 +192,12 @@ var buildTarget = "compile"
throw new Exception("COHERENCE_FEED not specified. Usually this is Packages-NoTimestamp directory of Coherence-Signed."); 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[] var excludeReposForJson = new[]
{ {
"Coherence", "Coherence",
@ -216,7 +222,7 @@ var buildTarget = "compile"
var repoPath = Path.Combine(Directory.GetCurrentDirectory(), repo); 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 // Build projects to produce project.lock.json
Exec("build.cmd", "compile", repo); Exec("build.cmd", "compile", repo);

View File

@ -14,16 +14,18 @@ namespace PinVersion
{ {
public void Main(string[] args) public void Main(string[] args)
{ {
if (args.Length != 2) if (args.Length != 3)
{ {
Console.Error.WriteLine("Usage <repository-path> <package source>"); Console.Error.WriteLine("Usage <repository-path> <package source> <Korebuild Version>");
} }
var repositoryPath = args[0]; var repositoryPath = args[0];
var packageSource = args[1]; var packageSource = args[1];
var korebuildVersion = args[2];
var packageRepository = PackageRepositoryFactory.Default.CreateRepository(packageSource); var packageRepository = PackageRepositoryFactory.Default.CreateRepository(packageSource);
// Pin project.json files
foreach (var file in Directory.EnumerateFiles(repositoryPath, "project.json", SearchOption.AllDirectories)) foreach (var file in Directory.EnumerateFiles(repositoryPath, "project.json", SearchOption.AllDirectories))
{ {
var projectJson = JObject.Parse(File.ReadAllText(file)); var projectJson = JObject.Parse(File.ReadAllText(file));
@ -69,6 +71,35 @@ namespace PinVersion
projectJson.WriteTo(fileWriter); 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);
} }
} }
} }