1
1
#include " ModuleManager.hpp"
2
2
3
+ #include " Building.hpp"
3
4
#include " Converters.hpp"
4
5
#include " DynamicLoader.hpp"
5
6
#include " Evaluator.hpp"
@@ -292,7 +293,10 @@ static void OnCompileProcessOutput(const char* output)
292
293
struct BuiltObject
293
294
{
294
295
int buildStatus;
296
+ std::string sourceFilename;
295
297
std::string filename;
298
+
299
+ ProcessCommand* buildCommandOverride;
296
300
};
297
301
298
302
void builtObjectsFree (std::vector<BuiltObject*>& objects)
@@ -315,6 +319,12 @@ bool moduleManagerBuild(ModuleManager& manager)
315
319
{
316
320
Module* module = manager.modules [moduleIndex];
317
321
322
+ ProcessCommand* buildCommandOverride =
323
+ (!module->buildTimeBuildCommand .fileToExecute .empty () &&
324
+ !module->buildTimeBuildCommand .arguments .empty ()) ?
325
+ &module->buildTimeBuildCommand :
326
+ nullptr ;
327
+
318
328
if (log .buildProcess )
319
329
printf (" Build module %s\n " , module->sourceOutputName .c_str ());
320
330
for (ModuleDependency& dependency : module->dependencies )
@@ -326,48 +336,70 @@ bool moduleManagerBuild(ModuleManager& manager)
326
336
// ourselves with them
327
337
if (dependency.type == ModuleDependency_Cakelisp)
328
338
continue ;
339
+
340
+ if (dependency.type == ModuleDependency_CFile)
341
+ {
342
+ BuiltObject* newBuiltObject = new BuiltObject;
343
+ newBuiltObject->buildStatus = 0 ;
344
+ // TODO: Better to use search directories
345
+ char sourceName[MAX_PATH_LENGTH] = {0 };
346
+ makePathRelativeToFile (module->sourceOutputName .c_str (), dependency.name .c_str (),
347
+ sourceName, sizeof (sourceName));
348
+ newBuiltObject->sourceFilename = sourceName;
349
+
350
+ char buildObjectName[MAX_PATH_LENGTH] = {0 };
351
+ if (!objectFilenameFromSourceFilename (cakelispWorkingDir,
352
+ newBuiltObject->sourceFilename .c_str (),
353
+ buildObjectName, sizeof (buildObjectName)))
354
+ {
355
+ builtObjectsFree (builtObjects);
356
+ return false ;
357
+ }
358
+
359
+ newBuiltObject->filename = buildObjectName;
360
+ newBuiltObject->buildCommandOverride = buildCommandOverride;
361
+ builtObjects.push_back (newBuiltObject);
362
+ }
329
363
}
330
364
331
365
// TODO: Importing needs to set this on the module, not the dependency...
332
366
if (module->skipBuild )
333
367
continue ;
334
368
335
- // TODO: Lots of overlap between this and compile-time building
336
- char buildFilename[MAX_NAME_LENGTH] = {0 };
337
- getFilenameFromPath (module->sourceOutputName .c_str (), buildFilename, sizeof (buildFilename));
338
- if (!buildFilename[0 ])
369
+ char buildObjectName[MAX_PATH_LENGTH] = {0 };
370
+ if (!objectFilenameFromSourceFilename (cakelispWorkingDir, module->sourceOutputName .c_str (),
371
+ buildObjectName, sizeof (buildObjectName)))
339
372
{
340
373
builtObjectsFree (builtObjects);
341
374
return false ;
342
375
}
343
376
344
- // TODO: Trim .cake.cpp
345
- char buildObjectName[MAX_PATH_LENGTH] = {0 };
346
- PrintfBuffer (buildObjectName, " %s/%s.o" , cakelispWorkingDir, buildFilename);
347
-
348
377
// At this point, we do want to build the object. We might skip building it if it is cached.
349
378
// In that case, the status code should still be 0, as if we built and succeeded building it
350
379
BuiltObject* newBuiltObject = new BuiltObject;
351
380
newBuiltObject->buildStatus = 0 ;
381
+ newBuiltObject->sourceFilename = module->sourceOutputName .c_str ();
352
382
newBuiltObject->filename = buildObjectName;
383
+ newBuiltObject->buildCommandOverride = buildCommandOverride;
353
384
builtObjects.push_back (newBuiltObject);
385
+ }
354
386
355
- if (!fileIsMoreRecentlyModified (module->sourceOutputName .c_str (), buildObjectName))
387
+ for (BuiltObject* object : builtObjects)
388
+ {
389
+ if (!fileIsMoreRecentlyModified (object->sourceFilename .c_str (), object->filename .c_str ()))
356
390
{
357
391
if (log .buildProcess )
358
- printf (" Skipping compiling %s (using cached object)\n " ,
359
- module->sourceOutputName .c_str ());
392
+ printf (" Skipping compiling %s (using cached object)\n " , object->sourceFilename .c_str ());
360
393
}
361
394
else
362
395
{
363
- ProcessCommand& buildCommand = (!module->buildTimeBuildCommand .fileToExecute .empty () &&
364
- !module->buildTimeBuildCommand .arguments .empty ()) ?
365
- module->buildTimeBuildCommand :
396
+ ProcessCommand& buildCommand = object->buildCommandOverride ?
397
+ *object->buildCommandOverride :
366
398
manager.environment .buildTimeBuildCommand ;
367
399
368
400
ProcessCommandInput buildTimeInputs[] = {
369
- {ProcessCommandArgumentType_SourceInput, {module-> sourceOutputName .c_str ()}},
370
- {ProcessCommandArgumentType_ObjectOutput, {buildObjectName }}};
401
+ {ProcessCommandArgumentType_SourceInput, {object-> sourceFilename .c_str ()}},
402
+ {ProcessCommandArgumentType_ObjectOutput, {object-> filename . c_str () }}};
371
403
const char ** buildArguments = MakeProcessArgumentsFromCommand (
372
404
buildCommand, buildTimeInputs, ArraySize (buildTimeInputs));
373
405
if (!buildArguments)
@@ -381,7 +413,7 @@ bool moduleManagerBuild(ModuleManager& manager)
381
413
compileArguments.arguments = buildArguments;
382
414
// PrintProcessArguments(buildArguments);
383
415
384
- if (runProcess (compileArguments, &newBuiltObject ->buildStatus ) != 0 )
416
+ if (runProcess (compileArguments, &object ->buildStatus ) != 0 )
385
417
{
386
418
printf (" error: failed to invoke compiler\n " );
387
419
free (buildArguments);
@@ -408,7 +440,6 @@ bool moduleManagerBuild(ModuleManager& manager)
408
440
// TODO: Make configurable
409
441
const char * outputExecutableName = " a.out" ;
410
442
411
- int objectNameBufferSize = 0 ;
412
443
int numObjectsToLink = 0 ;
413
444
bool succeededBuild = true ;
414
445
bool needsLink = false ;
@@ -424,7 +455,7 @@ bool moduleManagerBuild(ModuleManager& manager)
424
455
}
425
456
426
457
if (log .buildProcess )
427
- printf (" Linking %s\n " , object->filename .c_str ());
458
+ printf (" Need to link %s\n " , object->filename .c_str ());
428
459
429
460
++numObjectsToLink;
430
461
0 commit comments