Skip to content

Commit b2fb685

Browse files
committed
Fixed: Archiver now putting object files correctly
1 parent ce2fff1 commit b2fb685

File tree

7 files changed

+61
-67
lines changed

7 files changed

+61
-67
lines changed

source/redub/building/compile.d

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,13 +126,13 @@ CompilationResult execCompilation(immutable ThreadBuildData data, shared Project
126126
if(!pack.isCopyEnough)
127127
ret = cast(ExecutionResult)execCompiler(cfg, compiler.binOrPath, getCompilationFlags(cfg, info, hash.rootHash, data.extra.isRoot), res.compilationCommand, compiler, inDir);
128128

129-
if(!isDCompiler(compiler) && !ret.status) //Always requires link.
129+
if(!isDCompiler(compiler) && !ret.status && isStaticLibrary(data.cfg.targetType)) //Must call archiver when
130130
{
131131
string cmd ;
132132
auto archiverRes = executeArchiver(data, info, cmd);
133133
ret.status = archiverRes.status;
134134
ret.output~= archiverRes.output;
135-
res.compilationCommand~= cmd;
135+
res.compilationCommand~= "\n\nArchiving: \n\t"~cmd;
136136
}
137137

138138
copyDir(inDir, dirName(outDir));

source/redub/building/utils.d

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,13 @@ auto linkBase(const ThreadBuildData data, CompilingSession session, string rootH
6060
);
6161
}
6262

