diff --git a/source/app.d b/source/app.d index 67bb904..eaf2bf4 100644 --- a/source/app.d +++ b/source/app.d @@ -106,6 +106,27 @@ } Dub dub = new Dub; + string def_config; + + bool loadCwdPackage() + { + if( !existsFile("package.json") && !existsFile("source/app.d") ){ + logInfo(""); + logInfo("Neither package.json, nor source/app.d was found in the current directory."); + logInfo("Please run dub from the root directory of an existing package, or create a new"); + logInfo("package using \"dub init \"."); + logInfo(""); + showHelp(null); + return false; + } + + dub.loadPackageFromCwd(); + + def_config = dub.getDefaultConfiguration(build_platform); + if( !build_config.length ) build_config = def_config; + + return true; + } // handle the command switch( cmd ){ @@ -182,17 +203,7 @@ case "run": case "build": case "generate": - if( !existsFile("package.json") && !existsFile("source/app.d") ){ - logInfo(""); - logInfo("Neither package.json, nor source/app.d was found in the current directory."); - logInfo("Please run dub from the root directory of an existing package, or create a new"); - logInfo("package using \"dub init \"."); - logInfo(""); - showHelp(null); - return 1; - } - - dub.loadPackageFromCwd(); + if (!loadCwdPackage()) return 1; string generator; if( cmd == "run" || cmd == "build" ) generator = rdmd ? "rdmd" : "build"; @@ -204,10 +215,6 @@ } } - - auto def_config = dub.getDefaultConfiguration(build_platform); - if( !build_config.length ) build_config = def_config; - if( print_builds ){ logInfo("Available build types:"); foreach( tp; ["debug", "release", "unittest", "profile"] ) @@ -244,6 +251,10 @@ dub.generateProject(generator, gensettings); if( build_type == "ddox" ) dub.runDdox(); break; + case "describe": + if (!loadCwdPackage()) return 1; + dub.describeProject(build_platform, build_config); + break; } return 0; @@ -300,7 +311,7 @@ DUB options from options passed to the application. If the command is omitted, dub will default to "run". -Possible commands: +Available commands: help Prints this help screen init [] Initializes an empy project in the specified directory run Compiles and runs the application (default command) @@ -316,6 +327,8 @@ list-user Prints a list of all user installed packages. generate Generates project files using the specified generator: visuald, mono-d, build, rdmd + describe Prints a JSON description of the project and its + dependencies General options: --annotate Do not execute dependency installations, just print diff --git a/source/dub/dub.d b/source/dub/dub.d index c02a117..0631d79 100644 --- a/source/dub/dub.d +++ b/source/dub/dub.d @@ -170,6 +170,19 @@ m_project.createZip(zipFile); } + /// Outputs a JSON description of the project, including its deoendencies. + void describeProject(BuildPlatform platform, string config) + { + auto dst = Json.EmptyObject; + dst.configuration = config; + dst.compiler = platform.compiler; + dst.architecture = platform.architecture.serializeToJson(); + dst.platform = platform.platform.serializeToJson(); + + m_project.describe(dst, platform, config); + logInfo("%s", dst.toPrettyString()); + } + /// Gets all installed packages as a "packageId" = "version" associative array string[string] installedPackages() const { return m_project.installedPackagesIDs(); } diff --git a/source/dub/package_.d b/source/dub/package_.d index 2c5a51a..3161a2c 100644 --- a/source/dub/package_.d +++ b/source/dub/package_.d @@ -215,7 +215,31 @@ if (packageId in m_info.dependencies) m_info.dependencies.remove(packageId); } -} + + void describe(ref Json dst, BuildPlatform platform, string config) + { + dst.path = m_path.toNativeString(); + dst.name = m_info.name; + dst["version"] = m_info.version_; + dst.description = m_info.description; + dst.homepage = m_info.homepage; + dst.authors = m_info.authors.serializeToJson(); + dst.copyright = m_info.copyright; + dst.license = m_info.license; + dst.dependencies = m_info.dependencies.keys.serializeToJson(); + + auto jconfig = Json.EmptyObject; + Json[string] files; + BuildSettings bs = getBuildSettings(platform, config); + foreach (f; bs.sourceFiles) { + auto jf = Json.EmptyObject; + jf.path = f; + jf["type"] = "source"; + files[f] = jf; + } + dst.files = Json(files); + } +} /// Specifying package information without any connection to a certain /// installed package, like Package class is doing. diff --git a/source/dub/project.d b/source/dub/project.d index 31877cc..c7c0b82 100644 --- a/source/dub/project.d +++ b/source/dub/project.d @@ -398,6 +398,24 @@ */ } + /// Outputs a JSON description of the project, including its deoendencies. + void describe(ref Json dst, BuildPlatform platform, string config) + { + dst.mainPackage = m_main.name; + + auto configs = getPackageConfigs(platform, config); + + auto mp = Json.EmptyObject; + m_main.describe(mp, platform, config); + dst.packages = Json([mp]); + + foreach (dep; m_dependencies) { + auto dp = Json.EmptyObject; + dep.describe(dp, platform, configs[dep.name]); + dst.packages = dst.packages.get!(Json[]) ~ dp; + } + } + /// Tries to add the specified dependency. /// If an existing dependencies is already current, this one is compared to /// the supplied one, in order to check if these are compatible.