Browse Source

Change UpdateAssemblyInfo to use git.

pull/1/head
Daniel Grunwald 15 years ago
parent
commit
7674a910ad
  1. 97
      src/Tools/UpdateAssemblyInfo/Main.cs
  2. 17
      src/Tools/UpdateAssemblyInfo/UpdateAssemblyInfo.csproj

97
src/Tools/UpdateAssemblyInfo/Main.cs

@ -14,7 +14,6 @@ using System.Runtime.CompilerServices; @@ -14,7 +14,6 @@ using System.Runtime.CompilerServices;
using System.Text;
using System.Text.RegularExpressions;
using SharpSvn;
using System.Threading;
namespace UpdateAssemblyInfo
@ -29,6 +28,9 @@ namespace UpdateAssemblyInfo @@ -29,6 +28,9 @@ namespace UpdateAssemblyInfo
const string configFile2 = "Main/ICSharpCode.SharpDevelop.Sda/ICSharpCode.SharpDevelop.Sda.dll.config";
const string subversionLibraryDir = "Libraries/SharpSvn";
const string BaseCommit = "69a9221f57e6b184010f5bad16aa181ced91a0df";
const int BaseCommitRev = 6351;
public static int Main(string[] args)
{
try {
@ -54,8 +56,6 @@ namespace UpdateAssemblyInfo @@ -54,8 +56,6 @@ namespace UpdateAssemblyInfo
Console.WriteLine("Working directory must be SharpDevelop\\src!");
return 2;
}
FileCopy(Path.Combine(subversionLibraryDir, "SharpSvn.dll"),
Path.Combine(exeDir, "SharpSvn.dll"));
RetrieveRevisionNumber();
string versionNumber = GetMajorVersion() + "." + revisionNumber;
UpdateStartup();
@ -68,16 +68,6 @@ namespace UpdateAssemblyInfo @@ -68,16 +68,6 @@ namespace UpdateAssemblyInfo
}
}
static void FileCopy(string source, string target)
{
if (File.Exists(target)) {
// don't copy file if it is up-to-date: repeatedly copying a 3 MB file slows down the build
if (File.GetLastWriteTimeUtc(source) == File.GetLastWriteTimeUtc(target))
return;
}
File.Copy(source, target, true);
}
static void UpdateStartup()
{
string content;
@ -85,6 +75,7 @@ namespace UpdateAssemblyInfo @@ -85,6 +75,7 @@ namespace UpdateAssemblyInfo
content = r.ReadToEnd();
}
content = content.Replace("-INSERTREVISION-", revisionNumber);
content = content.Replace("-INSERTCOMMITHASH-", gitCommitHash);
if (File.Exists(globalAssemblyInfo)) {
using (StreamReader r = new StreamReader(globalAssemblyInfo)) {
if (r.ReadToEnd() == content) {
@ -106,6 +97,7 @@ namespace UpdateAssemblyInfo @@ -106,6 +97,7 @@ namespace UpdateAssemblyInfo
content = r.ReadToEnd();
}
content = content.Replace("$INSERTVERSION$", fullVersionNumber);
content = content.Replace("$INSERTCOMMITHASH$", gitCommitHash);
if (File.Exists(configFile) && File.Exists(configFile2)) {
using (StreamReader r = new StreamReader(configFile)) {
if (r.ReadToEnd() == content) {
@ -168,12 +160,50 @@ namespace UpdateAssemblyInfo @@ -168,12 +160,50 @@ namespace UpdateAssemblyInfo
}
#region Retrieve Revision Number
static string revisionNumber = "0";
static string ReadRevisionFromFile()
static string revisionNumber;
static string gitCommitHash;
static void RetrieveRevisionNumber()
{
if (revisionNumber == null) {
if (Directory.Exists("..\\..\\.git")) {
ReadRevisionNumberFromGit();
}
}
if (revisionNumber == null) {
ReadRevisionFromFile();
}
}
static void ReadRevisionNumberFromGit()
{
ProcessStartInfo info = new ProcessStartInfo("cmd", "/c git rev-list " + BaseCommit + "..HEAD");
info.RedirectStandardOutput = true;
info.UseShellExecute = false;
using (Process p = Process.Start(info)) {
string line;
int revNum = BaseCommitRev;
while ((line = p.StandardOutput.ReadLine()) != null) {
if (gitCommitHash == null) {
// first entry is HEAD
gitCommitHash = line;
}
revNum++;
}
revisionNumber = revNum.ToString();
p.WaitForExit();
if (p.ExitCode != 0)
throw new Exception("git-rev-list exit code was " + p.ExitCode);
}
}
static void ReadRevisionFromFile()
{
try {
using (StreamReader reader = new StreamReader(@"..\REVISION")) {
return reader.ReadLine();
revisionNumber = reader.ReadLine();
gitCommitHash = reader.ReadLine();
}
} catch (Exception e) {
Console.WriteLine(e.Message);
@ -181,40 +211,9 @@ namespace UpdateAssemblyInfo @@ -181,40 +211,9 @@ namespace UpdateAssemblyInfo
Console.WriteLine("The revision number of the SharpDevelop version being compiled could not be retrieved.");
Console.WriteLine();
Console.WriteLine("Build continues with revision number '0'...");
try {
Process[] p = Process.GetProcessesByName("msbuild");
if (p != null && p.Length > 0) {
System.Threading.Thread.Sleep(3000);
}
} catch {}
return "0";
}
}
static void RetrieveRevisionNumber()
{
string oldWorkingDir = Environment.CurrentDirectory;
try {
// Change working dir so that the subversion libraries can be found
Environment.CurrentDirectory = Path.Combine(Environment.CurrentDirectory, subversionLibraryDir);
using (SvnClient client = new SvnClient()) {
client.Info(
oldWorkingDir,
(sender, info) => {
revisionNumber = info.Revision.ToString(CultureInfo.InvariantCulture);
});
}
} catch (Exception e) {
Console.WriteLine("Reading revision number with SharpSvn failed: " + e.ToString());
} finally {
Environment.CurrentDirectory = oldWorkingDir;
}
if (revisionNumber == null || revisionNumber.Length == 0 || revisionNumber == "0") {
revisionNumber = ReadRevisionFromFile();
}
if (revisionNumber == null || revisionNumber.Length == 0 || revisionNumber == "0") {
throw new ApplicationException("Error reading revision number");
revisionNumber = "0";
gitCommitHash = null;
}
}
#endregion

17
src/Tools/UpdateAssemblyInfo/UpdateAssemblyInfo.csproj

@ -1,4 +1,5 @@ @@ -1,4 +1,5 @@
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5">
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5">
<PropertyGroup>
<OutputType>Exe</OutputType>
<RootNamespace>UpdateAssemblyInfo</RootNamespace>
@ -9,7 +10,6 @@ @@ -9,7 +10,6 @@
<AllowUnsafeBlocks>False</AllowUnsafeBlocks>
<CheckForOverflowUnderflow>False</CheckForOverflowUnderflow>
<NoStdLib>False</NoStdLib>
<DebugType>PdbOnly</DebugType>
<RegisterForComInterop>False</RegisterForComInterop>
<GenerateSerializationAssemblies>Auto</GenerateSerializationAssemblies>
<BaseAddress>4194304</BaseAddress>
@ -17,7 +17,6 @@ @@ -17,7 +17,6 @@
<FileAlignment>4096</FileAlignment>
<WarningLevel>4</WarningLevel>
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
<DebugSymbols>false</DebugSymbols>
<NoWarn>1607</NoWarn>
<TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
<ApplicationManifest>app.manifest</ApplicationManifest>
@ -33,11 +32,15 @@ @@ -33,11 +32,15 @@
<Optimize>true</Optimize>
<DefineConstants>TRACE</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<DebugType>Full</DebugType>
<DebugSymbols>true</DebugSymbols>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<DebugType>None</DebugType>
<DebugSymbols>false</DebugSymbols>
</PropertyGroup>
<ItemGroup>
<Reference Include="SharpSvn">
<HintPath>..\..\Libraries\SharpSvn\SharpSvn.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />

Loading…
Cancel
Save