Skip to content

Commit cc80167

Browse files
Adding link cache when external dependencies change
1 parent 96faa6b commit cc80167

File tree

3 files changed

+49
-16
lines changed

3 files changed

+49
-16
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ or `Header`
8787
cleaning up
8888

8989
To access the source files of the dependencies, you can specify runcpp2 to build locally at
90-
where it is invoked from by passing the `--local` flag. This is useful when you want to
90+
where it script is by passing the `--local` flag. This is useful when you want to
9191
look at the headers of the dependencies.
9292

9393
```shell

Src/runcpp2/runcpp2.cpp

Lines changed: 46 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -370,18 +370,36 @@ namespace
370370
bool buildExecutable,
371371
const std::string& scriptName,
372372
const std::string& exeExt,
373-
ghc::filesystem::file_time_type& finalObjectWriteTime)
373+
const std::vector<std::string>& copiedBinariesPaths,
374+
const ghc::filesystem::file_time_type& finalObjectWriteTime)
374375
{
375376
for(int i = 0; i < sourceHasCache.size(); ++i)
376377
{
377378
if(!sourceHasCache.at(i))
378379
return false;
379380
}
380381

381-
//TODO: Check dependencies objects timestamps
382-
382+
ghc::filesystem::file_time_type currentFinalObjectWriteTime = finalObjectWriteTime;
383383
std::error_code e;
384384

385+
for(int i = 0; i < copiedBinariesPaths.size(); ++i)
386+
{
387+
if(ghc::filesystem::exists(copiedBinariesPaths.at(i), e))
388+
{
389+
ghc::filesystem::file_time_type lastObjectWriteTime =
390+
ghc::filesystem::last_write_time(copiedBinariesPaths.at(i), e);
391+
392+
if(lastObjectWriteTime > currentFinalObjectWriteTime)
393+
currentFinalObjectWriteTime = lastObjectWriteTime;
394+
}
395+
else
396+
{
397+
ssLOG_ERROR("Somehow copied binary path " << copiedBinariesPaths.at(i) <<
398+
" doesn't exist");
399+
return false;
400+
}
401+
}
402+
385403
//Check if output is cached
386404
if(buildExecutable)
387405
{
@@ -397,7 +415,7 @@ namespace
397415
ghc::filesystem::file_time_type lastExecutableWriteTime =
398416
ghc::filesystem::last_write_time(exeToCopy, e);
399417

400-
if(lastExecutableWriteTime > finalObjectWriteTime)
418+
if(lastExecutableWriteTime > currentFinalObjectWriteTime)
401419
{
402420
ssLOG_INFO("Using output cache");
403421
return true;
@@ -435,7 +453,7 @@ namespace
435453
ghc::filesystem::file_time_type lastSharedLibWriteTime =
436454
ghc::filesystem::last_write_time(sharedLibBuild, e);
437455

438-
if(lastSharedLibWriteTime > finalObjectWriteTime)
456+
if(lastSharedLibWriteTime > currentFinalObjectWriteTime)
439457
{
440458
ssLOG_INFO("Using output cache");
441459
return true;
@@ -778,17 +796,31 @@ runcpp2::StartPipeline( const std::string& scriptPath,
778796
return PipelineResult::UNEXPECTED_FAILURE;
779797
}
780798

799+
//Update finalObjectWriteTime
800+
for(int i = 0; i < copiedBinariesPaths.size(); ++i)
801+
{
802+
if(!ghc::filesystem::exists(copiedBinariesPaths.at(i), e))
803+
{
804+
ssLOG_ERROR(copiedBinariesPaths.at(i) << " reported as cached but doesn't exist");
805+
return PipelineResult::UNEXPECTED_FAILURE;
806+
}
807+
808+
ghc::filesystem::file_time_type lastWriteTime =
809+
ghc::filesystem::last_write_time(copiedBinariesPaths.at(i), e);
810+
811+
if(lastWriteTime > finalObjectWriteTime)
812+
finalObjectWriteTime = lastWriteTime;
813+
}
781814

782-
//TODO: Use this once we implement checking dependencies objects timestamps
783-
(void)HasOutputCache;
784-
//if(HasOutputCache( sourceHasCache,
785-
// buildDir,
786-
// profiles.at(profileIndex),
787-
// currentOptions.count(CmdOptions::EXECUTABLE) > 0,
788-
// scriptName,
789-
// exeExt,
790-
// finalObjectWriteTime))
791815
//Compiling/Linking
816+
if(!HasOutputCache( sourceHasCache,
817+
buildDir,
818+
profiles.at(profileIndex),
819+
currentOptions.count(CmdOptions::EXECUTABLE) > 0,
820+
scriptName,
821+
exeExt,
822+
copiedBinariesPaths,
823+
finalObjectWriteTime))
792824
{
793825
for(int i = 0; i < cachedObjectsFiles.size(); ++i)
794826
copiedBinariesPaths.push_back(cachedObjectsFiles.at(i));

TODO.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
TODO:
22
- Group object files in folders to avoid name collision
3-
3+
- Option for build only
4+
- Allow runcpp2 to be library
45
- Add ability to add defines for cross-compiler
56
- Ability to compile runcpp2 as single cpp
67

0 commit comments

Comments
 (0)