IronPython.Zlib / default.ps1

properties {
    $Configuration = $(?? {$config} {'Debug'})
    $TargetFrameworkVersion = $(Get-FrameworkVersion)
    $OutputPath = "bin\$TargetFrameworkVersion\$Configuration"
    $IronPythonVersion = $(?? {$ipy} {'2.6'})
    $ProjectName = 'IronPython.Zlib'
    $ProjectVersion = '2.6.0'
    $ProjectPath = "src\$ProjectName.csproj"
    $TargetFile = "$ProjectName.dll"
    $TargetPath = "$OutputPath\$TargetFile"
    $ExtraPackageFiles = @('readme.txt', 'licence.txt', 'tests\gzip.py')
}

task Info {
    Write-Host "Configuration $Configuration"
    Write-Host "TargetFrameworkVersion $TargetFrameworkVersion"
    Write-Host "OutputPath $OutputPath"
    Write-Host "IronPythonVersion $IronPythonVersion"
    Write-Host "ProjectName $ProjectName"
    Write-Host "ProjectPath $ProjectPath"
    Write-Host "TargetFile $TargetFile"
    Write-Host "TargetPath $TargetPath"
}

task Default -Depends Build,Test

task Build -Depends GenVersion {
    exec { 
        msbuild /nologo /verbosity:minimal "$ProjectPath" `
            /t:Build `
            /p:Configuration=$Configuration `
            /p:TargetFrameworkVersion=$TargetFrameworkVersion `
            /p:OutputPath="..\$OutputPath" `
            /p:IronPythonVersion=$IronPythonVersion
    }
}

task Clean {
    exec { 
        msbuild /nologo /verbosity:minimal "$ProjectPath" `
            /t:Clean `
            /p:Configuration=$Configuration `
            /p:TargetFrameworkVersion=$TargetFrameworkVersion `
            /p:OutputPath="..\$OutputPath" `
            /p:IronPythonVersion=$IronPythonVersion
    }
}

task Rebuild -Depends Clean,Build

task Package -Depends Rebuild {
    Assert ( $Configuration -eq 'Release' ) "Packages can only be built in Release mode"
    Assert ( Test-Path $TargetPath ) "Output DLL does not exist"
    
    $packageRoot = "packages"
    $packageFolder = "${ProjectName}-${ProjectVersion}_ipy-${IronPythonVersion}_clr-${TargetFrameworkVersion}"
    $packageFile = "$packageFolder.zip"
    $packagePath = "$packageRoot\$packageFolder"
    
    if($(Test-Path $packagePath)) {
        remove-item $packagePath -Recurse -Force
    }
    
    New-Item -Type Directory $packagePath | out-null
    
    Copy-Item $TargetPath $packagePath
    if($ExtraPackageFiles) {
        Copy-Item -r $ExtraPackageFiles $packagePath
    }
    
    Push-Location $packageRoot
    
    if($(Test-Path $packageFile)) {
        remove-item $packageFile -Recurse -Force
    }
    
    exec {
        & 7za a "$packageFile" "$packageFolder"
    }
    Pop-Location
}

task Test -Depends Build {
    Copy-Item -Force $TargetPath .\tests\
    
    if(($IronPythonVersion -eq '2.6') -and ($TargetFrameworkVersion -eq 'v4.0')) {
        $ipyPaths = "C:\Program Files\IronPython 2.6 for .NET 4.0","C:\Program Files (x86)\IronPython 2.6 for .NET 4.0"
    } else {
        $ipyPaths = "C:\Program Files\IronPython $IronPythonVersion","C:\Program Files (x86)\IronPython $IronPythonVersion"
    }
    
    $oldEnvPath = $env:Path
    $env:Path = $ipyPaths + @("$env:Path") -join ';'
    
    Push-Location .\tests\
    ipy test_zlib.py
    Pop-Location
    
    $env:Path = $oldEnvPath
}

task GenVersion {
    $template = @"
namespace $ProjectName
{
    internal partial class AssemblyInfo
    {
        internal const string Version = "$ProjectVersion";
    }
}
"@
    
    $template | Out-File 'src\Version.cs'
}

function Get-Platform {
    if($framework -match '(\d\.\d)(x86|x64)?') {
        if($matches[2] -ne $null) {
            return $matches[2]
        }
    }
    
    return 'AnyCPU'
}

function Get-FrameworkVersion {
    if($framework -match '(\d\.\d)(x86|x64)?') {
        return 'v' + $matches[1]
    }
    
    return 'v3.5'
}

filter Invoke-NullCoalescing {
    param([scriptblock]$PrimaryExpr   = $(throw "Parameter '-primaryExpr' (position 1) required"), 
          [scriptblock]$AlternateExpr = $(throw "Parameter '-alternateExpr' (position 2) required"))

    if ($primaryExpr -ne $null) {
        $result = &$primaryExpr
        if ($result -ne $null -and "$result" -ne '') {
            $result
        }
        else {
            &$alternateExpr
        }
    }
    else {
        &$alternateExpr
    }
}

New-Alias ?? Invoke-NullCoalescing
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.