diff --git a/source/app.d b/source/app.d index 10d66c5..eae8689 100644 --- a/source/app.d +++ b/source/app.d @@ -109,7 +109,7 @@ // handle the command switch( cmd ){ default: - enforce(false, "Command is unknown."); + enforce(false, "Command is unknown: " ~ cmd); assert(false); case "help": showHelp(cmd); @@ -291,11 +291,9 @@ return -1; } - Vpm vpm = new Vpm(Path(appPath), new RegistryPS(registryUrl)); - logDebug("vpm initialized, calling generate"); - vpm.generateProject(ide); + dub.generateProject(ide); logDebug("Project files generated."); - return 0; + break; } return 0; diff --git a/source/dub/dub.d b/source/dub/dub.d index 6d4c33c..8aadb38 100644 --- a/source/dub/dub.d +++ b/source/dub/dub.d @@ -14,7 +14,6 @@ import dub.package_; import dub.packagemanager; import dub.packagesupplier; -import dub.packagestore; import dub.generators.generator; import vibe.core.file; @@ -127,8 +126,8 @@ return pkgs; } - const(Package[string]) installedPackages() const { - return m_packages; + const(Package[]) installedPackages() const { + return m_dependencies; } const (Package) mainPackage() const { @@ -373,32 +372,30 @@ different = true; break; } - if(!different) { - logWarn("Could not resolve dependencies"); - return false; - } } + if(!different) { + logWarn("Could not resolve dependencies"); + return false; + } + } - oldMissing = missing.dup; - logTrace("There are %s packages missing.", missing.length); - foreach(string pkg, reqDep; missing) { - if(!reqDep.dependency.valid()) { - logTrace("Dependency to "~pkg~" is invalid. Trying to fix by modifying others."); - continue; - } - + oldMissing = missing.dup; + logTrace("There are %s packages missing.", missing.length); + foreach(string pkg, reqDep; missing) { + if(!reqDep.dependency.valid()) { + logTrace("Dependency to "~pkg~" is invalid. Trying to fix by modifying others."); + continue; + } + // TODO: auto update and update interval by time logTrace("Adding package to graph: "~pkg); Package p = m_packageManager.getBestPackage(pkg, reqDep.dependency); if( p ) logTrace("Found installed package %s %s", pkg, p.ver); - + // Try an already installed package first if( p && p.installLocation != InstallLocation.Local && needsUpToDateCheck(pkg) ){ logInfo("Triggering update of package %s", pkg); p = null; - - if(p) - graph.insert(p); } if( !p ){ @@ -415,7 +412,9 @@ if(p) graph.insert(p); } - + graph.clearUnused(); + missing = graph.missing(); + } return true; } @@ -425,7 +424,13 @@ if( !time.length ) return true; return (Clock.currTime() - SysTime.fromISOExtString(time)) > dur!"days"(1); } catch(Exception t) return true; - + } + + void markUpToDate(string packageId) { + logTrace("markUpToDate(%s)", packageId); + Json create(ref Json json, string object) { + if( object !in json ) json[object] = Json.EmptyObject; + return json[object]; } create(m_json, "dub"); create(m_json["dub"], "lastUpdate"); @@ -479,7 +484,6 @@ Json m_systemConfig, m_userConfig; PackageManager m_packageManager; Application m_app; - PackageStore m_packageStore; } /// Initiales the package manager for the vibe application @@ -503,10 +507,6 @@ m_packageSupplier = ps; m_packageManager = new PackageManager(m_systemDubPath ~ "packages/", m_userDubPath ~ "packages/"); - - /// HACK - m_packageStore.includePath(Path("E:\\dev\\")); - m_packageStore.includePath(Path("E:\\dev\\dub\\modules")); } /// Returns the name listed in the package.json of the current @@ -590,6 +590,18 @@ return newActions.length == 0; } + /// Generate project files for a specified IDE. + /// Any existing project files will be overridden. + void generateProject(string ide) { + auto generator = createProjectGenerator(ide, m_app, m_packageManager); + if(null is generator) + throw new Exception("Unsupported IDE, there is no generator available for '"~ide~"'"); + + // Q: update before generating? + + generator.generateProject(); + } + /// Creates a zip from the application. void createZip(string zipFile) { m_app.createZip(zipFile); @@ -706,18 +718,6 @@ dst.put(p.toNativeString()); } else dst.put(var); } - - /// Generate project files for a specified IDE. - /// Any existing project files will be overridden. - void generateProject(string ide) { - auto generator = createProjectGenerator(ide, m_app, m_packageStore); - if(null is generator) - throw new Exception("Unsupported IDE, there is no generator available for '"~ide~"'"); - - // Q: update before generating? - - generator.generateProject(); - } } private bool isIdentChar(char ch) diff --git a/source/dub/generators/generator.d b/source/dub/generators/generator.d index 9c7d251..76e740b 100644 --- a/source/dub/generators/generator.d +++ b/source/dub/generators/generator.d @@ -8,7 +8,7 @@ module dub.generators.generator; import dub.dub; -import dub.packagestore; +import dub.packagemanager; import dub.generators.visuald; /// A project generator generates projects :-/ @@ -18,7 +18,7 @@ } /// Creates a project generator. -ProjectGenerator createProjectGenerator(string projectType, Application app, PackageStore store) { +ProjectGenerator createProjectGenerator(string projectType, Application app, PackageManager store) { switch(projectType) { default: return null; case "VisualD": return new VisualDGenerator(app, store); diff --git a/source/dub/generators/visuald.d b/source/dub/generators/visuald.d index e512499..94a0f9a 100644 --- a/source/dub/generators/visuald.d +++ b/source/dub/generators/visuald.d @@ -19,7 +19,7 @@ import dub.dub; import dub.package_; -import dub.packagestore; +import dub.packagemanager; import dub.generators.generator; // version = VISUALD_SEPERATE_PROJECT_FILES; @@ -28,14 +28,14 @@ class VisualDGenerator : ProjectGenerator { private { Application m_app; - PackageStore m_store; + PackageManager m_pkgMgr; string[string] m_projectUuids; bool[string] m_generatedProjects; } - this(Application app, PackageStore store) { + this(Application app, PackageManager mgr) { m_app = app; - m_store = store; + m_pkgMgr = mgr; } override void generateProject() { @@ -347,8 +347,8 @@ // TODO: cyclic check foreach(id, dependency; main.dependencies) { - logDebug("Retrieving package %s from store.", id); - auto pack = m_store.package_(id, dependency); + logDebug("Retrieving package %s from package manager.", id); + auto pack = m_pkgMgr.getBestPackage(id, dependency); if(pack is null) { logWarn("Package %s (%s) could not be retrieved continuing...", id, to!string(dependency)); continue; diff --git a/source/dub/package_.d b/source/dub/package_.d index 91880cd..5321ea6 100644 --- a/source/dub/package_.d +++ b/source/dub/package_.d @@ -13,6 +13,7 @@ import std.array; import std.conv; import std.exception; +import std.file; import vibe.core.file; import vibe.data.json; import vibe.inet.url; @@ -124,20 +125,19 @@ // } // } class Package { - static struct LocalPacageDef { string name; Version version_; Path path; } + static struct LocalPackageDef { string name; Version version_; Path path; } private { InstallLocation m_location; Path m_path; Json m_meta; Dependency[string] m_dependencies; - LocalPacageDef[] m_localPackageDefs; + LocalPackageDef[] m_localPackageDefs; } this(InstallLocation location, Path root) { this(jsonFromFile(root ~ PackageJsonFilename), location, root); - m_root = root; } this(Json package_info, InstallLocation location = InstallLocation.Local, Path root = Path()) @@ -153,7 +153,7 @@ if( verspec.type == Json.Type.Object ){ auto ver = verspec["version"].get!string; m_dependencies[pkg] = new Dependency("==", ver); - m_localPackageDefs ~= LocalPacageDef(pkg, Version(ver), Path(verspec.path.get!string())); + m_localPackageDefs ~= LocalPackageDef(pkg, Version(ver), Path(verspec.path.get!string())); } else m_dependencies[pkg] = new Dependency(verspec.get!string()); } } @@ -166,7 +166,7 @@ @property Path path() const { return m_path; } @property const(Url) url() const { return Url.parse(cast(string)m_meta["url"]); } @property const(Dependency[string]) dependencies() const { return m_dependencies; } - @property const(LocalPacageDef)[] localPackageDefs() const { return m_localPackageDefs; } + @property const(LocalPackageDef)[] localPackageDefs() const { return m_localPackageDefs; } @property string binaryPath() const { return m_meta["binaryPath"].opt!string; } @property string[] configurations() @@ -194,11 +194,9 @@ } @property const(Path[]) sources() const { - enforce(m_root != Path(), "Cannot assemble sources from package, m_root == Path()."); Path[] allSources; - foreach(DirEntry d; dirEntries(to!string(m_root ~ Path("source")), "*.d", SpanMode.depth)) { + foreach(DirEntry d; dirEntries(to!string(m_path ~ Path("source")), "*.d", SpanMode.depth)) allSources ~= Path(d.name); - } return allSources; } diff --git a/source/dub/packagestore.d b/source/dub/packagestore.d deleted file mode 100644 index 51bc0e6..0000000 --- a/source/dub/packagestore.d +++ /dev/null @@ -1,38 +0,0 @@ -/** - A package store, storing and retrieving installed packages. - - Copyright: © 2012 Matthias Dondorff - License: Subject to the terms of the MIT license, as written in the included LICENSE.txt file. - Authors: Matthias Dondorff -*/ -module dub.packagestore; - -import std.conv; - -import vibe.core.log; -import vibe.inet.path; - -import dub.dependency; -import dub.package_; - -class PackageStore { - - this() { - } - - /// The PackageStore will use this directory to lookup packages. - void includePath(Path path) { m_includePaths ~= path; } - - /// Retrieves an installed package. - Package package_(string packageId, const Dependency dep) { - logDebug("PackageStore.package_('%s', '%s')", packageId, to!string(dep)); - if(packageId == "vibe.d") { - return new Package(Path("E:\\dev\\vibe.d")); - } - return null; - } - - private { - Path[] m_includePaths; - } -}