Browse Source

Merge UpdateSetupInfo into UpdateAssemblyInfo.

pull/1/head
Daniel Grunwald 15 years ago
parent
commit
c190de5a0b
  1. 2
      src/Main/GlobalAssemblyInfo.template
  2. 6
      src/Setup/SharpDevelop.Setup.wixproj.user
  3. 2
      src/Setup/SharpDevelop.Setup.wixproj.user.template
  4. 2
      src/Setup/buildSetup.bat
  5. 97
      src/Tools/UpdateAssemblyInfo/Main.cs
  6. 36
      src/Tools/UpdateAssemblyInfo/Readme.txt
  7. 232
      src/Tools/UpdateSetupInfo/Main.cs
  8. 36
      src/Tools/UpdateSetupInfo/Readme.txt
  9. 52
      src/Tools/UpdateSetupInfo/UpdateSetupInfo.csproj
  10. 18
      src/Tools/UpdateSetupInfo/UpdateSetupInfo.sln

2
src/Main/GlobalAssemblyInfo.template

@ -29,7 +29,7 @@ internal static class RevisionClass @@ -29,7 +29,7 @@ internal static class RevisionClass
public const string Major = "3";
public const string Minor = "2";
public const string Build = "0";
public const string Revision = "-INSERTREVISION-";
public const string Revision = "$INSERTREVISION$";
public const string MainVersion = Major + "." + Minor;
public const string FullVersion = Major + "." + Minor + "." + Build + "." + Revision;

6
src/Setup/SharpDevelop.Setup.wixproj.user

@ -1,6 +0,0 @@ @@ -1,6 +0,0 @@
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<SetupProductBuildVersion>1</SetupProductBuildVersion>
<DefineConstants>PRODUCTBUILDVERSION=$(SetupProductBuildVersion)</DefineConstants>
</PropertyGroup>
</Project>

2
src/Setup/SharpDevelop.Setup.wixproj.user.template

@ -1,6 +1,6 @@ @@ -1,6 +1,6 @@
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<SetupProductBuildVersion>$INSERTPRODUCTBUILDVERSION$</SetupProductBuildVersion>
<SetupProductBuildVersion>$INSERTREVISION$</SetupProductBuildVersion>
<DefineConstants>PRODUCTBUILDVERSION=$(SetupProductBuildVersion)</DefineConstants>
</PropertyGroup>
</Project>

2
src/Setup/buildSetup.bat

@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
del "bin\SharpDevelop.msi"
"..\Tools\UpdateSetupInfo\bin\UpdateSetupInfo.exe"
"..\Tools\UpdateAssemblyInfo\bin\Debug\UpdateAssemblyInfo.exe"
%windir%\microsoft.net\framework\v2.0.50727\msbuild SharpDevelop.Setup.sln "/p:SharpDevelopBinPath=%CD%\..\..\bin"
@IF %ERRORLEVEL% NEQ 0 PAUSE

97
src/Tools/UpdateAssemblyInfo/Main.cs

