Fully implemented support for build configurations + added build config fields "lflags", "importPath", "stringImportPath" and "versions".
1 parent fbc7ba3 commit 799ed9ab0de2df89ef640b82641128c50880d9eb
@Sönke Ludwig Sönke Ludwig authored on 12 Jan 2013
Showing 3 changed files
View
62
source/app.d
logDebug("dub initialized");
dub.update(annotate ? UpdateOptions.JustAnnotate : UpdateOptions.None);
}
 
assert(build_config.length == 0, "Build configurations not yet supported.");
enforce(build_config.length == 0 || dub.configurations.canFind(build_config), "Unknown build configuration: "~build_config);
 
//Added check for existance of [AppNameInPackagejson].d
//If exists, use that as the starting file.
auto outfile = getBinName(dub);
flags ~= "-of"~run_exe_file;
}
}
 
flags ~= "-w";
flags ~= "-property";
flags ~= dub.getDflags(build_platform);
flags ~= getPackagesAsVersion(dub);
auto settings = dub.getBuildSettings(build_platform, build_config);
settings.addDFlags(["-w", "-property"]);
settings.addVersions(getPackagesAsVersion(dub));
 
// TODO: this belongs to the builder/generator
if( settings.libs.length ){
try {
logDebug("Trying to use pkg-config to resolve library flags for %s.", settings.libs);
auto libflags = execute("pkg-config", "--libs" ~ settings.libs.map!(l => "lib"~l)().array());
enforce(libflags.status == 0, "pkg-config exited with error code "~to!string(libflags.status));
settings.addLFlags(libflags.output.split());
settings.libs = null;
} catch( Exception e ){
logDebug("pkg-config failed: %s", e.msg);
logDebug("Falling back to direct -lxyz flags.");
settings.addLFlags(settings.libs.map!(l => "-l"~l)().array());
settings.libs = null;
}
}
 
flags ~= settings.dflags;
flags ~= settings.lflags.map!(f => "-L"~f)().array();
flags ~= settings.importPath.map!(f => "-I"~f)().array();
flags ~= settings.stringImportPath.map!(f => "-J"~f)().array();
flags ~= settings.versions.map!(f => "-version="~f)().array();
flags ~= (mainsrc).toNativeString();
 
string dflags = environment.get("DFLAGS");
if( dflags ){
case "profile": dflags = "-g -O -inline -profile"; break;
}
}
 
if( build_type.length ) logInfo("Building configuration "~build_type);
if( build_config.length ) logInfo("Building configuration "~build_config~", build type "~build_type);
else logInfo("Building default configuration, build type "~build_type);
 
logInfo("Running %s", "rdmd " ~ dflags ~ " " ~ join(flags, " "));
auto rdmd_pid = spawnProcess("rdmd " ~ dflags ~ " " ~ join(flags, " "));
auto result = rdmd_pid.wait();
enforce(result == 0, "Build command failed with exit code "~to!string(result));
return 0;
}
catch(Throwable e)
{
logError("Error executing command '%s': %s\n", cmd, e.msg);
logError("Error: %s\n", e.msg);
logDebug("Full exception: %s", sanitizeUTF8(cast(ubyte[])e.toString()));
logInfo("Run 'dub help' for usage information.");
return 1;
}
{
string[] ret;
string[string] pkgs = dub.installedPackages();
foreach(id, vers; pkgs)
ret ~= "-version=VPM_package_" ~ stripDlangSpecialChars(id);
ret ~= "VPM_package_" ~ stripDlangSpecialChars(id);
return ret;
}
 
private string getBinName(const Dub dub)
View
119
source/dub/dub.d
 
/// Returns the applications name.
@property string name() const { return m_main ? m_main.name : "app"; }
 
@property string[] configurations() const { return m_main ? m_main.configurations : null; }
@property string[] configurations()
const {
string[] ret;
if( m_main ) ret = m_main.configurations;
foreach( p; m_packages ){
auto cfgs = p.configurations;
foreach( c; cfgs )
if( !ret.canFind(c) ) ret ~= c;
}
return ret;
}
 
/// Returns the DFLAGS
string[] getDflags(BuildPlatform platform)
BuildSettings getBuildSettings(BuildPlatform platform, string config)
const {
auto ret = appender!(string[])();
string[] libs;
if( m_main ){
processVars(ret, ".", m_main.getDflags(platform));
libs ~= m_main.getLibs(platform);
}
ret.put("-Isource");
ret.put("-Jviews");
BuildSettings ret;
 
void addImportPath(string path, bool src)
{
if( !exists(path) ) return;
if( src ) ret.addImportDirs([path]);
else ret.addStringImportDirs([path]);
}
 
if( m_main ) processVars(ret, ".", m_main.getBuildSettings(platform, config));
addImportPath("source", true);
addImportPath("views", false);
 
foreach( string s, pkg; m_packages ){
auto pack_path = ".dub/modules/"~pkg.name;
void addPath(string prefix, string name){
auto path = pack_path~"/"~name;
if( exists(path) )
ret.put(prefix ~ path);
}
processVars(ret, pack_path, pkg.getDflags(platform));
libs ~= pkg.getLibs(platform);
addPath("-I", "source");
addPath("-J", "views");
}
 
if( libs.length ){
try {
logDebug("Trying to use pkg-config to resolve library flags for %s.", libs);
auto libflags = execute("pkg-config", "--libs" ~ libs.map!(l => "lib"~l)().array());
enforce(libflags.status == 0, "pkg-config exited with error code "~to!string(libflags.status));
ret.put(libflags.output.split().map!(f => "-L"~f)().array());
} catch( Exception e ){
logDebug("pkg-config failed: %s", e.msg);
logDebug("Falling back to direct -lxyz flags.");
ret.put(libs.map!(l => "-L-l"~l)().array());
}
}
 
return ret.data();
processVars(ret, pack_path, pkg.getBuildSettings(platform, config));
addImportPath(pack_path ~ "/source", true);
addImportPath(pack_path ~ "/views", false);
}
 
return ret;
}
 
/// Actions which can be performed to update the application.
Action[] actions(PackageSupplier packageSupplier, int option) {
@property string[] configurations() const { return m_app.configurations; }
 
/// Returns a list of flags which the application needs to be compiled
/// properly.
string[] getDflags(BuildPlatform platform) { return m_app.getDflags(platform); }
BuildSettings getBuildSettings(BuildPlatform platform, string config) { return m_app.getBuildSettings(platform, config); }
 
/// Lists all installed modules
void list() {
logInfo(m_app.info());
logInfo("Uninstalled package: '"~packageId~"'");
}
}
 
private void processVars(ref BuildSettings dst, string project_path, BuildSettings settings)
{
dst.addDFlags(processVars(project_path, settings.dflags));
dst.addLFlags(processVars(project_path, settings.lflags));
dst.addLibs(processVars(project_path, settings.libs));
dst.addVersions(processVars(project_path, settings.versions));
dst.addImportDirs(processVars(project_path, settings.importPath)); // TODO: prepend project_path to relative paths here
dst.addStringImportDirs(processVars(project_path, settings.stringImportPath)); // TODO: prepend project_path to relative paths here
}
 
private string[] processVars(string project_path, string[] vars)
{
auto ret = appender!(string[])();
processVars(ret, project_path, vars);
return ret.data;
 
}
private void processVars(ref Appender!(string[]) dst, string project_path, string[] vars)
{
foreach( var; vars ){
auto idx = std.string.indexOf(var, '$');
View
source/dub/package_.d