Skip to content
Merged
Show file tree
Hide file tree
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
11 changes: 11 additions & 0 deletions Src/runcpp2/IncludeManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,16 @@ namespace runcpp2
INTERNAL_RUNCPP2_SAFE_START();
ssLOG_FUNC_DEBUG();

ssLOG_DEBUG("Checking includes for " << sourceFile.string());

std::error_code e;
ghc::filesystem::file_time_type sourceTime = ghc::filesystem::last_write_time(sourceFile, e);

if(sourceTime > recordTime)
{
ssLOG_DEBUG("Source file newer than include record");
return true;
}

for(const ghc::filesystem::path& include : includes)
{
Expand All @@ -123,11 +128,17 @@ namespace runcpp2
ghc::filesystem::file_time_type includeTime =
ghc::filesystem::last_write_time(include, e);
if(includeTime > recordTime)
{
ssLOG_DEBUG("Include time for " << include.string() <<
" is newer than record time");
return true;
}
}
}

ssLOG_DEBUG("No update needed for " << sourceFile.string());
return false;

INTERNAL_RUNCPP2_SAFE_CATCH_RETURN(true);
}

Expand Down
72 changes: 69 additions & 3 deletions Src/runcpp2/PipelineSteps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,8 @@ bool runcpp2::CopyFiles(const ghc::filesystem::path& destDir,
const std::vector<std::string>& filePaths,
std::vector<std::string>& outCopiedPaths)
{
ssLOG_FUNC_DEBUG();
ssLOG_FUNC_INFO();
INTERNAL_RUNCPP2_SAFE_START();

std::error_code e;
for (const std::string& srcPath : filePaths)
Expand Down Expand Up @@ -213,6 +214,8 @@ bool runcpp2::CopyFiles(const ghc::filesystem::path& destDir,
}

return true;

INTERNAL_RUNCPP2_SAFE_CATCH_RETURN(false);
}

runcpp2::PipelineResult
Expand All @@ -221,6 +224,9 @@ runcpp2::RunProfileCommands(const Data::ProfilesCommands* commands,
const std::string& workingDir,
const std::string& commandType)
{
ssLOG_FUNC_INFO();
INTERNAL_RUNCPP2_SAFE_START();

if(commands != nullptr)
{
const std::vector<std::string>* commandSteps =
Expand All @@ -246,6 +252,8 @@ runcpp2::RunProfileCommands(const Data::ProfilesCommands* commands,
}
}
return PipelineResult::SUCCESS;

INTERNAL_RUNCPP2_SAFE_CATCH_RETURN(PipelineResult::UNEXPECTED_FAILURE);
}

