Merge remote-tracking branch 'upstream/master' into stable
commit 5650b7440e0cda8df4fbc9108ba600792a737781
2 parents fe13e0f + 8e2b94c
@Iain Buclaw Iain Buclaw authored on 9 Oct 2022
Showing 3 changed files
View
103
source/dub/commandline.d
}
 
return cmd;
}
 
/** Get a configured dub instance.
 
Returns:
A dub instance
*/
Dub prepareDub() {
Dub dub;
 
if (options.bare) {
dub = new Dub(NativePath(getcwd()));
dub.rootPath = NativePath(options.root_path);
dub.defaultPlacementLocation = options.placementLocation;
 
return dub;
}
 
// initialize DUB
auto package_suppliers = options.registry_urls
.map!((url) {
// Allow to specify fallback mirrors as space separated urls. Undocumented as we
// should simply retry over all registries instead of using a special
// FallbackPackageSupplier.
auto urls = url.splitter(' ');
PackageSupplier ps = getRegistryPackageSupplier(urls.front);
urls.popFront;
if (!urls.empty)
ps = new FallbackPackageSupplier(ps ~ urls.map!getRegistryPackageSupplier.array);
return ps;
})
.array;
 
dub = new Dub(options.root_path, package_suppliers, options.skipRegistry);
dub.dryRun = options.annotate;
dub.defaultPlacementLocation = options.placementLocation;
 
// 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);
catch (Exception e) { logDiagnostic("No valid package found in current working directory: %s", e.msg); }
 
return dub;
}
}
 
/// Can get the command names
unittest {
logInfo(`Type "%s" to get a list of all supported flags.`, text("dub ", cmd.name, " -h").color(Mode.bold));
return 1;
}
 
Dub dub;
 
// initialize the root package
if (!cmd.skipDubInitialization) {
dub = handler.prepareDub;
}
Dub dub = cmd.prepareDub(handler.options);
 
// execute the command
try return cmd.execute(dub, remaining_args, command_args.appArgs);
catch (UsageException e) {
string description;
string[] helpText;
bool acceptsAppArgs;
bool hidden = false; // used for deprecated commands
bool skipDubInitialization = false;
 
/** Parses all known command line options without executing any actions.
 
This function will be called prior to execute, or may be called as
 
Only `args.getopt` should be called within this method.
*/
abstract void prepare(scope CommandArgs args);
 
/**
* Initialize the dub instance used by `execute`
*/
public Dub prepareDub(CommonOptions options) {
Dub dub;
 
if (options.bare) {
dub = new Dub(NativePath(options.root_path), NativePath(getcwd()));
dub.defaultPlacementLocation = options.placementLocation;
 
return dub;
}
 
// initialize DUB
auto package_suppliers = options.registry_urls
.map!((url) {
// Allow to specify fallback mirrors as space separated urls. Undocumented as we
// should simply retry over all registries instead of using a special
// FallbackPackageSupplier.
auto urls = url.splitter(' ');
PackageSupplier ps = getRegistryPackageSupplier(urls.front);
urls.popFront;
if (!urls.empty)
ps = new FallbackPackageSupplier(ps ~ urls.map!getRegistryPackageSupplier.array);
return ps;
})
.array;
 
dub = new Dub(options.root_path, package_suppliers, options.skipRegistry);
dub.dryRun = options.annotate;
dub.defaultPlacementLocation = options.placementLocation;
 
// 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);
catch (Exception e) { logDiagnostic("No valid package found in current working directory: %s", e.msg); }
 
return dub;
}
 
/** Executes the actual action.
 
Note that `prepare` will be called before any call to `execute`.
super.prepare(args);
 
// speed up loading when in test mode
if (m_testPackage.length) {
skipDubInitialization = true;
m_nodeps = true;
}
}
 
/// Returns: A minimally-initialized dub instance in test mode
override Dub prepareDub(CommonOptions options)
{
if (!m_testPackage.length)
return super.prepareDub(options);
return new Dub(NativePath(options.root_path), NativePath(getcwd()));
}
 
override int execute(Dub dub, string[] free_args, string[] app_args)
{
import std.format : formattedWrite;
 
if (m_testPackage.length) {
dub = new Dub(NativePath(getcwd()));
 
setupPackage(dub, m_testPackage);
m_defaultConfig = dub.project.getDefaultConfiguration(this.baseSettings.platform);
 
GeneratorSettings gensettings = this.baseSettings;
View
42
source/dub/dub.d
/** Initializes the instance with a single package search path, without
loading a package.
 
This constructor corresponds to the "--bare" option of the command line
interface. Use
*/
this(NativePath override_path)
{
interface.
 
Params:
root = The root path of the Dub instance itself.
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.
*/
this(NativePath root, NativePath pkg_root)
{
// Note: We're doing `init()` before setting the `rootPath`,
// to prevent `init` from reading the project's settings.
init();
m_packageManager = new PackageManager(override_path);
this.m_rootPath = root;
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);
}
 
private void init()
{
/** Returns the root path (usually the current working directory).
*/
@property NativePath rootPath() const { return m_rootPath; }
/// ditto
deprecated("Changing the root path is deprecated as it has non-obvious pitfalls " ~
"(e.g. settings aren't reloaded). Instantiate a new `Dub` instead")
@property void rootPath(NativePath root_path)
{
m_rootPath = root_path;
if (!m_rootPath.absolute) m_rootPath = NativePath(getcwd()) ~ m_rootPath;
View
source/dub/packagemanager.d