diff --git a/source/dub/dub.d b/source/dub/dub.d index 22c52a3..c3853b0 100644 --- a/source/dub/dub.d +++ b/source/dub/dub.d @@ -92,9 +92,8 @@ PackageManager m_packageManager; PackageSupplier[] m_packageSuppliers; Path m_rootPath; - Path m_tempPath; - Path m_userDubPath, m_systemDubPath; - Json m_systemConfig, m_userConfig; + SpecialDirs m_dirs; + DubConfig m_config; Path m_projectPath; Project m_project; Path m_overrideSearchPath; @@ -133,25 +132,16 @@ PackageSupplier[] ps = additional_package_suppliers; - if (skip_registry < SkipPackageSuppliers.all) { - if (auto pp = "registryUrls" in m_userConfig) - ps ~= deserializeJson!(string[])(*pp) - .map!(url => cast(PackageSupplier)new RegistryPackageSupplier(URL(url))) - .array; - } - - if (skip_registry < SkipPackageSuppliers.all) { - if (auto pp = "registryUrls" in m_systemConfig) - ps ~= deserializeJson!(string[])(*pp) - .map!(url => cast(PackageSupplier)new RegistryPackageSupplier(URL(url))) - .array; - } + if (skip_registry < SkipPackageSuppliers.all) + ps ~= m_config.registryURLs + .map!(url => cast(PackageSupplier)new RegistryPackageSupplier(URL(url))) + .array; if (skip_registry < SkipPackageSuppliers.standard) ps ~= defaultPackageSuppliers(); m_packageSuppliers = ps; - m_packageManager = new PackageManager(m_userDubPath, m_systemDubPath); + m_packageManager = new PackageManager(m_dirs.userSettings, m_dirs.systemSettings); updatePackageSearchPath(); } @@ -172,19 +162,21 @@ private void init() { import std.file : tempDir; - version(Windows){ - m_systemDubPath = Path(environment.get("ProgramData")) ~ "dub/"; - m_userDubPath = Path(environment.get("APPDATA")) ~ "dub/"; + version(Windows) { + m_dirs.systemSettings = Path(environment.get("ProgramData")) ~ "dub/"; + m_dirs.userSettings = Path(environment.get("APPDATA")) ~ "dub/"; } else version(Posix){ - m_systemDubPath = Path("/var/lib/dub/"); - m_userDubPath = Path(environment.get("HOME")) ~ ".dub/"; - if(!m_userDubPath.absolute) - m_userDubPath = Path(getcwd()) ~ m_userDubPath; + m_dirs.systemSettings = Path("/var/lib/dub/"); + m_dirs.userSettings = Path(environment.get("HOME")) ~ ".dub/"; + if (!m_dirs.userSettings.absolute) + m_dirs.userSettings = Path(getcwd()) ~ m_dirs.userSettings; } - m_tempPath = Path(tempDir); - m_userConfig = jsonFromFile(m_userDubPath ~ "settings.json", true); - m_systemConfig = jsonFromFile(m_systemDubPath ~ "settings.json", true); + m_dirs.temp = Path(tempDir); + + m_config = new DubConfig(jsonFromFile(m_dirs.systemSettings ~ "settings.json", true), m_config); + m_config = new DubConfig(jsonFromFile(Path(thisExePath).parentPath ~ "../etc/dub/settings.json", true), m_config); + m_config = new DubConfig(jsonFromFile(m_dirs.userSettings ~ "settings.json", true), m_config); determineDefaultCompiler(); } @@ -402,7 +394,7 @@ if (basename == rootbasename) continue; if (!m_project.selections.hasSelectedVersion(basename)) { - logInfo("Package %s can be installed with version %s.", + logInfo("Non-selected package %s is available with version %s.", basename, ver); any = true; continue; @@ -638,8 +630,8 @@ Path placement; final switch (location) { case PlacementLocation.local: placement = m_rootPath; break; - case PlacementLocation.user: placement = m_userDubPath ~ "packages/"; break; - case PlacementLocation.system: placement = m_systemDubPath ~ "packages/"; break; + case PlacementLocation.user: placement = m_dirs.userSettings ~ "packages/"; break; + case PlacementLocation.system: placement = m_dirs.systemSettings ~ "packages/"; break; } // always upgrade branch based versions - TODO: actually check if there is a new commit available @@ -1088,10 +1080,7 @@ { import std.process : environment; - m_defaultCompiler = m_userConfig["defaultCompiler"].opt!string(); - if (m_defaultCompiler.length) return; - - m_defaultCompiler = m_systemConfig["defaultCompiler"].opt!string(); + m_defaultCompiler = m_config.defaultCompiler; if (m_defaultCompiler.length) return; version (Windows) enum sep = ";", exe = ".exe"; @@ -1376,3 +1365,39 @@ return null; } } + +private struct SpecialDirs { + Path temp; + Path userSettings; + Path systemSettings; +} + +private class DubConfig { + private { + DubConfig m_parentConfig; + Json m_data; + } + + this(Json data, DubConfig parent_config) + { + m_data = data; + m_parentConfig = parent_config; + } + + @property string[] registryURLs() + { + string[] ret; + if (auto pv = "registryUrls" in m_data) + ret = (*pv).deserializeJson!(string[]); + if (m_parentConfig) ret ~= m_parentConfig.registryURLs; + return ret; + } + + @property string defaultCompiler() + const { + if (auto pv = "defaultCompiler" in m_data) + return pv.get!string; + if (m_parentConfig) return m_parentConfig.defaultCompiler; + return null; + } +} diff --git a/test/issue895-local-configuration.sh b/test/issue895-local-configuration.sh new file mode 100755 index 0000000..8edc10f --- /dev/null +++ b/test/issue895-local-configuration.sh @@ -0,0 +1,25 @@ +#!/usr/bin/env bash +set -e + +cd ${CURR_DIR} +mkdir ../etc +mkdir ../etc/dub +echo "{\"defaultCompiler\": \"foo\"}" > ../etc/dub/settings.json + +if [ -e /var/lib/dub/settings.json ]; then + echo "Found existing system wide DUB configuration. Aborting." + exit 1 +fi + +if [ -e ~/.dub/settings.json ]; then + echo "Found existing user wide DUB configuration. Aborting." + exit 1 +fi + +if ! ${DUB} describe --single issue103-single-file-package.d 2>&1 | grep -e "Unknown compiler: foo" -c > /dev/null; then + rm -r ../etc + echo "DUB didn't find the local configuration" + exit 1 +fi + +rm -r ../etc