Nuke.Cola
Loading...
Searching...
No Matches
VcpkgTasks.cs
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Threading.Tasks;
5using Nuke.Common;
6using Nuke.Common.IO;
7using Nuke.Common.Tooling;
8using Nuke.Common.Tools.Git;
9using Serilog;
10
12
13/// <summary>
14/// Wrapper class for VCPKG a C++ package manager by Microsoft
15/// </summary>
16public class VcpkgTasks
17{
18 /// <summary>
19 /// Set this property if your project already has an instance of VCPKG placed somewhere inside the project
20 /// </summary>
21 public static AbsolutePath? VcpkgPathOverride { private get; set; }
22
23 /// <summary>
24 /// Path to a place where a local VCPKG instance can be found / should be set up.
25 /// </summary>
26 public static AbsolutePath VcpkgPathInProject => VcpkgPathOverride ?? NukeBuild.TemporaryDirectory / "vcpkg";
27
28 internal static void Setup()
29 {
30 VcpkgPathInProject.CreateOrCleanDirectory();
31 GitTasks.Git($"clone --recurse-submodules https://github.com/microsoft/vcpkg.git {VcpkgPathInProject}");
32
33 var bootstrapPath = EnvironmentInfo.Platform == PlatformFamily.Windows
34 ? VcpkgPathInProject / "bootstrap-vcpkg.bat"
35 : VcpkgPathInProject / "bootstrap-vcpkg.sh";
36
37 ToolResolver.GetTool(bootstrapPath)("-disableMetrics");
38 }
39
40 /// <summary>
41 /// Get an instance of VCPKG or an error if setup has failed.
42 /// </summary>
43 public static ValueOrError<Tool> EnsureVcpkg { get
44 {
45 var vcpkgPath = EnvironmentInfo.Platform == PlatformFamily.Windows
46 ? VcpkgPathInProject / "vcpkg.exe"
47 : VcpkgPathInProject / "vcpkg";
48
49 if (vcpkgPath.FileExists())
50 return ToolResolver.GetTool(vcpkgPath);
51
52 Log.Warning("Installing VCPKG for this project in {0}", VcpkgPathInProject);
53 Setup();
54 return ToolResolver.GetTool(vcpkgPath);
55 }}
56
57 /// <summary>
58 /// Get an instance of VCPKG. It throws an exception if setup has failed.
59 /// </summary>
60 public static Tool Vcpkg => EnsureVcpkg.Get();
61}
Wrapper class for VCPKG a C++ package manager by Microsoft.
Definition VcpkgTasks.cs:17
static ValueOrError< Tool > EnsureVcpkg
Get an instance of VCPKG or an error if setup has failed.
Definition VcpkgTasks.cs:43
static ? AbsolutePath VcpkgPathOverride
Set this property if your project already has an instance of VCPKG placed somewhere inside the projec...
Definition VcpkgTasks.cs:21
static AbsolutePath VcpkgPathInProject
Path to a place where a local VCPKG instance can be found / should be set up.
Definition VcpkgTasks.cs:26
static Tool Vcpkg
Get an instance of VCPKG. It throws an exception if setup has failed.
Definition VcpkgTasks.cs:60