Skip to content

Commit

Permalink
Bash tweaks in server script
Browse files Browse the repository at this point in the history
* use bash directly instead of via Send-Process
* drop bash for commands that don't need it
* use powershell redirection (which is pretty much like bash redirection)
* use powershell native Write-Output command for simple text message
  rather than making a detour via 'bash -lc echo'

Notes on the redirection
* sometimes the bash command still includes the error redirection
  This is because powershell make error output much more verbose
  and I wasn't sure that was adding much useful info.
* Powershell redirections don't work with Write-Host. They
  do work with Write-Output so I have replaced those.
  • Loading branch information
gjanssens committed Sep 25, 2019
1 parent 709e278 commit 533ac3b
Showing 1 changed file with 22 additions and 18 deletions.
40 changes: 22 additions & 18 deletions buildserver/build_package.ps1
Expand Up @@ -65,19 +65,22 @@ $progressPreference = 'silentlyContinue'
$env:MSYSTEM = 'MINGW32'
$env:TERM = 'dumb' #Prevent escape codes in the log.
$env:TARGET = "$package-$branch"
# This allows us to run Msys2 commands such as bash.exe directly
$Env:Path = "$Env:Path;$target_dir\msys2\usr\bin"

if ($PSVersionTable.PSVersion.Major -ge 3) {
$PSDefaultParameterValues['*:Encoding'] = 'utf8'
}
}

if (!(test-path -path $target_dir\msys2\usr\bin\bash.exe)) {
Write-Output "Shell program not found, aborting."
Exit 1
}

function bash-command() {
param ([string]$command = "")
if (!(test-path -path $target_dir\msys2\usr\bin\bash.exe)) {
write-host "Shell program not found, aborting."
return
}
#write-host "Running bash command ""$command"""
Start-Process -FilePath "$target_dir\msys2\usr\bin\bash.exe" -ArgumentList "-lc ""$command""" -NoNewWindow -Wait
#Write-Output "Running bash command ""$command"""
bash.exe -lc "$command 2>&1"
}

function make-unixpath([string]$path) {
Expand All @@ -95,15 +98,15 @@ $log_file = "$target_dir\build-$branch-$time_stamp.log"
$log_unix = make-unixpath -path $log_file
$time_stamp = get-date -format "yyyy-MM-dd HH:mm:ss"

bash-command -command "cd $script_unix && git pull"
bash-command -command "echo Build Started $time_stamp > $log_unix"
Write-Output "Build Started $time_stamp" | Tee-Object -FilePath $log_file
git.exe -C $script_unix pull 2>&1 | Tee-Object -FilePath $log_file -Append
#copy the file to the download server so that everyone can see we've started
if ($hostname) {
bash-command -command "$script_unix/buildserver/upload_build_log.sh $log_unix $hostname $log_dir $branch"
bash.exe -lc "$script_unix/buildserver/upload_build_log.sh $log_unix $hostname $log_dir $branch"
}

# Update MinGW-w64
bash-command -command "pacman -Su --noconfirm > >(tee -a $log_unix) 2>&1"
pacman.exe -Su --noconfirm 2>&1 | Tee-Object -FilePath $log_file -Append

#GnuCash build still behaves badly if it finds its old build products. Clean them out.
if ($branch -eq "releases") {
Expand All @@ -124,26 +127,27 @@ if (test-path -path $install_manifest) {
}

# Update the gnucash-on-windows repository
#bash-command -command "cd $script_unix && git reset --hard && git pull --rebase"
#git.exe -C $script_unix reset --hard 2>&1 | Tee-Object -FilePath $log_file -Append
#git.exe -C $script_unix pull --rebase 2>&1 | Tee-Object -FilePath $log_file -Append
# Build the latest GnuCash and all dependencies not installed via mingw64
bash-command -command "jhbuild --no-interact -f $script_unix/jhbuildrc build --clean > >(tee -a $log_unix) 2>&1"
bash.exe -lc "jhbuild --no-interact -f $script_unix/jhbuildrc build --clean 2>&1" | Tee-Object -FilePath $log_file -Append
$new_file = test-path -path $target_dir\$package\$branch\inst\bin\gnucash.exe -NewerThan $time_stamp
if ($new_file) {
#Build the installer
$is_git = ($branch.CompareTo("releases") -ne 0)
bash-command -command "echo 'Creating GnuCash installer.' > >(tee -a $log_unix)"
Write-Output "Creating GnuCash installer." | Tee-Object -FilePath $log_file -Append
$setup_file = & $script_dir\bundle-mingw64.ps1 -root_dir $target_dir -target_dir $target_dir\$package\$branch -package $package -git_build $is_git 2>&1 | Tee-Object -FilePath $log_file -Append
$setup_file = make-unixpath -path $setup_file
write-host "Created GnuCash Setup File $setup_file"
Write-Output "Created GnuCash Setup File $setup_file" | Tee-Object -FilePath $log_file -Append
}

$time_stamp = get-date -format "yyyy-MM-dd HH:mm:ss"
bash-command -command "echo Build Ended $time_stamp >> $log_unix"
Write-Output "Build Ended $time_stamp" | Tee-Object -FilePath $log_file -Append

# Copy the transcript and installer to the download server and delete them.
if ($hostname) {
bash-command -command "$script_unix/buildserver/upload_build_log.sh $log_unix $hostname $log_dir $branch"
bash.exe -lc "$script_unix/buildserver/upload_build_log.sh $log_unix $hostname $log_dir $branch 2>&1"
if ($new_file) {
bash-command -command "rsync -e ssh -a $setup_file $hostname/$branch"
rsync.exe -e ssh -a "$setup_file $hostname/$branch" 2>&1
}
}

0 comments on commit 533ac3b

Please sign in to comment.