Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate Win32 version string based on build no, git tag or fallback to changelog #1730

Merged
merged 27 commits into from
Apr 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
1662678
fixed line endings
DRSDavidSoft Mar 28, 2018
a85cd81
added version resources and manifest.
DRSDavidSoft Mar 28, 2018
dc9e385
add cmder manifest file
DRSDavidSoft Mar 28, 2018
96736fe
added version.rc2.sample
DRSDavidSoft Mar 28, 2018
f4321bb
add functions to get version and generate rc
DRSDavidSoft Mar 28, 2018
eaf7048
add automatic version creation
DRSDavidSoft Mar 28, 2018
249f7b9
add build flags; use spaces
DRSDavidSoft Mar 28, 2018
f8359fc
add verbose version info
DRSDavidSoft Mar 28, 2018
018bf45
add version string handler
DRSDavidSoft Mar 28, 2018
57a28f1
add template for version string
DRSDavidSoft Mar 28, 2018
3aeca3c
add required block to else statement
DRSDavidSoft Mar 28, 2018
ae473ec
add escaped quotes handling
DRSDavidSoft Mar 28, 2018
2bc17c4
renamed app.manifest
DRSDavidSoft Mar 28, 2018
1dadade
replaces spaces to tabs
DRSDavidSoft Mar 28, 2018
cb4d95e
added build number, removed duplicated manifest
DRSDavidSoft Mar 28, 2018
2f3f1d4
specified custom manifest file
DRSDavidSoft Mar 28, 2018
236aefe
add build version string
DRSDavidSoft Mar 28, 2018
c817df2
add build version str; fix padding
DRSDavidSoft Mar 28, 2018
624deec
minor edit – added a character to the verbose output
DRSDavidSoft Mar 28, 2018
93d2c42
respect powershell naming convention
DRSDavidSoft Mar 28, 2018
3965852
clean before build
DRSDavidSoft Mar 28, 2018
b36b8a4
new version handle logic
DRSDavidSoft Mar 30, 2018
502129d
minor fix
DRSDavidSoft Mar 30, 2018
5c3f46f
fix git detection statement
DRSDavidSoft Mar 30, 2018
7d04ded
add appveyor message
DRSDavidSoft Mar 30, 2018
d656919
replace tabs to spaces
DRSDavidSoft Mar 30, 2018
94e7c24
minor typo fix
DRSDavidSoft Mar 30, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion launcher/CmderLauncher.vcxproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
Expand Down Expand Up @@ -61,6 +61,9 @@
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
<Manifest>
<AdditionalManifestFiles>src/app.manifest %(AdditionalManifestFiles)</AdditionalManifestFiles>
</Manifest>
<ResourceCompile>
<PreprocessorDefinitions>_USING_V110_SDK71_;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ResourceCompile>
Expand All @@ -84,6 +87,9 @@
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
<Manifest>
<AdditionalManifestFiles>src/app.manifest %(AdditionalManifestFiles)</AdditionalManifestFiles>
</Manifest>
<PostBuildEvent>
<Command>copy $(TargetPath) $(SolutionDir)..\$(TargetFileName)</Command>
</PostBuildEvent>
Expand Down
Binary file modified launcher/src/Resource.rc
Binary file not shown.
54 changes: 54 additions & 0 deletions launcher/src/app.manifest
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>

<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0" xmlns:asmv3="urn:schemas-microsoft-com:asm.v3">

<!-- Project description definition -->
<description>Cmder Console Emulator</description>

<!-- Project dependency definition -->
<dependency>
<dependentAssembly>
<assemblyIdentity
type="win32"
name="Microsoft.Windows.Common-Controls"
version="6.0.0.0" processorArchitecture="*"
publicKeyToken="6595b64144ccf1df"
language="*" />
</dependentAssembly>
</dependency>

<!-- Win32 User Account Control definition -->
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
<security>
<requestedPrivileges>
<requestedExecutionLevel
level="asInvoker"
uiAccess="false" />
</requestedPrivileges>
</security>
</trustInfo>

<!-- Required for appcompat behaviour -->
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
<application>
<!-- Windows Vista -->
<supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}"/>
<!-- Windows 7 -->
<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/>
<!-- Windows 8 -->
<supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}"/>
<!-- Windows 8.1 -->
<supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}"/>
<!-- Windows 10 -->
<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}"/>
</application>
</compatibility>

<!-- Add dpi awareness -->
<asmv3:application>
<asmv3:windowsSettings xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">
<dpiAware>true/pm</dpiAware>
</asmv3:windowsSettings>
</asmv3:application>

</assembly>
27 changes: 27 additions & 0 deletions launcher/src/version.rc2.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@

/**
* WARNING: do NOT modify this file! the content of this file should be
* automatically genereted before AppVeyor builds using the
* respective .ps1 Powershell scripts.
*
*/

/////////////////////////////////////////////////////////////////////////////
// Define the version numbers and build information manually here:

#define CMDER_MAJOR_VERSION {Cmder-Major-Version}
#define CMDER_MINOR_VERSION {Cmder-Minor-Version}
#define CMDER_REVISION_VERSION {Cmder-Revision-Version}
#define CMDER_BUILD_VERSION {Cmder-Build-Version}
#define CMDER_VERSION_STR {Cmder-Version-Str}

