Skip to content
Open
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
29 changes: 29 additions & 0 deletions source/dub/generators/build.d
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,32 @@ class BuildGenerator : ProjectGenerator {
return cached;
}

// Deletes any old library build artifacts (.a, .lib, .so) from the specified build path.
// This is done to ensure a clean build and prevent issues from stale or partial files.
private void cleanupLibraryFiles(NativePath buildPath)
{
import std.path : extension;
import std.file : dirEntries, remove, SpanMode;

if(std.file.exists(buildPath.toNativeString()))
{
logDiagnostic("Deleting old build artifacts from %s..." , buildPath.toNativeString());

foreach (entry; std.file.dirEntries(buildPath.toNativeString() , SpanMode.shallow))
{
if(entry.isFile){
auto fileExtension = extension(entry.name);
if(fileExtension == ".a" || fileExtension == ".lib" || fileExtension == ".so")
{
auto fullPath = buildPath.toNativeString() ~ entry.name;
std.file.remove(fullPath);
}
}
}
}

}

private bool performCachedBuild(GeneratorSettings settings, BuildSettings buildsettings, in Package pack, string config,
string build_id, in Package[] packages, in NativePath[] additional_dep_files, out NativePath target_binary_path)
{
Expand Down Expand Up @@ -280,6 +306,9 @@ class BuildGenerator : ProjectGenerator {
return false;
}

// Clean up any existing library files from the previous build to ensure a fresh start.
cleanupLibraryFiles(target_path);

logInfo("Building", Color.light_green, "%s %s: building configuration [%s]", pack.name.color(Mode.bold), pack.version_, config.color(Color.blue));

if( buildsettings.preBuildCommands.length ){
Expand Down