63+
/**
64+
* Generates a static library using archiver. FIXME: BuildRequirements should know its files.
65+
* Params:
66+
* data = The data containing project information
67+
* s = Compiling Session
68+
* command = Command for being able to print it later
69+
*/
6370
auto executeArchiver(const ThreadBuildData data, CompilingSession s, out string command)
6471
{
6572
import std.process;
@@ -72,17 +79,25 @@ auto executeArchiver(const ThreadBuildData data, CompilingSession s, out string
7279
string[] cmd = [a.bin];
7380
final switch(a.type) with(AcceptedArchiver)
7481
{
75-
case ar, llvmAr: cmd~= "rcs"; break;
82+
case ar, llvmAr: cmd~= ["rcs"]; break;
7683
case libtool: cmd~= ["-static", "-o"]; break;
7784
case none: break;
7885
}
7986

80-
cmd~= getOutputName(data.cfg, s.os, s.isa);
81-
82-
string objExt = getObjectExtension(s.os);
83-
cmd = mapAppend(cmd, data.cfg.sourceFiles, (string src) => stripExtension(src)~ objExt);
87+
cmd~= buildNormalizedPath(data.cfg.outputDirectory, getOutputName(data.cfg, s.os, s.isa));
8488

89+
putObjectFiles(cmd, data.cfg, s.os, s.compiler.compiler.gcc ? cExt : cppExt);
8590
command = cmd.join(" ");
8691

8792
return executeShell(command);
93+
}
94+
95+
private void putObjectFiles(ref string[] target, const BuildConfiguration b, OS os, scope const string[] extensions...)
96+
{
97+
import redub.command_generators.commons;
98+
import std.file;
99+
import std.path;
100+
string[] objectFiles;
101+
putSourceFiles(objectFiles, b.workingDir, b.sourcePaths, b.sourceFiles, b.excludeSourceFiles, extensions);
102+
target = mapAppend(target, objectFiles, (string src) => setExtension(src, getObjectExtension(os)));
88103
}

source/redub/command_generators/automatic.d

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,13 @@ string escapeCompilationCommands(string compilerBin, string[] flags)
2323
*/
2424
string[] getCompilationFlags(const BuildConfiguration cfg, CompilingSession s, string mainPackHash, bool isRoot)
2525
{
26+
import redub.command_generators.commons;
2627
switch(s.compiler.compiler) with(AcceptedCompiler)
2728
{
2829
case gxx:
29-
return redub.command_generators.gnu_based.parseBuildConfiguration(cfg, s, mainPackHash, isRoot, ".c", ".cpp", ".cc", ".i", ".cxx", ".c++");
30+
return redub.command_generators.gnu_based.parseBuildConfiguration(cfg, s, mainPackHash, isRoot, cppExt);
3031
case gcc:
31-
return redub.command_generators.gnu_based.parseBuildConfiguration(cfg, s, mainPackHash, isRoot, ".c", ".i");
32+
return redub.command_generators.gnu_based.parseBuildConfiguration(cfg, s, mainPackHash, isRoot, cExt);
3233
case dmd:
3334
return redub.command_generators.dmd.parseBuildConfiguration(cfg, s, mainPackHash, isRoot);
3435
case ldc2:
@@ -48,9 +49,7 @@ string[] getLinkFlags(const ThreadBuildData data, CompilingSession s, string mai
4849

4950
string getLinkerBin(Compiler compiler)
5051
{
51-
if(compiler.isDCompiler)
52-
return compiler.binOrPath;
53-
return compiler.linker.bin;
52+
return compiler.binOrPath;
5453
}
5554

5655

@@ -61,9 +60,7 @@ string getLinkCommands(const ThreadBuildData data, CompilingSession s, string ma
6160
if(s.compiler.compiler == AcceptedCompiler.invalid)
6261
throw new Exception("Unsupported compiler '" ~ s.compiler.binOrPath~"'");
6362

64-
if(s.compiler.isDCompiler)
65-
return escapeShellCommand(s.compiler.binOrPath) ~ " "~ processFlags(flags);
66-
return escapeShellCommand(s.compiler.linker.bin) ~ " " ~ processFlags(flags);
63+
return escapeShellCommand(s.compiler.binOrPath) ~ " "~ processFlags(flags);
6764
}
6865

6966

source/redub/command_generators/commons.d

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@ public import redub.compiler_identification;
77
import redub.buildapi;
88
public import std.file:DirEntry;
99

10+
///Valid d extensions
11+
immutable string[] dExt = [".d"];
12+
///Valid c extensions
13+
immutable string[] cExt = [".c", ".i"];
14+
///Valid c++ extensions
15+
immutable string[] cppExt = [".c", ".cpp", ".cc", ".i", ".cxx", ".c++"];
16+
1017

1118
OS osFromArch(string arch)
1219
{

source/redub/command_generators/gnu_based.d

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ public import redub.buildapi;
44
public import std.system;
55
import redub.command_generators.commons;
66
import redub.logging;
7+
import redub.building.cache;
78

89
/// Parse G++ configuration
910
string[] parseBuildConfiguration(const BuildConfiguration b, CompilingSession s, string requirementCache, bool isRoot, const string[] extensions...)
@@ -16,6 +17,7 @@ string[] parseBuildConfiguration(const BuildConfiguration b, CompilingSession s,
1617
with(b)
1718
{
1819
if(isDebug) commands~= "-g";
20+
if(targetType.isLinkedSeparately) commands~= "-c";
1921

2022
commands = mapAppendPrefix(commands, versions, "-D", false);
2123
commands~= dFlags;
@@ -29,10 +31,9 @@ string[] parseBuildConfiguration(const BuildConfiguration b, CompilingSession s,
2931
if(targetType.isLinkedSeparately)
3032
{
3133
commands~= "-o";
32-
commands ~= buildNormalizedPath(outputDirectory, getOutputName(targetType, name, os));
34+
string cacheDir = getCacheOutputDir(requirementCache, b, s, isRoot);
35+
commands ~= buildNormalizedPath(cacheDir, getConfigurationOutputName(b, s.os)).escapePath;
3336
}
34-
35-
3637
}
3738

3839
return commands;

source/redub/command_generators/linkers.d

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,30 +10,38 @@ string[] parseLinkConfiguration(const ThreadBuildData data, CompilingSession s,
1010
import redub.misc.path;
1111
import redub.building.cache;
1212
string[] commands;
13-
AcceptedLinker linker = s.compiler.linker.type;
13+
AcceptedLinker linker = s.compiler.linker;
1414
bool emitStartGroup = s.isa != ISA.webAssembly && linker != AcceptedLinker.ld64;
1515

1616

1717
const BuildConfiguration b = data.cfg;
1818
with(b)
1919
{
20-
if(s.compiler.isDCompiler)
2120
{
2221
import redub.command_generators.d_compilers;
2322

2423
if (targetType.isLinkedSeparately)
2524
{
2625
string cacheDir = getCacheOutputDir(requirementCache, b, s, data.extra.isRoot);
2726
string objExtension = getObjectExtension(s.os);
28-
commands~= "-of"~buildNormalizedPath(cacheDir, getOutputName(b, s.os)).escapePath;
27+
if(s.compiler.isDCompiler)
28+
commands~= "-of"~buildNormalizedPath(cacheDir, getOutputName(b, s.os)).escapePath;
29+
else
30+
{
31+
commands~= "-o";
32+
commands~= buildNormalizedPath(cacheDir, getOutputName(b, s.os)).escapePath;
33+
}
2934
if(b.outputsDeps)
3035
putSourceFiles(commands, null, [getObjectDir(cacheDir)], null, null, objExtension);
3136
else
3237
commands~= buildNormalizedPath(outputDirectory, targetName~objExtension).escapePath;
3338
}
34-
string arch = mapArch(s.compiler.compiler, b.arch);
35-
if(arch)
36-
commands~= arch;
39+
if(s.compiler.isDCompiler)
40+
{
41+
string arch = mapArch(s.compiler.compiler, b.arch);
42+
if(arch)
43+
commands~= arch;
44+
}
3745
commands~= filterLinkFlags(b.dFlags);
3846
}
3947
if(targetType == TargetType.dynamicLibrary)
@@ -57,13 +65,6 @@ string[] parseLinkConfiguration(const ThreadBuildData data, CompilingSession s,
5765
commands = mapAppend(commands, libraries, (string l) => "-L-l"~stripLibraryExtension(l));
5866

5967
}
60-
else if(!s.compiler.isDCompiler) //Generates a static library using archiver. FIXME: BuildRequirements should know its files.
61-
{
62-
commands~= "--format=default";
63-
commands~= "rcs";
64-
commands~= buildNormalizedPath(outputDirectory, getOutputName(b, s.os));
65-
putObjectFiles(commands, b, s.os, ".c", ".cpp", ".cc", ".i", ".cxx", ".c++");
66-
}
6768
}
6869

6970
return commands;
@@ -133,11 +134,3 @@ string getTargetTypeFlag(TargetType o, Compiler compiler)
133134
}
134135

135136

136-
private void putObjectFiles(ref string[] target, const BuildConfiguration b, OS os, scope const string[] extensions...)
137-
{
138-
import std.file;
139-
import std.path;
140-
string[] objectFiles;
141-
putSourceFiles(objectFiles, b.workingDir, b.sourcePaths, b.sourceFiles, b.excludeSourceFiles, extensions);
142-
target = mapAppend(target, objectFiles, (string src) => setExtension(src, getObjectExtension(os)));
143-
}

source/redub/compiler_identification.d

Lines changed: 9 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,6 @@ struct Archiver
4444
AcceptedArchiver type;
4545
string bin;
4646
}
47-
struct Linker
48-
{
49-
AcceptedLinker type;
50-
string bin;
51-
}
5247

5348
AcceptedCompiler acceptedCompilerfromString(string str)
5449
{
@@ -91,14 +86,6 @@ AcceptedArchiver acceptedArchiverFromString(string str)
9186
}
9287
}
9388

94-
private Linker acceptedLinker(JSONValue v)
95-
{
96-
JSONValue* acc = "defaultLinker" in v;
97-
if(!acc)
98-
return Linker(AcceptedLinker.unknown);
99-
return Linker(acceptedLinkerfromString(acc.object["type"].str), acc.object["bin"].str);
100-
}
101-
10289
private Archiver acceptedArchiver(JSONValue v)
10390
{
10491
JSONValue* acc = "defaultArchiver" in v;
@@ -141,7 +128,7 @@ struct Compiler
141128

142129
///Currently unused. Was used before for checking whether --start-group should be emitted or not. Since it is emitted
143130
///by default, only on webAssembly which is not, it lost its usage for now.
144-
Linker linker = Linker(AcceptedLinker.unknown);
131+
AcceptedLinker linker = AcceptedLinker.unknown;
145132

146133

147134
string getCompilerString() const
@@ -298,7 +285,7 @@ Compiler getCompiler(string compilerOrPath = "dmd", string compilerAssumption =
298285
if(ret == Compiler.init)
299286
ret = inferCompiler(compilerOrPath, compilerAssumption, compilersInfo, isDefault, isGlobal);
300287

301-
ret.linker = acceptedLinker(compilersInfo);
288+
ret.linker = acceptedLinkerfromString(compilersInfo["defaultLinker"].str);
302289
ret.archiver = acceptedArchiver(compilersInfo);
303290

304291
//Checks for ldc.conf switches to see if it is using gnu linker by default
@@ -436,7 +423,7 @@ private Compiler getCompilerFromCache(JSONValue allCompilersInfo, string compile
436423
SemVer(arr[VERSION_].str),
437424
SemVer(arr[FRONTEND_VERSION].str),
438425
arr[VERSION_STRING].str,
439-
key, acceptedArchiver(allCompilersInfo), false, acceptedLinker(allCompilersInfo)
426+
key, acceptedArchiver(allCompilersInfo), false, acceptedLinkerfromString(allCompilersInfo["defaultLinker"].str)
440427
);
441428
}
442429
}
@@ -487,14 +474,8 @@ private void saveCompilerInfo(JSONValue allCompilersInfo, ref Compiler compiler,
487474
}
488475

489476
if(!("defaultLinker" in allCompilersInfo))
490-
{
491-
JSONValue defaultLinker = JSONValue.emptyObject;
492-
auto def = getDefaultLinker();
493-
defaultLinker["type"] = def.type.to!string;
494-
defaultLinker["bin"] = def.bin;
495-
allCompilersInfo["defaultLinker"] = defaultLinker;
496-
}
497-
compiler.linker = acceptedLinker(allCompilersInfo);
477+
allCompilersInfo["defaultLinker"] = getDefaultLinker.to!string;
478+
compiler.linker = acceptedLinkerfromString(allCompilersInfo["defaultLinker"].str);
498479

499480
if(!("compilers" in allCompilersInfo))
500481
allCompilersInfo["compilers"] = JSONValue.emptyObject;
@@ -548,7 +529,7 @@ private Compiler assumeCompiler(string compilerOrPath, string compilerAssumption
548529
}
549530

550531

551-
Linker getDefaultLinker()
532+
AcceptedLinker getDefaultLinker()
552533
{
553534
with(AcceptedLinker)
554535
{
@@ -560,12 +541,12 @@ Linker getDefaultLinker()
560541
if(res.status == 0)
561542
{
562543
if(res.output.startsWith("GNU ld"))
563-
return Linker(gnuld, "ld");
544+
return gnuld;
564545
else if(res.output.startsWith("@(#)PROGRAM:ld"))
565-
return Linker(ld64, "ld");
546+
return ld64;
566547
}
567548
}
568-
return Linker(unknown);
549+
return unknown;
569550
}
570551
}
571552

0 commit comments

Comments
 (0)