diff --git a/source/dub/commandline.d b/source/dub/commandline.d index 9f371b8..9c2eb32 100644 --- a/source/dub/commandline.d +++ b/source/dub/commandline.d @@ -978,13 +978,16 @@ settings.platform = m_buildPlatform; settings.config = config; settings.buildType = m_buildType; - settings.compiler = m_dataList ? null : m_compiler; + settings.compiler = m_compiler; if (m_importPaths) { m_data = ["import-paths"]; m_dataList = true; } else if (m_stringImportPaths) { m_data = ["string-import-paths"]; m_dataList = true; } if (m_data.length) { - dub.listProjectData(settings, m_data, m_dataNullDelim); + ListBuildSettingsFormat lt; + with (ListBuildSettingsFormat) + lt = m_dataList ? (m_dataNullDelim ? listNul : list) : (m_dataNullDelim ? commandLineNul : commandLine); + dub.listProjectData(settings, m_data, lt); } else { auto desc = dub.project.describe(settings); writeln(desc.serializeToPrettyJson()); diff --git a/source/dub/dub.d b/source/dub/dub.d index 7ccd7cd..f4a979d 100644 --- a/source/dub/dub.d +++ b/source/dub/dub.d @@ -531,7 +531,7 @@ /** Prints the specified build settings necessary for building the root package. */ - void listProjectData(GeneratorSettings settings, string[] requestedData, bool nullDelim) + void listProjectData(GeneratorSettings settings, string[] requestedData, ListBuildSettingsFormat list_type) { import std.stdio; import std.ascii : newline; @@ -543,22 +543,32 @@ .joiner() .array(); - auto data = m_project.listBuildSettings(settings, requestedDataSplit, nullDelim); + auto data = m_project.listBuildSettings(settings, requestedDataSplit, list_type); - write( data.joiner(nullDelim? "\0" : newline) ); - if(!nullDelim) - writeln(); + string delimiter; + final switch (list_type) with (ListBuildSettingsFormat) { + case list: delimiter = newline ~ newline; break; + case listNul: delimiter = "\0\0"; break; + case commandLine: delimiter = " "; break; + case commandLineNul: delimiter = "\0\0"; break; + } + + write(data.joiner(delimiter)); + if (delimiter != "\0\0") writeln(); } deprecated("Use the overload taking GeneratorSettings instead.") void listProjectData(BuildPlatform platform, string config, string buildType, - string[] requestedData, Compiler formattingCompiler, bool nullDelim) + string[] requestedData, Compiler formattingCompiler, bool null_delim) { GeneratorSettings settings; settings.platform = platform; settings.compiler = formattingCompiler; settings.config = config; settings.buildType = buildType; - listProjectData(settings, requestedData, nullDelim); + ListBuildSettingsFormat lt; + with (ListBuildSettingsFormat) + lt = formattingCompiler ? (null_delim ? commandLineNul : commandLine) : (null_delim ? listNul : list); + listProjectData(settings, requestedData, lt); } /// Cleans intermediate/cache files of the given package diff --git a/source/dub/project.d b/source/dub/project.d index 22f0978..8dae9f3 100644 --- a/source/dub/project.d +++ b/source/dub/project.d @@ -952,7 +952,7 @@ } /// Outputs requested data for the project, optionally including its dependencies. - string[] listBuildSettings(GeneratorSettings settings, string[] requestedData, bool nullDelim) + string[] listBuildSettings(GeneratorSettings settings, string[] requestedData, ListBuildSettingsFormat list_type) { import dub.compilers.utils : isLinkerFile; @@ -976,25 +976,27 @@ .array(); projectDescription.lookupTarget(projectDescription.rootPackage) = target; - // Genrate results - if (settings.compiler) - { - // Format for a compiler - return [ - requestedData - .map!(dataName => listBuildSetting(settings.platform, configs, projectDescription, dataName, settings.compiler, nullDelim)) - .join().join(nullDelim? "\0" : " ") - ]; + Compiler compiler; + bool no_escape; + final switch (list_type) with (ListBuildSettingsFormat) { + case list: break; + case listNul: no_escape = true; break; + case commandLine: compiler = settings.compiler; break; + case commandLineNul: compiler = settings.compiler; no_escape = true; break; + } - else - { - // Format list-style - return requestedData - .map!(dataName => listBuildSetting(settings.platform, configs, projectDescription, dataName, null, nullDelim)) - .joiner([""]) // Blank entry between each type of requestedData - .array(); + + auto result = requestedData + .map!(dataName => listBuildSetting(settings.platform, configs, projectDescription, dataName, compiler, no_escape)); + + final switch (list_type) with (ListBuildSettingsFormat) { + case list: return result.map!(l => l.join("\n")).array(); + case listNul: return result.map!(l => l.join("\0")).array; + case commandLine: return result.map!(l => l.join(" ")).array; + case commandLineNul: return result.map!(l => l.join("\0")).array; } } + deprecated("Use the overload taking a GeneratorSettings instance instead.") string[] listBuildSettings(BuildPlatform platform, string config, string buildType, string[] requestedData, Compiler formattingCompiler, bool nullDelim) @@ -1004,7 +1006,10 @@ settings.config = config; settings.buildType = buildType; settings.compiler = formattingCompiler; - return listBuildSettings(settings, requestedData, nullDelim); + ListBuildSettingsFormat listtype; + with (ListBuildSettingsFormat) + listtype = formattingCompiler ? (nullDelim ? commandLineNul : commandLine) : (nullDelim ? listNul : list); + return listBuildSettings(settings, requestedData, listtype); } /// Outputs the import paths for the project, including its dependencies. @@ -1111,6 +1116,16 @@ } } + +/// Determines the output format used for `Project.listBuildSettings`. +enum ListBuildSettingsFormat { + list, /// Newline separated list entries + listNul, /// NUL character separated list entries (unescaped) + commandLine, /// Formatted for compiler command line (one data list per line) + commandLineNul, /// NUL character separated list entries (unescaped, data lists separated by two NUL characters) +} + + /// Actions to be performed by the dub deprecated struct Action { enum Type {