Skip to content

Commit 5d10851

Browse files
Fixing cache not working properly when importing dependencies
1 parent 559ff38 commit 5d10851

File tree

3 files changed

+50
-25
lines changed

3 files changed

+50
-25
lines changed

Include/runcpp2/PipelineSteps.hpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ namespace runcpp2
3737
ParseAndValidateScriptInfo( const ghc::filesystem::path& absoluteScriptPath,
3838
const ghc::filesystem::path& scriptDirectory,
3939
const std::string& scriptName,
40-
const Data::ScriptInfo* lastScriptInfo,
4140
Data::ScriptInfo& outScriptInfo);
4241

4342
PipelineResult HandleCleanup( const Data::ScriptInfo& scriptInfo,
@@ -62,7 +61,7 @@ namespace runcpp2
6261
PipelineResult CheckScriptInfoChanges( const ghc::filesystem::path& buildDir,
6362
const Data::ScriptInfo& scriptInfo,
6463
const Data::Profile& profile,
65-
const ghc::filesystem::path& scriptDirectory,
64+
const ghc::filesystem::path& absoluteScriptPath,
6665
const Data::ScriptInfo* lastScriptInfo,
6766
bool& outRecompileNeeded,
6867
bool& outRelinkNeeded,

Src/runcpp2/PipelineSteps.cpp

Lines changed: 46 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,6 @@ runcpp2::PipelineResult
304304
runcpp2::ParseAndValidateScriptInfo(const ghc::filesystem::path& absoluteScriptPath,
305305
const ghc::filesystem::path& scriptDirectory,
306306
const std::string& scriptName,
307-
const Data::ScriptInfo* lastScriptInfo,
308307
Data::ScriptInfo& outScriptInfo)
309308
{
310309
ssLOG_FUNC_INFO();
@@ -357,8 +356,8 @@ runcpp2::ParseAndValidateScriptInfo(const ghc::filesystem::path& absoluteScriptP
357356

358357
if(!parsableInfo.empty())
359358
{
360-
ssLOG_INFO("Parsed script info YAML:");
361-
ssLOG_INFO("\n" << outScriptInfo.ToString(""));
359+
ssLOG_DEBUG("Parsed script info YAML:");
360+
ssLOG_DEBUG("\n" << outScriptInfo.ToString(""));
362361
}
363362

364363
return PipelineResult::SUCCESS;
@@ -507,7 +506,7 @@ runcpp2::PipelineResult
507506
runcpp2::CheckScriptInfoChanges(const ghc::filesystem::path& buildDir,
508507
const Data::ScriptInfo& scriptInfo,
509508
const Data::Profile& profile,
510-
const ghc::filesystem::path& scriptDirectory,
509+
const ghc::filesystem::path& absoluteScriptPath,
511510
const Data::ScriptInfo* lastScriptInfo,
512511
bool& outRecompileNeeded,
513512
bool& outRelinkNeeded,
@@ -516,6 +515,7 @@ runcpp2::CheckScriptInfoChanges(const ghc::filesystem::path& buildDir,
516515
ssLOG_FUNC_INFO();
517516
INTERNAL_RUNCPP2_SAFE_START();
518517

518+
const ghc::filesystem::path scriptDirectory = absoluteScriptPath.parent_path();
519519
ghc::filesystem::path lastScriptInfoFilePath = buildDir / "LastScriptInfo.yaml";
520520
Data::ScriptInfo lastScriptInfoFromDisk;
521521

@@ -540,18 +540,45 @@ runcpp2::CheckScriptInfoChanges(const ghc::filesystem::path& buildDir,
540540

541541
//Compare script info in memory or from disk
542542
const Data::ScriptInfo* lastInfo = lastScriptInfo;
543-
if(lastScriptInfo == nullptr && ghc::filesystem::exists(lastScriptInfoFilePath, e))
543+
if(lastInfo == nullptr && ghc::filesystem::exists(lastScriptInfoFilePath, e))
544544
{
545545
ssLOG_DEBUG("Last script info file exists: " << lastScriptInfoFilePath);
546546
std::ifstream lastScriptInfoFile;
547547
lastScriptInfoFile.open(lastScriptInfoFilePath);
548548
std::stringstream lastScriptInfoBuffer;
549549
lastScriptInfoBuffer << lastScriptInfoFile.rdbuf();
550550

551-
if(ParseScriptInfo(lastScriptInfoBuffer.str(), lastScriptInfoFromDisk))
551+
int currentThreadTargetLevel = ssLOG_GET_CURRENT_THREAD_TARGET_LEVEL();
552+
ssLOG_SET_CURRENT_THREAD_TARGET_LEVEL(ssLOG_LEVEL_NONE);
553+
554+
do
555+
{
556+
{
557+
bool result = ParseScriptInfo(lastScriptInfoBuffer.str(), lastScriptInfoFromDisk);
558+
if(!result)
559+
break;
560+
}
561+
562+
//Resolve imports for last script info
563+
runcpp2::PipelineResult result = ResolveScriptImports( lastScriptInfoFromDisk,
564+
absoluteScriptPath,
565+
buildDir);
566+
if(result != PipelineResult::SUCCESS)
567+
break;
568+
552569
lastInfo = &lastScriptInfoFromDisk;
570+
}
571+
while(false);
572+
573+
ssLOG_SET_CURRENT_THREAD_TARGET_LEVEL(currentThreadTargetLevel);
574+
575+
if(lastInfo != nullptr)
576+
ssLOG_INFO("Last script info parsed");
577+
else
578+
ssLOG_INFO("Failed to parse last script info");
553579
}
554580

581+
//Check if the cached script info has changed
555582
if(lastInfo != nullptr)
556583
{
557584
//Check link flags
@@ -626,6 +653,9 @@ runcpp2::CheckScriptInfoChanges(const ghc::filesystem::path& buildDir,
626653
!lastDefines->Equals(*currentDefines)
627654
);
628655
}
656+
657+
if(outRecompileNeeded || outRelinkNeeded)
658+
ssLOG_INFO("Last script info is out of date, recompiling or relinking...");
629659
}
630660
else
631661
outRecompileNeeded = true;
@@ -647,34 +677,31 @@ runcpp2::CheckScriptInfoChanges(const ghc::filesystem::path& buildDir,
647677
ssLOG_DEBUG("Wrote current script info to " << lastScriptInfoFilePath.string());
648678
}
649679

680+
if(!lastInfo)
681+
return PipelineResult::SUCCESS;
682+
650683
//Check if include paths have changed
651684
std::vector<ghc::filesystem::path> currentIncludePaths;
652-
if(!GatherIncludePaths( scriptDirectory,
653-
scriptInfo,
654-
profile,
655-
{}, //Empty dependencies since we're just comparing paths
656-
currentIncludePaths))
685+
if(!GatherIncludePaths(scriptDirectory, scriptInfo, profile, {}, currentIncludePaths))
657686
{
658687
ssLOG_ERROR("Failed to gather current include paths");
659688
return PipelineResult::UNEXPECTED_FAILURE;
660689
}
661690

662691
std::vector<ghc::filesystem::path> lastIncludePaths;
663-
if(lastScriptInfo && !GatherIncludePaths( scriptDirectory,
664-
*lastScriptInfo,
665-
profile,
666-
{}, // Empty dependencies
667-
lastIncludePaths))
692+
if(!GatherIncludePaths(scriptDirectory, *lastInfo, profile, {}, lastIncludePaths))
668693
{
669-
ssLOG_ERROR("Failed to gather last include paths");
670-
return PipelineResult::UNEXPECTED_FAILURE;
694+
ssLOG_WARNING("Failed to gather last include paths");
695+
return PipelineResult::SUCCESS;
671696
}
672697

673698
if(currentIncludePaths != lastIncludePaths)
674699
{
675700
ssLOG_INFO("Include paths have changed");
676701
outRecompileNeeded = true;
677702
}
703+
else if(!outRecompileNeeded && !outRelinkNeeded)
704+
ssLOG_INFO("Using script info cache");
678705

679706
return PipelineResult::SUCCESS;
680707

@@ -1236,7 +1263,7 @@ bool runcpp2::GatherFilesIncludes( const std::vector<ghc::filesystem::path>& fi
12361263

12371264
if(found)
12381265
{
1239-
ssLOG_INFO("Found include file: " << resolvedInclude.string());
1266+
ssLOG_DEBUG("Found include file: " << resolvedInclude.string());
12401267
currentIncludes.push_back(resolvedInclude);
12411268
filesToProcess.push(resolvedInclude);
12421269
}

Src/runcpp2/runcpp2.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ namespace
204204
ghc::filesystem::file_time_type lastExecutableWriteTime =
205205
ghc::filesystem::last_write_time(exeToCopy, e);
206206

207-
if(lastExecutableWriteTime > currentFinalObjectWriteTime)
207+
if(lastExecutableWriteTime >= currentFinalObjectWriteTime)
208208
{
209209
ssLOG_INFO("Using output cache");
210210
outOutputCache = true;
@@ -257,7 +257,7 @@ namespace
257257
ghc::filesystem::file_time_type lastSharedLibWriteTime =
258258
ghc::filesystem::last_write_time(sharedLibBuild, e);
259259

260-
if(lastSharedLibWriteTime > currentFinalObjectWriteTime)
260+
if(lastSharedLibWriteTime >= currentFinalObjectWriteTime)
261261
{
262262
ssLOG_INFO("Using output cache");
263263
outOutputCache = true;
@@ -425,7 +425,6 @@ runcpp2::StartPipeline( const std::string& scriptPath,
425425
result = ParseAndValidateScriptInfo(absoluteScriptPath,
426426
scriptDirectory,
427427
scriptName,
428-
lastScriptInfo,
429428
scriptInfo);
430429

431430
if(result != PipelineResult::SUCCESS)
@@ -499,7 +498,7 @@ runcpp2::StartPipeline( const std::string& scriptPath,
499498
result = CheckScriptInfoChanges(buildDir,
500499
scriptInfo,
501500
profiles.at(profileIndex),
502-
scriptDirectory,
501+
absoluteScriptPath,
503502
lastScriptInfo,
504503
recompileNeeded,
505504
relinkNeeded,

0 commit comments

Comments
 (0)