Merge pull request #897 from dlang/issue895-dub-config-in-exe-dir
Search for dub configuration in ../etc/dub/. Fixes #895.
commit eeff313d6e797276f273b0e7efa62821fefa5f1c
2 parents 8fc18d4 + a1cd0b0
@Sönke Ludwig Sönke Ludwig authored on 8 Aug 2016
GitHub committed on 8 Aug 2016
Showing 2 changed files
View
112
source/dub/dub.d
bool m_dryRun = false;
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;
string m_defaultCompiler;
init();
 
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();
}
 
/** Initializes the instance with a single package search path, without
 
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_tempPath = Path(tempDir);
m_userConfig = jsonFromFile(m_userDubPath ~ "settings.json", true);
m_systemConfig = jsonFromFile(m_systemDubPath ~ "settings.json", true);
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_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();
}
 
auto basename = getBasePackageName(p);
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;
}
 
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
Package existing;
private void determineDefaultCompiler()
{
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";
version (Posix) enum sep = ":", exe = "";
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;
}
}
View
26
test/issue895-local-configuration.sh 0 → 100755
#!/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