# # G N O K I I # # A Linux/Unix tool$env:and driver for the mobile phones. # # This file is part of gnokii. # # Gnokii is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # Gnokii is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with gnokii; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # # Copyright (C) 2006-2009 Jari Turkia # # Nightly build script. # Power shell may require: Set-ExecutionPolicy Unrestricted # # gnokii.dll # Build log was saved at "file://d:\temp\gnokii-0.6.14\win32\MSVS2005\Release\BuildLog.htm" # gnokii.exe # Build log was saved at "file://d:\temp\gnokii-0.6.14\win32\MSVS2005\Release\BuildLog.htm" $sourceDir = "C:\Projects\Gnokii" $buildDir = "C:\temp" $cygwinDir = "C:\Cygwin\bin" $MSVC_ver = "MSVS2008" $env:include = $env:include + ";%BUILDDIR%\gnokii\include" $env:lib = $env:lib $env:PATH = $env:PATH + ";" + $cygwinDir # MSbuild # $env:MSBuildEmitSolution=1 $FTPhost = "-missing-" $FTPuser = "-missing-" $FTPpassword = "-missing-" $FTPdir = "-missing-" $FTP_URL = "ftp://" + $FTPuser + ":" + $FTPpassword + "@" + $FTPhost + "/" + $FTPdir $version = "unknown" $revision = get-date -uformat "%Y%m%d" # Debugging... # Set-PSDebug -Trace 1 # # UpdateSourceTree # Basically execute a git pull command # Function UpdateSourceTree() { cd ($sourceDir + "\gnokii") #return $true # init 1st: git clone git://git.sv.gnu.org/gnokii.git & ($cygwinDir + "\git") pull return $? } # # GetGnokiiVersion # The only place where Gnokii version exists is in configure.in # Cygwin M4 macro processor is used for extracting the information. # Function GetGnokiiVersion() { # OLD: # echo %M4MACROS% | %CYGWINDIR%\m4 - configure.in | %CYGWINDIR%\sed -e "s/\[//" | %CYGWINDIR%\sed -e "s/]//" > VERSION $m4macro = "define(" + '`' + "AC_INIT', " + '`' + "divert(0)" + '$' + "2divert(-1)')divert(" + '`' + "-1')" Out-File -filePath ($Env:TEMP + "\gnokii-macro.m4") -inputobject $m4macro -encoding ASCII $version = & ($cygwinDir + "\m4") ($Env:TEMP + "\gnokii-macro.m4") configure.in $stat = $? Remove-Item ($Env:TEMP + "\gnokii-macro.m4") if ($stat) { return $version.Substring(1).TrimEnd("]") } return "unknown" } # # CreateBuildEnv # Make sure that all required directories exist and are empty. # Function CreateBuildEnv() { $destDir = "$buildDir\gnokii-$version" if (Test-Path -path $destDir) { get-childitem "$destDir\*" -recurse | remove-item -recurse -force remove-item $destDir -recurse } cd $sourceDir New-Item $destDir -type directory | Out-Null # There are .git\ directories, skip them. copy -path "gnokii\*" -destination $destDir -recurse -exclude ".*" } # # GenerateGnokiiH # Since gnokii.h is not in repo anymore, we need to generate it # Function GenerateGnokiiH() { cd ("$buildDir\gnokii-$version\Windows") # & "$buildDir\gnokii-$version\Windows\gen_gnokii_h.bat" & "$buildDir\gnokii-$version\Windows\gen_gnokii_h.ps1" } # # PackSource # Create a Zip-file from gnokii source code # Cygwin Info-Zip is used for packing # Function PackSource() { cd $buildDir $packedSourceFile = $Env:TEMP + "\gnokii-$version-$revision.src.zip" if (Test-Path -path $packedSourceFile) { Remove-Item $packedSourceFile } & ($cygwinDir + "\zip") -9r $packedSourceFile ("gnokii-$version/*") } # # RegressionTest # Execute the built binary with a simple configuration file # Function RegressionTest([String]$destArch) { Write-Host "Simple regression testing..." $conf = '[global]' + "`n" $conf += 'port = foobar' + "`n" $conf += 'model = fake' + "`n" $conf += 'connection = serial' + "`n" Out-File -filePath ($Env:TEMP + "\gnokiirc.fake") -inputobject $conf -encoding ASCII # Execute a gnokii --config gnokiirc.fake --identify # to see if the newly compiled binary is alive or not & ("$buildDir\gnokii-$version\Windows\$MSVC_ver\$destArch\Release\gnokii") --config ($Env:TEMP + "\gnokiirc.fake") --identify | Out-Null $stat = $lastexitcode Remove-Item ($Env:TEMP + "\gnokiirc.fake") Write-Host "Regression status: $stat" return ($stat -le 0) } # # BuildFail # Function BuildFail([String]$destArch) { cd $Env:TEMP Write-Host "Transferring failure info for $destArch..." $ftpSess = "cd $FTPdir`n" $ftpSess += "cd $destArch`n" $ftpSess += "del *`n" $ftpSess += "bin`n" $ftpSess += "put BuildLog-$version-$revision.html`n" $ftpSess += "quit`n" # This is really not needed, NcFTP will quit when input ends # Execute NcFTP with input generated above. # Cygwin is in path, so that should work. # The command on right side of pipe cannot be an expression. $ftpSess | ncftp $FTP_URL $ftpStat = $lastexitcode if ($ftpStat -gt 0) { return $False } Write-Host "Stat:" $ftpStat Write-Host "Transfer success for $destArch!" # Remove-Item "BuildLog-$version-$revision.html" return $True } # # BuildSuccess # Cygwin NcFTP is used for transferring files # Function BuildSuccess([String]$destArch) { cd $Env:TEMP Write-Host "Transferring prepared packages for $destArch..." $ftpSess = "cd $FTPdir`n" $ftpSess += "cd $destArch`n" $ftpSess += "del *`n" $ftpSess += "bin`n" $ftpSess += "put gnokii-$version-$revision.zip`n" $ftpSess += "put gnokii-$version-$revision.src.zip`n" $ftpSess += "put BuildLog-$version-$revision.html`n" $ftpSess += "quit`n" # This is really not needed, NcFTP will quit when input ends # Execute NcFTP with input generated above. # Cygwin is in path, so that should work. # The command on right side of pipe cannot be an expression. $ftpSess | ncftp $FTP_URL $ftpStat = $lastexitcode if ($ftpStat -gt 0) { return $False } Write-Host "Stat:" $ftpStat Write-Host "Transfer success for $destArch!" Remove-Item "gnokii-$version-$revision.zip" Remove-Item "BuildLog-$version-$revision.html" return $True } # # Build # @param string Processor architecture to set up build environment for # @param string Configuration and processor architecture to use from for building # @param string Build results directory # @param string Destination directory to transfer results to # Function Build([String]$buildArch, [String]$confPlatform, [String]$destArch, [String]$destDir) { cd ("$buildDir\gnokii-$version\Windows\$MSVC_ver") $batFile = 'call "C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\vcvarsall.bat" ' + $buildArch + "`n" $batFile += 'vcbuild /useenv gnokii.sln "' + $confPlatform + '"' + "`n" Out-File -filePath ($Env:TEMP + "\gnokii-build.bat") -inputobject $batFile -encoding ASCII & ($Env:TEMP + "\gnokii-build.bat") $buildStat = $lastexitcode Write-Host "Build status:" $buildStat Remove-Item ($Env:TEMP + "\gnokii-build.bat") # If a build-log was made, copy it to be transferred if (Test-Path -path ($destArch + "\Release\BuildLog.htm")) { copy -path ($destArch + "\Release\BuildLog.htm") -destination ($Env:TEMP + "\BuildLog-" + $version + "-" + $revision + ".html") } else { Write-Error "Cannot find buildlog: $destArch\Release\BuildLog.htm" return $False } # Confirm build status by errorlevel if ($buildStat -gt 0) { Write-Error "Build reported error!" BuildFail $destDir return $False } # Confirm build status by expected resulting files if (!(Test-Path -path ($destArch + "\Release\gnokii.exe"))) { Write-Error "gnokii.exe missing!" BuildFail $destDir return $False } if (!(Test-Path -path ($destArch + "\Release\gnokii.dll"))) { Write-Error "gnokii.dll missing!" BuildFail $destDir return $False } # Create a Zip package of the built binaries cd ($destArch + "\Release") & ($cygwinDir + "\zip") ($Env:TEMP + "\gnokii-" + $version + "-" + $revision + ".zip") gnokii.exe gnokii.dll | Out-Null if (!(RegressionTest $destArch)) { Write-Error "Regression failed!" BuildFail $destDir return $False } # Success! Write-Host "Build success!" # Transfer the produced files to public web server return BuildSuccess $destDir } # # Start # $gitStat = UpdateSourceTree if (!$gitStat) { exit 1 } $version = GetGnokiiVersion Write-Host "Version: $version-$revision" CreateBuildEnv GenerateGnokiiH PackSource Build "x86" "Release|Win32" "Win32" "Win32" #Build "amd64" "Release|x64" "x64" "Win64" # Clean up the build directory cd $sourceDir Write-Host "Clean up..." Get-Childitem "$buildDir\gnokii-$version\*" -recurse | remove-item -recurse -force Remove-Item "$buildDir\gnokii-$version" -recurse Remove-Item ($Env:TEMP + "\gnokii-$version-$revision.src.zip")