Merge pull request #152 from bliker/scripts

New build and pack scripts
This commit is contained in:
Samuel Vasko 2014-04-10 14:44:39 +02:00
commit f6c3a0c390
8 changed files with 205 additions and 158 deletions

2
.gitignore vendored
View File

@ -4,6 +4,8 @@
vendor/*
!vendor/*.md
!vendor/*.bat
!vendor/*.json
config/.history
Thumbs.db
*.exe

110
build.rb
View File

@ -1,110 +0,0 @@
# Samuel Vasko 2013
# Cmder build script
# Like really a beta
#
# This script downloads dependencies form google code. Each software is extracted
# in a folder with same name as the project on google code. So Conemu becomes
# conemu-maximus5. Correct files are beeing picked by using labels.
# I will move the script for getting files by labels from php to here as soon I feel like it
require 'fileutils'
require 'open-uri'
require 'uri'
def get_file project, query
urlToFile = URI.escape('http://samuelvasko.tk/gcode/?project='+project+'&query='+query)
open(urlToFile) do |resp|
urlToFile = URI.escape(resp.read.split(/\r?\n/).first)
end
extension = urlToFile.split('.').last
filename = project+'.'+extension
puts "\n ------ Downloading #{project} from #{urlToFile} ------- \n \n"
begin
open(urlToFile, 'rb') do |infile|
open(filename, 'wb') do |outfile|
outfile.write(infile.read)
end
end
rescue IOError => error
puts error
FileUtils.rm(filename) if File.exists?(filename)
exit(1)
end
system("7z x -o\"#{project}\" #{filename}")
File.unlink(project+"."+extension);
# When the folder contains another folder
# that is not what we want
if Dir.glob("#{project}/*").length == 1
temp_name = "#{project}_temp"
FileUtils.mv(project, temp_name)
FileUtils.mv(Dir.glob("#{temp_name}/*")[0], project)
FileUtils.rm_r(temp_name)
end
end
def find_on_path exe
path = ENV['PATH'].split(File::PATH_SEPARATOR)
for dir in path
if File.exists?(File.join(dir, exe))
return true
end
end
return false
end
puts '
______ _ _ _ _ _
| ___ \ (_) | | (_) | |
| |_/ /_ _ _| | __| |_ _ __ __ _ ___ _ __ ___ __| | ___ _ __
| ___ \ | | | | |/ _` | | \'_ \ / _` | / __| \'_ ` _ \ / _` |/ _ \ \'__|
| |_/ / |_| | | | (_| | | | | | (_| | | (__| | | | | | (_| | __/ |
\____/ \__,_|_|_|\__,_|_|_| |_|\__, | \___|_| |_| |_|\__,_|\___|_|
__/ |
|___/
'
unless find_on_path('7z.exe')
puts '7z.exe not found. Ensure 7-zip is installed and on the PATH.'
exit(1)
end
build_exe = true
unless find_on_path('msbuild.exe')
puts 'msbuild.exe not found. We need that to build the executable.'
puts 'Do you want to continue? [Y/n]'
build_exe = false
exit(1) unless gets.chomp.downcase == 'y'
end
puts 'Cleanup'
if Dir.exists?('vendor')
Dir.glob('vendor/*') { |file| FileUtils.rm_rf(file) if File.directory?(file) }
end
Dir.chdir('vendor')
puts 'Getting files'
get_file('clink', 'label:Type-Archive label:Featured')
get_file('conemu-maximus5', 'label:Type-Archive label:Preview label:Featured')
get_file('msysgit', 'label:Type-Archive label:Featured')
puts 'Creating executable'
if build_exe
Dir.chdir('../launcher')
status = system('msbuild /p:Configuration=Release')
unless status
puts 'Looks like the build failied'
exit(1)
end
end
puts 'Done, bye'

40
pack.rb
View File

@ -1,40 +0,0 @@
# Samuel Vasko 2013
# Cmder packing script -- Creates zip files for relase
require "fileutils"
def create_archive name, exclude
if exclude
exclude = " -x!cmder\\" + exclude
else
exclude = ""
end
system('ls')
puts "Running 7z a -x@cmder\\packignore" + exclude + " " + name + " cmder"
system("7z a -x@cmder\\packignore" + exclude + " " + name + " cmder")
end
targets = [
["cmder.zip"],
["cmder.7z"],
["cmder_mini.zip", "vendor\\msysgit"]
]
unless system("git describe --abbrev=0 --tags")
puts "Failied to get the last tag from git, looks like something is missing"
end
version = `git describe --abbrev=0 --tags`
FileUtils.touch('Version ' + version.chomp)
FileUtils.rm('config/.history') if File.exists?('config/.history')
Dir.chdir('..')
targets.each do |ar|
create_archive ar[0], ar[1]
end
Dir.chdir('cmder')
FileUtils.rm('Version ' + version.chomp)

View File

@ -1,8 +1,10 @@
cmder\launcher
cmder\icons
cmder\.gitignore
cmder\.gitattributes
cmder\.git
cmder\*.rb
cmder\packignore
cmder\Cmder.bat
launcher
icons
.gitignore
.gitattributes
.git
*.rb
build
config\.history
packignore
Cmder.bat

71
scripts/build.ps1 Normal file
View File

@ -0,0 +1,71 @@
<#
.Synopsis
Build Cmder
.DESCRIPTION
Use this script to build your own edition of Cmder
This script builds dependencies from current vendor/sources.json file and unpacks them.
You will need to make this script executable by setting your Powershell Execution Policy to Remote signed
Then unblock the script for execution with UnblockFile .\build.ps1
.EXAMPLE
.\build.ps1
Executes the default build for cmder, this is equivalent to the "minimum" style package in the releases
.EXAMPLE
.\build -verbose
Execute the build and see what's going on.
.EXAMPLE
.\build.ps1 -SourcesPath '~/custom/vendors.json'
Build cmder with your own packages. See vendor/sources.json for the syntax you need to copy.
.NOTES
AUTHORS
Samuel Vasko, Jack Bennett
Part of the Cmder project.
.LINK
https://github.com/bliker/cmder - Project Home
#>
[CmdletBinding(SupportsShouldProcess=$true)]
Param(
# CmdletBinding will give us;
# -verbose switch to turn on logging and
# -whatif switch to not actually make changes
# Path to the vendor configuration source file
[string]$sourcesPath = "..\vendor\sources.json",
# Vendor folder locaton
[string]$saveTo = "..\vendor\"
)
. "$PSScriptRoot\utils.ps1"
$ErrorActionPreference = "Stop"
Push-Location -Path $saveTo
$sources = Get-Content $sourcesPath | Out-String | Convertfrom-Json
# Check for requirements
Ensure-Exists $sourcesPath
Ensure-Executable "7z"
foreach ($s in $sources) {
Write-Output "Getting $($s.name) from URL $($s.url)"
# We do not care about the extensions/type of archive
$tempArchive = "$($s.name).tmp"
Delete-Existing $tempArchive
Delete-Existing $s.name
Invoke-WebRequest -Uri $s.url -OutFile $tempArchive -ErrorAction Stop
Extract-Archive $tempArchive $s.name
if ((Get-Childitem $s.name).Count -eq 1) {
Flatten-Directory($s.name)
}
}
Pop-Location
Write-Verbose "All good and done!"

56
scripts/pack.ps1 Normal file
View File

@ -0,0 +1,56 @@
<#
.Synopsis
Pack cmder
.DESCRIPTION
Use this script to pack cmder into release archives
You will need to make this script executable by setting your Powershell Execution Policy to Remote signed
Then unblock the script for execution with UnblockFile .\pack.ps1
.EXAMPLE
.\pack.ps1
Creates default archives for cmder
.EXAMPLE
.\build -verbose
Creates default archives for cmder with plenty of information
.NOTES
AUTHORS
Samuel Vasko, Jack Bennett
Part of the Cmder project.
.LINK
https://github.com/bliker/cmder - Project Home
#>
[CmdletBinding(SupportsShouldProcess=$true)]
Param(
# CmdletBinding will give us;
# -verbose switch to turn on logging and
# -whatif switch to not actually make changes
# Path to the vendor configuration source file
[string]$cmderRoot = "..",
# Vendor folder locaton
[string]$saveTo = "..\build"
)
. "$PSScriptRoot\utils.ps1"
$ErrorActionPreference = "Stop"
$targets = @{
"cmder.zip" = $null;
"cmder.7z" = $null;
"cmder_mini.zip" = "-x!`"vendor\msysgit`"";
}
Delete-Existing "..\Version*"
$version = Invoke-Expression "git describe --abbrev=0 --tags"
(New-Item -ItemType file "$cmderRoot\Version $version") | Out-Null
foreach ($t in $targets.GetEnumerator()) {
Create-Archive $cmderRoot "$saveTo\$($t.Name)" $t.Value
$hash = (Digest-MD5 "$saveTo\$($t.Name)")
Add-Content "$saveTo\hashes.txt" $hash
}

49
scripts/utils.ps1 Normal file
View File

@ -0,0 +1,49 @@
function Ensure-Exists ($path) {
if (-not (Test-Path $path)) {
Write-Error "Missing required $path file"
exit 1
}
}
function Ensure-Executable ($command) {
try { Get-Command $command -ErrorAction Stop > $null }
catch {
Write-Error "Missing $command! Ensure it is installed and on in the PATH"
exit 1
}
}
function Delete-Existing ($path) {
Write-Verbose "Remove $path"
Remove-Item -Recurse -force $path -ErrorAction SilentlyContinue
}
function Extract-Archive ($source, $target) {
Invoke-Expression "7z x -y -o$($target) $source > `$null"
if ($lastexitcode -ne 0) {
Write-Error "Extracting of $source failied"
}
Remove-Item $source
}
function Create-Archive ($source, $target, $params) {
$command = "7z a -x@`"$source\packignore`" $params $target $source > `$null"
Write-Verbose "Running: $command"
Invoke-Expression $command
if ($lastexitcode -ne 0) {
Write-Error "Compressing $source failied"
}
}
# If directory contains only one child directory
# Flatten it instead
function Flatten-Directory ($name) {
$child = (Get-Childitem $name)[0]
Rename-Item $name -NewName "$($name)_moving"
Move-Item -Path "$($name)_moving\$child" -Destination $name
Remove-Item -Recurse "$($name)_moving"
}
function Digest-MD5 ($path) {
return Invoke-Expression "md5sum $path"
}

17
vendor/sources.json vendored Normal file
View File

@ -0,0 +1,17 @@
[
{
"name": "msysgit",
"version": "1.9.0-preview",
"url": "https://msysgit.googlecode.com/files/PortableGit-1.9.0-preview20140217.7z"
},
{
"name": "clink",
"version": "0.4.1",
"url": "https://github.com/mridgers/clink/releases/download/0.4.1/clink_0.4.1.zip"
},
{
"name": "conemu-maximus5",
"version": "140404",
"url": "https://conemu.codeplex.com/downloads/get/823971"
}
]