Browse Source

migrate build script to csproj

bump version number due to project file type changing we are reseting the build counter.
af/merge-core
Scott Williams 9 years ago
parent
commit
4568430f25
  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
**/BenchmarkDotNet.Artifacts/ **/BenchmarkDotNet.Artifacts/
# Build process
*.csproj.bak
#CodeCoverage #CodeCoverage
**/CodeCoverage/* **/CodeCoverage/*

98
build/Program.cs

@ -10,10 +10,10 @@ namespace ConsoleApplication
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Xml;
using LibGit2Sharp; using LibGit2Sharp;
using Microsoft.DotNet.ProjectModel; using Microsoft.Build.Construction;
using Newtonsoft.Json; using Microsoft.Build.Evaluation;
using NuGet.Versioning; using NuGet.Versioning;
/// <summary> /// <summary>
@ -65,31 +65,29 @@ namespace ConsoleApplication
{ {
var resetmode = args.Contains("reset"); var resetmode = args.Contains("reset");
// Find the project root where glbal.json lives // Find the project root
var root = ProjectRootResolver.ResolveRootDirectory("."); var root = Path.GetFullPath(Path.Combine(LibGit2Sharp.Repository.Discover("."), ".."));
// Lets find the repo // Lets find the repo
var repo = new LibGit2Sharp.Repository(root); var repo = new LibGit2Sharp.Repository(root);
// Lets find all the project.json files in the src folder (don't care about versioning `tests`) // 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 // 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)) .Select(x => new SourceProject(x, repo.Info.WorkingDirectory))
.ToList(); .ToList();
if (resetmode) if (!resetmode)
{
ResetProject(projects);
}
else
{ {
CaclulateProjectVersionNumber(projects, repo); CaclulateProjectVersionNumber(projects, repo);
UpdateVersionNumbers(projects); UpdateVersionNumbers(projects);
CreateBuildScript(projects); CreateBuildScript(projects, root);
foreach (var p in projects) 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(); var sb = new StringBuilder();
foreach (var p in projects) 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()); File.WriteAllText("build-inner.cmd", sb.ToString());
@ -113,17 +113,17 @@ namespace ConsoleApplication
{ {
foreach (var p in projects) 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 // create a backup file so we can rollback later without breaking formatting
File.Copy(p.FullProjectFilePath, $"{p.FullProjectFilePath}.bak", true); 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}-*"; p.UpdateVersion(newVersion);
File.WriteAllText(p.FullProjectFilePath, JsonConvert.SerializeObject(projectFile, Formatting.Indented));
} }
} }
@ -168,7 +168,7 @@ namespace ConsoleApplication
projects.ForEach(x => x.CalculateVersion(repo, branch)); 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")) 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 // 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.Copy($"{p}.bak", p, true);
File.Delete($"{p.FullProjectFilePath}.bak"); File.Delete($"{p}.bak");
} }
} }
} }
@ -192,21 +192,24 @@ namespace ConsoleApplication
public class SourceProject public class SourceProject
{ {
private readonly IEnumerable<string> dependencies; private readonly IEnumerable<string> dependencies;
private readonly ProjectRootElement project;
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="SourceProject"/> class. /// Initializes a new instance of the <see cref="SourceProject"/> class.
/// </summary> /// </summary>
/// <param name="project">The project.</param> /// <param name="project">The project.</param>
/// <param name="root">The root.</param> /// <param name="root">The root.</param>
public SourceProject(Project project, string root) public SourceProject(ProjectRootElement project, string root)
{ {
this.Name = project.Name; this.Name = project.Properties.FirstOrDefault(x => x.Name == "AssemblyTitle").Value;
this.ProjectDirectory = project.ProjectDirectory.Substring(root.Length);
this.ProjectFilePath = project.ProjectFilePath.Substring(root.Length); this.ProjectDirectory = project.DirectoryPath.Substring(root.Length);
this.FullProjectFilePath = project.ProjectFilePath; this.ProjectFilePath = project.ProjectFileLocation.File.Substring(root.Length);
this.Version = project.Version; this.FullProjectFilePath = Path.GetFullPath(project.ProjectFileLocation.File);
this.dependencies = project.Dependencies.Select(x => x.Name); 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.FinalVersionNumber = this.Version.ToFullString();
this.project = project;
} }
/// <summary> /// <summary>
@ -223,7 +226,7 @@ namespace ConsoleApplication
/// <value> /// <value>
/// The version. /// The version.
/// </value> /// </value>
public NuGetVersion Version { get; } public NuGetVersion Version { get; private set; }
/// <summary> /// <summary>
/// Gets the dependent projects. /// Gets the dependent projects.
@ -279,7 +282,18 @@ namespace ConsoleApplication
/// <param name="projects">The projects.</param> /// <param name="projects">The projects.</param>
public void PopulateDependencies(IEnumerable<SourceProject> projects) 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> /// <summary>
@ -334,11 +348,15 @@ namespace ConsoleApplication
var blob = repo.Lookup<Blob>(projectFileChange.Oid); var blob = repo.Lookup<Blob>(projectFileChange.Oid);
using (var s = blob.GetContentStream()) using (var s = blob.GetContentStream())
{ {
var project = new ProjectReader().ReadProject(s, this.Name, this.FullProjectFilePath, null); using (var reader = XmlReader.Create(s))
if (project.Version != this.Version)
{ {
// version changed var proj = ProjectRootElement.Create(reader);
return false; 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" /> <AdditionalFiles Include="..\src\Shared\stylecop.json" />
</ItemGroup> </ItemGroup>
<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="LibGit2Sharp" Version="0.23.0" />
<PackageReference Include="StyleCop.Analyzers" Version="1.1.0-beta001"> <PackageReference Include="StyleCop.Analyzers" Version="1.1.0-beta001">
<PrivateAssets>All</PrivateAssets> <PrivateAssets>All</PrivateAssets>

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

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

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

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

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

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

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

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

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

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

2
src/ImageSharp/ImageSharp.csproj

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

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

@ -7,7 +7,7 @@
<Prefer32Bit>false</Prefer32Bit> <Prefer32Bit>false</Prefer32Bit>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <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" /> <PackageReference Include="System.Numerics.Vectors" Version="4.3.0" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

Loading…
Cancel
Save