runcpp2::PipelineResult runcpp2::ValidateInputs(const std::string& scriptPath,
Expand All @@ -254,6 +262,7 @@ runcpp2::PipelineResult runcpp2::ValidateInputs(const std::string& scriptPath,
ghc::filesystem::path& outScriptDirectory,
std::string& outScriptName)
{
ssLOG_FUNC_INFO();
INTERNAL_RUNCPP2_SAFE_START();

if(profiles.empty())
Expand Down Expand Up @@ -298,6 +307,7 @@ runcpp2::ParseAndValidateScriptInfo(const ghc::filesystem::path& absoluteScriptP
const Data::ScriptInfo* lastScriptInfo,
Data::ScriptInfo& outScriptInfo)
{
ssLOG_FUNC_INFO();
INTERNAL_RUNCPP2_SAFE_START();

//Check if there's script info as yaml file instead
Expand Down Expand Up @@ -360,6 +370,9 @@ runcpp2::PipelineResult runcpp2::HandleCleanup( const Data::ScriptInfo& scriptIn
const ghc::filesystem::path& absoluteScriptPath,
BuildsManager& buildsManager)
{
ssLOG_FUNC_INFO();
INTERNAL_RUNCPP2_SAFE_START();

const Data::ProfilesCommands* cleanupCommands =
runcpp2::GetValueFromPlatformMap(scriptInfo.Cleanup);

Expand Down Expand Up @@ -407,6 +420,8 @@ runcpp2::PipelineResult runcpp2::HandleCleanup( const Data::ScriptInfo& scriptIn
return PipelineResult::UNEXPECTED_FAILURE;
}
return PipelineResult::SUCCESS;

INTERNAL_RUNCPP2_SAFE_CATCH_RETURN(PipelineResult::UNEXPECTED_FAILURE);
}

runcpp2::PipelineResult
Expand All @@ -417,6 +432,9 @@ runcpp2::InitializeBuildDirectory( const ghc::filesystem::path& configDir,
ghc::filesystem::path& outBuildDir,
IncludeManager& outIncludeManager)
{
ssLOG_FUNC_INFO();
INTERNAL_RUNCPP2_SAFE_START();

//Create build directory
ghc::filesystem::path buildDirPath = useLocalBuildDir ?
ghc::filesystem::current_path() / ".runcpp2" :
Expand Down Expand Up @@ -458,6 +476,8 @@ runcpp2::InitializeBuildDirectory( const ghc::filesystem::path& configDir,
}

return PipelineResult::SUCCESS;

INTERNAL_RUNCPP2_SAFE_CATCH_RETURN(PipelineResult::UNEXPECTED_FAILURE);
}

runcpp2::PipelineResult
Expand All @@ -470,6 +490,9 @@ runcpp2::CheckScriptInfoChanges(const ghc::filesystem::path& buildDir,
bool& outRelinkNeeded,
std::vector<std::string>& outChangedDependencies)
{
ssLOG_FUNC_INFO();
INTERNAL_RUNCPP2_SAFE_START();

ghc::filesystem::path lastScriptInfoFilePath = buildDir / "LastScriptInfo.yaml";
Data::ScriptInfo lastScriptInfoFromDisk;

Expand Down Expand Up @@ -631,6 +654,8 @@ runcpp2::CheckScriptInfoChanges(const ghc::filesystem::path& buildDir,
}

return PipelineResult::SUCCESS;

INTERNAL_RUNCPP2_SAFE_CATCH_RETURN(PipelineResult::UNEXPECTED_FAILURE);
}

runcpp2::PipelineResult
Expand All @@ -643,6 +668,9 @@ runcpp2::ProcessDependencies( Data::ScriptInfo& scriptInfo,
std::vector<Data::DependencyInfo*>& outAvailableDependencies,
std::vector<std::string>& outGatheredBinariesPaths)
{
ssLOG_FUNC_INFO();
INTERNAL_RUNCPP2_SAFE_START();

for(int i = 0; i < scriptInfo.Dependencies.size(); ++i)
{
if(IsDependencyAvailableForThisPlatform(scriptInfo.Dependencies.at(i)))
Expand Down Expand Up @@ -730,13 +758,18 @@ runcpp2::ProcessDependencies( Data::ScriptInfo& scriptInfo,
}

return PipelineResult::SUCCESS;

INTERNAL_RUNCPP2_SAFE_CATCH_RETURN(PipelineResult::UNEXPECTED_FAILURE);
}

void runcpp2::SeparateDependencyFiles( const Data::FilesTypesInfo& filesTypes,
const std::vector<std::string>& gatheredBinariesPaths,
std::vector<std::string>& outLinkFilesPaths,
std::vector<std::string>& outFilesToCopyPaths)
{
ssLOG_FUNC_INFO();
INTERNAL_RUNCPP2_SAFE_START();

std::unordered_set<std::string> linkExtensions;

//Populate the set of link extensions
Expand Down Expand Up @@ -777,12 +810,16 @@ void runcpp2::SeparateDependencyFiles( const Data::FilesTypesInfo& filesTypes,
ssLOG_INFO("Files to copy:");
for(int i = 0; i < outFilesToCopyPaths.size(); ++i)
ssLOG_INFO(" " << outFilesToCopyPaths[i]);

INTERNAL_RUNCPP2_SAFE_CATCH_RETURN(void());
}

runcpp2::PipelineResult runcpp2::HandlePreBuild(const Data::ScriptInfo& scriptInfo,
const Data::Profile& profile,
const ghc::filesystem::path& buildDir)
{
ssLOG_FUNC_INFO();

const Data::ProfilesCommands* preBuildCommands =
runcpp2::GetValueFromPlatformMap(scriptInfo.PreBuild);

Expand All @@ -793,6 +830,8 @@ runcpp2::PipelineResult runcpp2::HandlePostBuild( const Data::ScriptInfo& scri
const Data::Profile& profile,
const ghc::filesystem::path& buildDir)
{
ssLOG_FUNC_INFO();

const Data::ProfilesCommands* postBuildCommands =
GetValueFromPlatformMap(scriptInfo.PostBuild);

Expand All @@ -807,6 +846,9 @@ runcpp2::RunCompiledOutput( const ghc::filesystem::path& target,
const std::unordered_map<CmdOptions, std::string>& currentOptions,
int& returnStatus)
{
ssLOG_FUNC_INFO();
INTERNAL_RUNCPP2_SAFE_START();

//Prepare run arguments
std::vector<std::string> finalRunArgs;
finalRunArgs.push_back(target.string());
Expand Down Expand Up @@ -837,6 +879,8 @@ runcpp2::RunCompiledOutput( const ghc::filesystem::path& target,
}

return PipelineResult::SUCCESS;

INTERNAL_RUNCPP2_SAFE_CATCH_RETURN(PipelineResult::UNEXPECTED_FAILURE);
}

runcpp2::PipelineResult
Expand All @@ -847,6 +891,9 @@ runcpp2::HandleBuildOutput( const ghc::filesystem::path& target,
const std::string& buildOutputDir,
const std::unordered_map<CmdOptions, std::string>& currentOptions)
{
ssLOG_FUNC_INFO();
INTERNAL_RUNCPP2_SAFE_START();

//Copy the output file
std::vector<std::string> filesToCopy = filesToCopyPaths;
filesToCopy.push_back(target);
Expand All @@ -869,6 +916,8 @@ runcpp2::HandleBuildOutput( const ghc::filesystem::path& target,

ssLOG_BASE("Build completed. Files copied to " << buildOutputDir);
return PipelineResult::SUCCESS;

INTERNAL_RUNCPP2_SAFE_CATCH_RETURN(PipelineResult::UNEXPECTED_FAILURE);
}

runcpp2::PipelineResult
Expand All @@ -878,6 +927,9 @@ runcpp2::GetTargetPath( const ghc::filesystem::path& buildDir,
const std::unordered_map<CmdOptions, std::string>& currentOptions,
ghc::filesystem::path& outTarget)
{
ssLOG_FUNC_INFO();
INTERNAL_RUNCPP2_SAFE_START();

std::string exeExt = "";
#ifdef _WIN32
exeExt = ".exe";
Expand Down Expand Up @@ -913,13 +965,18 @@ runcpp2::GetTargetPath( const ghc::filesystem::path& buildDir,
}

return PipelineResult::SUCCESS;

INTERNAL_RUNCPP2_SAFE_CATCH_RETURN(PipelineResult::UNEXPECTED_FAILURE);
}

bool runcpp2::GatherSourceFiles(const ghc::filesystem::path& absoluteScriptPath,
const Data::ScriptInfo& scriptInfo,
const Data::Profile& currentProfile,
std::vector<ghc::filesystem::path>& outSourcePaths)
{
ssLOG_FUNC_INFO();
INTERNAL_RUNCPP2_SAFE_START();

if(!currentProfile.FileExtensions.count(absoluteScriptPath.extension()))
{
ssLOG_ERROR("File extension of script doesn't match profile");
Expand Down Expand Up @@ -1005,6 +1062,8 @@ bool runcpp2::GatherSourceFiles(const ghc::filesystem::path& absoluteScriptPath,
}

return true;

INTERNAL_RUNCPP2_SAFE_CATCH_RETURN(false);
}

bool runcpp2::GatherIncludePaths( const ghc::filesystem::path& scriptDirectory,
Expand All @@ -1013,7 +1072,9 @@ bool runcpp2::GatherIncludePaths( const ghc::filesystem::path& scriptDirectory
const std::vector<Data::DependencyInfo*>& dependencies,
std::vector<ghc::filesystem::path>& outIncludePaths)
{
ssLOG_FUNC_DEBUG();
ssLOG_FUNC_INFO();
INTERNAL_RUNCPP2_SAFE_START();

outIncludePaths.clear();

if(!scriptDirectory.is_absolute())
Expand Down Expand Up @@ -1077,20 +1138,24 @@ bool runcpp2::GatherIncludePaths( const ghc::filesystem::path& scriptDirectory
}

return true;

INTERNAL_RUNCPP2_SAFE_CATCH_RETURN(false);
}

bool runcpp2::GatherFilesIncludes( const std::vector<ghc::filesystem::path>& files,
const std::vector<ghc::filesystem::path>& includePaths,
SourceIncludeMap& outSourceIncludes)
{
ssLOG_FUNC_INFO();
INTERNAL_RUNCPP2_SAFE_START();
ssLOG_FUNC_DEBUG();

outSourceIncludes.clear();
std::unordered_set<std::string> visitedFiles;

for(const ghc::filesystem::path& file : files)
{
ssLOG_INFO("Gathering includes for " << file.string());

std::vector<ghc::filesystem::path>& currentIncludes = outSourceIncludes[file.string()];
std::queue<ghc::filesystem::path> filesToProcess;
filesToProcess.push(file);
Expand Down Expand Up @@ -1148,6 +1213,7 @@ bool runcpp2::GatherFilesIncludes( const std::vector<ghc::filesystem::path>& fi

if(found)
{
ssLOG_INFO("Found include file: " << resolvedInclude.string());
currentIncludes.push_back(resolvedInclude);
filesToProcess.push(resolvedInclude);
}
Expand Down
19 changes: 15 additions & 4 deletions Src/runcpp2/runcpp2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ namespace
std::vector<ghc::filesystem::path>& outCachedObjectsFiles,
ghc::filesystem::file_time_type& outFinalObjectWriteTime)
{
ssLOG_FUNC_DEBUG();
ssLOG_FUNC_INFO();

outHasCache.clear();
outHasCache = std::vector<bool>(sourceFiles.size(), false);
Expand Down Expand Up @@ -108,17 +108,21 @@ namespace

if(needsGather)
{
ssLOG_DEBUG("Needs to update include record for " <<
sourceFiles.at(i).string());
sourcesNeedGathering.push_back(sourceFiles.at(i));
useCache = false;
}
}

if(useCache)
{
ssLOG_DEBUG("Using cache for " << sourceFiles.at(i).string());
ssLOG_INFO("Using cache for " << sourceFiles.at(i).string());
outHasCache.at(i) = true;
outCachedObjectsFiles.push_back(currentObjectFilePath);
}
else
ssLOG_INFO("Cache invalidated for " << sourceFiles.at(i).string());

if(lastObjectWriteTime > outFinalObjectWriteTime)
outFinalObjectWriteTime = lastObjectWriteTime;
Expand All @@ -132,6 +136,7 @@ namespace

for(auto it = sourcesIncludes.cbegin(); it != sourcesIncludes.cend(); ++it)
{
ssLOG_DEBUG("Updating include record for " << it->first);
if(!includeManager.WriteIncludeRecord( ghc::filesystem::path(it->first),
it->second))
{
Expand Down Expand Up @@ -305,7 +310,7 @@ runcpp2::CheckSourcesNeedUpdate( const std::string& scriptPath,
bool& outNeedsUpdate)
{
INTERNAL_RUNCPP2_SAFE_START();
ssLOG_FUNC_DEBUG();
ssLOG_FUNC_INFO();

//Validate inputs and get paths
ghc::filesystem::path absoluteScriptPath;
Expand Down Expand Up @@ -345,13 +350,19 @@ runcpp2::CheckSourcesNeedUpdate( const std::string& scriptPath,
if(!GatherSourceFiles(absoluteScriptPath, scriptInfo, currentProfile, sourceFiles))
return PipelineResult::UNEXPECTED_FAILURE;

for(int i = 0; i < sourceFiles.size(); ++i)
ssLOG_DEBUG("sourceFiles.at(i).string(): " << sourceFiles.at(i).string());

//Get include paths
std::vector<ghc::filesystem::path> includePaths;
if(!GatherIncludePaths(scriptDirectory, scriptInfo, currentProfile, {}, includePaths))
{
ssLOG_ERROR("Failed to gather include paths");
return PipelineResult::UNEXPECTED_FAILURE;
}

for(int i = 0; i < includePaths.size(); ++i)
ssLOG_DEBUG("includePaths.at(i).string(): " << includePaths.at(i).string());

for(int i = 0; i < sourceFiles.size(); ++i)
{
Expand Down Expand Up @@ -390,7 +401,7 @@ runcpp2::StartPipeline( const std::string& scriptPath,
int& returnStatus)
{
INTERNAL_RUNCPP2_SAFE_START();
ssLOG_FUNC_DEBUG();
ssLOG_FUNC_INFO();

//Validate inputs and get paths
ghc::filesystem::path absoluteScriptPath;
Expand Down
Loading