Nuke.Cola
Loading...
Searching...
No Matches
XRepoTasks.cs
1using Nuke.Common;
2using Nuke.Common.IO;
3using Nuke.Common.Tooling;
4using Nuke.Common.Utilities;
5
7
8/// <summary>
9/// XRepo is a meta package manager for C/C++ built on top of XMake
10/// </summary>
11public static class XRepoTasks
12{
13 /// <summary>
14 /// Get XRepo or an error if downloading it has failed.
15 /// </summary>
16 public static ValueOrError<ToolEx> EnsureXRepo => XMakeTasks.EnsureXMake
17 .Transform(t => t.With("lua private.xrepo"));
18
19 /// <summary>
20 /// Get XRepo. It throws an exception if downloading it has failed.
21 /// </summary>
22 public static ToolEx XRepo => EnsureXRepo.Get();
23
24 private static void ForbidExternalPackageSources(string package)
25 {
26 Assert.False(package.Contains("::"), "Cannot handle packages external to xrepo, via xrepo.");
27 }
28
29 /// <summary>
30 /// Install a package using xrepo. Using xrepo as a meta package manager is not supported, so it can only use
31 /// its own repository of packages through Nuke.Cola.
32 /// </summary>
33 /// <param name="package">
34 /// package specification including version syntax. See https://xrepo.xmake.io/#/?id=installation-package
35 /// </param>
36 /// <param name="options">
37 /// Extra options configuring the package. It should be comma separated key=value pairs.
38 /// </param>
39 /// <param name="extraArgs">
40 /// Extra arguments provided through command line before package specification.
41 /// </param>
42 /// <returns></returns>
43 public static ToolEx Install(string package, string options = "", string extraArgs = "")
44 {
45 ForbidExternalPackageSources(package);
46 return XRepo.With(
47 $"""
48 install -v -y
49 {("--configs=", options):quote}
50 {extraArgs}
51 {package:quote}
52 """
53 );
54 }
55
56 /// <summary>
57 /// Fetch a package info installed via xrepo. Using xrepo as a meta package manager is not supported, so it can
58 /// only use its own repository of packages through Nuke.Cola.
59 /// </summary>
60 /// <param name="package">
61 /// package specification including version syntax. See https://xrepo.xmake.io/#/?id=installation-package
62 /// </param>
63 /// <param name="options">
64 /// Extra options configuring the package. It should be comma separated key=value pairs. It is
65 /// important to provide the same options here as provided in install to get accurate information
66 /// from the package (like dependencies, linking methods, etc)
67 /// </param>
68 /// <param name="extraArgs">
69 /// Extra arguments provided through command line before package specification.
70 /// </param>
71 /// <returns></returns>
72 public static ToolEx Fetch(string package, string options = "", string extraArgs = "")
73 {
74 ForbidExternalPackageSources(package);
75 return XRepo.With(
76 $"""
77 fetch -v -y
78 --deps --json
79 {("--configs=", options):quote}
80 {extraArgs}
81 {package:quote}
82 """
83 );
84 }
85}
XRepo is a meta package manager for C/C++ built on top of XMake.
Definition XRepoTasks.cs:12
static ValueOrError< ToolEx > EnsureXRepo
Get XRepo or an error if downloading it has failed.
Definition XRepoTasks.cs:16
static ToolEx XRepo
Get XRepo. It throws an exception if downloading it has failed.
Definition XRepoTasks.cs:22
static ToolEx Fetch(string package, string options="", string extraArgs="")
Fetch a package info installed via xrepo. Using xrepo as a meta package manager is not supported,...
Definition XRepoTasks.cs:72
static ToolEx Install(string package, string options="", string extraArgs="")
Install a package using xrepo. Using xrepo as a meta package manager is not supported,...
Definition XRepoTasks.cs:43
delegate? IReadOnlyCollection< Output > ToolEx(ArgumentStringHandlerEx arguments=default, string? workingDirectory=null, IReadOnlyDictionary< string, string >? environmentVariables=null, int? timeout=null, bool? logOutput=null, bool? logInvocation=null, Action< OutputType, string >? logger=null, Action< IProcess >? exitHandler=null, Action< StreamWriter >? input=null, Encoding? standardOutputEncoding=null, Encoding? standardInputEncoding=null, ToolExRetry? retry=null)
Extended copy of Tool delegate of Nuke.