From 83c4029c06b933db237a705542e44650e45c5213 Mon Sep 17 00:00:00 2001 From: Geod24 Date: Sat, 20 Aug 2022 20:30:47 +0200 Subject: [PATCH] Dub: Move environment read one level up the stack Avoid a unittest modifying the environment, and pave the way for having a single read of this variable, instead of once per function call. --- source/dub/dub.d | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/source/dub/dub.d b/source/dub/dub.d index 6db24f2d8..04197ce86 100644 --- a/source/dub/dub.d +++ b/source/dub/dub.d @@ -162,7 +162,8 @@ class Dub { init(m_rootPath); - m_packageSuppliers = this.computePkgSuppliers(additional_package_suppliers, skip_registry); + m_packageSuppliers = this.computePkgSuppliers(additional_package_suppliers, + skip_registry, environment.get("DUB_REGISTRY", null)); m_packageManager = new PackageManager(m_rootPath, m_dirs.localRepository, m_dirs.systemSettings); auto ccps = m_config.customCachePaths; @@ -254,17 +255,19 @@ class Dub { "suppliers once a `Dub` instance has been constructed.") public PackageSupplier[] getPackageSuppliers(PackageSupplier[] additional_package_suppliers, SkipPackageSuppliers skip_registry) { - return this.computePkgSuppliers(additional_package_suppliers, skip_registry); + return this.computePkgSuppliers(additional_package_suppliers, skip_registry, environment.get("DUB_REGISTRY", null)); } /// Ditto - private PackageSupplier[] computePkgSuppliers(PackageSupplier[] additional_package_suppliers, SkipPackageSuppliers skip_registry) + private PackageSupplier[] computePkgSuppliers( + PackageSupplier[] additional_package_suppliers, SkipPackageSuppliers skip_registry, + string dub_registry_var) { PackageSupplier[] ps = additional_package_suppliers; if (skip_registry < SkipPackageSuppliers.all) { - ps ~= environment.get("DUB_REGISTRY", null) + ps ~= dub_registry_var .splitter(";") .map!(url => getRegistryPackageSupplier(url)) .array; @@ -294,15 +297,14 @@ class Dub { unittest { - scope (exit) environment.remove("DUB_REGISTRY"); auto dub = new Dub(".", null, SkipPackageSuppliers.none); - assert(dub.computePkgSuppliers(null, SkipPackageSuppliers.none).length == 1); - assert(dub.computePkgSuppliers(null, SkipPackageSuppliers.configured).length == 0); - assert(dub.computePkgSuppliers(null, SkipPackageSuppliers.standard).length == 0); + assert(dub.computePkgSuppliers(null, SkipPackageSuppliers.none, null).length == 1); + assert(dub.computePkgSuppliers(null, SkipPackageSuppliers.configured, null).length == 0); + assert(dub.computePkgSuppliers(null, SkipPackageSuppliers.standard, null).length == 0); - environment["DUB_REGISTRY"] = "http://example.com/"; - assert(dub.computePkgSuppliers(null, SkipPackageSuppliers.standard).length == 1); + assert(dub.computePkgSuppliers(null, SkipPackageSuppliers.standard, "http://example.com/") + .length == 1); } @property bool dryRun() const { return m_dryRun; }