@ -21,16 +21,34 @@ namespace UpdateAssemblyInfo @@ -21,16 +21,34 @@ namespace UpdateAssemblyInfo
// Updates the version numbers in the assembly information.
class MainClass
{
const string templateFile = "Main/GlobalAssemblyInfo.template";
const string globalAssemblyInfo = "Main/GlobalAssemblyInfo.cs";
const string configTemplateFile = "Main/StartUp/Project/app.template.config";
const string configFile = "Main/StartUp/Project/SharpDevelop.exe.config";
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;
const string globalAssemblyInfoTemplateFile = "Main/GlobalAssemblyInfo.template";
static readonly TemplateFile[] templateFiles = {
new TemplateFile {
Input = globalAssemblyInfoTemplateFile,
Output = "Main/GlobalAssemblyInfo.cs"
},
new TemplateFile {
Input = "Main/StartUp/Project/app.template.config",
Output = "Main/StartUp/Project/SharpDevelop.exe.config"
},
new TemplateFile {
Input = "Main/StartUp/Project/app.template.config",
Output = "Main/ICSharpCode.SharpDevelop.Sda/ICSharpCode.SharpDevelop.Sda.dll.config"
},
new TemplateFile {
Input = "Setup/SharpDevelop.Setup.wixproj.user.template",
Output = "Setup/SharpDevelop.Setup.wixproj.user"
},
};
class TemplateFile
{
public string Input, Output;
}
public static int Main(string[] args)
{
try {
@ -57,9 +75,7 @@ namespace UpdateAssemblyInfo @@ -57,9 +75,7 @@ namespace UpdateAssemblyInfo
return 2;
}
RetrieveRevisionNumber();
string versionNumber = GetMajorVersion() + "." + revisionNumber;
UpdateStartup();
UpdateRedirectionConfig(versionNumber);
UpdateFiles();
return 0;
}
} catch (Exception ex) {
@ -68,50 +84,29 @@ namespace UpdateAssemblyInfo @@ -68,50 +84,29 @@ namespace UpdateAssemblyInfo
}
}
static void UpdateStartup()
static void UpdateFiles()
{
string content;
using (StreamReader r = new StreamReader(templateFile)) {
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) {
// nothing changed, do not overwrite file to prevent recompilation
// every time.
return;
}
string fullVersionNumber = GetMajorVersion() + "." + revisionNumber;
foreach (var file in templateFiles) {
string content;
using (StreamReader r = new StreamReader(file.Input)) {
content = r.ReadToEnd();
}
}
using (StreamWriter w = new StreamWriter(globalAssemblyInfo, false, Encoding.UTF8)) {
w.Write(content);
}
}
static void UpdateRedirectionConfig(string fullVersionNumber)
{
string content;
using (StreamReader r = new StreamReader(configTemplateFile)) {
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) {
// nothing changed, do not overwrite file to prevent recompilation
// every time.
return;
content = content.Replace("$INSERTVERSION$", fullVersionNumber);
content = content.Replace("$INSERTREVISION$", revisionNumber);
content = content.Replace("$INSERTCOMMITHASH$", gitCommitHash);
if (File.Exists(file.Output)) {
using (StreamReader r = new StreamReader(file.Output)) {
if (r.ReadToEnd() == content) {
// nothing changed, do not overwrite file to prevent recompilation
// every time.
continue;
}
}
}
}
using (StreamWriter w = new StreamWriter(configFile, false, Encoding.UTF8)) {
w.Write(content);
}
using (StreamWriter w = new StreamWriter(configFile2, false, Encoding.UTF8)) {
w.Write(content);
using (StreamWriter w = new StreamWriter(file.Output, false, Encoding.UTF8)) {
w.Write(content);
}
}
}
@ -119,7 +114,7 @@ namespace UpdateAssemblyInfo @@ -119,7 +114,7 @@ namespace UpdateAssemblyInfo
{
string version = "?";
// Get main version from startup
using (StreamReader r = new StreamReader(templateFile)) {
using (StreamReader r = new StreamReader(globalAssemblyInfoTemplateFile)) {
string line;
while ((line = r.ReadLine()) != null) {
string search = "string Major = \"";

36
src/Tools/UpdateAssemblyInfo/Readme.txt

@ -1 +1,35 @@ @@ -1 +1,35 @@
Read doc/technotes/Versioning.html
Assembly versioning: Please read doc/technotes/Versioning.html
Updates the SharpDevelop Setup information
------------------------------------------
Product Revision (Subversion revision number)
With WiX 3 the package code and product code guids do not need to be generated by
this tool and can be autogenerated by WiX.
The build server and the buildSetup.bat executes the UpdateSetupInfo tool before
building SharpDevelop.Setup.sln. The SharpDevelop.Setup project does not use the tool.
Operation
---------
1) The SharpDevelop.Setup.wixproj.user is is generated each time the tool is run
based on the SharpDevelop.Setup.wixproj.user.template file. The product revision is inserted
into the newly generated file.
2) The build server and buildSetup.bat will run the UpdateSetupInfo tool.
This is not done by the SharpDevelop.Setup project itself intentionally so
nothing changes when building the project from inside SharpDevelop. The
modified SharpDevelop.Setup.wixproj.user need not be checked into the
repository on each build on the build server.
Creating Releases
-----------------
When creating a release either the setup msi from the build server should be
used or that generated after running buildSetup.bat. This will revision number
if the current revision has changed.

232
src/Tools/UpdateSetupInfo/Main.cs

@ -1,232 +0,0 @@ @@ -1,232 +0,0 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
using System;
using System.Globalization;
using System.IO;
using System.Text;
using SharpSvn;
namespace UpdateSetupInfo
{
/// <summary>
/// Creates the SharpDevelop.Setup.wixproj.user file based on the
/// SharpDevelop.Setup.wixproj.user.template.
/// </summary>
class UpdateApplication
{
/// <summary>
/// Path to the setup project relative to the UpdateSetupInfo.exe file.
/// </summary>
const string SetupProjectFolderRelativePath = @"..\..\..\Setup";
/// <summary>
/// Name of the setup template file.
/// </summary>
const string SetupTemplateFileName = "SharpDevelop.Setup.wixproj.user.template";
/// <summary>
/// Name of the setup project user file that will be generated.
/// </summary>
const string SetupProjectUserFileName = "SharpDevelop.Setup.wixproj.user";
const int SetupTemplateFileNotFoundReturnCode = 1;
const int UpdateSetupInfoExceptionReturnCode = 2;
/// <summary>
/// The full filename including path to the setup template file.
/// </summary>
string setupTemplateFullFileName;
/// <summary>
/// The full filename including path to the setup project user file that
/// will be generated.
/// </summary>
string setupProjectUserFullFileName;
/// <summary>
/// The folder containing the UpdateSetupInfo application.
/// </summary>
string applicationFolder;
/// <summary>
/// The file that contains the last revision number used to update the
/// template.
/// </summary>
string previousRevisionFileName;
/// <summary>
/// The folder that contains the last revision number used to update the
/// template.
/// </summary>
string previousRevisionFolder;
public UpdateApplication()
{
// Work out filenames.
applicationFolder = Path.GetDirectoryName(GetType().Assembly.Location);
string setupProjectFolder = Path.Combine(applicationFolder, SetupProjectFolderRelativePath);
setupProjectFolder = Path.GetFullPath(setupProjectFolder);
setupTemplateFullFileName = Path.Combine(setupProjectFolder, SetupTemplateFileName);
setupProjectUserFullFileName = Path.Combine(setupProjectFolder, SetupProjectUserFileName);
previousRevisionFolder = Path.Combine(setupProjectFolder, @"bin");
previousRevisionFileName = Path.Combine(previousRevisionFolder, "REVISION");
FileCopy(Path.Combine(Path.Combine(applicationFolder, subversionLibraryDir), "SharpSvn.dll"),
Path.Combine(applicationFolder, "SharpSvn.dll"));
// Set current directory to a folder that is in the repository.
Environment.CurrentDirectory = setupProjectFolder;
}
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);
}
public static int Main(string[] args)
{
try {
UpdateApplication app = new UpdateApplication();
return app.Run();
} catch (Exception ex) {
Console.WriteLine(ex.ToString());
return UpdateApplication.UpdateSetupInfoExceptionReturnCode;
}
}
public int Run()
{
// Read setup template contents.
if (!SetupTemplateFileExists) {
Console.WriteLine(String.Concat(SetupTemplateFileName, " not found. Unable to update setup information."));
return SetupTemplateFileNotFoundReturnCode;
}
string template = ReadSetupTemplate();
// Get current revision.
string currentRevision = GetCurrentRevision();
// Populate setup template.
template = PopulateSetupTemplate(template, currentRevision);
// Create setup user file.
SaveSetupUserFile(template);
return 0;
}
bool SetupUserFileExists {
get { return File.Exists(setupProjectUserFullFileName); }
}
bool SetupTemplateFileExists {
get { return File.Exists(setupTemplateFullFileName); }
}
string ReadSetupTemplate() {
using (StreamReader reader = new StreamReader(setupTemplateFullFileName, true)) {
return reader.ReadToEnd();
}
}
string PopulateSetupTemplate(string template, string revision)
{
return template.Replace("$INSERTPRODUCTBUILDVERSION$", revision);
}
string GetNewGuid()
{
return Guid.NewGuid().ToString().ToUpperInvariant();
}
void SaveSetupUserFile(string contents)
{
using (StreamWriter writer = new StreamWriter(setupProjectUserFullFileName, false, Encoding.UTF8)) {
writer.Write(contents);
}
}
const string subversionLibraryDir = @"..\..\..\Libraries\SharpSvn";
/// <summary>
/// Code taken directly from UpdateAssemblyInfo and the paths slightly modified.
/// </summary>
/// <remarks>
/// The product build version maps to the Subversion revision number.
/// </remarks>
string GetCurrentRevision()
{
string revisionNumber = null;
string oldWorkingDir = Environment.CurrentDirectory;
try {
// Set working directory so msvcp70.dll and msvcr70.dll can be found
Environment.CurrentDirectory = Path.Combine(applicationFolder, 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 Svn.Net failed: " + e.ToString());
} finally {
Environment.CurrentDirectory = oldWorkingDir;
}
if (revisionNumber == null || revisionNumber.Length == 0 || revisionNumber == "0") {
revisionNumber = ReadCurrentRevisionFromFile();
}
if (revisionNumber == null || revisionNumber.Length == 0 || revisionNumber == "0") {
throw new ApplicationException("Error reading revision number");
}
return revisionNumber;
}
string ReadCurrentRevisionFromFile()
{
using (StreamReader reader = new StreamReader(Path.Combine(applicationFolder, @"..\..\..\..\REVISION"))) {
return reader.ReadLine();
}
}
/// <summary>
/// Checks that the current revision matches the revision last used to
/// update the SharpDevelop.Setup.wixproj.user file.
/// </summary>
bool RevisionExists(string currentRevision)
{
// Read previous revision.
string previousRevision = ReadPreviousRevision();
if (previousRevision != null) {
return previousRevision == currentRevision;
}
return false;
}
/// <summary>
/// Reads the previous revision number from the Setup\bin\REVISION file.
/// </summary>
string ReadPreviousRevision()
{
if (File.Exists(previousRevisionFileName)) {
using (StreamReader reader = new StreamReader(previousRevisionFileName, true)) {
return reader.ReadLine();
}
}
return null;
}
}
}

36
src/Tools/UpdateSetupInfo/Readme.txt

@ -1,36 +0,0 @@ @@ -1,36 +0,0 @@

Updates the SharpDevelop Setup information
------------------------------------------
Product Revision (Subversion revision number)
With WiX 3 the package code and product code guids do not need to be generated by
this tool and can be autogenerated by WiX.
The build server and the buildSetup.bat executes the UpdateSetupInfo tool before
building SharpDevelop.Setup.sln. The SharpDevelop.Setup project does not use the tool.
Operation
---------
1) The SharpDevelop.Setup.wixproj.user is is generated each time the tool is run
based on the SharpDevelop.Setup.wixproj.user.template file. The product revision is inserted
into the newly generated file. The last used revision is written to a REVISION
file which is put in the Setup\bin folder. This not in the repository and is only
used to stop the tool from regenerating the product guid if the revision number has not
changed.
2) The build server and buildSetup.bat will run the UpdateSetupInfo tool.
This is not done by the SharpDevelop.Setup project itself intentionally so
nothing changes when building the project from inside SharpDevelop. The
modified SharpDevelop.Setup.wixproj.user need not be checked into the
repository on each build on the build server.
Creating Releases
-----------------
When creating a release either the setup msi from the build server should be
used or that generated after running buildSetup.bat. This will revision number
if the current revision has changed.

