| |
---|
| | 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; |
---|
| | } |
---|
| | } |
---|
| | |
---|
| | |