Skip to content

Commit

Permalink
CKAN client version now supplied by Meta.Version();
Browse files Browse the repository at this point in the history
Also fixed the build system so this actually gets found again.
  • Loading branch information
pjf committed Oct 17, 2014
1 parent c5ed1c3 commit a5c7062
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 27 deletions.
1 change: 1 addition & 0 deletions CKAN/CKAN/CKAN.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
<Compile Include="Types\KSPVersion.cs" />
<Compile Include="Types\JsonSimpleStringConverter.cs" />
<Compile Include="Repo.cs" />
<Compile Include="Meta.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ItemGroup>
Expand Down
27 changes: 27 additions & 0 deletions CKAN/CKAN/Meta.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
namespace CKAN {
using System;
using System.Reflection;

public static class Meta {
/// <summary>
/// Returns the version of the CKAN.dll used.
/// </summary>

public static string Version() {

var assembly = Assembly.GetExecutingAssembly();

// SeriouslyLongestClassNamesEverThanksMicrosoft
var attr = (AssemblyInformationalVersionAttribute[]) assembly.GetCustomAttributes (typeof(AssemblyInformationalVersionAttribute), false);

if (attr.Length == 0 || attr [0].InformationalVersion == null) {
// Dunno the version. Some dev probably built it.
return "development";
} else {
return attr[0].InformationalVersion;
}

}
}
}

10 changes: 1 addition & 9 deletions CKAN/CmdLine/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,15 +131,7 @@ static int Gui() {

static int Version() {

// SeriouslyLongestClassNamesEverThanksMicrosoft
var assemblies = (AssemblyInformationalVersionAttribute[]) Assembly.GetAssembly (typeof(MainClass)).GetCustomAttributes (typeof(AssemblyInformationalVersionAttribute), false);

if (assemblies.Length == 0 || assemblies[0].InformationalVersion == null) {
// Dunno the version. Some dev probably built it.
User.WriteLine ("development");
} else {
User.WriteLine (assemblies[0].InformationalVersion);
}
User.WriteLine (Meta.Version ());

return EXIT_OK;
}
Expand Down
11 changes: 1 addition & 10 deletions CKAN/GUI/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,8 @@ private void Main_Load(object sender, EventArgs e)

ApplyToolButton.Enabled = false;

var assemblies = (AssemblyInformationalVersionAttribute[])Assembly.GetAssembly(typeof(RegistryManager)).GetCustomAttributes(typeof(AssemblyInformationalVersionAttribute), false);
Text = "CKAN (" + Meta.Version() + ")";

if (assemblies.Length == 0 || assemblies[0].InformationalVersion == null)
{
// Dunno the version. Some dev probably built it.
Text = "CKAN (development)";
}
else
{
Text = String.Format("CKAN {0}", assemblies[0].InformationalVersion);
}
}

private static Main m_Instance = null;
Expand Down
15 changes: 11 additions & 4 deletions bin/build
Original file line number Diff line number Diff line change
Expand Up @@ -1153,7 +1153,11 @@ my $BUILD = "$Bin/../build";
my $SOURCE = "$Bin/../CKAN";
my @CP = qw(cp -r --reflink=auto --sparse=always);
my $VERSION = capturex(qw(git describe --long));
my $ASSEMBLY_INFO = File::Spec->catdir($BUILD,"CKAN/Properties/AssemblyInfo.cs");
my @ASSEMBLY_INFO = (
File::Spec->catdir($BUILD,"CKAN/Properties/AssemblyInfo.cs"),
File::Spec->catdir($BUILD,"CmdLine/Properties/AssemblyInfo.cs"),
File::Spec->catdir($BUILD,"GUI/Properties/AssemblyInfo.cs"),
);

# Remove newline
chomp($VERSION);
Expand All @@ -1169,9 +1173,12 @@ remove_tree(File::Spec->catdir($BUILD, "CKAN/bin"));
remove_tree(File::Spec->catdir($BUILD, "CKAN/obj"));

# Before we build, add our version number in.
open(my $assembly_fh, ">>", $ASSEMBLY_INFO);
say {$assembly_fh} qq{[assembly: AssemblyInformationalVersion ("$VERSION")]};
close($assembly_fh);

foreach my $assembly (@ASSEMBLY_INFO) {
open(my $assembly_fh, ">>", $assembly);
say {$assembly_fh} qq{[assembly: AssemblyInformationalVersion ("$VERSION")]};
close($assembly_fh);
}

# Change to our build directory
chdir($BUILD);
Expand Down
15 changes: 11 additions & 4 deletions bin/build.lean
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ my $BUILD = "$Bin/../build";
my $SOURCE = "$Bin/../CKAN";
my @CP = qw(cp -r --reflink=auto --sparse=always);
my $VERSION = capturex(qw(git describe --long));
my $ASSEMBLY_INFO = File::Spec->catdir($BUILD,"CKAN/Properties/AssemblyInfo.cs");
my @ASSEMBLY_INFO = (
File::Spec->catdir($BUILD,"CKAN/Properties/AssemblyInfo.cs"),
File::Spec->catdir($BUILD,"CmdLine/Properties/AssemblyInfo.cs"),
File::Spec->catdir($BUILD,"GUI/Properties/AssemblyInfo.cs"),
);

# Remove newline
chomp($VERSION);
Expand All @@ -33,9 +37,12 @@ remove_tree(File::Spec->catdir($BUILD, "CKAN/bin"));
remove_tree(File::Spec->catdir($BUILD, "CKAN/obj"));

# Before we build, add our version number in.
open(my $assembly_fh, ">>", $ASSEMBLY_INFO);
say {$assembly_fh} qq{[assembly: AssemblyInformationalVersion ("$VERSION")]};
close($assembly_fh);

foreach my $assembly (@ASSEMBLY_INFO) {
open(my $assembly_fh, ">>", $assembly);
say {$assembly_fh} qq{[assembly: AssemblyInformationalVersion ("$VERSION")]};
close($assembly_fh);
}

# Change to our build directory
chdir($BUILD);
Expand Down

0 comments on commit a5c7062

Please sign in to comment.