52
src/Tools/UpdateSetupInfo/UpdateSetupInfo.csproj

@ -1,52 +0,0 @@ @@ -1,52 +0,0 @@
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5">
<PropertyGroup>
<OutputType>Exe</OutputType>
<RootNamespace>UpdateSetupInfo</RootNamespace>
<AssemblyName>UpdateSetupInfo</AssemblyName>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{75E6D78C-DC66-40F1-90AC-F9F97ADE3506}</ProjectGuid>
<AllowUnsafeBlocks>False</AllowUnsafeBlocks>
<NoStdLib>False</NoStdLib>
<RegisterForComInterop>False</RegisterForComInterop>
<GenerateSerializationAssemblies>Auto</GenerateSerializationAssemblies>
<BaseAddress>4194304</BaseAddress>
<PlatformTarget>x86</PlatformTarget>
<FileAlignment>4096</FileAlignment>
<WarningLevel>4</WarningLevel>
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
<OutputPath>bin</OutputPath>
<SourceAnalysisOverrideSettingsFile>C:\Users\Daniel\AppData\Roaming\ICSharpCode/SharpDevelop3.0\Settings.SourceAnalysis</SourceAnalysisOverrideSettingsFile>
<TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<IntermediateOutputPath>obj\Debug\</IntermediateOutputPath>
<Optimize>False</Optimize>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DebugSymbols>true</DebugSymbols>
<DebugType>Full</DebugType>
<CheckForOverflowUnderflow>True</CheckForOverflowUnderflow>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<IntermediateOutputPath>obj\Release\</IntermediateOutputPath>
<Optimize>True</Optimize>
<DefineConstants>TRACE</DefineConstants>
<DebugSymbols>False</DebugSymbols>
<DebugType>None</DebugType>
<CheckForOverflowUnderflow>False</CheckForOverflowUnderflow>
</PropertyGroup>
<ItemGroup>
<Reference Include="SharpSvn">
<HintPath>..\..\Libraries\SharpSvn\SharpSvn.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="System" />
</ItemGroup>
<ItemGroup>
<Compile Include="Main.cs" />
</ItemGroup>
<ItemGroup>
<Content Include="Readme.txt" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.Targets" />
</Project>

18
src/Tools/UpdateSetupInfo/UpdateSetupInfo.sln

@ -1,18 +0,0 @@ @@ -1,18 +0,0 @@

Microsoft Visual Studio Solution File, Format Version 10.00
# Visual Studio 2008
# SharpDevelop 3.1.0.3932
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UpdateSetupInfo", "UpdateSetupInfo.csproj", "{75E6D78C-DC66-40F1-90AC-F9F97ADE3506}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{75E6D78C-DC66-40F1-90AC-F9F97ADE3506}.Debug|Any CPU.Build.0 = Debug|Any CPU
{75E6D78C-DC66-40F1-90AC-F9F97ADE3506}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{75E6D78C-DC66-40F1-90AC-F9F97ADE3506}.Release|Any CPU.Build.0 = Release|Any CPU
{75E6D78C-DC66-40F1-90AC-F9F97ADE3506}.Release|Any CPU.ActiveCfg = Release|Any CPU
EndGlobalSection
EndGlobal
Loading…
Cancel
Save