diff --git a/source/dub/dub.d b/source/dub/dub.d index 3e4802b..f34e115 100644 --- a/source/dub/dub.d +++ b/source/dub/dub.d @@ -291,6 +291,7 @@ { import dub.recipe.io : parsePackageRecipe; import std.file : mkdirRecurse, readText; + import std.path : baseName, stripExtension; path = makeAbsolute(path); @@ -317,8 +318,9 @@ enforce(idx > 0, "Missing recipe file name (e.g. \"dub.sdl:\") in recipe comment"); auto recipe_filename = recipe_content[0 .. idx]; recipe_content = recipe_content[idx+1 .. $]; + auto recipe_default_package_name = path.toString.baseName.stripExtension.strip; - auto recipe = parsePackageRecipe(recipe_content, recipe_filename); + auto recipe = parsePackageRecipe(recipe_content, recipe_filename, null, recipe_default_package_name); enforce(recipe.buildSettings.sourceFiles.length == 0, "Single-file packages are not allowed to specify source files."); enforce(recipe.buildSettings.sourcePaths.length == 0, "Single-file packages are not allowed to specify source paths."); enforce(recipe.buildSettings.importPaths.length == 0, "Single-file packages are not allowed to specify import paths."); diff --git a/source/dub/recipe/io.d b/source/dub/recipe/io.d index 9704931..52dbefe 100644 --- a/source/dub/recipe/io.d +++ b/source/dub/recipe/io.d @@ -53,11 +53,14 @@ to determine the file format from the file extension parent_name = Optional name of the parent package (if this is a sub package) + default_package_name = Optional default package name (if no package name + is found in the recipe this value will be used) Returns: Returns the package recipe contents Throws: Throws an exception if an I/O or syntax error occurs */ -PackageRecipe parsePackageRecipe(string contents, string filename, string parent_name = null) +PackageRecipe parsePackageRecipe(string contents, string filename, string parent_name = null, + string default_package_name = null) { import std.algorithm : endsWith; import dub.internal.vibecompat.data.json; @@ -66,6 +69,8 @@ PackageRecipe ret; + ret.name = default_package_name; + if (filename.endsWith(".json")) parseJson(ret, parseJsonString(contents, filename), parent_name); else if (filename.endsWith(".sdl")) parseSDL(ret, contents, parent_name, filename); else assert(false, "readPackageRecipe called with filename with unknown extension: "~filename); diff --git a/test/single-file-sdl-default-name.d b/test/single-file-sdl-default-name.d new file mode 100644 index 0000000..e7e7bef --- /dev/null +++ b/test/single-file-sdl-default-name.d @@ -0,0 +1,10 @@ +/++dub.sdl: +dependency "sourcelib-simple" path="1-sourceLib-simple" ++/ +module single; + +void main(string[] args) +{ + import sourcelib.app; + entry(); +} diff --git a/test/single-file-sdl-default-name.sh b/test/single-file-sdl-default-name.sh new file mode 100755 index 0000000..1c61540 --- /dev/null +++ b/test/single-file-sdl-default-name.sh @@ -0,0 +1,11 @@ +#!/bin/sh +set -e +cd ${CURR_DIR} +rm -f single-file-sdl-default-name + +${DUB} run --single single-file-sdl-default-name.d --compiler=${DC} +if [ ! -f single-file-sdl-default-name ]; then + echo "Normal invocation did not produce a binary in the current directory" + exit 1 +fi +rm single-file-sdl-default-name