#define CMDER_PRODUCT_NAME_STR "Cmder"
#define CMDER_FILE_DESCRIPTION_STR "Cmder: Lovely Console Emulator."
#define CMDER_INTERNAL_NAME_STR "Cmder"
#define CMDER_ORIGINAL_FILENAME_STR "Cmder.exe"
#define CMDER_COMPANY_NAME_STR "Samuel Vasko"
#define CMDER_COPYRIGHT_YEAR_STR "2016"

#define CMDER_DEBUGFLAG 0x0L // set to 0x1L to enable debug mode
#define CMDER_BUILDFLAGS 0x0L
/////////////////////////////////////////////////////////////////////////////
14 changes: 12 additions & 2 deletions scripts/build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,15 @@ $ScriptRoot = Split-Path -Parent -Path $MyInvocation.MyCommand.Definition
$cmder_root = $ScriptRoot.replace("\scripts","")

# Dot source util functions into this scope
. ".\utils.ps1"
. "$PSScriptRoot\utils.ps1"
$ErrorActionPreference = "Stop"

Push-Location -Path $saveTo
$sources = Get-Content $sourcesPath | Out-String | Convertfrom-Json

# Get the version string
$version = Get-VersionStr

# Check for requirements
Ensure-Exists $sourcesPath
Ensure-Executable "7z"
Expand Down Expand Up @@ -116,10 +119,17 @@ Pop-Location

if($Compile) {
Push-Location -Path $launcher
msbuild CmderLauncher.vcxproj /p:configuration=Release
Create-RC $version ($launcher + '\src\version.rc2');
msbuild CmderLauncher.vcxproj /t:Clean,Build /p:configuration=Release
if ($LastExitCode -ne 0) {
throw "msbuild failed to build the executable."
}
else {
Write-Verbose "successfully built Cmder v$version!"
if ( $Env:APPVEYOR -eq 'True' ) {
Add-AppveyorMessage -Message "Building Cmder v$version was successful." -Category Information
}
}
Pop-Location
} else {
Write-Warning "You are not building a launcher, Use -Compile"
Expand Down
2 changes: 1 addition & 1 deletion scripts/pack.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ $targets = @{
Delete-Existing "..\Version*"
Delete-Existing "..\build\*"

$version = Invoke-Expression "git describe --abbrev=0 --tags"
$version = Get-VersionStr
(New-Item -ItemType file "$cmderRoot\Version $version") | Out-Null

foreach ($t in $targets.GetEnumerator()) {
Expand Down
79 changes: 79 additions & 0 deletions scripts/utils.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,85 @@ function Digest-Hash($path) {
return Invoke-Expression "md5sum $path"
}

function Get-VersionStr() {

# Clear existing variable
if ($string) { Clear-Variable -name string }

# Determine if git is available
if (Get-Command "git.exe" -ErrorAction SilentlyContinue)
{

# Determine if the current diesctory is a git repository
$GitPresent = Invoke-Expression "git rev-parse --is-inside-work-tree" -erroraction SilentlyContinue

if ( $GitPresent -eq 'true' )
{
$string = Invoke-Expression "git describe --abbrev=0 --tags"
}

}

# Fallback used when Git is not available
if ( -not($string) )
{
$string = Parse-Changelog ($PSScriptRoot + '\..\' + 'CHANGELOG.md')
}

# Add build number, if AppVeyor is present
if ( $Env:APPVEYOR -eq 'True' )
{
$string = $string + '.' + $Env:APPVEYOR_BUILD_NUMBER
}

# Remove starting 'v' characters
$string = $string -replace '^v+','' # normalize version string

return $string

}

function Parse-Changelog($file) {

# Define the regular expression to match the version string from changelog
[regex]$regex = '^## \[(?<version>[\w\-\.]+)\]\([^\n()]+\)\s+\([^\n()]+\)$';

# Find the first match of the version string which means the latest version
$version = Select-String -Path $file -Pattern $regex | Select-Object -First 1 | % { $_.Matches.Groups[1].Value }

return $version
}

function Create-RC($string, $path) {

$version = $string + '.0.0.0.0' # padding for version string

if ( !(Test-Path "$path.sample") ) {
throw "Invalid path provided for resources file."
}

$resource = Get-Content -Path "$path.sample"
$pattern = @( "Cmder-Major-Version", "Cmder-Minor-Version", "Cmder-Revision-Version", "Cmder-Build-Version" )
$index = 0

# Replace all non-numeric characters to dots and split to array
$version = $version -replace '[^0-9]+','.' -split '\.'

foreach ($fragment in $version) {
if ( !$fragment ) { break }
elseif ($index -le $pattern.length) {
$resource = $resource.Replace( "{" + $pattern[$index++] + "}", $fragment )
}
}

# Add the version string
$resource = $resource.Replace( "{Cmder-Version-Str}", '"' + $string + '"' )

# Write the results
Set-Content -Path $path -Value $resource

}

function Register-Cmder() {
[CmdletBinding()]
Param
Expand Down