From b35303eb4b3956df46a54f95a6ba0f0e388dcdeb Mon Sep 17 00:00:00 2001 From: hal-ler Date: Sat, 5 Mar 2016 01:13:42 +0100 Subject: [PATCH 1/7] Initial version of portable Cake build script. --- .gitignore | 2 +- .travis.yml | 2 +- appveyor.yml | 2 +- build.cake | 581 +++++++++++++++++++++++++ build.json | 7 +- build.ps1 | 33 +- build.sh | 49 +-- cake-bootstrap.ps1 | 138 ++++++ cake-bootstrap.sh | 78 ++++ tools/PublishProject/BuildPlan.cs | 44 -- tools/PublishProject/DotNetExecutor.cs | 105 ----- tools/PublishProject/Program.cs | 162 ------- tools/PublishProject/TestActions.cs | 193 -------- tools/PublishProject/project.json | 24 - 14 files changed, 810 insertions(+), 610 deletions(-) create mode 100644 build.cake create mode 100644 cake-bootstrap.ps1 create mode 100644 cake-bootstrap.sh delete mode 100644 tools/PublishProject/BuildPlan.cs delete mode 100644 tools/PublishProject/DotNetExecutor.cs delete mode 100755 tools/PublishProject/Program.cs delete mode 100644 tools/PublishProject/TestActions.cs delete mode 100755 tools/PublishProject/project.json diff --git a/.gitignore b/.gitignore index bab9b47ec9..5ab84672c2 100644 --- a/.gitignore +++ b/.gitignore @@ -35,5 +35,5 @@ buildlog *.nuget.targets # Build folder -.build/ +.tools/ .dotnet/ diff --git a/.travis.yml b/.travis.yml index bf83948237..c0fcc97cf7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,7 +14,7 @@ before_install: - if [ "$TRAVIS_OS_NAME" == "osx" ]; then brew update; fi - if [ "$TRAVIS_OS_NAME" == "osx" ]; then brew install jq; fi script: - - ./build.sh + - "./build.sh -target=All" addons: apt: packages: diff --git a/appveyor.yml b/appveyor.yml index cfcfad41ae..c53fb48bce 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -3,7 +3,7 @@ init: - git config --global core.autocrlf true test: off # this turns of AppVeyor automatic searching for test-assemblies, not the actual testing build_script: - - ps: .\build.ps1 + - ps: .\build.ps1 -target=All artifacts: - path: artifacts/package/*.zip deploy: diff --git a/build.cake b/build.cake new file mode 100644 index 0000000000..7bfdd84d53 --- /dev/null +++ b/build.cake @@ -0,0 +1,581 @@ +#addin "Cake.FileHelpers" +#addin "Cake.Json" + +using System.Text.RegularExpressions; +using System.ComponentModel; + +// Basic arguments +var target = Argument("target", "Default"); +var configuration = Argument("configuration", "Release"); +// Optional arguments +var testConfiguration = Argument("test-configuration", "Debug"); +var installFolder = Argument("install-path", IsRunningOnWindows() ? + $"{EnvironmentVariable("USERPROFILE")}/.omnisharp/local" : "~/.omnisharp/local"); + + +// Working directory +var workingDirectory = (new CakeEnvironment()).WorkingDirectory; + +// System specific shell configuration +var shell = IsRunningOnWindows() ? "powershell" : "bash"; +var shellArgument = IsRunningOnWindows() ? "/Command" : "-C"; +var shellExtension = IsRunningOnWindows() ? "ps1" : "sh"; + +/// +/// Class representing build.json +/// +public class BuildPlan +{ + public IDictionary TestProjects { get; set; } + public string BuildToolsFolder { get; set; } + public string ArtifactsFolder { get; set; } + public string DotNetFolder { get; set; } + public string DotNetInstallScriptURL { get; set; } + public string DotNetChannel { get; set; } + public string DotNetVersion { get; set; } + public string[] Frameworks { get; set; } + public string[] Rids { get; set; } + public string MainProject { get; set; } +} + +var buildPlan = DeserializeJsonFromFile($"{workingDirectory}/build.json"); + +// Folders and tools +var dotnetFolder = $"{workingDirectory}/{buildPlan.DotNetFolder}"; +var dotnetcli = $"{dotnetFolder}/cli/dotnet"; +var toolsFolder = $"{workingDirectory}/{buildPlan.BuildToolsFolder}"; +var xunitRunner = "xunit.runner.console"; + +var sourceFolder = $"{workingDirectory}/src"; +var testFolder = $"{workingDirectory}/tests"; + +var artifactFolder = $"{workingDirectory}/{buildPlan.ArtifactsFolder}"; +var publishFolder = $"{artifactFolder}/publish"; +var logFolder = $"{artifactFolder}/logs"; +var packageFolder = $"{artifactFolder}/package"; + +/// +/// Retrieve the default local RID from .NET CLI. +/// +/// Full path to .NET CLI binary +/// Default RID +string GetLocalRuntimeID(string dotnetcli) +{ + var process = StartAndReturnProcess(dotnetcli, + new ProcessSettings + { + Arguments = "--version", + RedirectStandardOutput = true + }); + process.WaitForExit(); + foreach (var line in process.GetStandardOutput()) + { + if (!line.Contains("Runtime Id")) + { + continue; + } + var colonIndex = line.IndexOf(':'); + return line.Substring(colonIndex + 1).Trim(); + } + throw new Exception("Failed to get default RID for system"); +} + +/// +/// Match the local RID with the ones specified in build.json. +/// Return exact match if found. +/// Return first OS match (without version number) otherwise. +/// Report error if no OS match found. +/// +/// Full path to .NET CLI binary +/// BuildPlan from build.json +/// Matched RID +string MatchLocalRuntimeID(string dotnetcli, BuildPlan buildPlan) +{ + var localRuntime = GetLocalRuntimeID(dotnetcli); + if (buildPlan.Rids.Contains(localRuntime)) + { + return localRuntime; + } + else + { + return buildPlan.Rids.First(runtime => { + var localRuntimeWithoutVersion = Regex.Replace(localRuntime, "(\\d|\\.)*-", "-"); + var runtimeWithoutVersion = Regex.Replace(runtime, "(\\d|\\.)*-", "-"); + return localRuntimeWithoutVersion.Equals(runtimeWithoutVersion); + }); + } +} + +/// +/// Generate an archive out of the given published folder. +/// Use ZIP for Windows runtimes. +/// Use TAR.GZ for non-Windows runtimes. +/// Use 7z to generate TAR.GZ on Windows if available. +/// +/// The runtime targeted by the published folder +/// The published folder +/// The target archive name (without extension) +void DoArchive(string runtime, DirectoryPath inputFolder, FilePath outputFile) +{ + // On all platforms use ZIP for Windows runtimes + if (runtime.Contains("win")) + { + var zipFile = outputFile.AppendExtension("zip"); + Zip(inputFolder, zipFile); + } + // On all platforms use TAR.GZ for Unix runtimes + else + { + var tarFile = outputFile.AppendExtension("tar.gz"); + // Use 7z to create TAR.GZ on Windows + if (IsRunningOnWindows()) + { + var tempFile = outputFile.AppendExtension("tar"); + try + { + var exitCode = StartProcess("7z", + new ProcessSettings + { + Arguments = $"a {tempFile}", + WorkingDirectory = inputFolder + }); + if (exitCode != 0) + { + throw new Exception($"Tar-ing failed for {inputFolder} {outputFile}"); + } + exitCode = StartProcess("7z", + new ProcessSettings + { + Arguments = $"a {tarFile} {tempFile}", + WorkingDirectory = inputFolder + }); + if (exitCode != 0) + { + throw new Exception($"Compression failed for {inputFolder} {outputFile}"); + } + DeleteFile(tempFile); + } + catch(Win32Exception) + { + Information("Warning: 7z not available on PATH to pack tar.gz results"); + } + } + // Use tar to create TAR.GZ on Unix + else + { + var exitCode = StartProcess("tar", + new ProcessSettings + { + Arguments = $"czf {tarFile} .", + WorkingDirectory = inputFolder + }); + if (exitCode != 0) + { + throw new Exception($"Compression failed for {inputFolder} {outputFile}"); + } + } + } +} + +/// +/// Extract the RID from a generated build folder. +/// Used when targeting unknown RID (for example during testing). +/// Throws exception when multiple RID folders found. +/// +/// Build path including RID folders +string GetRuntimeInPath(string path) +{ + var potentialRuntimes = GetDirectories(path); + if (potentialRuntimes.Count != 1) + { + throw new Exception($"Multiple runtimes when only one expected in {path}"); + } + var enumerator = potentialRuntimes.GetEnumerator(); + enumerator.MoveNext(); + return enumerator.Current.GetDirectoryName(); +} + +/// +/// Restrict the RIDs defined in build.json to a RID matching the local one. +/// +Task("RestrictToLocalRuntime") + .IsDependentOn("BuildEnvironment") + .Does(() => +{ + buildPlan.Rids = new string[] { MatchLocalRuntimeID(dotnetcli, buildPlan) }; +}); + +/// +/// Clean artifacts. +/// +Task("Cleanup") + .Does(() => +{ + if (DirectoryExists(artifactFolder)) + { + CleanDirectory(artifactFolder); + } + else + { + CreateDirectory(artifactFolder); + } + CreateDirectory(logFolder); + CreateDirectory(packageFolder); +}); + +/// +/// Install/update build environment. +/// +Task("BuildEnvironment") + .Does(() => +{ + var installScript = $"install.{shellExtension}"; + CreateDirectory(dotnetFolder); + var scriptPath = new FilePath($"{dotnetFolder}/{installScript}"); + DownloadFile($"{buildPlan.DotNetInstallScriptURL}/{installScript}", scriptPath); + if (!IsRunningOnWindows()) + { + StartProcess("chmod", + new ProcessSettings + { + Arguments = $"+x {scriptPath}" + }); + } + var installArgs = IsRunningOnWindows() ? $"{buildPlan.DotNetChannel} -version {buildPlan.DotNetVersion} -InstallDir {dotnetFolder}" : + $"-c {buildPlan.DotNetChannel} -v {buildPlan.DotNetVersion} -d {dotnetFolder}"; + StartProcess(shell, + new ProcessSettings + { + Arguments = $"{shellArgument} {scriptPath} {installArgs}" + }); + try + { + StartProcess(dotnetcli, + new ProcessSettings + { + Arguments = "--version" + }); + + } + catch (Win32Exception) + { + throw new Exception(".NET CLI binary cannot be found."); + } + + CreateDirectory(toolsFolder); + + NuGetInstall(xunitRunner, + new NuGetInstallSettings + { + ExcludeVersion = true, + OutputDirectory = toolsFolder, + NoCache = true, + Prerelease = true + }); +}); + +/// +/// Restore required NuGet packages. +/// +Task("Restore") + .IsDependentOn("BuildEnvironment") + .Does(() => +{ + var exitCode = StartProcess(dotnetcli, + new ProcessSettings + { + Arguments = "restore" + }); + if (exitCode != 0) + { + throw new Exception("Failed to restore."); + } +}); + +/// +/// Build Test projects. +/// +Task("BuildTest") + .IsDependentOn("BuildEnvironment") + .IsDependentOn("Restore") + .Does(() => +{ + foreach (var pair in buildPlan.TestProjects) + { + foreach (var framework in pair.Value) + { + var project = pair.Key; + var process = StartAndReturnProcess(dotnetcli, + new ProcessSettings + { + Arguments = $"build --framework {framework} --configuration {testConfiguration} {testFolder}/{project}", + RedirectStandardOutput = true + }); + process.WaitForExit(); + FileWriteLines($"{logFolder}/{project}-{framework}-build.log", process.GetStandardOutput().ToArray()); + } + } +}); + + +/// +/// Run tests for .NET Core (using .NET CLI). +/// +Task("TestCore") + .IsDependentOn("BuildEnvironment") + .IsDependentOn("BuildTest") + .Does(() => +{ + foreach (var pair in buildPlan.TestProjects) + { + foreach (var framework in pair.Value) + { + if (!framework.Equals("dnxcore50")) + { + continue; + } + + var project = pair.Key; + var exitCode = StartProcess(dotnetcli, + new ProcessSettings + { + Arguments = $"test -xml {logFolder}/{project}-{framework}-result.xml -notrait category=failing", + WorkingDirectory = $"{testFolder}/{project}" + }); + if (exitCode != 0) + { + throw new Exception($"Test failed {project} / {framework}"); + } + } + } +}); + +/// +/// Run tests for other frameworks (using XUnit2). +/// +Task("Test") + .IsDependentOn("BuildEnvironment") + .IsDependentOn("BuildTest") + .Does(() => +{ + foreach (var pair in buildPlan.TestProjects) + { + foreach (var framework in pair.Value) + { + // Testing against core happens in TestCore + if (framework.Equals("dnxcore50")) + { + continue; + } + + var project = pair.Key; + var runtime = GetRuntimeInPath($"{testFolder}/{project}/bin/{testConfiguration}/{framework}/*"); + var instanceFolder = $"{testFolder}/{project}/bin/{testConfiguration}/{framework}/{runtime}"; + // Copy xunit executable to test folder to solve path errors + CopyFileToDirectory($"{toolsFolder}/xunit.runner.console/tools/xunit.console.exe", instanceFolder); + CopyFileToDirectory($"{toolsFolder}/xunit.runner.console/tools/xunit.runner.utility.desktop.dll", instanceFolder); + var logFile = $"{logFolder}/{project}-{framework}-result.xml"; + var xunitSettings = new XUnit2Settings + { + ToolPath = $"{instanceFolder}/xunit.console.exe", + ArgumentCustomization = builder => + { + builder.Append("-xml"); + builder.Append(logFile); + return builder; + } + }; + xunitSettings.ExcludeTrait("category", new[] { "failing" }); + XUnit2($"{instanceFolder}/{project}.dll", xunitSettings); + } + } +}); + + +/// +/// Build, publish and package artifacts. +/// Targets all RIDs specified in build.json unless restricted by RestrictToLocalRuntime. +/// No dependencies on other tasks to support quick builds. +/// +Task("OnlyPublish") + .IsDependentOn("BuildEnvironment") + .Does(() => +{ + var project = buildPlan.MainProject; + foreach (var framework in buildPlan.Frameworks) + { + foreach (var runtime in buildPlan.Rids) + { + var outputFolder = $"{publishFolder}/{project}/{runtime}/{framework}"; + var exitCode = StartProcess(dotnetcli, + new ProcessSettings + { + Arguments = $"publish --framework {framework} --runtime {runtime} " + + $"--configuration {configuration} --output {outputFolder} " + + $"{sourceFolder}/{project}" + }); + if (exitCode != 0) + { + throw new Exception($"Failed to publish {project} / {framework}"); + } + + // Remove version number on Windows + var runtimeShort = Regex.Replace(runtime, "(\\d|\\.)*-", "-"); + // Simplify Ubuntu to Linux + runtimeShort = runtimeShort.Replace("ubuntu", "linux"); + var buildIdentifier = $"{runtimeShort}-{framework}"; + // Linux + dnx451 is renamed to Mono + if (runtimeShort.Contains("linux-") && framework.Equals("dnx451")) + { + buildIdentifier ="linux-mono"; + } + // No need to package OSX + dnx451 + else if (runtimeShort.Contains("osx-") && framework.Equals("dnx451")) + { + continue; + } + + DoArchive(runtime, outputFolder, $"{packageFolder}/{buildPlan.MainProject.ToLower()}-{buildIdentifier}"); + } + } +}); + + +/// +/// Alias for OnlyPublish. +/// Restricts publishing to local RID. +/// +Task("LocalPublish") + .IsDependentOn("Restore") + .IsDependentOn("RestrictToLocalRuntime") + .IsDependentOn("OnlyPublish") + .Does(() => +{ +}); + +/// +/// Alias for OnlyPublish. +/// Targets all RIDs as specified in build.json. +/// +Task("AllPublish") + .IsDependentOn("Restore") + .IsDependentOn("OnlyPublish") + .Does(() => +{ +}); + + +/// +/// Test the published binaries if they start up without errors. +/// Uses builds corresponding to local RID. +/// +Task("TestPublished") + .IsDependentOn("BuildEnvironment") + .Does(() => +{ + var project = buildPlan.MainProject; + foreach (var framework in buildPlan.Frameworks) + { + // Skip testing mono executables + if (!IsRunningOnWindows() && !framework.Equals("dnxcore50")) + { + continue; + } + var runtime = MatchLocalRuntimeID(dotnetcli, buildPlan); + var outputFolder = $"{publishFolder}/{project}/{runtime}/{framework}"; + var process = StartAndReturnProcess($"{outputFolder}/{project}", + new ProcessSettings + { + Arguments = $"-s {sourceFolder}/{project} --stdio", + }); + // Wait 10 seconds to see if project terminates early with error + bool exitsWithError = process.WaitForExit(10000); + if (exitsWithError) + { + throw new Exception($"Failed to run {project} / {runtime} / {framework}"); + } + } +}); + +/// +/// Clean install path. +/// +Task("CleanupInstall") + .Does(() => +{ + if (DirectoryExists(installFolder)) + { + CleanDirectory(installFolder); + } + else + { + CreateDirectory(installFolder); + } +}); + +/// +/// Quick build. +/// +Task("Quick") + .IsDependentOn("Cleanup") + .IsDependentOn("LocalPublish") + .Does(() => +{ +}); + +/// +/// Quick build + install. +/// +Task("Install") + .IsDependentOn("Cleanup") + .IsDependentOn("LocalPublish") + .IsDependentOn("CleanupInstall") + .Does(() => +{ + var project = buildPlan.MainProject; + foreach (var framework in buildPlan.Frameworks) + { + var outputFolder = $"{publishFolder}/{project}/{buildPlan.Rids[0]}/{framework}"; + CopyDirectory(outputFolder, installFolder); + } +}); + +/// +/// Full build targeting all RIDs specified in build.json. +/// +Task("All") + .IsDependentOn("Cleanup") + .IsDependentOn("Restore") + .IsDependentOn("TestCore") + .IsDependentOn("Test") + .IsDependentOn("AllPublish") + .IsDependentOn("TestPublished") + .Does(() => +{ +}); + +/// +/// Full build targeting local RID. +/// +Task("Local") + .IsDependentOn("Cleanup") + .IsDependentOn("Restore") + .IsDependentOn("TestCore") + .IsDependentOn("Test") + .IsDependentOn("LocalPublish") + .IsDependentOn("TestPublished") + .Does(() => +{ +}); + + +Task("Default") + .IsDependentOn("Local") + .Does(() => +{ +}); + +/// +/// Default to Local. +/// +RunTarget(target); diff --git a/build.json b/build.json index 56b8d565d7..a92fcf554e 100644 --- a/build.json +++ b/build.json @@ -1,6 +1,9 @@ { "DotNetFolder": ".dotnet", - "BuildToolsFolder": ".build", + "DotNetInstallScriptURL": "https://raw.githubusercontent.com/dotnet/cli/43ac2b45f4173b8228b44c8a9693ac7774104cbb/scripts/obtain", + "DotNetChannel": "beta", + "DotNetVersion": "1.0.0.001897", + "BuildToolsFolder": ".tools", "ArtifactsFolder": "artifacts", "TestProjects": { "OmniSharp.Bootstrap.Tests": [ @@ -29,4 +32,4 @@ "ubuntu.14.04-x64" ], "MainProject": "OmniSharp" -} \ No newline at end of file +} diff --git a/build.ps1 b/build.ps1 index 623fed54f9..e31fc9e485 100644 --- a/build.ps1 +++ b/build.ps1 @@ -1,30 +1,5 @@ -# Build OmniSharp -function _header($title) { - Write-Host *** $title *** -} +# Hack until updated install.sh is used with -InstallDir option +$env:DOTNET_INSTALL_DIR=$PWD.Path+"\.dotnet" -_header "Cleanup" -rm -r -force artifacts -ErrorAction SilentlyContinue - -_header "Installing dotnet" -$build_tools="$pwd\.build" -mkdir $build_tools -ErrorAction SilentlyContinue | Out-Null -invoke-webrequest -uri 'https://raw.githubusercontent.com/dotnet/cli/rel/1.0.0/scripts/obtain/install.ps1' -outfile $build_tools\install.ps1 - -if ($env:APPVEYOR -eq "True") -{ - $env:DOTNET_INSTALL_DIR=$PWD.Path+"\.dotnet" - $env:PATH=$env:PATH+";$pwd\.dotnet\cli" -} -else -{ - $env:PATH=$env:PATH+";$env:LocalAppData\Microsoft\dotnet\cli" -} - -& $build_tools\install.ps1 beta - -_header "Build tools" -& dotnet restore tools -& dotnet publish .\tools\PublishProject -o $build_tools\PublishProject - -& $build_tools\PublishProject\PublishProject.exe +.\cake-bootstrap.ps1 --experimental @args +exit $LASTEXITCODE diff --git a/build.sh b/build.sh index d81cf8f23c..a8d5856318 100755 --- a/build.sh +++ b/build.sh @@ -1,50 +1,3 @@ #!/bin/bash -work_dir=`pwd` -build_tools=$work_dir/.build - -header() { - if [ "$TRAVIS" == true ]; then - printf "%b\n" "*** $1 ***" - else - printf "%b\n" "\e[1;32m*** $1 ***\e[0m" - fi -} - -header "Cleanup" -rm -rf artifacts -mkdir -p $build_tools - -header "Installing dotnet" - -DOTNET_CHANNEL="beta" -DOTNET_VERSION="1.0.0.001897" -DOTNET_INSTALL="$work_dir/.dotnet" -DOTNET_SCRIPT="https://raw.githubusercontent.com/dotnet/cli/43ac2b45f4173b8228b44c8a9693ac7774104cbb/scripts/obtain/install.sh" -DOTNET="$work_dir/.dotnet/cli/dotnet" - -echo "Installing dotnet from $DOTNET_CHANNEL channel for version $DOTNET_VERSION" -echo "Execute install script" -echo " source: $DOTNET_SCRIPT" -echo " version: $DOTNET_VERSION" -echo " channel: $DOTNET_CHANNEL" -echo " install: $DOTNET_INSTALL" - -bash -c "`curl -s $DOTNET_SCRIPT`" install.sh -c $DOTNET_CHANNEL -v $DOTNET_VERSION -d $DOTNET_INSTALL - -$DOTNET --version # || { echo >&2 "dotnet is not installed correctly" && exit 1 } - -# Handle to many files on osx -if [ "$TRAVIS_OS_NAME" == "osx" ] || [ `uname` == "Darwin" ]; then - ulimit -n 4096 -fi - -# Build -header "Building" -$DOTNET restore tools -$DOTNET publish ./tools/PublishProject -o $build_tools/PublishProject/ -$build_tools/PublishProject/PublishProject - -# OmniSharp.Roslyn.CSharp.Tests is skipped on dnx451 target because an issue in MEF assembly load on xunit -# Failure repo: https://github.com/troydai/loaderfailure - +bash ./cake-bootstrap.sh "$@" diff --git a/cake-bootstrap.ps1 b/cake-bootstrap.ps1 new file mode 100644 index 0000000000..edb176d7b4 --- /dev/null +++ b/cake-bootstrap.ps1 @@ -0,0 +1,138 @@ +<# + +.SYNOPSIS +This is a Powershell script to bootstrap a Cake build. + +.DESCRIPTION +This Powershell script will download NuGet if missing, restore NuGet tools (including Cake) +and execute your Cake build script with the parameters you provide. + +.PARAMETER Script +The build script to execute. +.PARAMETER Target +The build script target to run. +.PARAMETER Configuration +The build configuration to use. +.PARAMETER Verbosity +Specifies the amount of information to be displayed. +.PARAMETER Experimental +Tells Cake to use the latest Roslyn release. +.PARAMETER WhatIf +Performs a dry run of the build script. +No tasks will be executed. +.PARAMETER Mono +Tells Cake to use the Mono scripting engine. + +.LINK +http://cakebuild.net + +#> + +[CmdletBinding()] +Param( + [string]$Script = "build.cake", + [ValidateSet("Quiet", "Minimal", "Normal", "Verbose", "Diagnostic")] + [string]$Verbosity = "Verbose", + [switch]$Experimental, + [Alias("DryRun","Noop")] + [switch]$WhatIf, + [switch]$Mono, + [switch]$SkipToolPackageRestore, + [Parameter(Position=0,Mandatory=$false,ValueFromRemainingArguments=$true)] + [string[]]$ScriptArgs +) + +Write-Host "Preparing to run build script..." + +$PS_SCRIPT_ROOT = split-path -parent $MyInvocation.MyCommand.Definition; +$TOOLS_DIR = Join-Path $PSScriptRoot ".tools" +$NUGET_EXE = Join-Path $TOOLS_DIR "nuget.exe" +$NUGET_URL = "http://dist.nuget.org/win-x86-commandline/latest/nuget.exe" +$CAKE_EXE = Join-Path $TOOLS_DIR "Cake/Cake.exe" +$PACKAGES_CONFIG = Join-Path $TOOLS_DIR "packages.config" + +# Should we use mono? +$UseMono = ""; +if($Mono.IsPresent) { + Write-Verbose -Message "Using the Mono based scripting engine." + $UseMono = "-mono" +} + +# Should we use the new Roslyn? +$UseExperimental = ""; +if($Experimental.IsPresent -and !($Mono.IsPresent)) { + Write-Verbose -Message "Using experimental version of Roslyn." + $UseExperimental = "-experimental" +} + +# Is this a dry run? +$UseDryRun = ""; +if($WhatIf.IsPresent) { + $UseDryRun = "-dryrun" +} + +# Make sure tools folder exists +if ((Test-Path $PSScriptRoot) -and !(Test-Path $TOOLS_DIR)) { + Write-Verbose -Message "Creating tools directory..." + New-Item -Path $TOOLS_DIR -Type directory | out-null +} + +# Make sure that packages.config exist. +if (!(Test-Path $PACKAGES_CONFIG)) { + Write-Verbose -Message "Downloading packages.config..." + try { Invoke-WebRequest -Uri http://cakebuild.net/bootstrapper/packages -OutFile $PACKAGES_CONFIG } catch { + Throw "Could not download packages.config." + } +} + +# Try find NuGet.exe in path if not exists +if (!(Test-Path $NUGET_EXE)) { + Write-Verbose -Message "Trying to find nuget.exe in PATH..." + $existingPaths = $Env:Path -Split ';' | Where-Object { Test-Path $_ } + $NUGET_EXE_IN_PATH = Get-ChildItem -Path $existingPaths -Filter "nuget.exe" | Select -First 1 + if ($NUGET_EXE_IN_PATH -ne $null -and (Test-Path $NUGET_EXE_IN_PATH.FullName)) { + Write-Verbose -Message "Found in PATH at $($NUGET_EXE_IN_PATH.FullName)." + $NUGET_EXE = $NUGET_EXE_IN_PATH.FullName + } +} + +# Try download NuGet.exe if not exists +if (!(Test-Path $NUGET_EXE)) { + Write-Verbose -Message "Downloading NuGet.exe..." + try { + (New-Object System.Net.WebClient).DownloadFile($NUGET_URL, $NUGET_EXE) + } catch { + Throw "Could not download NuGet.exe." + } +} + +# Save nuget.exe path to environment to be available to child processed +$ENV:NUGET_EXE = $NUGET_EXE + +# Restore tools from NuGet? +if(-Not $SkipToolPackageRestore.IsPresent) +{ + # Restore packages from NuGet. + Push-Location + Set-Location $TOOLS_DIR + + Write-Verbose -Message "Restoring tools from NuGet..." + $NuGetOutput = Invoke-Expression "&`"$NUGET_EXE`" install -ExcludeVersion -OutputDirectory `"$TOOLS_DIR`"" + Write-Verbose -Message ($NuGetOutput | out-string) + + Pop-Location + if ($LASTEXITCODE -ne 0) + { + exit $LASTEXITCODE + } +} + +# Make sure that Cake has been installed. +if (!(Test-Path $CAKE_EXE)) { + Throw "Could not find Cake.exe at $CAKE_EXE" +} + +# Start Cake +Write-Host "Running build script..." +Invoke-Expression "& `"$CAKE_EXE`" `"$Script`" -verbosity=`"$Verbosity`" $UseMono $UseDryRun $UseExperimental $ScriptArgs" +exit $LASTEXITCODE diff --git a/cake-bootstrap.sh b/cake-bootstrap.sh new file mode 100644 index 0000000000..5822455e17 --- /dev/null +++ b/cake-bootstrap.sh @@ -0,0 +1,78 @@ +#!/usr/bin/env bash +############################################################### +# This is the Cake bootstrapper script that is responsible for +# downloading Cake and all specified tools from NuGet. +############################################################### + +# Define directories. +SCRIPT_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) +TOOLS_DIR=$SCRIPT_DIR/.tools +export NUGET_EXE=$TOOLS_DIR/nuget.exe +CAKE_EXE=$TOOLS_DIR/Cake/Cake.exe + +# Define default arguments. +SCRIPT="build.cake" +VERBOSITY="verbose" +DRYRUN= +SHOW_VERSION=false +SCRIPT_ARGUMENTS=() + +# Parse arguments. +for i in "$@"; do + case $1 in + -s|--script) SCRIPT="$2"; shift ;; + -v|--verbosity) VERBOSITY="$2"; shift ;; + -d|--dryrun) DRYRUN="-dryrun" ;; + --version) SHOW_VERSION=true ;; + --) shift; SCRIPT_ARGUMENTS+=("$@"); break ;; + *) SCRIPT_ARGUMENTS+=("$1") ;; + esac + shift +done + +# Make sure the tools folder exist. +if [ ! -d "$TOOLS_DIR" ]; then + mkdir "$TOOLS_DIR" +fi + +# Make sure that packages.config exist. +if [ ! -f "$TOOLS_DIR/packages.config" ]; then + echo "Downloading packages.config..." + curl -Lsfo "$TOOLS_DIR/packages.config" http://cakebuild.net/bootstrapper/packages + if [ $? -ne 0 ]; then + echo "An error occured while downloading packages.config." + exit 1 + fi +fi + +# Download NuGet if it does not exist. +if [ ! -f "$NUGET_EXE" ]; then + echo "Downloading NuGet..." + curl -Lsfo "$NUGET_EXE" https://dist.nuget.org/win-x86-commandline/latest/nuget.exe + if [ $? -ne 0 ]; then + echo "An error occured while downloading nuget.exe." + exit 1 + fi +fi + +# Restore tools from NuGet. +pushd "$TOOLS_DIR" >/dev/null +mono "$NUGET_EXE" install -ExcludeVersion +if [ $? -ne 0 ]; then + echo "Could not restore NuGet packages." + exit 1 +fi +popd >/dev/null + +# Make sure that Cake has been installed. +if [ ! -f "$CAKE_EXE" ]; then + echo "Could not find Cake.exe at '$CAKE_EXE'." + exit 1 +fi + +# Start Cake +if $SHOW_VERSION; then + exec mono "$CAKE_EXE" -version +else + exec mono "$CAKE_EXE" $SCRIPT -verbosity=$VERBOSITY $DRYRUN "${SCRIPT_ARGUMENTS[@]}" +fi diff --git a/tools/PublishProject/BuildPlan.cs b/tools/PublishProject/BuildPlan.cs deleted file mode 100644 index e1cc462c5e..0000000000 --- a/tools/PublishProject/BuildPlan.cs +++ /dev/null @@ -1,44 +0,0 @@ -using System; -using System.Collections.Generic; -using System.IO; -using Newtonsoft.Json; - -namespace OmniSharp.Tools.PublishProject -{ - public class BuildPlan - { - public static BuildPlan Parse(string root) - { - try - { - var content = File.ReadAllText(Path.Combine(root, "build.json")); - var result = JsonConvert.DeserializeObject(content); - result.Root = root; - - return result; - } - catch (System.Exception ex) - { - Console.Error.WriteLine(ex.Message); - throw; - } - } - - public IDictionary TestProjects { get; set; } - - public string BuildToolsFolder { get; set; } - - public string ArtifactsFolder { get; set; } - - public string DotNetFolder { get; set; } - - public string[] Frameworks { get; set; } - - public string[] Rids { get; set; } - - public string MainProject { get; set; } - - [JsonIgnore] - public string Root { get; set; } - } -} \ No newline at end of file diff --git a/tools/PublishProject/DotNetExecutor.cs b/tools/PublishProject/DotNetExecutor.cs deleted file mode 100644 index 8d63b4d0a1..0000000000 --- a/tools/PublishProject/DotNetExecutor.cs +++ /dev/null @@ -1,105 +0,0 @@ -using System; -using System.Diagnostics; -using System.IO; -using System.Linq; -using Microsoft.Extensions.PlatformAbstractions; - -namespace OmniSharp.Tools.PublishProject -{ - public class DotNetExecutor - { - private readonly string _executablePath; - private readonly string _executableName; - - public DotNetExecutor(BuildPlan plan) - { - if (PlatformServices.Default.Runtime.OperatingSystemPlatform == Platform.Windows) - { - _executableName = "dotnet.exe"; - } - else - { - _executableName = "dotnet"; - } - - if (Directory.Exists(Path.Combine(plan.Root, plan.DotNetFolder))) - { - _executablePath = Directory.GetFiles(Path.Combine(plan.Root, plan.DotNetFolder), _executableName, SearchOption.AllDirectories) - .First(); - } - else - { - _executablePath = _executableName; - } - } - - public int Build(string testFolder) - { - var startInfo = new ProcessStartInfo(_executablePath, "build") - { - WorkingDirectory = testFolder, - UseShellExecute = false - }; - - var process = Process.Start(startInfo); - process.WaitForExit(); - - return process.ExitCode; - } - - public int Test(string testFolder) - { - var startInfo = new ProcessStartInfo(_executablePath, "test") - { - WorkingDirectory = testFolder, - UseShellExecute = false - }; - - var process = Process.Start(startInfo); - process.WaitForExit(); - - return process.ExitCode; - } - - public int Restore(string folder) - { - // restore the package for under given runtime - var restoreArgument = $"restore"; - var restoreStartInfo = new ProcessStartInfo(_executablePath, restoreArgument) - { - UseShellExecute = false, - WorkingDirectory = folder - }; - - var process = Process.Start(restoreStartInfo); - - process.WaitForExit(); - return process.ExitCode; - } - - public int Publish(string publishOutput, string projectPath, string rid, string framework) - { - var publishArgument = $"publish -o {publishOutput} -f {framework} -r {rid}"; - var publisStartInfo = new ProcessStartInfo(_executablePath, publishArgument) - { - UseShellExecute = false, - WorkingDirectory = projectPath - }; - - var process = Process.Start(publisStartInfo); - if (!process.WaitForExit((int)TimeSpan.FromMinutes(10).TotalMilliseconds)) - { - return -1; - } - else - { - return process.ExitCode; - } - } - - public override string ToString() - { - return _executablePath; - } - } -} diff --git a/tools/PublishProject/Program.cs b/tools/PublishProject/Program.cs deleted file mode 100755 index 04804ce8a2..0000000000 --- a/tools/PublishProject/Program.cs +++ /dev/null @@ -1,162 +0,0 @@ -using System; -using System.Diagnostics; -using System.IO; -using System.IO.Compression; -using System.Text.RegularExpressions; -using Microsoft.Extensions.PlatformAbstractions; - -namespace OmniSharp.Tools.PublishProject -{ - public class Program - { - public static int Main(string[] args) - { - Console.WriteLine("Publish project OmniSharp"); - var root = FindRoot(); - var buildPlan = BuildPlan.Parse(root); - - var projectPath = Path.Combine(root, "src", buildPlan.MainProject); - if (!Directory.Exists(projectPath)) - { - Console.WriteLine($"Can't find project {buildPlan.MainProject}"); - return 1; - } - - var publishOutput = Path.Combine(root, buildPlan.ArtifactsFolder, "publish"); - if (!Directory.Exists(publishOutput)) - { - Directory.CreateDirectory(publishOutput); - } - - var packageOutput = Path.Combine(root, buildPlan.ArtifactsFolder, "package"); - if (!Directory.Exists(packageOutput)) - { - Directory.CreateDirectory(packageOutput); - } - - var dotnetExecutable = new DotNetExecutor(buildPlan); - - Console.WriteLine($" root: {root}"); - Console.WriteLine($" project: {buildPlan.MainProject}"); - Console.WriteLine($" dotnet: {dotnetExecutable}"); - Console.WriteLine($" source: {projectPath}"); - Console.WriteLine($"publish out: {publishOutput}"); - Console.WriteLine($"package out: {packageOutput}"); - Console.WriteLine($" frameworks: {string.Join(", ", buildPlan.Frameworks)}"); - Console.WriteLine($" runtime: {string.Join(", ", buildPlan.Rids)}"); - - if (!TestActions.RunTests(buildPlan)) - { - return 1; - } - - if (dotnetExecutable.Restore(Path.Combine(root, "src")) != 0) - { - Console.Error.WriteLine("Fail to restore projects for {rid}"); - return 1; - } - - foreach (var rid in buildPlan.Rids) - { - foreach (var framework in buildPlan.Frameworks) - { - var publish = Path.Combine(publishOutput, buildPlan.MainProject, rid, framework); - if(dotnetExecutable.Publish(publish, projectPath, rid, framework) != 0) - { - Console.Error.WriteLine($"Fail to publish {projectPath} on {framework} for {rid}"); - return 1; - } - - Package(publish, packageOutput, buildPlan.MainProject, rid, framework); - } - } - - return 0; - } - - private static void Package(string publishOutput, - string packageOutput, - string projectName, - string rid, - string framework) - { - var runtimeString = Regex.Replace(rid, "(\\d|\\.)*-", "-"); - // Simplify Ubuntu to Linux - runtimeString = runtimeString.Replace("ubuntu", "linux"); - var buildIdentifier = $"{runtimeString}-{framework}"; - // Linux + dnx451 is renamed to Mono - if (runtimeString.Contains("linux-") && framework.Equals("dnx451")) - buildIdentifier ="linux-mono"; - // No need to package OSX + dnx451 - else if (runtimeString.Contains("osx-") && framework.Equals("dnx451")) - return; - var baseFilePath = Path.GetFullPath(Path.Combine(packageOutput, $"{projectName.ToLower()}-{buildIdentifier}")); - // On all platforms use ZIP for Windows runtimes - if (runtimeString.Contains("win-")) - { - var zipFilePath = Path.ChangeExtension(baseFilePath, "zip"); - ZipFile.CreateFromDirectory(publishOutput, zipFilePath); - } - // On all platforms use TAR.GZ for Unix runtimes - else - { - var tarFilePath = Path.ChangeExtension(baseFilePath, "tar.gz"); - // Use 7z to create TAR.GZ on Windows - if (PlatformServices.Default.Runtime.OperatingSystemPlatform == Platform.Windows) - { - var tempFilePath = Path.ChangeExtension(baseFilePath, "tar"); - var tarStartInfo = new ProcessStartInfo("7z", $"a {tempFilePath}") - { - UseShellExecute = false, - WorkingDirectory = publishOutput - }; - var tarProcess = Process.Start(tarStartInfo); - tarProcess.WaitForExit(); - if (tarProcess.ExitCode != 0) - throw new InvalidOperationException($"Tar-ing failed for {projectName} {rid}"); - var compressStartInfo = new ProcessStartInfo("7z", $"a {tarFilePath} {tempFilePath}") - { - UseShellExecute = false, - WorkingDirectory = publishOutput - }; - var compressProcess = Process.Start(compressStartInfo); - compressProcess.WaitForExit(); - if (tarProcess.ExitCode != 0) - throw new InvalidOperationException($"Compression failed for {projectName} {rid}"); - File.Delete(tempFilePath); - } - // Use tar to create TAR.GZ on Unix - else - { - var tarStartInfo = new ProcessStartInfo("tar", $"czf {tarFilePath} .") - { - UseShellExecute = false, - WorkingDirectory = publishOutput - }; - var tarProcess = Process.Start(tarStartInfo); - tarProcess.WaitForExit(); - if (tarProcess.ExitCode != 0) - throw new InvalidOperationException($"Compression failed for {projectName} {rid}"); - } - } - } - - private static string FindRoot() - { - var countDown = 100; - var currentDir = AppContext.BaseDirectory; - while (!File.Exists(Path.Combine(currentDir, "OmniSharp.sln")) && Path.GetPathRoot(currentDir) != currentDir && countDown > 0) - { - currentDir = Path.GetDirectoryName(currentDir); - countDown--; - } - - if (countDown < 0) - { - throw new InvalidOperationException("Can't find root directory"); - } - - return currentDir; - } - } -} diff --git a/tools/PublishProject/TestActions.cs b/tools/PublishProject/TestActions.cs deleted file mode 100644 index bea60cb665..0000000000 --- a/tools/PublishProject/TestActions.cs +++ /dev/null @@ -1,193 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.IO; -using System.Linq; -using System.Net.Http; -using Microsoft.Extensions.PlatformAbstractions; - -namespace OmniSharp.Tools.PublishProject -{ - public class TestActions - { - private const string NuGetCacheFileName = "nuget.latest.exe"; - - public static bool RunTests(BuildPlan buildPlan) - { - var xunitTools = PrepareTools(buildPlan); - var dotnet = new DotNetExecutor(buildPlan); - var failures = new List(); - - dotnet.Restore(Path.Combine(buildPlan.Root, "src")); - dotnet.Restore(Path.Combine(buildPlan.Root, "tests")); - - foreach (var pair in buildPlan.TestProjects) - { - RunTestProject(pair.Key, pair.Value, buildPlan, dotnet, xunitTools, failures); - } - - if (failures.Any()) - { - foreach (var f in failures) - { - Console.Error.WriteLine(f); - } - - return false; - } - else - { - return true; - } - } - - private static void RunTestProject(string project, - string[] frameworks, - BuildPlan buildPlan, - DotNetExecutor dotnet, - string xunitTools, - List failures) - { - var testFolder = Path.Combine(buildPlan.Root, "tests", project); - - if (dotnet.Build(testFolder) != 0) - { - failures.Add($"Test build failed: {project}"); - } - - foreach (var framework in frameworks) - { - if (framework == "dnx451") - { - if (!RunTestProjectForFullCLR(testFolder, project, xunitTools)) - { - failures.Add($"Test failed: {project} / {framework}"); - } - } - else - { - if (dotnet.Test(testFolder) != 0) - { - failures.Add($"Test failed: {project} / {framework}"); - } - } - } - } - - private static bool RunTestProjectForFullCLR(string testFolder, string project, string xunitTools) - { - var output = Directory.GetFiles(Path.Combine(testFolder, "bin", "Debug", "dnx451"), $"{project}.dll", SearchOption.AllDirectories) - .OrderByDescending(path=>path.Length) - .First(); - output = Path.GetDirectoryName(output); - - foreach (var file in Directory.GetFiles(xunitTools)) - { - File.Copy(file, Path.Combine(output, Path.GetFileName(file)), overwrite: true); - } - - var argument = $"{Path.Combine(output, project)}.dll -parallel none -notrait category=failing"; - ProcessStartInfo startInfo; - if (PlatformServices.Default.Runtime.OperatingSystemPlatform == Platform.Windows) - { - startInfo = new ProcessStartInfo(Path.Combine(output, "xunit.console.x86.exe"), argument); - } - else - { - startInfo = new ProcessStartInfo("mono", Path.Combine(output, "xunit.console.x86.exe") + " " + argument); - } - - var p = Process.Start(startInfo); - if (p.WaitForExit((int)TimeSpan.FromMinutes(30).TotalMilliseconds)) - { - return p.ExitCode == 0; - } - else - { - return false; - } - } - - private static string PrepareTools(BuildPlan buildPlan) - { - var nuget = GetNuGet(buildPlan); - return GetXunitRunner(nuget, buildPlan); - } - - private static string GetXunitRunner(string nuget, BuildPlan buildPlan) - { - var xunitRunnerFolder = Path.Combine(buildPlan.Root, buildPlan.BuildToolsFolder, "xunit.runner.console"); - if (!Directory.Exists(xunitRunnerFolder)) - { - var argument = $"install xunit.runner.console -ExcludeVersion -o {Path.Combine(buildPlan.Root, buildPlan.BuildToolsFolder)} -nocache -pre -Source https://api.nuget.org/v3/index.json"; - ProcessStartInfo startInfo; - if (PlatformServices.Default.Runtime.OperatingSystemPlatform == Platform.Windows) - { - startInfo = new ProcessStartInfo(nuget, argument); - } - else - { - startInfo = new ProcessStartInfo("mono", $"{nuget} {argument}"); - } - - var process = Process.Start(startInfo); - if (!process.WaitForExit((int)TimeSpan.FromMinutes(5).TotalMilliseconds)) - { - throw new InvalidOperationException($"Downloading NuGet.exe timeout"); - } - } - - return Path.Combine(xunitRunnerFolder, "tools"); - } - - private static string GetNuGet(BuildPlan buildPlan) - { - string nugetCache; - string home; - switch (PlatformServices.Default.Runtime.OperatingSystemPlatform) - { - case Platform.Windows: - nugetCache = Path.Combine(Environment.GetEnvironmentVariable("LocalAppData"), "NuGet"); - break; - case Platform.Darwin: - home = Environment.GetEnvironmentVariable("HOME"); - nugetCache = Path.Combine(home, "Library", "Caches", "OmniSharpBuild"); - break; - default: - home = Environment.GetEnvironmentVariable("XDG_DATA_HOME"); - if (string.IsNullOrEmpty(home)) - { - home = Environment.GetEnvironmentVariable("HOME"); - nugetCache = Path.Combine(home, ".local", "share"); - } - else - { - nugetCache = home; - } - break; - } - - if (!Directory.Exists(nugetCache)) - { - Directory.CreateDirectory(nugetCache); - } - - nugetCache = Path.Combine(nugetCache, NuGetCacheFileName); - - if (!File.Exists(nugetCache)) - { - var client = new HttpClient(); - var response = client.GetAsync("https://dist.nuget.org/win-x86-commandline/latest/nuget.exe").Result; - using (var fs = File.Create(nugetCache)) - { - response.Content.CopyToAsync(fs).Wait(); - } - } - - var result = Path.Combine(buildPlan.BuildToolsFolder, "nuget.exe"); - File.Copy(nugetCache, result, overwrite: true); - - return result; - } - } -} \ No newline at end of file diff --git a/tools/PublishProject/project.json b/tools/PublishProject/project.json deleted file mode 100755 index a8e176ac84..0000000000 --- a/tools/PublishProject/project.json +++ /dev/null @@ -1,24 +0,0 @@ -{ - "version": "1.0.0-*", - "compilationOptions": { - "emitEntryPoint": true - }, - "dependencies": { - "NETStandard.Library": "1.0.0-rc2-23910", - "Microsoft.Extensions.PlatformAbstractions": "1.0.0-rc2-20143", - "Newtonsoft.Json": "8.0.2", - "System.Diagnostics.Process": "4.1.0-rc2-23911", - "System.Dynamic.Runtime": "4.0.11-rc2-23911", - "System.IO.Compression": "4.1.0-rc2-23911", - "System.IO.Compression.ZipFile": "4.0.1-rc2-23911", - "System.IO.FileSystem": "4.0.1-rc2-23911", - "System.Runtime.Serialization.Primitives": "4.1.1-rc2-23911", - "System.Xml.XDocument": "4.0.11-rc2-23911", - "System.Net.Http": "4.0.1-rc2-23911" - }, - "frameworks": { - "netstandardapp1.5": { - "imports": "dnxcore50" - } - } -} \ No newline at end of file From f53c47ec115cd26e4b4339cc9ec516052c256d32 Mon Sep 17 00:00:00 2001 From: Istvan Haller Date: Thu, 24 Mar 2016 08:58:04 +0100 Subject: [PATCH 2/7] Merged with dev changes to allow OSX failure. --- .travis.yml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index c0fcc97cf7..fc0e4c4d42 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,6 +10,9 @@ os: - linux - osx osx_image: xcode7.1 +matrix: + allow_failures: + - os: osx before_install: - if [ "$TRAVIS_OS_NAME" == "osx" ]; then brew update; fi - if [ "$TRAVIS_OS_NAME" == "osx" ]; then brew install jq; fi @@ -26,7 +29,7 @@ addons: - zlib1g - curl notifications: - slack: + slack: rooms: - omnisharp:U358j4McaEOIzFqXvGexVokC#general on_success: change @@ -37,7 +40,7 @@ deploy: api_key: secure: N9hansErZKHl7G5Ed/hcBgwcvLuRjB7YAskAvSAYB+luacV6rSK7Vlm/4NyjaZCwWv5wOdBphle2S4yZLRDTdMwLrdQWwWYeZI60kE22c1amKJaf6j5ai2u/P3bt55klQ2yO2U/LacwHVoRtJlVdwSAXuDQ3zMd88VbBModQyxE= file_glob: true - file: artifacts/package/*${TRAVIS_OS_NAME}*.tar.gz + file: artifacts/package/*.tar.gz skip_cleanup: true on: repo: OmniSharp/omnisharp-roslyn From 11c67a94fd1fd0aefc0b9ed890d2c79e794c2fc5 Mon Sep 17 00:00:00 2001 From: Istvan Haller Date: Thu, 24 Mar 2016 09:21:27 +0100 Subject: [PATCH 3/7] Attempting to update to new install script. --- build.cake | 13 ++++++++++--- build.json | 3 ++- build.ps1 | 3 --- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/build.cake b/build.cake index 7bfdd84d53..9a623c650e 100644 --- a/build.cake +++ b/build.cake @@ -29,6 +29,7 @@ public class BuildPlan public IDictionary TestProjects { get; set; } public string BuildToolsFolder { get; set; } public string ArtifactsFolder { get; set; } + public bool UseSystemDotNetPath { get; set; } public string DotNetFolder { get; set; } public string DotNetInstallScriptURL { get; set; } public string DotNetChannel { get; set; } @@ -42,7 +43,8 @@ var buildPlan = DeserializeJsonFromFile($"{workingDirectory}/build.js // Folders and tools var dotnetFolder = $"{workingDirectory}/{buildPlan.DotNetFolder}"; -var dotnetcli = $"{dotnetFolder}/cli/dotnet"; +var dotnetcli = buildPlan.UseSystemDotNetPath ? "dotnet" : + $"{dotnetFolder}/dotnet"; var toolsFolder = $"{workingDirectory}/{buildPlan.BuildToolsFolder}"; var xunitRunner = "xunit.runner.console"; @@ -241,8 +243,13 @@ Task("BuildEnvironment") Arguments = $"+x {scriptPath}" }); } - var installArgs = IsRunningOnWindows() ? $"{buildPlan.DotNetChannel} -version {buildPlan.DotNetVersion} -InstallDir {dotnetFolder}" : - $"-c {buildPlan.DotNetChannel} -v {buildPlan.DotNetVersion} -d {dotnetFolder}"; + var installArgs = IsRunningOnWindows() ? $"{buildPlan.DotNetChannel} -version {buildPlan.DotNetVersion}" : + $"-c {buildPlan.DotNetChannel} -v {buildPlan.DotNetVersion}"; + if (!buildPlan.UseSystemDotNetPath) + { + installArgs = IsRunningOnWindows() ? $"{installArgs} -InstallDir {dotnetFolder}" : + $"{installArgs} -i {dotnetFolder}"; + } StartProcess(shell, new ProcessSettings { diff --git a/build.json b/build.json index a92fcf554e..f1fb8344a1 100644 --- a/build.json +++ b/build.json @@ -1,6 +1,7 @@ { + "UseSystemDotNetPath" : "false", "DotNetFolder": ".dotnet", - "DotNetInstallScriptURL": "https://raw.githubusercontent.com/dotnet/cli/43ac2b45f4173b8228b44c8a9693ac7774104cbb/scripts/obtain", + "DotNetInstallScriptURL": "https://raw.githubusercontent.com/dotnet/cli/78e60bcb8b06c7787a9eb0356cf9ab3f1e76b86e/scripts/obtain", "DotNetChannel": "beta", "DotNetVersion": "1.0.0.001897", "BuildToolsFolder": ".tools", diff --git a/build.ps1 b/build.ps1 index e31fc9e485..eb0e3b79f9 100644 --- a/build.ps1 +++ b/build.ps1 @@ -1,5 +1,2 @@ -# Hack until updated install.sh is used with -InstallDir option -$env:DOTNET_INSTALL_DIR=$PWD.Path+"\.dotnet" - .\cake-bootstrap.ps1 --experimental @args exit $LASTEXITCODE From cf5272841beb48df1a9f79ed1132d5a78b0f01bc Mon Sep 17 00:00:00 2001 From: David Driscoll Date: Thu, 24 Mar 2016 21:38:29 -0400 Subject: [PATCH 4/7] move cake scripts into /scripts --- build.ps1 | 2 +- build.sh | 2 +- cake-bootstrap.ps1 => scripts/cake-bootstrap.ps1 | 0 cake-bootstrap.sh => scripts/cake-bootstrap.sh | 0 4 files changed, 2 insertions(+), 2 deletions(-) rename cake-bootstrap.ps1 => scripts/cake-bootstrap.ps1 (100%) rename cake-bootstrap.sh => scripts/cake-bootstrap.sh (100%) diff --git a/build.ps1 b/build.ps1 index eb0e3b79f9..f7467e4c92 100644 --- a/build.ps1 +++ b/build.ps1 @@ -1,2 +1,2 @@ -.\cake-bootstrap.ps1 --experimental @args +.\scripts\cake-bootstrap.ps1 --experimental @args exit $LASTEXITCODE diff --git a/build.sh b/build.sh index a8d5856318..b7cdd953df 100755 --- a/build.sh +++ b/build.sh @@ -1,3 +1,3 @@ #!/bin/bash -bash ./cake-bootstrap.sh "$@" +bash ./scripts/cake-bootstrap.sh "$@" diff --git a/cake-bootstrap.ps1 b/scripts/cake-bootstrap.ps1 similarity index 100% rename from cake-bootstrap.ps1 rename to scripts/cake-bootstrap.ps1 diff --git a/cake-bootstrap.sh b/scripts/cake-bootstrap.sh similarity index 100% rename from cake-bootstrap.sh rename to scripts/cake-bootstrap.sh From 5688b25c1900932abad5f294f27e62889a069e2e Mon Sep 17 00:00:00 2001 From: David Driscoll Date: Thu, 24 Mar 2016 21:50:16 -0400 Subject: [PATCH 5/7] limit deployment uploads for mac --- .travis.yml | 2 +- build.sh | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 6a2962e0c1..7b830e7e50 100644 --- a/.travis.yml +++ b/.travis.yml @@ -37,7 +37,7 @@ deploy: api_key: secure: N9hansErZKHl7G5Ed/hcBgwcvLuRjB7YAskAvSAYB+luacV6rSK7Vlm/4NyjaZCwWv5wOdBphle2S4yZLRDTdMwLrdQWwWYeZI60kE22c1amKJaf6j5ai2u/P3bt55klQ2yO2U/LacwHVoRtJlVdwSAXuDQ3zMd88VbBModQyxE= file_glob: true - file: artifacts/package/*.tar.gz + file: artifacts/package/*${TRAVIS_OS_NAME}*.tar.gz skip_cleanup: true on: repo: OmniSharp/omnisharp-roslyn diff --git a/build.sh b/build.sh index b7cdd953df..cd1fde7c34 100755 --- a/build.sh +++ b/build.sh @@ -1,3 +1,6 @@ #!/bin/bash - +# Handle to many files on osx +if [ "$TRAVIS_OS_NAME" == "osx" ] || [uname== "Darwin" ]; then + ulimit -n 4096 +fi bash ./scripts/cake-bootstrap.sh "$@" From cd65e419ff4b58afe95f3be290723158fbb0153f Mon Sep 17 00:00:00 2001 From: David Driscoll Date: Thu, 24 Mar 2016 22:02:31 -0400 Subject: [PATCH 6/7] Limit Rids to given platform, needs improvement for osx/linux --- build.cake | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/build.cake b/build.cake index 9a623c650e..6d78d636b2 100644 --- a/build.cake +++ b/build.cake @@ -40,6 +40,18 @@ public class BuildPlan } var buildPlan = DeserializeJsonFromFile($"{workingDirectory}/build.json"); +// Limit scope if things we build +buildPlan.Rids = buildPlan.Rids.Where(rid => { + if (IsRunningOnWindows()) + { + return rid.StartsWith("win"); + } + else + { + // Need to fix this for osx / linux + return !rid.StartsWith("win"); + } +}).ToArray(); // Folders and tools var dotnetFolder = $"{workingDirectory}/{buildPlan.DotNetFolder}"; From be219b272a5cd9ad6322362f6875c7ff618fd24f Mon Sep 17 00:00:00 2001 From: David Driscoll Date: Fri, 25 Mar 2016 16:07:44 -0400 Subject: [PATCH 7/7] Updated runtime to filter to local runtimes for *nix/osx --- build.cake | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/build.cake b/build.cake index 6d78d636b2..d182cfc84f 100644 --- a/build.cake +++ b/build.cake @@ -41,15 +41,17 @@ public class BuildPlan var buildPlan = DeserializeJsonFromFile($"{workingDirectory}/build.json"); // Limit scope if things we build -buildPlan.Rids = buildPlan.Rids.Where(rid => { +buildPlan.Rids = buildPlan.Rids.Where(runtime => { if (IsRunningOnWindows()) { - return rid.StartsWith("win"); + return runtime.StartsWith("win"); } else { - // Need to fix this for osx / linux - return !rid.StartsWith("win"); + var localRuntime = GetLocalRuntimeID(dotnetcli); + var localRuntimeWithoutVersion = Regex.Replace(localRuntime, "(\\d|\\.)*-", "-"); + var runtimeWithoutVersion = Regex.Replace(runtime, "(\\d|\\.)*-", "-"); + return localRuntimeWithoutVersion.Equals(runtimeWithoutVersion); } }).ToArray();