cmder/scripts/build.ps1

153 lines
5.1 KiB
PowerShell
Raw Normal View History

2014-02-25 00:33:14 +08:00
<#
.Synopsis
Build Cmder
.DESCRIPTION
Use this script to build your own edition of Cmder
2014-02-25 00:33:14 +08:00
This script builds dependencies from current vendor/sources.json file and unpacks them.
2014-02-25 00:33:14 +08:00
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
2014-02-25 00:33:14 +08:00
2015-08-24 02:21:45 +08:00
Executes the default build for Cmder; Conemu, clink. This is equivalent to the "minimum" style package in the releases
.EXAMPLE
.\build.ps1 -Compile
Recompile the launcher executable if you have the requisite build tools for C++ installed.
.EXAMPLE
.\build -verbose
2014-02-25 00:33:14 +08:00
Execute the build and see what's going on.
.EXAMPLE
.\build.ps1 -SourcesPath '~/custom/vendors.json'
2014-02-25 00:33:14 +08:00
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
http://cmder.net/ - 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
2022-09-10 05:17:10 +08:00
[string]$sourcesPath = "$PSScriptRoot\..\vendor\sources.json",
2014-08-27 06:52:49 +08:00
# Vendor folder location
2022-09-10 05:17:10 +08:00
[string]$saveTo = "$PSScriptRoot\..\vendor\",
2014-08-27 06:52:49 +08:00
# Launcher folder location
2022-09-10 05:17:10 +08:00
[string]$launcher = "$PSScriptRoot\..\launcher",
# Config folder location
2022-09-10 05:17:10 +08:00
[string]$config = "$PSScriptRoot\..\config",
# New launcher if you have MSBuild tools installed
[switch]$Compile
)
2014-02-25 00:33:14 +08:00
2016-07-18 07:28:38 +08:00
# Get the scripts and cmder root dirs we are building in.
2022-09-10 05:17:10 +08:00
$cmder_root = Resolve-Path "$PSScriptRoot\.."
2016-07-18 07:28:38 +08:00
# Dot source util functions into this scope
2018-03-31 02:53:44 +08:00
. "$PSScriptRoot\utils.ps1"
$ErrorActionPreference = "Stop"
2014-04-10 18:41:19 +08:00
Push-Location -Path $saveTo
$sources = Get-Content $sourcesPath | Out-String | Convertfrom-Json
# Get the version string
2018-03-31 02:53:44 +08:00
$version = Get-VersionStr
# Check for requirements
Ensure-Exists $sourcesPath
Ensure-Executable "7z"
New-Item -Type Directory -Path (Join-Path $saveTo "/tmp/") -ErrorAction SilentlyContinue >$null
# Preserve modified (by user) ConEmu setting file
if ($config -ne "") {
$ConEmuXml = Join-Path $saveTo "conemu-maximus5\ConEmu.xml"
if (Test-Path $ConEmuXml -pathType leaf) {
$ConEmuXmlSave = Join-Path $config "ConEmu.xml"
Write-Verbose "Backup '$ConEmuXml' to '$ConEmuXmlSave'"
Copy-Item $ConEmuXml $ConEmuXmlSave
} else { $ConEmuXml = "" }
} else { $ConEmuXml = "" }
2016-07-18 07:28:38 +08:00
# Kill ssh-agent.exe if it is running from the $env:cmder_root we are building
foreach ($ssh_agent in $(get-process ssh-agent -erroraction silentlycontinue)) {
if ([string]$($ssh_agent.path) -match [string]$cmder_root.replace('\','\\')) {
write-verbose $("Stopping " + $ssh_agent.path + "!")
stop-process $ssh_agent.id
}
}
$vend = $pwd
foreach ($s in $sources) {
2014-04-28 19:21:03 +08:00
Write-Verbose "Getting $($s.name) from URL $($s.url)"
# We do not care about the extensions/type of archive
$tempArchive = "tmp/$($s.name).tmp"
Delete-Existing $tempArchive
Delete-Existing $s.name
Download-File -Url $s.url -File $vend\$tempArchive -ErrorAction Stop
2014-03-05 21:31:01 +08:00
Extract-Archive $tempArchive $s.name
if ((Get-Childitem $s.name).Count -eq 1) {
Flatten-Directory($s.name)
2014-02-25 00:33:14 +08:00
}
# Write current version to .cmderver file, for later.
2015-05-18 05:13:04 +08:00
"$($s.version)" | Out-File "$($s.name)/.cmderver"
}
# Restore user configuration
if ($ConEmuXml -ne "") {
Write-Verbose "Restore '$ConEmuXmlSave' to '$ConEmuXml'"
Copy-Item $ConEmuXmlSave $ConEmuXml
}
Pop-Location
2014-08-27 06:52:49 +08:00
if($Compile) {
Push-Location -Path $launcher
2018-03-31 02:53:44 +08:00
Create-RC $version ($launcher + '\src\version.rc2');
2022-10-15 00:32:03 +08:00
# https://docs.microsoft.com/visualstudio/msbuild/msbuild-command-line-reference
msbuild CmderLauncher.vcxproj /t:Clean,Build /p:configuration=Release /m
if ($LastExitCode -ne 0) {
throw "msbuild failed to build the executable."
}
2018-03-29 00:46:27 +08:00
else {
2018-03-31 02:53:44 +08:00
Write-Verbose "successfully built Cmder v$version!"
2018-03-31 03:22:32 +08:00
if ( $Env:APPVEYOR -eq 'True' ) {
2018-03-31 03:33:39 +08:00
Add-AppveyorMessage -Message "Building Cmder v$version was successful." -Category Information
2018-03-31 03:22:32 +08:00
}
2018-03-29 00:46:27 +08:00
}
Pop-Location
} else {
Write-Warning "You are not building a launcher, Use -Compile"
Write-Warning "This cannot be a release. Test build only!"
}
2014-08-27 06:52:49 +08:00
# Put vendor\cmder.sh in /etc/profile.d so it runs when we start bash or mintty
if ( (Test-Path $($SaveTo + "git-for-windows/etc/profile.d") ) ) {
write-verbose "Adding cmder.sh /etc/profile.d"
Copy-Item $($SaveTo + "cmder.sh") $($SaveTo + "git-for-windows/etc/profile.d/cmder.sh")
}
# Replace /etc/profile.d/git-prompt.sh with cmder lambda prompt so it runs when we start bash or mintty
if ( !(Test-Path $($SaveTo + "git-for-windows/etc/profile.d/git-prompt.sh.bak") ) ) {
write-verbose "Replacing /etc/profile.d/git-prompt.sh with our git-prompt.sh"
Move-Item $($SaveTo + "git-for-windows/etc/profile.d/git-prompt.sh") $($SaveTo + "git-for-windows/etc/profile.d/git-prompt.sh.bak")
Copy-Item $($SaveTo + "git-prompt.sh") $($SaveTo + "git-for-windows/etc/profile.d/git-prompt.sh")
}
2014-08-27 06:52:49 +08:00
Write-Verbose "All good and done!"