Nuke.Cola
Loading...
Searching...
No Matches
XRepoTasks.cs
1using System;
2using System.Collections;
3using System.Collections.Generic;
4using System.Collections.Specialized;
5using System.Linq;
6using System.Threading.Tasks;
9using Nuke.Common;
10using Nuke.Common.IO;
11using Nuke.Common.Tooling;
12using Nuke.Common.Utilities;
13using Serilog;
14
15namespace Nuke.Cola.Tooling;
16
17/// <summary>
18/// XRepo is a meta package manager for C/C++ built on top of XMake
19/// </summary>
20public static class XRepoTasks
21{
22 /// <summary>
23 /// Get XRepo or an error if downloading it has failed.
24 /// </summary>
25 public static ValueOrError<Tool> EnsureXRepo => XMakeTasks.EnsureXMake
26 .Transform(t => t.With("lua private.xrepo"));
27
28 /// <summary>
29 /// Get XRepo. It throws an exception if downloading it has failed.
30 /// </summary>
31 public static Tool XRepo => EnsureXRepo.Get();
32
33 private static void EnsureSupportedPackageManagers(ref Tool xrepo, string package)
34 {
35 if (package.Contains("vcpkg::"))
36 {
37 VcpkgTasks.EnsureVcpkg.Get($"VCPKG is needed for package(s) {package} but it couldn't be installed");
38 if (VcpkgTasks.VcpkgPathInProject.DirectoryExists())
39 {
40 xrepo = xrepo.WithEnvVar("VCPKG_ROOT", VcpkgTasks.VcpkgPathInProject);
41 }
42 }
43 else if (package.Contains("conan::"))
44 ToolCola.Use("conan", () => PythonTasks.Pip("install conan"))
45 .Get($"Conan is needed for package(s) {package} but it couldn't be installed");
46 }
47
48 /// <summary>
49 /// Install a package using xrepo. Using this function also ensures setting up conan or VCPKG if
50 /// they're referenced in the package specification
51 /// </summary>
52 /// <param name="package">
53 /// package specification including third-party manager identifier (e.g.: conan::),
54 /// version syntax (depending on the selected manager), and other extensions (e.g. vcpkg::boost[core])
55 /// <br />
56 /// See https://xmake.io/#/package/remote_package?id=install-third-party-packages
57 /// See https://xrepo.xmake.io/#/?id=installation-package
58 /// </param>
59 /// <param name="options">
60 /// Extra options configuring the package. It should be comma separated key=value pairs.
61 /// </param>
62 /// <param name="extraArgs">
63 /// Extra arguments provided through command line before package specification.
64 /// </param>
65 /// <returns></returns>
66 public static Tool Install(string package, string options = "", string extraArgs = "")
67 {
68 var xrepo = XRepo.With($"install -v -y {options.PrependNonEmpty("-f "):nq} {extraArgs:nq} {package}");
69 EnsureSupportedPackageManagers(ref xrepo, package);
70 return xrepo;
71 }
72
73 /// <summary>
74 /// Fetch a package info installed via xrepo. Using this function also ensures setting up conan
75 /// or VCPKG if they're referenced in the package specification
76 /// </summary>
77 /// <param name="package">
78 /// package specification including third-party manager identifier (e.g.: conan::),
79 /// version syntax (depending on the selected manager), and other extensions (e.g. vcpkg::boost[core])
80 /// <br />
81 /// See https://xmake.io/#/package/remote_package?id=install-third-party-packages
82 /// See https://xrepo.xmake.io/#/?id=installation-package
83 /// </param>
84 /// <param name="options">
85 /// Extra options configuring the package. It should be comma separated key=value pairs. It is
86 /// important to provide the same options here as provided in install to get accurate information
87 /// from the package (like dependencies, linking methods, etc)
88 /// </param>
89 /// <param name="extraArgs">
90 /// Extra arguments provided through command line before package specification.
91 /// </param>
92 /// <returns></returns>
93 public static Tool Info(string package, string options = "", string extraArgs = "")
94 {
95 var xrepo = XRepo.With($"info -y {options.PrependNonEmpty("-f "):nq} {extraArgs:nq} {package}");
96 EnsureSupportedPackageManagers(ref xrepo, package);
97 return xrepo;
98 }
99
100 /// <summary>
101 /// Parse the Tool output of XRepoTasks.Info into structured data.
102 /// </summary>
103 public static XRepoItem ParseXRepoInfo(this IEnumerable<Output> output)
104 => XRepoItem.Parse(output.RemoveAnsiEscape());
105}
static ValueOrError< Tool > Use(string tool, Action? setup=null)
Get a tool which should be in PATH, and provide an optional way to set it up automatically if it wasn...
A structured representation of the data xrepo info prints out about a package. xrepo info uses a besp...
Definition XRepoItem.cs:23
XRepo is a meta package manager for C/C++ built on top of XMake.
Definition XRepoTasks.cs:21
static Tool Install(string package, string options="", string extraArgs="")
Install a package using xrepo. Using this function also ensures setting up conan or VCPKG if they're ...
Definition XRepoTasks.cs:66
static XRepoItem ParseXRepoInfo(this IEnumerable< Output > output)
Parse the Tool output of XRepoTasks.Info into structured data.
static Tool XRepo
Get XRepo. It throws an exception if downloading it has failed.
Definition XRepoTasks.cs:31
static ValueOrError< Tool > EnsureXRepo
Get XRepo or an error if downloading it has failed.
Definition XRepoTasks.cs:25
static Tool Info(string package, string options="", string extraArgs="")
Fetch a package info installed via xrepo. Using this function also ensures setting up conan or VCPKG ...
Definition XRepoTasks.cs:93
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 VcpkgPathInProject
Path to a place where a local VCPKG instance can be found / should be set up.
Definition VcpkgTasks.cs:26