diff --git a/source/dub/commandline.d b/source/dub/commandline.d index ccb2c7b..8d8b149 100644 --- a/source/dub/commandline.d +++ b/source/dub/commandline.d @@ -98,6 +98,11 @@ environment["TEMP"] = environment["TEMP"].replace("/", "\\"); } + // special single-file package shebang syntax + if (args.length >= 2 && args[1].endsWith(".d")) { + args = args[0] ~ ["run", "-q", "--single", args[1], "--"] ~ args[2 ..$]; + } + // split application arguments from DUB arguments string[] app_args; auto app_args_idx = args.countUntil("--"); @@ -146,15 +151,8 @@ string cmdname; args = common_args.extractRemainingArgs(); if (args.length >= 1 && !args[0].startsWith("-")) { - if (args[0].endsWith(".d")) { - cmdname = "run"; - if (app_args.length) app_args = args[1 .. $] ~ "--" ~ app_args; - else app_args = args[1 .. $]; - args = ["--single", args[0]]; - } else { - cmdname = args[0]; - args = args[1 .. $]; - } + cmdname = args[0]; + args = args[1 .. $]; } else { if (options.help) { showHelp(commands, common_args); diff --git a/source/dub/dub.d b/source/dub/dub.d index e27aea7..1ea03f8 100644 --- a/source/dub/dub.d +++ b/source/dub/dub.d @@ -299,7 +299,12 @@ recipe_content = recipe_content[idx+1 .. $]; auto recipe = parsePackageRecipe(recipe_content, recipe_filename); + 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."); recipe.buildSettings.sourceFiles[""] = [path.toNativeString()]; + recipe.buildSettings.sourcePaths[""] = []; + recipe.buildSettings.importPaths[""] = []; recipe.buildSettings.mainSourceFile = path.toNativeString(); if (recipe.buildSettings.targetType == TargetType.autodetect) recipe.buildSettings.targetType = TargetType.executable; diff --git a/source/dub/generators/build.d b/source/dub/generators/build.d index b2d4ae0..3e30acd 100644 --- a/source/dub/generators/build.d +++ b/source/dub/generators/build.d @@ -34,6 +34,7 @@ private { PackageManager m_packageMan; Path[] m_temporaryFiles; + Path m_targetExecutablePath; } this(Project project) @@ -94,9 +95,13 @@ override void performPostGenerateActions(GeneratorSettings settings, in TargetInfo[string] targets) { // run the generated executable - auto buildsettings = targets[m_project.rootPackage.name].buildSettings; + auto buildsettings = targets[m_project.rootPackage.name].buildSettings.dup; if (settings.run && !(buildsettings.options & BuildOption.syntaxOnly)) { - auto exe_file_path = getTargetPath(buildsettings, settings); + Path exe_file_path; + if (!m_targetExecutablePath.length) + exe_file_path = getTargetPath(buildsettings, settings); + else + exe_file_path = m_targetExecutablePath ~ settings.compiler.getTargetFileName(buildsettings, settings.platform); runTarget(exe_file_path, buildsettings, settings.runArgs, settings); } } @@ -148,7 +153,7 @@ auto cwd = Path(getcwd()); Path target_path; - if (settings.tempBuild) target_path = getTempDir() ~ format(".dub/build/%s-%s/%s/", pack.name, pack.version_, build_id); + if (settings.tempBuild) m_targetExecutablePath = target_path = getTempDir() ~ format(".dub/build/%s-%s/%s/", pack.name, pack.version_, build_id); else target_path = pack.path ~ format(".dub/build/%s/", build_id); if (!settings.force && isUpToDate(target_path, buildsettings, settings, pack, packages, additional_dep_files)) { @@ -180,7 +185,8 @@ cbuildsettings.targetPath = target_path.relativeTo(cwd).toNativeString(); buildWithCompiler(settings, cbuildsettings); - copyTargetFile(target_path, buildsettings, settings); + if (!settings.tempBuild) + copyTargetFile(target_path, buildsettings, settings); return false; }