Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add output-path, configs, builds to dub describe #2204

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 44 additions & 6 deletions source/dub/project.d
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,14 @@ class Project {
possible configuration instead of the first "executable"
configuration.
*/
string getDefaultConfiguration(in BuildPlatform platform, bool allow_non_library_configs = true)
string getDefaultConfiguration(const BuildPlatform platform, bool allow_non_library_configs = true)
const {
auto cfgs = getPackageConfigs(platform, null, allow_non_library_configs);
return cfgs[m_rootPackage.name];
}

/// ditto
string getDefaultConfiguration(scope const ref BuildPlatform platform, bool allow_non_library_configs = true)
const {
auto cfgs = getPackageConfigs(platform, null, allow_non_library_configs);
return cfgs[m_rootPackage.name];
Expand Down Expand Up @@ -890,14 +897,14 @@ class Project {
return ret;
}

private string[] listBuildSetting(string attributeName)(ref GeneratorSettings settings,
private string[] listBuildSetting(string attributeName)(const ref GeneratorSettings settings,
string config, ProjectDescription projectDescription, Compiler compiler, bool disableEscaping)
{
return listBuildSetting!attributeName(settings, getPackageConfigs(settings.platform, config),
projectDescription, compiler, disableEscaping);
}

private string[] listBuildSetting(string attributeName)(ref GeneratorSettings settings,
private string[] listBuildSetting(string attributeName)(const ref GeneratorSettings settings,
string[string] configs, ProjectDescription projectDescription, Compiler compiler, bool disableEscaping)
{
if (compiler)
Expand All @@ -907,7 +914,7 @@ class Project {
}

// Output a build setting formatted for a compiler
private string[] formatBuildSettingCompiler(string attributeName)(ref GeneratorSettings settings,
private string[] formatBuildSettingCompiler(string attributeName)(const ref GeneratorSettings settings,
string[string] configs, ProjectDescription projectDescription, Compiler compiler, bool disableEscaping)
{
import std.process : escapeShellFileName;
Expand Down Expand Up @@ -996,7 +1003,7 @@ class Project {
}

// Output a build setting without formatting for any particular compiler
private string[] formatBuildSettingPlain(string attributeName)(ref GeneratorSettings settings, string[string] configs, ProjectDescription projectDescription)
private string[] formatBuildSettingPlain(string attributeName)(const ref GeneratorSettings settings, string[string] configs, ProjectDescription projectDescription)
{
import std.path : buildNormalizedPath, dirSeparator;
import std.range : only;
Expand Down Expand Up @@ -1109,7 +1116,7 @@ class Project {

// The "compiler" arg is for choosing which compiler the output should be formatted for,
// or null to imply "list" format.
private string[] listBuildSetting(ref GeneratorSettings settings, string[string] configs,
private string[] listBuildSetting(const ref GeneratorSettings settings, string[string] configs,
ProjectDescription projectDescription, string requestedData, Compiler compiler, bool disableEscaping)
{
// Certain data cannot be formatter for a compiler
Expand Down Expand Up @@ -1139,6 +1146,11 @@ class Project {
case "post-build-environments":
case "pre-run-environments":
case "post-run-environments":
case "output-paths":
case "default-config":
case "configs":
case "default-build":
case "builds":
enforce(false, "--data="~requestedData~" can only be used with `--data-list` or `--data-list --data-0`.");
break;

Expand Down Expand Up @@ -1191,6 +1203,12 @@ class Project {
case "requirements": return listBuildSetting!"requirements"(args);
case "options": return listBuildSetting!"options"(args);

case "output-paths": return determineOutputPaths(settings).map!"a.toNativeString".array;
case "default-config": return [getDefaultConfiguration(settings.platform)];
case "configs": return configurations;
case "default-build": return [builtinBuildTypes[0]];
case "builds": return builds;

default:
enforce(false, "--data="~requestedData~
" is not a valid option. See 'dub describe --help' for accepted --data= values.");
Expand All @@ -1199,6 +1217,23 @@ class Project {
assert(0);
}

/// Returns the relative or absolute path to the output file for the given
/// generator settings including target name and platform specific file
/// extension.
final NativePath[] determineOutputPaths(const ref GeneratorSettings settings)
{
return determineOutputPaths(settings.platform, settings.buildSettings, settings.compiler);
}

/// ditto
NativePath[] determineOutputPaths(const ref BuildPlatform platform, const ref BuildSettings buildSettings, const Compiler compiler)
{
auto root = NativePath(buildSettings.targetPath);
if (!root.absolute)
root = m_rootPackage.path ~ root;
return [root ~ compiler.getTargetFileName(buildSettings, platform)];
}

/// Outputs requested data for the project, optionally including its dependencies.
string[] listBuildSettings(GeneratorSettings settings, string[] requestedData, ListBuildSettingsFormat list_type)
{
Expand All @@ -1218,6 +1253,9 @@ class Project {
foreach (file; target.buildSettings.sourceFiles.filter!(f => isLinkerFile(settings.platform, f)))
target.buildSettings.addLinkerFiles(file);

// override passed in build settings with actual final build settings
settings.buildSettings = target.buildSettings;

// Remove linker files from sourceFiles
target.buildSettings.sourceFiles =
target.buildSettings.sourceFiles
Expand Down