diff --git a/source/dub/dub.d b/source/dub/dub.d index 1d0ac8d..ff7e9bf 100644 --- a/source/dub/dub.d +++ b/source/dub/dub.d @@ -37,7 +37,7 @@ /// The default supplier for packages, which is the registry -/// hosted by vibed.org. +/// hosted by code.dlang.org. PackageSupplier[] defaultPackageSuppliers() { Url url = Url.parse("http://code.dlang.org/"); @@ -97,11 +97,14 @@ @property inout(PackageManager) packageManager() inout { return m_packageManager; } + /// Loads the package from the current working directory as the main + /// project package. void loadPackageFromCwd() { loadPackage(m_cwd); } + /// Loads the package from the specified path as the main project package. void loadPackage(Path path) { m_projectPath = path; @@ -162,7 +165,7 @@ generator.generateProject(settings); } - /// Outputs a JSON description of the project, including its deoendencies. + /// Outputs a JSON description of the project, including its dependencies. void describeProject(BuildPlatform platform, string config) { auto dst = Json.EmptyObject; diff --git a/source/dub/generators/generator.d b/source/dub/generators/generator.d index 0d13b5c..ded08eb 100644 --- a/source/dub/generators/generator.d +++ b/source/dub/generators/generator.d @@ -78,7 +78,7 @@ /** - Runs pre-build commands and performs an other required setup before project files are generated. + Runs pre-build commands and performs other required setup before project files are generated. */ void prepareGeneration(BuildSettings buildsettings) { diff --git a/source/dub/installation.d b/source/dub/installation.d deleted file mode 100644 index b3a8d1c..0000000 --- a/source/dub/installation.d +++ /dev/null Binary files differ diff --git a/source/dub/package_.d b/source/dub/package_.d index 3d7f930..39cc81d 100644 --- a/source/dub/package_.d +++ b/source/dub/package_.d @@ -725,14 +725,14 @@ } } -// @deprecated (move to private?) +/// Returns all package names, starting with the root package in [0]. string[] getSubPackagePath(string package_name) { return package_name.split(":"); } -// Returns the name of the base package in the case of some sub package or the -// package itself, if it is already a full package. +/// Returns the name of the base package in the case of some sub package or the +/// package itself, if it is already a full package. string getBasePackage(string package_name) { return package_name.getSubPackagePath()[0]; diff --git a/source/dub/packagemanager.d b/source/dub/packagemanager.d index 8f65a86..7100824 100644 --- a/source/dub/packagemanager.d +++ b/source/dub/packagemanager.d @@ -49,7 +49,8 @@ system } - +/// The PackageManager can retrieve installed packages and install / uninstall +/// packages. class PackageManager { private { Repository[LocalPackageType] m_repositories; @@ -176,6 +177,8 @@ return &iterator; } + /// Installs the package supplied as a path to it's zip file to the + /// destination. Package install(Path zip_file_path, Json package_info, Path destination) { auto package_name = package_info.name.get!string(); @@ -267,6 +270,7 @@ return pack; } + /// Uninstalls the given the package. void uninstall(in Package pack) { logDebug("Uninstall %s, version %s, path '%s'", pack.name, pack.vers, pack.path); @@ -406,12 +410,14 @@ return pack; } + /// For the given type add another path where packages will be looked up. void addSearchPath(Path path, LocalPackageType type) { m_repositories[type].searchPath ~= path; writeLocalPackageList(type); } + /// Removes a search path from the given type. void removeSearchPath(Path path, LocalPackageType type) { m_repositories[type].searchPath = m_repositories[type].searchPath.filter!(p => p != path)().array(); @@ -560,3 +566,77 @@ writeJsonFile(path ~ LocalPackagesFilename, Json(newlist)); } } + + +/** + Installation journal for later uninstallation, keeping track of installed + files. + Example Json: + { + "version": 1, + "files": { + "file1": "typeoffile1", + ... + } + } +*/ +private class Journal { + private enum Version = 1; + + enum Type { + RegularFile, + Directory, + Alien + } + + struct Entry { + this( Type t, Path f ) { type = t; relFilename = f; } + Type type; + Path relFilename; + } + + @property const(Entry[]) entries() const { return m_entries; } + + this() {} + + /// Initializes a Journal from a json file. + this(Path journalFile) { + auto jsonJournal = jsonFromFile(journalFile); + enforce(cast(int)jsonJournal["Version"] == Version, "Mismatched version: "~to!string(cast(int)jsonJournal["Version"]) ~ "vs. " ~to!string(Version)); + foreach(string file, type; jsonJournal["Files"]) + m_entries ~= Entry(to!Type(cast(string)type), Path(file)); + } + + void add(Entry e) { + foreach(Entry ent; entries) { + if( e.relFilename == ent.relFilename ) { + enforce(e.type == ent.type, "Duplicate('"~to!string(e.relFilename)~"'), different types: "~to!string(e.type)~" vs. "~to!string(ent.type)); + return; + } + } + m_entries ~= e; + } + + /// Save the current state to the path. + void save(Path path) { + Json jsonJournal = serialize(); + auto fileJournal = openFile(path, FileMode.CreateTrunc); + scope(exit) fileJournal.close(); + if(PRETTY_JOURNAL) fileJournal.writePrettyJsonString(jsonJournal); + else fileJournal.writeJsonString(jsonJournal); + } + + private Json serialize() const { + Json[string] files; + foreach(Entry e; m_entries) + files[to!string(e.relFilename)] = to!string(e.type); + Json[string] json; + json["Version"] = Version; + json["Files"] = files; + return Json(json); + } + + private { + Entry[] m_entries; + } +} diff --git a/source/dub/project.d b/source/dub/project.d index 5504f33..138e7d8 100644 --- a/source/dub/project.d +++ b/source/dub/project.d @@ -136,14 +136,6 @@ return m_main.getDefaultConfiguration(platform, true); } - - /// Writes the application's metadata to the package.json file - /// in it's root folder. - void writeMetadata() const { - assert(false); - // TODO - } - /// Rereads the applications state. void reinit() { @@ -551,7 +543,7 @@ continue; } - auto ppath = pkg.split(":"); + auto ppath = pkg.getSubPackagePath(); // TODO: auto update and update interval by time logDebug("Adding package to graph: "~pkg); @@ -569,7 +561,7 @@ if( !p ){ try { - logDiagnostic("Fechting package %s (%d suppliers registered)", pkg, packageSuppliers.length); + logDiagnostic("Fetching package %s (%d suppliers registered)", pkg, packageSuppliers.length); foreach (ps; packageSuppliers) { try { auto sp = new Package(ps.getPackageDescription(ppath[0], reqDep.dependency));