Browse Source

Change UpdateAssemblyInfo to use git.

pull/1/head
Daniel Grunwald 16 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;
using System.Text; using System.Text;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using SharpSvn;
using System.Threading; using System.Threading;
namespace UpdateAssemblyInfo namespace UpdateAssemblyInfo
@ -29,6 +28,9 @@ namespace UpdateAssemblyInfo
const string configFile2 = "Main/ICSharpCode.SharpDevelop.Sda/ICSharpCode.SharpDevelop.Sda.dll.config"; const string configFile2 = "Main/ICSharpCode.SharpDevelop.Sda/ICSharpCode.SharpDevelop.Sda.dll.config";
const string subversionLibraryDir = "Libraries/SharpSvn"; const string subversionLibraryDir = "Libraries/SharpSvn";
const string BaseCommit = "69a9221f57e6b184010f5bad16aa181ced91a0df";
const int BaseCommitRev = 6351;
public static int Main(string[] args) public static int Main(string[] args)
{ {
try { try {
@ -54,8 +56,6 @@ namespace UpdateAssemblyInfo
Console.WriteLine("Working directory must be SharpDevelop\\src!"); Console.WriteLine("Working directory must be SharpDevelop\\src!");
return 2; return 2;
} }
FileCopy(Path.Combine(subversionLibraryDir, "SharpSvn.dll"),
Path.Combine(exeDir, "SharpSvn.dll"));
RetrieveRevisionNumber(); RetrieveRevisionNumber();
string versionNumber = GetMajorVersion() + "." + revisionNumber; string versionNumber = GetMajorVersion() + "." + revisionNumber;
UpdateStartup(); UpdateStartup();
@ -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() static void UpdateStartup()
{ {
string content; string content;
@ -85,6 +75,7 @@ namespace UpdateAssemblyInfo
content = r.ReadToEnd(); content = r.ReadToEnd();
} }
content = content.Replace("-INSERTREVISION-", revisionNumber); content = content.Replace("-INSERTREVISION-", revisionNumber);
content = content.Replace("-INSERTCOMMITHASH-", gitCommitHash);
if (File.Exists(globalAssemblyInfo)) { if (File.Exists(globalAssemblyInfo)) {
using (StreamReader r = new StreamReader(globalAssemblyInfo)) { using (StreamReader r = new StreamReader(globalAssemblyInfo)) {
if (r.ReadToEnd() == content) { if (r.ReadToEnd() == content) {
@ -106,6 +97,7 @@ namespace UpdateAssemblyInfo
content = r.ReadToEnd(); content = r.ReadToEnd();
} }
content = content.Replace("$INSERTVERSION$", fullVersionNumber); content = content.Replace("$INSERTVERSION$", fullVersionNumber);
content = content.Replace("$INSERTCOMMITHASH$", gitCommitHash);
if (File.Exists(configFile) && File.Exists(configFile2)) { if (File.Exists(configFile) && File.Exists(configFile2)) {
using (StreamReader r = new StreamReader(configFile)) { using (StreamReader r = new StreamReader(configFile)) {
if (r.ReadToEnd() == content) { if (r.ReadToEnd() == content) {
@ -168,12 +160,50 @@ namespace UpdateAssemblyInfo
} }
#region Retrieve Revision Number #region Retrieve Revision Number
static string revisionNumber = "0"; static string revisionNumber;
static string ReadRevisionFromFile() 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 { try {
using (StreamReader reader = new StreamReader(@"..\REVISION")) { using (StreamReader reader = new StreamReader(@"..\REVISION")) {
return reader.ReadLine(); revisionNumber = reader.ReadLine();
gitCommitHash = reader.ReadLine();
} }
} catch (Exception e) { } catch (Exception e) {
Console.WriteLine(e.Message); Console.WriteLine(e.Message);
@ -181,40 +211,9 @@ namespace UpdateAssemblyInfo
Console.WriteLine("The revision number of the SharpDevelop version being compiled could not be retrieved."); Console.WriteLine("The revision number of the SharpDevelop version being compiled could not be retrieved.");
Console.WriteLine(); Console.WriteLine();
Console.WriteLine("Build continues with revision number '0'..."); 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()) { revisionNumber = "0";
client.Info( gitCommitHash = null;
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");
} }
} }
#endregion #endregion

17
src/Tools/UpdateAssemblyInfo/UpdateAssemblyInfo.csproj

@ -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> <PropertyGroup>
<OutputType>Exe</OutputType> <OutputType>Exe</OutputType>
<RootNamespace>UpdateAssemblyInfo</RootNamespace> <RootNamespace>UpdateAssemblyInfo</RootNamespace>
@ -9,7 +10,6 @@
<AllowUnsafeBlocks>False</AllowUnsafeBlocks> <AllowUnsafeBlocks>False</AllowUnsafeBlocks>
<CheckForOverflowUnderflow>False</CheckForOverflowUnderflow> <CheckForOverflowUnderflow>False</CheckForOverflowUnderflow>
<NoStdLib>False</NoStdLib> <NoStdLib>False</NoStdLib>
<DebugType>PdbOnly</DebugType>
<RegisterForComInterop>False</RegisterForComInterop> <RegisterForComInterop>False</RegisterForComInterop>
<GenerateSerializationAssemblies>Auto</GenerateSerializationAssemblies> <GenerateSerializationAssemblies>Auto</GenerateSerializationAssemblies>
<BaseAddress>4194304</BaseAddress> <BaseAddress>4194304</BaseAddress>
@ -17,7 +17,6 @@
<FileAlignment>4096</FileAlignment> <FileAlignment>4096</FileAlignment>
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
<TreatWarningsAsErrors>false</TreatWarningsAsErrors> <TreatWarningsAsErrors>false</TreatWarningsAsErrors>
<DebugSymbols>false</DebugSymbols>
<NoWarn>1607</NoWarn> <NoWarn>1607</NoWarn>
<TargetFrameworkVersion>v2.0</TargetFrameworkVersion> <TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
<ApplicationManifest>app.manifest</ApplicationManifest> <ApplicationManifest>app.manifest</ApplicationManifest>
@ -33,11 +32,15 @@
<Optimize>true</Optimize> <Optimize>true</Optimize>
<DefineConstants>TRACE</DefineConstants> <DefineConstants>TRACE</DefineConstants>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<DebugType>Full</DebugType>
<DebugSymbols>true</DebugSymbols>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<DebugType>None</DebugType>
<DebugSymbols>false</DebugSymbols>
</PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="SharpSvn">
<HintPath>..\..\Libraries\SharpSvn\SharpSvn.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="System" /> <Reference Include="System" />
<Reference Include="System.Data" /> <Reference Include="System.Data" />
<Reference Include="System.Xml" /> <Reference Include="System.Xml" />

Loading…
Cancel
Save