Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented recipe files for dub #2684 #2685

Merged
merged 11 commits into from
Aug 13, 2023
10 changes: 6 additions & 4 deletions source/dub/commandline.d
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ struct CommonOptions {
bool verbose, vverbose, quiet, vquiet, verror, version_;
bool help, annotate, bare;
string[] registry_urls;
string root_path;
string root_path, recipeFile;
enum Color { automatic, on, off }
Color colorMode = Color.automatic;
SkipPackageSuppliers skipRegistry = SkipPackageSuppliers.none;
Expand Down Expand Up @@ -568,6 +568,7 @@ struct CommonOptions {
{
args.getopt("h|help", &help, ["Display general or command specific help"]);
args.getopt("root", &root_path, ["Path to operate in instead of the current working dir"]);
args.getopt("recipe", &recipeFile, ["Make dub use custom path as its recipe file"]);
args.getopt("registry", &registry_urls, [
"Search the given registry URL first when resolving dependencies. Can be specified multiple times. Available registry types:",
" DUB: URL to DUB registry (default)",
Expand Down Expand Up @@ -812,7 +813,7 @@ class Command {
Dub dub;

if (options.bare) {
dub = new Dub(NativePath(options.root_path), getWorkingDirectory());
dub = new Dub(NativePath(options.root_path), getWorkingDirectory(), NativePath(options.recipeFile));
dub.defaultPlacementLocation = options.placementLocation;

return dub;
Expand All @@ -839,7 +840,7 @@ class Command {

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

return dub;
Expand Down Expand Up @@ -1168,6 +1169,7 @@ abstract class PackageBuildCommand : Command {
return true;
}


bool from_cwd = package_name.length == 0 || package_name.startsWith(":");
// load package in root_path to enable searching for sub packages
if (loadCwdPackage(dub, from_cwd)) {
Expand Down Expand Up @@ -2430,7 +2432,7 @@ class DustmiteCommand : PackageBuildCommand {
{
if (!m_testPackage.length)
return super.prepareDub(options);
return new Dub(NativePath(options.root_path), getWorkingDirectory());
return new Dub(NativePath(options.root_path), getWorkingDirectory(), NativePath(options.recipeFile));
}

override int execute(Dub dub, string[] free_args, string[] app_args)
Expand Down
10 changes: 6 additions & 4 deletions source/dub/dub.d
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ class Dub {
bool m_dryRun = false;
PackageManager m_packageManager;
PackageSupplier[] m_packageSuppliers;
NativePath m_rootPath;
NativePath m_rootPath, m_recipeFile;
SpecialDirs m_dirs;
Settings m_config;
Project m_project;
Expand Down Expand Up @@ -191,20 +191,22 @@ class Dub {
pkg_root = The root of the location where packages are located
Only packages under this location will be accessible.
Note that packages at the top levels will be ignored.
recipeFile = A file containing a dub build recipe
*/
this(NativePath root, NativePath pkg_root)
this(NativePath root, NativePath pkg_root, NativePath recipeFile)
{
// Note: We're doing `init()` before setting the `rootPath`,
// to prevent `init` from reading the project's settings.
init();
this.m_rootPath = root;
this.m_recipeFile = recipeFile;
m_packageManager = new PackageManager(pkg_root);
}

deprecated("Use the overload that takes `(NativePath pkg_root, NativePath root)`")
this(NativePath pkg_root)
{
this(pkg_root, pkg_root);
this(pkg_root, pkg_root, pkg_root);
}

private void init()
Expand Down Expand Up @@ -440,7 +442,7 @@ class Dub {
*/
void loadPackage()
{
loadPackage(m_rootPath);
loadPackage(!m_recipeFile.empty ? m_recipeFile : m_rootPath);
}

/// Loads the package from the specified path as the main project package.
Expand Down