Browse Source

migrate build script to csproj

bump version number due to project file type changing we are reseting the build counter.
pull/131/head
Scott Williams 9 years ago
parent
commit
a3296ff9d9
  1. 3
      .gitignore
  2. 98
      build/Program.cs
  3. 2
      build/build.csproj
  4. 2
      src/ImageSharp.Drawing/ImageSharp.Drawing.csproj
  5. 2
      src/ImageSharp.Formats.Bmp/ImageSharp.Formats.Bmp.csproj
  6. 2
      src/ImageSharp.Formats.Gif/ImageSharp.Formats.Gif.csproj
  7. 2
      src/ImageSharp.Formats.Jpeg/ImageSharp.Formats.Jpeg.csproj
  8. 2
      src/ImageSharp.Processing/ImageSharp.Processing.csproj
  9. 2
      src/ImageSharp/ImageSharp.csproj
  10. 2
      tests/ImageSharp.Benchmarks/ImageSharp.Benchmarks.csproj

3
.gitignore

@ -211,5 +211,8 @@ artifacts/
#BenchmarkDotNet
**/BenchmarkDotNet.Artifacts/
# Build process
*.csproj.bak
#CodeCoverage
**/CodeCoverage/*

98
build/Program.cs

@ -10,10 +10,10 @@ namespace ConsoleApplication
using System.IO;
using System.Linq;
using System.Text;
using System.Xml;
using LibGit2Sharp;
using Microsoft.DotNet.ProjectModel;
using Newtonsoft.Json;
using Microsoft.Build.Construction;
using Microsoft.Build.Evaluation;
using NuGet.Versioning;
/// <summary>
@ -65,31 +65,29 @@ namespace ConsoleApplication
{
var resetmode = args.Contains("reset");
// Find the project root where glbal.json lives
var root = ProjectRootResolver.ResolveRootDirectory(".");
// Find the project root
var root = Path.GetFullPath(Path.Combine(LibGit2Sharp.Repository.Discover("."), ".."));
// Lets find the repo
var repo = new LibGit2Sharp.Repository(root);
// Lets find all the project.json files in the src folder (don't care about versioning `tests`)
var projectFiles = Directory.EnumerateFiles(Path.Combine(root, "src"), Project.FileName, SearchOption.AllDirectories);
var projectFiles = Directory.EnumerateFiles(Path.Combine(root, "src"), "*.csproj", SearchOption.AllDirectories);
ResetProject(projectFiles);
// Open them and convert them to source projects
var projects = projectFiles.Select(x => ProjectReader.GetProject(x))
var projects = projectFiles.Select(x => ProjectRootElement.Open(x, ProjectCollection.GlobalProjectCollection, true))
.Select(x => new SourceProject(x, repo.Info.WorkingDirectory))
.ToList();
if (resetmode)
{
ResetProject(projects);
}
else
if (!resetmode)
{
CaclulateProjectVersionNumber(projects, repo);
UpdateVersionNumbers(projects);
CreateBuildScript(projects);
CreateBuildScript(projects, root);
foreach (var p in projects)
{
@ -98,12 +96,14 @@ namespace ConsoleApplication
}
}
private static void CreateBuildScript(IEnumerable<SourceProject> projects)
private static void CreateBuildScript(IEnumerable<SourceProject> projects, string root)
{
var outputDir = Path.GetFullPath(Path.Combine(root, @"artifacts\bin\ImageSharp"));
var sb = new StringBuilder();
foreach (var p in projects)
{
sb.AppendLine($@"dotnet pack --configuration Release --output ""artifacts\bin\ImageSharp"" ""{p.ProjectFilePath}""");
sb.AppendLine($@"dotnet pack --configuration Release --output ""{outputDir}"" ""{p.ProjectFilePath}""");
}
File.WriteAllText("build-inner.cmd", sb.ToString());
@ -113,17 +113,17 @@ namespace ConsoleApplication
{
foreach (var p in projects)
{
// TODO force update of all dependent projects to point to the newest build.
// we skip the build number and standard CI prefix on first commits
var newVersion = p.FinalVersionNumber;
// create a backup file so we can rollback later without breaking formatting
File.Copy(p.FullProjectFilePath, $"{p.FullProjectFilePath}.bak", true);
}
dynamic projectFile = JsonConvert.DeserializeObject(File.ReadAllText(p.FullProjectFilePath));
foreach (var p in projects)
{
// TODO force update of all dependent projects to point to the newest build.
// we skip the build number and standard CI prefix on first commits
var newVersion = p.FinalVersionNumber;
projectFile.version = $"{newVersion}-*";
File.WriteAllText(p.FullProjectFilePath, JsonConvert.SerializeObject(projectFile, Formatting.Indented));
p.UpdateVersion(newVersion);
}
}
@ -168,7 +168,7 @@ namespace ConsoleApplication
projects.ForEach(x => x.CalculateVersion(repo, branch));
}
private static void ResetProject(List<SourceProject> projects)
private static void ResetProject(IEnumerable<string> projectPaths)
{
if (File.Exists("build-inner.cmd"))
{
@ -176,12 +176,12 @@ namespace ConsoleApplication
}
// revert the project.json change be reverting it but skipp all the git stuff as its not needed
foreach (var p in projects)
foreach (var p in projectPaths)
{
if (File.Exists($"{p.FullProjectFilePath}.bak"))
if (File.Exists($"{p}.bak"))
{
File.Copy($"{p.FullProjectFilePath}.bak", p.FullProjectFilePath, true);
File.Delete($"{p.FullProjectFilePath}.bak");
File.Copy($"{p}.bak", p, true);
File.Delete($"{p}.bak");
}
}
}
@ -192,21 +192,24 @@ namespace ConsoleApplication
public class SourceProject
{
private readonly IEnumerable<string> dependencies;
private readonly ProjectRootElement project;
/// <summary>
/// Initializes a new instance of the <see cref="SourceProject"/> class.
/// </summary>
/// <param name="project">The project.</param>
/// <param name="root">The root.</param>
public SourceProject(Project project, string root)
public SourceProject(ProjectRootElement project, string root)
{
this.Name = project.Name;
this.ProjectDirectory = project.ProjectDirectory.Substring(root.Length);
this.ProjectFilePath = project.ProjectFilePath.Substring(root.Length);
this.FullProjectFilePath = project.ProjectFilePath;
this.Version = project.Version;
this.dependencies = project.Dependencies.Select(x => x.Name);
this.Name = project.Properties.FirstOrDefault(x => x.Name == "AssemblyTitle").Value;
this.ProjectDirectory = project.DirectoryPath.Substring(root.Length);
this.ProjectFilePath = project.ProjectFileLocation.File.Substring(root.Length);
this.FullProjectFilePath = Path.GetFullPath(project.ProjectFileLocation.File);
this.Version = new NuGetVersion(project.Properties.FirstOrDefault(x => x.Name == "VersionPrefix").Value);
this.dependencies = project.Items.Where(x => x.ItemType == "ProjectReference").Select(x => Path.GetFullPath(Path.Combine(project.DirectoryPath, x.Include)));
this.FinalVersionNumber = this.Version.ToFullString();
this.project = project;
}
/// <summary>
@ -223,7 +226,7 @@ namespace ConsoleApplication
/// <value>
/// The version.
/// </value>
public NuGetVersion Version { get; }
public NuGetVersion Version { get; private set; }
/// <summary>
/// Gets the dependent projects.
@ -279,7 +282,18 @@ namespace ConsoleApplication
/// <param name="projects">The projects.</param>
public void PopulateDependencies(IEnumerable<SourceProject> projects)
{
this.DependentProjects = projects.Where(x => this.dependencies.Contains(x.Name)).ToList();
this.DependentProjects = projects.Where(x => this.dependencies.Contains(x.FullProjectFilePath)).ToList();
}
/// <summary>
/// Update the version number in the project file
/// </summary>
/// <param name="versionnumber">the new version number to save.</param>
internal void UpdateVersion(string versionnumber)
{
this.project.AddProperty("VersionPrefix", versionnumber);
this.Version = new NuGetVersion(versionnumber);
this.project.Save();
}
/// <summary>
@ -334,11 +348,15 @@ namespace ConsoleApplication
var blob = repo.Lookup<Blob>(projectFileChange.Oid);
using (var s = blob.GetContentStream())
{
var project = new ProjectReader().ReadProject(s, this.Name, this.FullProjectFilePath, null);
if (project.Version != this.Version)
using (var reader = XmlReader.Create(s))
{
// version changed
return false;
var proj = ProjectRootElement.Create(reader);
var version = new NuGetVersion(proj.Properties.FirstOrDefault(x => x.Name == "VersionPrefix").Value);
if (version != this.Version)
{
// version changed
return false;
}
}
}
}

2
build/build.csproj

@ -13,7 +13,7 @@
<AdditionalFiles Include="..\src\Shared\stylecop.json" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.DotNet.ProjectModel" Version="1.0.0-rc3-003121" />
<PackageReference Include="Microsoft.Build" Version="15.1.0-preview-000523-01" />
<PackageReference Include="LibGit2Sharp" Version="0.23.0" />
<PackageReference Include="StyleCop.Analyzers" Version="1.1.0-beta001">
<PrivateAssets>All</PrivateAssets>

2
src/ImageSharp.Drawing/ImageSharp.Drawing.csproj

@ -2,7 +2,7 @@
<PropertyGroup>
<Description>A cross-platform library for the processing of image files; written in C#</Description>
<AssemblyTitle>ImageSharp.Drawing</AssemblyTitle>
<VersionPrefix>1.0.0-alpha1</VersionPrefix>
<VersionPrefix>1.0.0-alpha2</VersionPrefix>
<Authors>James Jackson-South and contributors</Authors>
<TargetFrameworks>netstandard1.1;net45;net461</TargetFrameworks>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>

2
src/ImageSharp.Formats.Bmp/ImageSharp.Formats.Bmp.csproj

@ -2,7 +2,7 @@
<PropertyGroup>
<Description>A cross-platform library for the processing of image files; written in C#</Description>
<AssemblyTitle>ImageSharp.Formats.Bmp</AssemblyTitle>
<VersionPrefix>1.0.0-alpha1</VersionPrefix>
<VersionPrefix>1.0.0-alpha2</VersionPrefix>
<Authors>James Jackson-South and contributors</Authors>
<TargetFrameworks>netstandard1.1;net45;net461</TargetFrameworks>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>

2
src/ImageSharp.Formats.Gif/ImageSharp.Formats.Gif.csproj

@ -2,7 +2,7 @@
<PropertyGroup>
<Description>A cross-platform library for the processing of image files; written in C#</Description>
<AssemblyTitle>ImageSharp.Formats.Gif</AssemblyTitle>
<VersionPrefix>1.0.0-alpha1</VersionPrefix>
<VersionPrefix>1.0.0-alpha2</VersionPrefix>
<Authors>James Jackson-South and contributors</Authors>
<TargetFrameworks>netstandard1.1;net45;net461</TargetFrameworks>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>

2
src/ImageSharp.Formats.Jpeg/ImageSharp.Formats.Jpeg.csproj

@ -2,7 +2,7 @@
<PropertyGroup>
<Description>A cross-platform library for the processing of image files; written in C#</Description>
<AssemblyTitle>ImageSharp.Formats.Jpeg</AssemblyTitle>
<VersionPrefix>1.0.0-alpha1</VersionPrefix>
<VersionPrefix>1.0.0-alpha2</VersionPrefix>
<Authors>James Jackson-South and contributors</Authors>
<TargetFrameworks>netstandard1.1;net45;net461</TargetFrameworks>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>

2
src/ImageSharp.Processing/ImageSharp.Processing.csproj

@ -2,7 +2,7 @@
<PropertyGroup>
<Description>A cross-platform library for the processing of image files; written in C#</Description>
<AssemblyTitle>ImageSharp.Processing</AssemblyTitle>
<VersionPrefix>1.0.0-alpha1</VersionPrefix>
<VersionPrefix>1.0.0-alpha2</VersionPrefix>
<Authors>James Jackson-South and contributors</Authors>
<TargetFrameworks>netstandard1.1;net45;net461</TargetFrameworks>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>

2
src/ImageSharp/ImageSharp.csproj

@ -2,7 +2,7 @@
<PropertyGroup>
<Description>A cross-platform library for the processing of image files; written in C#</Description>
<AssemblyTitle>ImageSharp</AssemblyTitle>
<VersionPrefix>1.0.0-alpha1</VersionPrefix>
<VersionPrefix>1.0.0-alpha2</VersionPrefix>
<Authors>James Jackson-South and contributors</Authors>
<TargetFrameworks>netstandard1.1;net45;net461</TargetFrameworks>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>

2
tests/ImageSharp.Benchmarks/ImageSharp.Benchmarks.csproj

@ -7,7 +7,7 @@
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="BenchmarkDotNet.Diagnostics.Windows" Version="0.10.2.295" />
<PackageReference Include="BenchmarkDotNet.Diagnostics.Windows" Version="0.10.2" />
<PackageReference Include="System.Numerics.Vectors" Version="4.3.0" />
</ItemGroup>
<ItemGroup>

Loading…
Cancel
Save