Skip to content

Commit b5c5e04

Browse files
committed
Implemented recipe files for dub dlang#2684
1 parent 52fd928 commit b5c5e04

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

source/dub/commandline.d

+6-4
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@ struct CommonOptions {
534534
bool verbose, vverbose, quiet, vquiet, verror, version_;
535535
bool help, annotate, bare;
536536
string[] registry_urls;
537-
string root_path;
537+
string root_path, recipeFile;
538538
enum Color { automatic, on, off }
539539
Color colorMode = Color.automatic;
540540
SkipPackageSuppliers skipRegistry = SkipPackageSuppliers.none;
@@ -568,6 +568,7 @@ struct CommonOptions {
568568
{
569569
args.getopt("h|help", &help, ["Display general or command specific help"]);
570570
args.getopt("root", &root_path, ["Path to operate in instead of the current working dir"]);
571+
args.getopt("recipe", &recipeFile, ["Make dub use custom path as its recipe file"]);
571572
args.getopt("registry", &registry_urls, [
572573
"Search the given registry URL first when resolving dependencies. Can be specified multiple times. Available registry types:",
573574
" DUB: URL to DUB registry (default)",
@@ -812,7 +813,7 @@ class Command {
812813
Dub dub;
813814

814815
if (options.bare) {
815-
dub = new Dub(NativePath(options.root_path), getWorkingDirectory());
816+
dub = new Dub(NativePath(options.root_path), getWorkingDirectory(), NativePath(options.recipeFile));
816817
dub.defaultPlacementLocation = options.placementLocation;
817818

818819
return dub;
@@ -839,7 +840,7 @@ class Command {
839840

840841
// make the CWD package available so that for example sub packages can reference their
841842
// parent package.
842-
try dub.packageManager.getOrLoadPackage(NativePath(options.root_path), NativePath.init, false, StrictMode.Warn);
843+
try dub.packageManager.getOrLoadPackage(NativePath(options.root_path), NativePath(options.recipeFile), false, StrictMode.Warn);
843844
catch (Exception e) { logDiagnostic("No valid package found in current working directory: %s", e.msg); }
844845

845846
return dub;
@@ -1168,6 +1169,7 @@ abstract class PackageBuildCommand : Command {
11681169
return true;
11691170
}
11701171

1172+
11711173
bool from_cwd = package_name.length == 0 || package_name.startsWith(":");
11721174
// load package in root_path to enable searching for sub packages
11731175
if (loadCwdPackage(dub, from_cwd)) {
@@ -2430,7 +2432,7 @@ class DustmiteCommand : PackageBuildCommand {
24302432
{
24312433
if (!m_testPackage.length)
24322434
return super.prepareDub(options);
2433-
return new Dub(NativePath(options.root_path), getWorkingDirectory());
2435+
return new Dub(NativePath(options.root_path), getWorkingDirectory(), NativePath(options.recipeFile));
24342436
}
24352437

24362438
override int execute(Dub dub, string[] free_args, string[] app_args)

source/dub/dub.d

+6-4
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ class Dub {
125125
bool m_dryRun = false;
126126
PackageManager m_packageManager;
127127
PackageSupplier[] m_packageSuppliers;
128-
NativePath m_rootPath;
128+
NativePath m_rootPath, m_recipeFile;
129129
SpecialDirs m_dirs;
130130
Settings m_config;
131131
Project m_project;
@@ -191,20 +191,22 @@ class Dub {
191191
pkg_root = The root of the location where packages are located
192192
Only packages under this location will be accessible.
193193
Note that packages at the top levels will be ignored.
194+
recipeFile = A file containing a dub build recipe
194195
*/
195-
this(NativePath root, NativePath pkg_root)
196+
this(NativePath root, NativePath pkg_root, NativePath recipeFile)
196197
{
197198
// Note: We're doing `init()` before setting the `rootPath`,
198199
// to prevent `init` from reading the project's settings.
199200
init();
200201
this.m_rootPath = root;
202+
this.m_recipeFile = recipeFile;
201203
m_packageManager = new PackageManager(pkg_root);
202204
}
203205

204206
deprecated("Use the overload that takes `(NativePath pkg_root, NativePath root)`")
205207
this(NativePath pkg_root)
206208
{
207-
this(pkg_root, pkg_root);
209+
this(pkg_root, pkg_root, pkg_root);
208210
}
209211

210212
private void init()
@@ -440,7 +442,7 @@ class Dub {
440442
*/
441443
void loadPackage()
442444
{
443-
loadPackage(m_rootPath);
445+
loadPackage(!m_recipeFile.empty ? m_recipeFile : m_rootPath);
444446
}
445447

446448
/// Loads the package from the specified path as the main project package.

0 commit comments

Comments
 (0)