Skip to content

Commit

Permalink
Cake.Frosting ToolInstaller working directory example
Browse files Browse the repository at this point in the history
An example using Cake.Frosting 1.0.0-rc0002 which shows
the `ToolInstaller` still uses a hardcoded
`_environment.WorkingDirectory.Combine("tools").MakeAbsolute(_environment);`
path to install tools into.


Observe that CakeHost() was configured with a .UseWorkingDirectory("../..")
but surprisingly the tools end up being installed in `./build/source/tools`
instead of the expected `./tools` directory as was the case
in Cake.Frosting 1.0.0-rc0001.

Now, as far as the `ToolInstaller` is concerned, both are wrong in this case.
The [Paths][Tools] setting from the cake.config file has been specified and
should be used instead.

See cake-build/cake#2904 (comment)
  • Loading branch information
Dieter Verfaillie committed Jan 4, 2021
1 parent 0ac29ab commit 76e6518
Show file tree
Hide file tree
Showing 9 changed files with 109 additions and 23 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
##
## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore

# Build
build/*
!build/source/

# User-specific files
*.rsuser
*.suo
Expand Down
71 changes: 69 additions & 2 deletions build.ps1
Original file line number Diff line number Diff line change
@@ -1,2 +1,69 @@
dotnet run --project build/Build.csproj -- $args
exit $LASTEXITCODE;
# Script root
$PSScriptRoot = Split-Path $MyInvocation.MyCommand.Path -Parent

# Read configuration file
function Get-IniContent ($filePath)
{
$ini = @{}
switch -regex -file $FilePath
{
"^\[(.+)\]$" # Section
{
$section = $matches[1]
$ini[$section] = @{}
$CommentCount = 0
}
"^(;.*)$" # Comment
{
if (!($section))
{
$section = "No-Section"
$ini[$section] = @{}
}
$value = $matches[1]
$CommentCount = $CommentCount + 1
$name = "Comment" + $CommentCount
$ini[$section][$name] = $value
}
"(.+?)\s*=\s*(.*)" # Key
{
if (!($section))
{
$section = "No-Section"
$ini[$section] = @{}
}
$name,$value = $matches[1..2]
$ini[$section][$name] = $value
}
}
return $ini
}

$buildConfig = Get-IniContent(Join-Path $PSScriptRoot "cake.config")

# Make sure tools folder exists
$ToolPath = $buildConfig["Paths"]["Tools"]
if (!(Test-Path $ToolPath)) {
Write-Verbose "Creating tools directory..."
New-Item -Path $ToolPath -Type directory | out-null
}

Push-Location
Set-Location build\source

Write-Host "Preparing Cake.Frosting build runner..."
Invoke-Expression "dotnet restore"
if($LASTEXITCODE -ne 0) {
Pop-Location;
exit $LASTEXITCODE;
}

Write-Host "Running Cake.Frosting build runner..."
Write-Host "dotnet run -- $args"
Invoke-Expression "dotnet run -- $args"
if($LASTEXITCODE -ne 0) {
Pop-Location;
exit $LASTEXITCODE;
}

Pop-Location
2 changes: 1 addition & 1 deletion build.sh
Original file line number Diff line number Diff line change
@@ -1 +1 @@
dotnet run --project ./build/Build.csproj -- "$@"
dotnet run --project ./build/source/Build.csproj -- "$@"
File renamed without changes.
17 changes: 10 additions & 7 deletions build/Program.cs → build/source/Program.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
using System.Threading.Tasks;
using System;

using Cake.Common;
using Cake.Common.IO;
using Cake.Common.Tools.DotNetCore;
using Cake.Common.Tools.DotNetCore.Build;
using Cake.Common.Tools.DotNetCore.Test;
using Cake.Core;
using Cake.Core.Diagnostics;
using Cake.Frosting;

public static class Program
{
public static int Main(string[] args)
{
return new CakeHost()
.UseWorkingDirectory("../..")
.UseContext<BuildContext>()
.UseWorkingDirectory("..")
.UseTool(new Uri("nuget:?package=ReportGenerator&version=4.8.1"))
.UseTool(new Uri("nuget:?package=NuGet.CommandLine&version=5.8.0"))
.Run(args);
}
}
Expand All @@ -27,14 +29,15 @@ public BuildContext(ICakeContext context)
: base(context)
{
MsBuildConfiguration = context.Argument("configuration", "Release");
}}
}
}

[TaskName("Clean")]
public sealed class CleanTask : FrostingTask<BuildContext>
{
public override void Run(BuildContext context)
{
context.CleanDirectory($"./src/Example/bin/{context.MsBuildConfiguration}");
context.CleanDirectory($"./source/Example/bin/{context.MsBuildConfiguration}");
}
}

Expand All @@ -44,7 +47,7 @@ public sealed class BuildTask : FrostingTask<BuildContext>
{
public override void Run(BuildContext context)
{
context.DotNetCoreBuild("./src/Example.sln", new DotNetCoreBuildSettings
context.DotNetCoreBuild("./source/Example.sln", new DotNetCoreBuildSettings
{
Configuration = context.MsBuildConfiguration,
});
Expand All @@ -57,7 +60,7 @@ public sealed class TestTask : FrostingTask<BuildContext>
{
public override void Run(BuildContext context)
{
context.DotNetCoreTest("./src/Example.sln", new DotNetCoreTestSettings
context.DotNetCoreTest("./source/Example.sln", new DotNetCoreTestSettings
{
Configuration = context.MsBuildConfiguration,
NoBuild = true,
Expand Down
12 changes: 12 additions & 0 deletions cake.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[Nuget]
Source=http://privateget.workplace.local:8000/nuget/workplace-feed/
UseInProcessClient=true
LoadDependencies=false

[Paths]
Tools=./build/tools
Addins=./build/tools/Addins
Modules=./build/tools/Modules

[Settings]
SkipVerification=false
26 changes: 13 additions & 13 deletions src/Example.sln → source/Example.sln
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ VisualStudioVersion = 16.0.30804.86
MinimumVisualStudioVersion = 15.0.26124.0
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Example", "Example\Example.csproj", "{9D3E3D52-E7B5-4C3C-B5E4-62D8058CDB36}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Build", "..\build\Build.csproj", "{4960B65A-E1C7-4FC2-8504-FE48F6D8EDF5}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Build", "..\build\source\Build.csproj", "{39B2B144-2F4B-4BD7-A541-F6DFF50AA8C0}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -29,18 +29,18 @@ Global
{9D3E3D52-E7B5-4C3C-B5E4-62D8058CDB36}.Release|x64.Build.0 = Release|Any CPU
{9D3E3D52-E7B5-4C3C-B5E4-62D8058CDB36}.Release|x86.ActiveCfg = Release|Any CPU
{9D3E3D52-E7B5-4C3C-B5E4-62D8058CDB36}.Release|x86.Build.0 = Release|Any CPU
{4960B65A-E1C7-4FC2-8504-FE48F6D8EDF5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4960B65A-E1C7-4FC2-8504-FE48F6D8EDF5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4960B65A-E1C7-4FC2-8504-FE48F6D8EDF5}.Debug|x64.ActiveCfg = Debug|Any CPU
{4960B65A-E1C7-4FC2-8504-FE48F6D8EDF5}.Debug|x64.Build.0 = Debug|Any CPU
{4960B65A-E1C7-4FC2-8504-FE48F6D8EDF5}.Debug|x86.ActiveCfg = Debug|Any CPU
{4960B65A-E1C7-4FC2-8504-FE48F6D8EDF5}.Debug|x86.Build.0 = Debug|Any CPU
{4960B65A-E1C7-4FC2-8504-FE48F6D8EDF5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4960B65A-E1C7-4FC2-8504-FE48F6D8EDF5}.Release|Any CPU.Build.0 = Release|Any CPU
{4960B65A-E1C7-4FC2-8504-FE48F6D8EDF5}.Release|x64.ActiveCfg = Release|Any CPU
{4960B65A-E1C7-4FC2-8504-FE48F6D8EDF5}.Release|x64.Build.0 = Release|Any CPU
{4960B65A-E1C7-4FC2-8504-FE48F6D8EDF5}.Release|x86.ActiveCfg = Release|Any CPU
{4960B65A-E1C7-4FC2-8504-FE48F6D8EDF5}.Release|x86.Build.0 = Release|Any CPU
{39B2B144-2F4B-4BD7-A541-F6DFF50AA8C0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{39B2B144-2F4B-4BD7-A541-F6DFF50AA8C0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{39B2B144-2F4B-4BD7-A541-F6DFF50AA8C0}.Debug|x64.ActiveCfg = Debug|Any CPU
{39B2B144-2F4B-4BD7-A541-F6DFF50AA8C0}.Debug|x64.Build.0 = Debug|Any CPU
{39B2B144-2F4B-4BD7-A541-F6DFF50AA8C0}.Debug|x86.ActiveCfg = Debug|Any CPU
{39B2B144-2F4B-4BD7-A541-F6DFF50AA8C0}.Debug|x86.Build.0 = Debug|Any CPU
{39B2B144-2F4B-4BD7-A541-F6DFF50AA8C0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{39B2B144-2F4B-4BD7-A541-F6DFF50AA8C0}.Release|Any CPU.Build.0 = Release|Any CPU
{39B2B144-2F4B-4BD7-A541-F6DFF50AA8C0}.Release|x64.ActiveCfg = Release|Any CPU
{39B2B144-2F4B-4BD7-A541-F6DFF50AA8C0}.Release|x64.Build.0 = Release|Any CPU
{39B2B144-2F4B-4BD7-A541-F6DFF50AA8C0}.Release|x86.ActiveCfg = Release|Any CPU
{39B2B144-2F4B-4BD7-A541-F6DFF50AA8C0}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
File renamed without changes.
File renamed without changes.

0 comments on commit 76e6518

Please sign in to comment.