From e708767b0d9cd760f6e44a07b43d54bee29d3210 Mon Sep 17 00:00:00 2001 From: anon Date: Sun, 11 Jan 2026 01:46:26 +0000 Subject: [PATCH 1/3] WIP --- CMakeLists.txt | 1 + External/DSResult | 2 +- Include/runcpp2/ConfigParsing.hpp | 6 ++--- Src/runcpp2/ConfigParsing.cpp | 39 +++++++++++-------------------- 4 files changed, 19 insertions(+), 29 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5d26efd..a2280d6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -105,6 +105,7 @@ add_subdirectory("${CMAKE_CURRENT_LIST_DIR}/External/variant") set(EXPECTED_BUILD_PACKAGE OFF) set(BUILD_TESTING OFF) +set(DS_USE_DEBUG_BREAK ON) add_subdirectory("${CMAKE_CURRENT_LIST_DIR}/External/DSResult") set(BUILD_TESTING ON) diff --git a/External/DSResult b/External/DSResult index 32f2867..a8edc10 160000 --- a/External/DSResult +++ b/External/DSResult @@ -1 +1 @@ -Subproject commit 32f2867a7e001a3ced4453236e6a67239b3695ca +Subproject commit a8edc10d20a7441d01276280f451e8a0c2100c9b diff --git a/Include/runcpp2/ConfigParsing.hpp b/Include/runcpp2/ConfigParsing.hpp index 849ac8a..bd79211 100644 --- a/Include/runcpp2/ConfigParsing.hpp +++ b/Include/runcpp2/ConfigParsing.hpp @@ -16,9 +16,9 @@ namespace runcpp2 const bool writeUserConfig, const bool writeDefaultConfigs); - bool ReadUserConfig(std::vector& outProfiles, - std::string& outPreferredProfile, - const std::string& customConfigPath = ""); + DS::Result ReadUserConfig(std::vector& outProfiles, + std::string& outPreferredProfile, + const std::string& customConfigPath = ""); bool ParseScriptInfo(const std::string& scriptInfo, Data::ScriptInfo& outScriptInfo); } diff --git a/Src/runcpp2/ConfigParsing.cpp b/Src/runcpp2/ConfigParsing.cpp index bf99f9a..2970c74 100644 --- a/Src/runcpp2/ConfigParsing.cpp +++ b/Src/runcpp2/ConfigParsing.cpp @@ -29,9 +29,9 @@ extern "C" const size_t Vs2022_v17Plus_size; namespace { - bool ResovleProfileImport( runcpp2::YAML::NodePtr currentProfileNode, - const ghc::filesystem::path& configPath, - runcpp2::YAML::ResourceHandle& currentYamlResources) + DS::Result ResovleProfileImport( runcpp2::YAML::NodePtr currentProfileNode, + const ghc::filesystem::path& configPath, + runcpp2::YAML::ResourceHandle& currentYamlResources) { using namespace runcpp2; @@ -196,44 +196,36 @@ namespace return {}; } - bool ParseUserConfig( const std::string& userConfigString, - const ghc::filesystem::path& configPath, - std::vector& outProfiles, - std::string& outPreferredProfile) + DS::Result ParseUserConfig( const std::string& userConfigString, + const ghc::filesystem::path& configPath, + std::vector& outProfiles, + std::string& outPreferredProfile) { ssLOG_FUNC_INFO(); using namespace runcpp2; YAML::ResourceHandle parseResource; - std::vector parsedNodes = - YAML::ParseYAML(userConfigString, parseResource).DS_TRY_ACT(return false); - + std::vector parsedNodes = YAML::ParseYAML( userConfigString, + parseResource).DS_TRY(); DEFER { YAML::FreeYAMLResource(parseResource); }; - if(parsedNodes.empty()) - return false; + DS_ASSERT_FALSE(parsedNodes.empty()); for(int i = 0; i < parsedNodes.size(); ++i) { YAML::NodePtr configNode = parsedNodes[i]; - YAML::ResolveAnchors(configNode).DS_TRY_ACT(return false); + YAML::ResolveAnchors(configNode).DS_TRY(); if(!ExistAndHasChild(configNode, "Profiles")) continue; if(!configNode->GetMapValueNode("Profiles")->IsSequence()) - { - ssLOG_ERROR("Profiles must be a sequence"); - return false; - } + return DS_ERROR_MSG("Profiles must be a sequence"); YAML::NodePtr profilesNode = configNode->GetMapValueNode("Profiles"); if(profilesNode->GetChildrenCount() == 0) - { - ssLOG_ERROR("No compiler profiles found"); - return false; - } + return DS_ERROR_MSG("No compiler profiles found"); ssLOG_INFO(profilesNode->GetChildrenCount() << " profiles found in user config"); @@ -244,10 +236,7 @@ namespace YAML::NodePtr currentProfileNode = profilesNode->GetSequenceChildNode(j); if(!currentProfileNode->IsMap()) - { - ssLOG_ERROR("Profile entry must be a map"); - return false; - } + return DS_ERROR_MSG("Profile entry must be a map"); if(!ResovleProfileImport(currentProfileNode, configPath, parseResource)) return false; From 1fd8f4c9143fd13f5fb62f46a27c5ea62eba44ef Mon Sep 17 00:00:00 2001 From: anon Date: Wed, 21 Jan 2026 17:26:18 +0000 Subject: [PATCH 2/3] WIP --- CMakeLists.txt | 4 + Include/runcpp2/ConfigParsing.hpp | 10 +- Include/runcpp2/DependenciesHelper.hpp | 76 ++-- Src/runcpp2/ConfigParsing.cpp | 240 +++++------- Src/runcpp2/DependenciesHelper.cpp | 489 +++++++++++-------------- Src/runcpp2/PipelineSteps.cpp | 130 ++++--- Src/runcpp2/main.cpp | 19 +- Src/runcpp2/runcpp2.cpp | 9 +- 8 files changed, 431 insertions(+), 546 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a2280d6..db6d273 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,6 +24,10 @@ else() option(RUNCPP2_BUILD_TESTS "Build runcpp2 tests" OFF) endif() +# Don't build any tests for now until we have rewritten th +option(RUNCPP2_BUILD_TESTS "Build runcpp2 tests" OFF) +set(RUNCPP2_BUILD_TESTS OFF) + # ========================================================================= # Retrieving Version String # ========================================================================= diff --git a/Include/runcpp2/ConfigParsing.hpp b/Include/runcpp2/ConfigParsing.hpp index bd79211..a47e8af 100644 --- a/Include/runcpp2/ConfigParsing.hpp +++ b/Include/runcpp2/ConfigParsing.hpp @@ -10,17 +10,17 @@ #include namespace runcpp2 { - std::string GetConfigFilePath(); + DS::Result GetConfigFilePath(); - bool WriteDefaultConfigs( const ghc::filesystem::path& userConfigPath, - const bool writeUserConfig, - const bool writeDefaultConfigs); + DS::Result WriteDefaultConfigs( const ghc::filesystem::path& userConfigPath, + const bool writeUserConfig, + const bool writeDefaultConfigs); DS::Result ReadUserConfig(std::vector& outProfiles, std::string& outPreferredProfile, const std::string& customConfigPath = ""); - bool ParseScriptInfo(const std::string& scriptInfo, Data::ScriptInfo& outScriptInfo); + DS::Result ParseScriptInfo(const std::string& scriptInfo, Data::ScriptInfo& outScriptInfo); } #endif diff --git a/Include/runcpp2/DependenciesHelper.hpp b/Include/runcpp2/DependenciesHelper.hpp index 1994e3a..6ef452d 100644 --- a/Include/runcpp2/DependenciesHelper.hpp +++ b/Include/runcpp2/DependenciesHelper.hpp @@ -14,52 +14,58 @@ namespace runcpp2 { - bool GetDependenciesPaths( const std::vector& availableDependencies, - std::vector& outCopiesPaths, - std::vector& outSourcesPaths, - const ghc::filesystem::path& scriptPath, - const ghc::filesystem::path& buildDir); + DS::Result + GetDependenciesPaths( const std::vector& availableDependencies, + std::vector& outCopiesPaths, + std::vector& outSourcesPaths, + const ghc::filesystem::path& scriptPath, + const ghc::filesystem::path& buildDir); bool IsDependencyAvailableForThisPlatform(const Data::DependencyInfo& dependency); - bool CleanupDependencies( const runcpp2::Data::Profile& profile, + DS::Result + CleanupDependencies(const runcpp2::Data::Profile& profile, + const Data::ScriptInfo& scriptInfo, + const std::vector& availableDependencies, + const std::vector& dependenciesLocalCopiesPaths, + const std::string& dependenciesToReset); + + DS::Result + SetupDependenciesIfNeeded( const runcpp2::Data::Profile& profile, + const ghc::filesystem::path& buildDir, const Data::ScriptInfo& scriptInfo, - const std::vector& availableDependencies, + std::vector& availableDependencies, const std::vector& dependenciesLocalCopiesPaths, - const std::string& dependenciesToReset); - - bool SetupDependenciesIfNeeded( const runcpp2::Data::Profile& profile, - const ghc::filesystem::path& buildDir, - const Data::ScriptInfo& scriptInfo, - std::vector& availableDependencies, - const std::vector& dependenciesLocalCopiesPaths, - const std::vector& dependenciesSourcePaths, - const int maxThreads); + const std::vector& dependenciesSourcePaths, + const int maxThreads); - bool BuildDependencies( const runcpp2::Data::Profile& profile, - const Data::ScriptInfo& scriptInfo, - const std::vector& availableDependencies, - const std::vector& dependenciesLocalCopiesPaths, - const int maxThreads); + DS::Result + BuildDependencies( const runcpp2::Data::Profile& profile, + const Data::ScriptInfo& scriptInfo, + const std::vector& availableDependencies, + const std::vector& dependenciesLocalCopiesPaths, + const int maxThreads); - bool GatherDependenciesBinaries(const std::vector& availableDependencies, - const std::vector& dependenciesCopiesPaths, - const Data::Profile& profile, - std::vector& outBinariesPaths); + DS::Result + GatherDependenciesBinaries( const std::vector& availableDependencies, + const std::vector& dependenciesCopiesPaths, + const Data::Profile& profile, + std::vector& outBinariesPaths); - bool HandleImport(Data::DependencyInfo& dependency, const ghc::filesystem::path& basePath); + DS::Result HandleImport( Data::DependencyInfo& dependency, + const ghc::filesystem::path& basePath); - bool ResolveImports(Data::ScriptInfo& scriptInfo, - const ghc::filesystem::path& scriptPath, - const ghc::filesystem::path& buildDir); + DS::Result ResolveImports(Data::ScriptInfo& scriptInfo, + const ghc::filesystem::path& scriptPath, + const ghc::filesystem::path& buildDir); - bool SyncLocalDependency( const Data::DependencyInfo& dependency, - const ghc::filesystem::path& sourcePath, - const ghc::filesystem::path& copyPath); + DS::Result SyncLocalDependency( const Data::DependencyInfo& dependency, + const ghc::filesystem::path& sourcePath, + const ghc::filesystem::path& copyPath); - bool SyncLocalDependencies( const std::vector& dependencies, - const std::vector& dependenciesSourcePaths, - const std::vector& dependenciesCopiesPaths); + DS::Result SyncLocalDependencies(const std::vector& dependencies, + const std::vector& dependenciesSourcePaths, + const std::vector& dependenciesCopiesPaths); } #endif diff --git a/Src/runcpp2/ConfigParsing.cpp b/Src/runcpp2/ConfigParsing.cpp index 2970c74..939d72d 100644 --- a/Src/runcpp2/ConfigParsing.cpp +++ b/Src/runcpp2/ConfigParsing.cpp @@ -39,8 +39,7 @@ namespace ghc::filesystem::path currentImportFilePath = configPath; std::stack pathsToImport; - while( runcpp2::ExistAndHasChild(currentProfileNode, "Import") || - !pathsToImport.empty()) + while(runcpp2::ExistAndHasChild(currentProfileNode, "Import") || !pathsToImport.empty()) { //If we import field, we should deal with it instead if(runcpp2::ExistAndHasChild(currentProfileNode, "Import")) @@ -49,36 +48,28 @@ namespace if( importNode->GetType() != YAML::NodeType::Scalar && importNode->GetType() != YAML::NodeType::Sequence) { - ssLOG_ERROR("Import must be a path or sequence of paths of YAML file(s)"); - return false; + return DS_ERROR_MSG("Import must be a path or sequence of paths of YAML file(s)"); } ghc::filesystem::path currentImportDir = currentImportFilePath; currentImportDir = currentImportDir.parent_path(); if(importNode->GetType() == YAML::NodeType::Scalar) { - std::string importPath = importNode ->GetScalar() - .DS_TRY_ACT(return false); + std::string importPath = importNode->GetScalar().DS_TRY(); pathsToImport.push(currentImportDir / importPath); } else { if(importNode->GetChildrenCount() == 0) - { - ssLOG_ERROR("An import sequence cannot be an empty"); - return false; - } + return DS_ERROR_MSG("An import sequence cannot be an empty"); for(int i = 0; i < importNode->GetChildrenCount(); ++i) { if(importNode->GetSequenceChildNode(i)->GetType() != YAML::NodeType::Scalar) - { - ssLOG_ERROR("It must be a sequence of paths"); - return false; - } + return DS_ERROR_MSG("It must be a sequence of paths"); std::string importPath = importNode ->GetSequenceChildScalar(i) - .DS_TRY_ACT(return false); + .DS_TRY(); pathsToImport.push(currentImportDir / importPath); } } @@ -89,10 +80,7 @@ namespace std::error_code ec; if(!ghc::filesystem::exists(currentImportFilePath, ec)) - { - ssLOG_ERROR("Import path doesn't exist: " << currentImportFilePath.string()); - return false; - } + return DS_ERROR_MSG("Import path doesn't exist: " + currentImportFilePath.string()); //Read compiler profiles std::stringstream buffer; @@ -100,8 +88,8 @@ namespace std::ifstream importProfileFile(currentImportFilePath); if(!importProfileFile) { - ssLOG_ERROR("Failed to open profile import file: " << currentImportFilePath); - return false; + return DS_ERROR_MSG("Failed to open profile import file: " + + DS_STR(currentImportFilePath)); } buffer << importProfileFile.rdbuf(); } @@ -109,42 +97,33 @@ namespace YAML::ResourceHandle yamlResources; DEFER { YAML::FreeYAMLResource(yamlResources); }; - std::vector yamlRootNodes = - YAML::ParseYAML(buffer.str(), yamlResources).DS_TRY_ACT(return false); - - if(yamlRootNodes.empty()) - return false; - + std::vector yamlRootNodes = YAML::ParseYAML( buffer.str(), + yamlResources).DS_TRY(); + DS_ASSERT_FALSE(yamlRootNodes.empty()); for(int i = 0; i < yamlRootNodes.size(); ++i) { - YAML::ResolveAnchors(yamlRootNodes[i]).DS_TRY_ACT(return false); + YAML::ResolveAnchors(yamlRootNodes[i]).DS_TRY(); YAML::NodePtr importProfileNode = yamlRootNodes[i]; - if(!MergeYAML_NodeChildren( importProfileNode, - currentProfileNode, - currentYamlResources)) - { - return false; - } - + DS_ASSERT_TRUE(MergeYAML_NodeChildren( importProfileNode, + currentProfileNode, + currentYamlResources)); if(ExistAndHasChild(importProfileNode, "Import")) { - currentProfileNode->RemoveMapChild("Import").DS_TRY_ACT(return false); + currentProfileNode->RemoveMapChild("Import").DS_TRY(); importProfileNode ->GetMapValueNode("Import") ->CloneToMapChild( "Import", currentProfileNode, - currentYamlResources) - .DS_TRY_ACT(return false); + currentYamlResources).DS_TRY(); } else { - currentProfileNode->RemoveMapChild("Import").DS_TRY_ACT(return false); + currentProfileNode->RemoveMapChild("Import").DS_TRY(); } } - } //while( runcpp2::ExistAndHasChild(currentProfileNode, "Import") || - // !pathsToImport.empty()) + } //while(runcpp2::ExistAndHasChild(currentProfileNode, "Import") || !pathsToImport.empty()) - return true; + return {}; } DS::Result GetPreferredProfile( runcpp2::YAML::NodePtr configNode, @@ -189,7 +168,7 @@ namespace } else { - return DS_ERROR_MSG(DS_STR("PreferredProfile needs to be a map or string value: ") + + return DS_ERROR_MSG("PreferredProfile needs to be a map or string value: " + DS_STR(YAML::NodeTypeToString(preferredProfilesMapNode->GetType()))); } @@ -238,19 +217,16 @@ namespace if(!currentProfileNode->IsMap()) return DS_ERROR_MSG("Profile entry must be a map"); - if(!ResovleProfileImport(currentProfileNode, configPath, parseResource)) - return false; - + ResovleProfileImport(currentProfileNode, configPath, parseResource).DS_TRY(); outProfiles.push_back({}); if(!outProfiles.back().ParseYAML_Node(currentProfileNode)) { outProfiles.erase(outProfiles.end() - 1); - ssLOG_ERROR("Failed to parse compiler profile at index " << j); - return false; + return DS_ERROR_MSG("Failed to parse compiler profile at index " + DS_STR(j)); } } //for(int j = 0; j < profilesNode->GetChildrenCount(); ++j) - GetPreferredProfile(configNode, outPreferredProfile).DS_TRY_ACT(return false); + GetPreferredProfile(configNode, outPreferredProfile).DS_TRY(); } //for(int i = 0; i < parsedNodes.size(); ++i) if(outPreferredProfile.empty()) @@ -260,34 +236,25 @@ namespace } if(outProfiles.empty()) - { - ssLOG_ERROR("No profiles registered"); - return false; - } + return DS_ERROR_MSG("No profiles registered"); - return true; + return {}; } } -std::string runcpp2::GetConfigFilePath() +DS::Result runcpp2::GetConfigFilePath() { - CO_INSERT_IMPL(OverrideInstance, std::string, ()); + CO_INSERT_IMPL(OverrideInstance, DS::Result, ()); //Check if user config exists char configDirC_Str[MAX_PATH] = {0}; get_user_config_folder(configDirC_Str, MAX_PATH, "runcpp2"); - if(strlen(configDirC_Str) == 0) - { - ssLOG_ERROR("Failed to retrieve user config path"); - return ""; - } - + DS_ASSERT_GT(strlen(configDirC_Str), 0); std::string configDir = std::string(configDirC_Str); ssLOG_INFO("configDir: " << configDir); - std::string compilerConfigFilePaths[2] = { configDir + "UserConfig.yaml", @@ -308,11 +275,13 @@ std::string runcpp2::GetConfigFilePath() return compilerConfigFilePaths[0]; } -bool runcpp2::WriteDefaultConfigs( const ghc::filesystem::path& userConfigPath, - const bool writeUserConfig, - const bool writeDefaultConfigs) +DS::Result runcpp2::WriteDefaultConfigs( const ghc::filesystem::path& userConfigPath, + const bool writeUserConfig, + const bool writeDefaultConfigs) { - CO_INSERT_IMPL(OverrideInstance, bool, (userConfigPath, writeUserConfig, writeDefaultConfigs)); + CO_INSERT_IMPL( OverrideInstance, + DS::Result, + (userConfigPath, writeUserConfig, writeDefaultConfigs)); //Backup existing user config std::error_code _; @@ -323,8 +292,8 @@ bool runcpp2::WriteDefaultConfigs( const ghc::filesystem::path& userConfigPath, { if(backupCount > 10) { - ssLOG_ERROR("Failed to backup existing user config: " << userConfigPath.string()); - return false; + return DS_ERROR_MSG("Failed to backup existing user config: " + + userConfigPath.string()); } std::string backupPath = userConfigPath.string(); @@ -345,17 +314,15 @@ bool runcpp2::WriteDefaultConfigs( const ghc::filesystem::path& userConfigPath, ghc::filesystem::copy(userConfigPath, backupPath, copyErrorCode); if(copyErrorCode) { - ssLOG_ERROR("Failed to backup existing user config: " << userConfigPath.string() << - " with error: " << _.message()); - - return false; + return DS_ERROR_MSG("Failed to backup existing user config: " + + userConfigPath.string() + " with error: " + _.message()); } ssLOG_INFO("Backed up existing user config: " << backupPath); if(!ghc::filesystem::remove(userConfigPath, _)) { - ssLOG_ERROR("Failed to delete existing user config: " << userConfigPath.string()); - return false; + return DS_ERROR_MSG("Failed to delete existing user config: " + + userConfigPath.string()); } break; @@ -368,15 +335,13 @@ bool runcpp2::WriteDefaultConfigs( const ghc::filesystem::path& userConfigPath, { std::ofstream configFile(userConfigPath, std::ios::binary); if(!configFile) - { - ssLOG_ERROR("Failed to create default config file: " << userConfigPath.string()); - return false; - } + return DS_ERROR_MSG("Failed to create default config file: " + userConfigPath.string()); + configFile.write((const char*)DefaultUserConfig, DefaultUserConfig_size); } if(!writeDefaultConfigs) - return true; + return {}; ghc::filesystem::path userConfigDirectory = userConfigPath; userConfigDirectory = userConfigDirectory.parent_path(); @@ -384,68 +349,57 @@ bool runcpp2::WriteDefaultConfigs( const ghc::filesystem::path& userConfigPath, //Default configs if(!ghc::filesystem::exists(defaultYamlDirectory , _)) - { - if(!ghc::filesystem::create_directories(defaultYamlDirectory, _)) - { - ssLOG_ERROR("Failed to create directory: " << defaultYamlDirectory.string()); - return false; - } - } + DS_ASSERT_TRUE(ghc::filesystem::create_directories(defaultYamlDirectory, _)); //Writing default profiles auto writeDefaultConfig = - [&defaultYamlDirectory] - (ghc::filesystem::path outputPath, const uint8_t* outputContent, size_t outputSize) + [&defaultYamlDirectory](ghc::filesystem::path outputPath, + const uint8_t* outputContent, + size_t outputSize) -> DS::Result { const ghc::filesystem::path currentOutputPath = defaultYamlDirectory / outputPath; std::ofstream defaultFile( currentOutputPath.string(), std::ios::binary | std::ios_base::trunc); if(!defaultFile) { - ssLOG_ERROR("Failed to create default config file: " << currentOutputPath.string()); - return false; + return DS_ERROR_MSG("Failed to create default config file: " + + currentOutputPath.string()); } defaultFile.write((const char*)outputContent, outputSize); - return true; + return {}; }; - if( !writeDefaultConfig("CommonFileTypes.yaml", CommonFileTypes, CommonFileTypes_size) || - !writeDefaultConfig("g++.yaml", G_PlusPlus, G_PlusPlus_size) || - !writeDefaultConfig("vs2022_v17+.yaml", Vs2022_v17Plus, Vs2022_v17Plus_size)) - { - return false; - } + writeDefaultConfig("CommonFileTypes.yaml", CommonFileTypes, CommonFileTypes_size).DS_TRY(); + writeDefaultConfig("g++.yaml", G_PlusPlus, G_PlusPlus_size).DS_TRY(); + writeDefaultConfig("vs2022_v17+.yaml", Vs2022_v17Plus, Vs2022_v17Plus_size).DS_TRY(); //Writing .version to indicate everything is up-to-date std::ofstream configVersionFile(userConfigDirectory / ".version", std::ios::binary | std::ios_base::trunc); if(!configVersionFile) { - ssLOG_ERROR("Failed to open version file: " << - ghc::filesystem::path(userConfigDirectory / ".version").string()); - return false; + return DS_ERROR_MSG("Failed to open version file: " + + ghc::filesystem::path(userConfigDirectory / ".version").string()); } configVersionFile << std::to_string(RUNCPP2_CONFIG_VERSION); - return true; + return {}; } -bool runcpp2::ReadUserConfig( std::vector& outProfiles, - std::string& outPreferredProfile, - const std::string& customConfigPath) +DS::Result runcpp2::ReadUserConfig( std::vector& outProfiles, + std::string& outPreferredProfile, + const std::string& customConfigPath) { - INTERNAL_RUNCPP2_SAFE_START(); - ssLOG_FUNC_INFO(); ghc::filesystem::path configPath = !customConfigPath.empty() ? customConfigPath : - GetConfigFilePath(); + GetConfigFilePath().DS_VALUE_OR(); + DS_CHECK_PREV(); ghc::filesystem::path configVersionPath = configPath.parent_path() / ".version"; - if(configPath.empty()) - return false; + DS_ASSERT_FALSE(configPath.empty()); std::error_code e; @@ -456,10 +410,7 @@ bool runcpp2::ReadUserConfig( std::vector& outProfiles, if(!ghc::filesystem::exists(configPath, e)) { if(!customConfigPath.empty()) - { - ssLOG_ERROR("Config file doesn't exist: " << configPath.string()); - return false; - } + return DS_ERROR_MSG("Config file doesn't exist: " + configPath.string()); ssLOG_INFO("Config file doesn't exist. Creating one at: " << configPath.string()); writeUserConfig = true; @@ -470,10 +421,8 @@ bool runcpp2::ReadUserConfig( std::vector& outProfiles, { std::ifstream configVersionFile(configVersionPath); if(!configVersionFile) - { - ssLOG_ERROR("Failed to open version file: " << configVersionPath.string()); - return false; - } + return DS_ERROR_MSG("Failed to open version file: " + configVersionPath.string()); + std::string configVersionStr; std::stringstream buffer; buffer << configVersionFile.rdbuf(); @@ -488,70 +437,45 @@ bool runcpp2::ReadUserConfig( std::vector& outProfiles, else writeDefaultConfigs = true; - if( (writeUserConfig || writeDefaultConfigs) && - !WriteDefaultConfigs(configPath, writeUserConfig, writeDefaultConfigs)) + if(writeUserConfig || writeDefaultConfigs) { - return false; + WriteDefaultConfigs(configPath, writeUserConfig, writeDefaultConfigs).DS_TRY(); } if(ghc::filesystem::is_directory(configPath, e)) - { - ssLOG_ERROR("Config file path is a directory: " << configPath.string()); - return false; - } + return DS_ERROR_MSG("Config file path is a directory: " + configPath.string()); //Read compiler profiles std::string userConfigContent; { std::ifstream userConfigFile(configPath); if(!userConfigFile) - { - ssLOG_ERROR("Failed to open config file: " << configPath.string()); - return false; - } + return DS_ERROR_MSG("Failed to open config file: " + configPath.string()); std::stringstream buffer; buffer << userConfigFile.rdbuf(); userConfigContent = buffer.str(); } - if(!ParseUserConfig(userConfigContent, configPath, outProfiles, outPreferredProfile)) - { - ssLOG_ERROR("Failed to parse config file: " << configPath.string()); - return false; - } - - return true; - - INTERNAL_RUNCPP2_SAFE_CATCH_RETURN(false); + ParseUserConfig(userConfigContent, configPath, outProfiles, outPreferredProfile).DS_TRY(); + return {}; } -bool runcpp2::ParseScriptInfo(const std::string& scriptInfo, Data::ScriptInfo& outScriptInfo) +DS::Result runcpp2::ParseScriptInfo( const std::string& scriptInfo, + Data::ScriptInfo& outScriptInfo) { - INTERNAL_RUNCPP2_SAFE_START(); - if(scriptInfo.empty()) - return true; + return {}; YAML::ResourceHandle resourceHandle; - std::vector scriptNodes = - YAML::ParseYAML(scriptInfo, resourceHandle).DS_TRY_ACT(return false); - + std::vector scriptNodes = YAML::ParseYAML(scriptInfo, resourceHandle).DS_TRY(); DEFER { YAML::FreeYAMLResource(resourceHandle); }; - if(scriptNodes.empty()) - return false; + DS_ASSERT_FALSE(scriptNodes.empty()); //NOTE: Use the first one - YAML::ResolveAnchors(scriptNodes.front()).DS_TRY_ACT(return false); + YAML::ResolveAnchors(scriptNodes.front()).DS_TRY(); YAML::NodePtr rootScriptNode = scriptNodes.front(); - - if(outScriptInfo.ParseYAML_Node(rootScriptNode)) - { - outScriptInfo.Populated = true; - return true; - } - else - return false; - - INTERNAL_RUNCPP2_SAFE_CATCH_RETURN(false); + DS_ASSERT_TRUE(outScriptInfo.ParseYAML_Node(rootScriptNode)); + outScriptInfo.Populated = true; + return {}; } diff --git a/Src/runcpp2/DependenciesHelper.cpp b/Src/runcpp2/DependenciesHelper.cpp index 54a3646..f4d291e 100644 --- a/Src/runcpp2/DependenciesHelper.cpp +++ b/Src/runcpp2/DependenciesHelper.cpp @@ -13,11 +13,11 @@ namespace { - bool GetDependencyPath( const runcpp2::Data::DependencyInfo& dependency, - const ghc::filesystem::path& scriptPath, - const ghc::filesystem::path& buildDir, - ghc::filesystem::path& outCopyPath, - ghc::filesystem::path& outSourcePath) + DS::Result GetDependencyPath( const runcpp2::Data::DependencyInfo& dependency, + const ghc::filesystem::path& scriptPath, + const ghc::filesystem::path& buildDir, + ghc::filesystem::path& outCopyPath, + ghc::filesystem::path& outSourcePath) { ssLOG_FUNC_INFO(); @@ -37,8 +37,7 @@ namespace lastDotGitFoundIndex == std::string::npos || lastDotGitFoundIndex < lastSlashFoundIndex) { - ssLOG_ERROR("Invalid git url: " << git->URL); - return false; + return DS_ERROR_MSG(DS_STR("Invalid git url: ") + git->URL); } else { @@ -75,8 +74,8 @@ namespace if(!ghc::filesystem::is_directory(outSourcePath)) { - ssLOG_ERROR("Local dependency path is not a directory: " << outSourcePath); - return false; + return DS_ERROR_MSG(DS_STR( "Local dependency path is not a directory: ") + + DS_STR(outSourcePath)); } if(currentSource.ImportPath.empty()) @@ -85,14 +84,14 @@ namespace outCopyPath = outSourcePath; } - return true; + return {}; } - bool PopulateLocalDependency( const runcpp2::Data::DependencyInfo& dependency, - const ghc::filesystem::path& copyPath, - const ghc::filesystem::path& sourcePath, - const ghc::filesystem::path& buildDir, - bool& outPrePopulated) + DS::Result PopulateLocalDependency( const runcpp2::Data::DependencyInfo& dependency, + const ghc::filesystem::path& copyPath, + const ghc::filesystem::path& sourcePath, + const ghc::filesystem::path& buildDir, + bool& outPrePopulated) { ssLOG_FUNC_DEBUG(); @@ -102,12 +101,11 @@ namespace { if(!ghc::filesystem::is_directory(copyPath, e)) { - ssLOG_ERROR("Dependency path is a file: " << copyPath.string()); - ssLOG_ERROR("It should be a folder instead"); - return false; + return DS_ERROR_MSG("Dependency path is a file: " + copyPath.string() + "\n" + + "It should be a folder instead"); } outPrePopulated = true; - return true; + return {}; } else { @@ -131,9 +129,8 @@ namespace break; default: { - ssLOG_ERROR("Invalid git submodule init type: " << - static_cast(git->CurrentSubmoduleInitType)); - return false; + return DS_ERROR_MSG("Invalid git submodule init type: " + + DS_STR(static_cast(git->CurrentSubmoduleInitType))); } } @@ -159,10 +156,8 @@ namespace output, returnCode)) { - ssLOG_ERROR("Failed to run git clone with result: " << returnCode); - ssLOG_ERROR("Was trying to run: " << gitCloneCommand); - //ssLOG_ERROR("Output: \n" << output); - return false; + return DS_ERROR_MSG("Failed to run git clone with result: " + DS_STR(returnCode) + + "\nWas trying to run: " + gitCloneCommand); } //else // ssLOG_INFO("Output: \n" << output); @@ -170,23 +165,23 @@ namespace else if(mpark::get_if(&(dependency.Source.Source))) { //Copy/link local directory if it doesn't have any import path - if( dependency.Source.ImportPath.empty() && - !runcpp2::SyncLocalDependency(dependency, sourcePath, copyPath)) + if(dependency.Source.ImportPath.empty()) { - return false; + runcpp2::SyncLocalDependency(dependency, sourcePath, copyPath).DS_TRY(); } } outPrePopulated = false; - return true; + return {}; } } - bool PopulateLocalDependencies( const std::vector& dependencies, - const std::vector& dependenciesCopiesPaths, - const std::vector& dependenciesSourcesPaths, - const ghc::filesystem::path& buildDir, - std::vector& outPrePopulated) + DS::Result + PopulateLocalDependencies( const std::vector& dependencies, + const std::vector& dependenciesCopiesPaths, + const std::vector& dependenciesSourcesPaths, + const ghc::filesystem::path& buildDir, + std::vector& outPrePopulated) { ssLOG_FUNC_INFO(); @@ -195,29 +190,23 @@ namespace for(int i = 0; i < dependencies.size(); ++i) { if(!dependencies.at(i)->Source.ImportPath.empty()) - { - ssLOG_ERROR("Dependency import not resolved before populating."); - return false; - } + return DS_ERROR_MSG("Dependency import not resolved before populating."); bool prePopulated = false; - if(!PopulateLocalDependency(*dependencies.at(i), - ghc::filesystem::path(dependenciesCopiesPaths.at(i)), - ghc::filesystem::path(dependenciesSourcesPaths.at(i)), - buildDir, - prePopulated)) - { - return false; - } - + PopulateLocalDependency(*dependencies.at(i), + ghc::filesystem::path(dependenciesCopiesPaths.at(i)), + ghc::filesystem::path(dependenciesSourcesPaths.at(i)), + buildDir, + prePopulated).DS_TRY(); outPrePopulated.at(i) = prePopulated; } - return true; + return {}; } - bool PopulateAbsoluteIncludePaths( std::vector& dependencies, - const std::vector& dependenciesCopiesPaths) + DS::Result + PopulateAbsoluteIncludePaths( std::vector& dependencies, + const std::vector& dependenciesCopiesPaths) { //Append absolute include paths from relative include paths for(int i = 0; i < dependencies.size(); ++i) @@ -227,10 +216,8 @@ namespace { if(ghc::filesystem::path(dependencies.at(i)->IncludePaths.at(j)).is_absolute()) { - ssLOG_ERROR("Dependency include path cannot be absolute: " << - dependencies.at(i)->IncludePaths.at(j)); - - return false; + return DS_ERROR_MSG("Dependency include path cannot be absolute: " + + dependencies.at(i)->IncludePaths.at(j)); } dependencies.at(i) @@ -250,31 +237,29 @@ namespace } } - return true; + return {}; } - bool RunDependenciesSteps( const runcpp2::Data::Profile& profile, - const std::unordered_map< PlatformName, - runcpp2::Data::ProfilesCommands> steps, - const std::string& dependenciesCopiedDirectory, - bool required, - bool redirectIO) + DS::Result + RunDependenciesSteps( const runcpp2::Data::Profile& profile, + const std::unordered_map< PlatformName, + runcpp2::Data::ProfilesCommands> steps, + const std::string& dependenciesCopiedDirectory, + bool required, + bool redirectIO) { ssLOG_FUNC_INFO(); if(steps.empty()) - return true; + return {}; //Find the platform name we use for setup if(!runcpp2::HasValueFromPlatformMap(steps)) { if(required) - { - ssLOG_ERROR("Failed to find steps for current platform"); - return false; - } + return DS_ERROR_MSG("Failed to find steps for current platform"); else - return true; + return {}; } const runcpp2::Data::ProfilesCommands& dependencySteps = @@ -285,32 +270,32 @@ namespace if(!commands) { - ssLOG_ERROR("Failed to find steps for profile " << profile.Name << - " for current platform"); - return false; + return DS_ERROR_MSG(DS_STR( "Failed to find steps for profile ") + profile.Name + + " for current platform"); } //Run the commands for(int k = 0; k < commands->size(); ++k) { std::string processedDependencyPath = runcpp2::ProcessPath(dependenciesCopiedDirectory); - ssLOG_INFO( "Running command: " << commands->at(k) << " in " << - processedDependencyPath); + ssLOG_INFO("Running command: " << commands->at(k) << " in " << processedDependencyPath); int returnCode = 0; std::string output; + //TODO: Change to ds result if(!runcpp2::RunCommand(commands->at(k), redirectIO, processedDependencyPath, output, returnCode)) { - ssLOG_ERROR("Failed to run command with result: " << returnCode); - ssLOG_ERROR("Was trying to run: " << commands->at(k)); + std::string errorMsg = + DS_STR("Failed to run command with result: ") + DS_STR(returnCode) + "\n" + "Was trying to run: " + commands->at(k); if(redirectIO) - ssLOG_ERROR("Output: \n" << output); - return false; + errorMsg += DS_STR("\nOutput: \n") + output; + return DS_ERROR_MSG(errorMsg); } else { @@ -319,7 +304,7 @@ namespace } } - return true; + return {}; } bool GetDependencyBinariesExtensionsToLink( const runcpp2::Data::DependencyInfo& dependencyInfo, @@ -406,11 +391,12 @@ namespace } } -bool runcpp2::GetDependenciesPaths( const std::vector& availableDependencies, - std::vector& outCopiesPaths, - std::vector& outSourcesPaths, - const ghc::filesystem::path& scriptPath, - const ghc::filesystem::path& buildDir) +DS::Result +runcpp2::GetDependenciesPaths( const std::vector& availableDependencies, + std::vector& outCopiesPaths, + std::vector& outSourcesPaths, + const ghc::filesystem::path& scriptPath, + const ghc::filesystem::path& buildDir) { ssLOG_FUNC_INFO(); @@ -418,21 +404,17 @@ bool runcpp2::GetDependenciesPaths( const std::vector& av { ghc::filesystem::path currentCopyPath; ghc::filesystem::path currentSourcePath; + GetDependencyPath( *availableDependencies.at(i), + scriptPath, + buildDir, + currentCopyPath, + currentSourcePath).DS_TRY(); - if(!GetDependencyPath( *availableDependencies.at(i), - scriptPath, - buildDir, - currentCopyPath, - currentSourcePath)) - { - return false; - } - outCopiesPaths.push_back(currentCopyPath.string()); outSourcesPaths.push_back(currentSourcePath.string()); } - return true; + return {}; } bool runcpp2::IsDependencyAvailableForThisPlatform(const Data::DependencyInfo& dependency) @@ -448,19 +430,20 @@ bool runcpp2::IsDependencyAvailableForThisPlatform(const Data::DependencyInfo& d return false; } -bool runcpp2::CleanupDependencies( const runcpp2::Data::Profile& profile, - const Data::ScriptInfo& scriptInfo, - const std::vector& availableDependencies, - const std::vector& dependenciesLocalCopiesPaths, - const std::string& dependenciesToReset) +DS::Result +runcpp2::CleanupDependencies( const runcpp2::Data::Profile& profile, + const Data::ScriptInfo& scriptInfo, + const std::vector& availableDependencies, + const std::vector& dependenciesLocalCopiesPaths, + const std::string& dependenciesToReset) { ssLOG_FUNC_DEBUG(); //If the script info is not populated (i.e. empty script info), don't do anything if(!scriptInfo.Populated) - return true; + return {}; - assert(availableDependencies.size() == dependenciesLocalCopiesPaths.size()); + DS_ASSERT_EQ(availableDependencies.size(), dependenciesLocalCopiesPaths.size()); //Split dependency names if not "all" std::unordered_set dependencyNames; @@ -510,65 +493,63 @@ bool runcpp2::CleanupDependencies( const runcpp2::Data::Profile& profile, std::error_code e; ssLOG_INFO("Running cleanup commands for " << availableDependencies.at(i)->Name); - if(!RunDependenciesSteps( profile, - availableDependencies.at(i)->Cleanup, - dependenciesLocalCopiesPaths.at(i), - false, - false)) + DS::Result depResult = RunDependenciesSteps( profile, + availableDependencies.at(i)->Cleanup, + dependenciesLocalCopiesPaths.at(i), + false, + false); + if(!depResult.HasValue()) { - ssLOG_ERROR("Failed to cleanup dependency " << availableDependencies.at(i)->Name); - return false; + depResult.Error().Message += "\nFailed to cleanup dependency " + + availableDependencies.at(i)->Name; + DS_APPEND_TRACE(depResult.Error()); + return depResult; } //Remove the directory if( ghc::filesystem::exists(dependenciesLocalCopiesPaths.at(i), e) && !ghc::filesystem::remove_all(dependenciesLocalCopiesPaths.at(i), e)) { - ssLOG_ERROR("Failed to reset dependency directory: " << - dependenciesLocalCopiesPaths.at(i)); - - return false; + return DS_ERROR_MSG("Failed to reset dependency directory: " + + dependenciesLocalCopiesPaths.at(i)); } ssLOG_DEBUG(availableDependencies.at(i)->Name << " removed"); } - return true; + return {}; } //#define RUNCPP2_USE_PARALLEL_FOR_DEP 0 -bool runcpp2::SetupDependenciesIfNeeded(const runcpp2::Data::Profile& profile, - const ghc::filesystem::path& buildDir, - const Data::ScriptInfo& scriptInfo, - std::vector& availableDependencies, - const std::vector& dependenciesLocalCopiesPaths, - const std::vector& dependenciesSourcePaths, - const int maxThreads) +DS::Result +runcpp2::SetupDependenciesIfNeeded( const runcpp2::Data::Profile& profile, + const ghc::filesystem::path& buildDir, + const Data::ScriptInfo& scriptInfo, + std::vector& availableDependencies, + const std::vector& dependenciesLocalCopiesPaths, + const std::vector& dependenciesSourcePaths, + const int maxThreads) { ssLOG_FUNC_INFO(); //If the script info is not populated (i.e. empty script info), don't do anything if(!scriptInfo.Populated) - return true; + return {}; std::vector prePolulatedDependencies; //Clone/copy the dependencies if needed - if(!PopulateLocalDependencies( availableDependencies, - dependenciesLocalCopiesPaths, - dependenciesSourcePaths, - buildDir, - prePolulatedDependencies)) - { - return false; - } + PopulateLocalDependencies( availableDependencies, + dependenciesLocalCopiesPaths, + dependenciesSourcePaths, + buildDir, + prePolulatedDependencies).DS_TRY(); - if(!PopulateAbsoluteIncludePaths(availableDependencies, dependenciesLocalCopiesPaths)) - return false; + PopulateAbsoluteIncludePaths(availableDependencies, dependenciesLocalCopiesPaths).DS_TRY(); #if RUNCPP2_USE_PARALLEL_FOR_DEP - std::vector> actions; + std::vector>> actions; std::vector finished; //Cache logs for worker threads @@ -592,25 +573,33 @@ bool runcpp2::SetupDependenciesIfNeeded(const runcpp2::Data::Profile& profile, std::async ( std::launch::async, - [i, &profile, &availableDependencies, &dependenciesLocalCopiesPaths, logLevel]() + [ + i, + &profile, + &availableDependencies, + &dependenciesLocalCopiesPaths, + logLevel + ]() -> DS::Result { ssLOG_SET_CURRENT_THREAD_TARGET_LEVEL(logLevel); #endif - ssLOG_INFO("Running setup commands for " << availableDependencies.at(i)->Name); - if(!RunDependenciesSteps( profile, + DS::Result depResult = + RunDependenciesSteps( profile, availableDependencies.at(i)->Setup, dependenciesLocalCopiesPaths.at(i), true, - false)) + false); + if(!depResult.HasValue()) { - ssLOG_ERROR("Failed to setup dependency " << - availableDependencies.at(i)->Name); - return false; + depResult.Error().Message += "\nFailed to setup dependency " + + availableDependencies.at(i)->Name; + DS_APPEND_TRACE(depResult.Error()); + return depResult; } #if RUNCPP2_USE_PARALLEL_FOR_DEP - return true; + return {}; } ) ); @@ -633,19 +622,20 @@ bool runcpp2::SetupDependenciesIfNeeded(const runcpp2::Data::Profile& profile, if(!actions.at(j).valid()) { - ssLOG_ERROR("Failed to construct actions for setup"); ssLOG_OUTPUT_ALL_CACHE_GROUPED(); - return false; + return DS_ERROR_MSG("Failed to construct actions for setup"); } std::future_status actionStatus = actions.at(j).wait_until(deadline); if(actionStatus == std::future_status::ready) { - if(!actions.at(j).get()) + DS::Result actionResult = actions.at(j).get(); + if(!actionResult.HasValue()) { - ssLOG_ERROR("Setup failed for dependencies"); ssLOG_OUTPUT_ALL_CACHE_GROUPED(); - return false; + actionResult.Error().Message += "\nSetup failed for dependencies"; + DS_APPEND_TRACE(actionResult.Error()); + return actionResult; } finished.at(j) = true; } @@ -667,20 +657,21 @@ bool runcpp2::SetupDependenciesIfNeeded(const runcpp2::Data::Profile& profile, } ssLOG_OUTPUT_ALL_CACHE_GROUPED(); - return true; + return {}; } -bool runcpp2::BuildDependencies(const runcpp2::Data::Profile& profile, - const Data::ScriptInfo& scriptInfo, - const std::vector& availableDependencies, - const std::vector& dependenciesLocalCopiesPaths, - const int maxThreads) +DS::Result +runcpp2::BuildDependencies( const runcpp2::Data::Profile& profile, + const Data::ScriptInfo& scriptInfo, + const std::vector& availableDependencies, + const std::vector& dependenciesLocalCopiesPaths, + const int maxThreads) { ssLOG_FUNC_INFO(); //If the script info is not populated (i.e. empty script info), don't do anything if(!scriptInfo.Populated) - return true; + return {}; #if RUNCPP2_USE_PARALLEL_FOR_DEP std::vector> actions; @@ -702,30 +693,38 @@ bool runcpp2::BuildDependencies(const runcpp2::Data::Profile& profile, std::async ( std::launch::async, - [i, &profile, &availableDependencies, &dependenciesLocalCopiesPaths, logLevel]() + [ + i, + &profile, + &availableDependencies, + &dependenciesLocalCopiesPaths, + logLevel + ]() -> DS::Result { ssLOG_SET_CURRENT_THREAD_TARGET_LEVEL(logLevel); #endif - - if(!RunDependenciesSteps( profile, + DS::Result depResult = + RunDependenciesSteps( profile, availableDependencies.at(i)->Build, dependenciesLocalCopiesPaths.at(i), true, - false)) + false); + if(!depResult.HasValue()) { - ssLOG_ERROR("Failed to build dependency " << availableDependencies.at(i)->Name); - return false; + depResult.Error().Message += "\nFailed to build dependency " + + availableDependencies.at(i)->Name; + DS_APPEND_TRACE(depResult.Error()); + return depResult; } - #if RUNCPP2_USE_PARALLEL_FOR_DEP - return true; + return {}; } ) ); finished.emplace_back(false); - //Evaluate the setup results for each batch + //Evaluate the build results for each batch if(actions.size() >= maxThreads || i == availableDependencies.size() - 1) { bool needsWaiting = false; @@ -741,19 +740,20 @@ bool runcpp2::BuildDependencies(const runcpp2::Data::Profile& profile, if(!actions.at(j).valid()) { - ssLOG_ERROR("Failed to construct actions for building dependencies"); ssLOG_OUTPUT_ALL_CACHE_GROUPED(); - return false; + return DS_ERROR_MSG("Failed to construct actions for building dependencies"); } std::future_status actionStatus = actions.at(j).wait_until(deadline); if(actionStatus == std::future_status::ready) { - if(!actions.at(j).get()) + DS::Result actionResult = actions.at(j).get(); + if(!actionResult.HasValue()) { - ssLOG_ERROR("Build failed for dependencies"); ssLOG_OUTPUT_ALL_CACHE_GROUPED(); - return false; + actionResult.Error().Message += "\nBuild failed for dependencies"; + DS_APPEND_TRACE(actionResult.Error()); + return actionResult; } finished.at(j) = true; } @@ -774,17 +774,16 @@ bool runcpp2::BuildDependencies(const runcpp2::Data::Profile& profile, } ssLOG_OUTPUT_ALL_CACHE_GROUPED(); - return true; + return {}; } -bool runcpp2::GatherDependenciesBinaries( const std::vector& - availableDependencies, - const std::vector& dependenciesCopiesPaths, - const Data::Profile& profile, - std::vector& outBinariesPaths) +DS::Result +runcpp2::GatherDependenciesBinaries(const std::vector& availableDependencies, + const std::vector& dependenciesCopiesPaths, + const Data::Profile& profile, + std::vector& outBinariesPaths) { ssLOG_FUNC_DEBUG(); - std::unordered_set binariesPathsSet; for(int i = 0; i < outBinariesPaths.size(); ++i) @@ -799,9 +798,8 @@ bool runcpp2::GatherDependenciesBinaries( const std::vector dependenciesCopiesPaths.size()) { - ssLOG_ERROR("The amount of available dependencies do not match" << - " the amount of dependencies copies paths"); - return false; + return DS_ERROR_MSG("The amount of available dependencies do not match" + " the amount of dependencies copies paths"); } int nonLinkFilesCount = 0; @@ -844,13 +842,9 @@ bool runcpp2::GatherDependenciesBinaries( const std::vectorName << - " is missing for the current platform"); - return false; + return DS_ERROR_MSG("Link properties for dependency " + availableDependencies.at(i)->Name + + " is missing for the current platform"); } const Data::DependencyLinkProperty& linkProperty = @@ -964,10 +957,7 @@ bool runcpp2::GatherDependenciesBinaries( const std::vector runcpp2::HandleImport( Data::DependencyInfo& dependency, + const ghc::filesystem::path& basePath) { ssLOG_FUNC_DEBUG(); if(dependency.Source.ImportPath.empty()) - return true; + return {}; const std::string fullPath = (basePath / dependency.Source.ImportPath).string(); std::error_code ec; if(!ghc::filesystem::exists(fullPath, ec)) - { - ssLOG_ERROR("Import file not found: " << fullPath); - return false; - } + return DS_ERROR_MSG("Import file not found: " + fullPath); if(ghc::filesystem::is_directory(fullPath)) - { - ssLOG_ERROR("Import path is a directory: " << fullPath); - return false; - } + return DS_ERROR_MSG("Import path is a directory: " + fullPath); //Parse the YAML file YAML::ResourceHandle resource; @@ -1026,23 +1011,16 @@ bool runcpp2::HandleImport(Data::DependencyInfo& dependency, const ghc::filesyst { std::ifstream file(fullPath); if(!file.is_open()) - { - ssLOG_ERROR("Failed to open import file: " << fullPath); - return false; - } + return DS_ERROR_MSG("Failed to open import file: " + fullPath); + std::stringstream buffer; buffer << file.rdbuf(); content = buffer.str(); } - rootNodes = YAML::ParseYAML(content, resource).DS_TRY_ACT(ssLOG_ERROR("Failed"); return false); + rootNodes = YAML::ParseYAML(content, resource).DS_TRY(); DEFER { YAML::FreeYAMLResource(resource); }; - - if(rootNodes.empty()) - { - ssLOG_ERROR("rootNodes.empty()"); - return false; - } + DS_ASSERT_FALSE(rootNodes.empty()); //Store the imported sources as copies for traciblity if needed std::vector> previouslyImportedSources; @@ -1063,7 +1041,7 @@ bool runcpp2::HandleImport(Data::DependencyInfo& dependency, const ghc::filesyst for(int i = 0; i < rootNodes.size(); ++i) { - YAML::ResolveAnchors(rootNodes[i]).DS_TRY_ACT(ssLOG_ERROR("Failed"); return false); + YAML::ResolveAnchors(rootNodes[i]).DS_TRY(); //Parse the imported dependency if(!dependency.ParseYAML_Node(rootNodes[i])) @@ -1072,32 +1050,30 @@ bool runcpp2::HandleImport(Data::DependencyInfo& dependency, const ghc::filesyst if(i != rootNodes.size() - 1) continue; - ssLOG_ERROR("Failed to parse imported dependency: " << fullPath); + std::string errMsg = "Failed to parse imported dependency: " + fullPath; //Print the list of imported sources for(int j = 0; j < previouslyImportedSources.size(); ++j) { - ssLOG_ERROR("Imported source[" << j << "]: " << - previouslyImportedSources.at(j)->ImportPath.string()); + errMsg += "Imported source[" + DS_STR(j) + "]: " = + previouslyImportedSources.at(j)->ImportPath.string(); } - return false; + return DS_ERROR_MSG(errMsg); } dependency.Source.ImportedSources = previouslyImportedSources; - return true; + return {}; } - ssLOG_ERROR("This should never be reached"); - return false; + return DS_ERROR_MSG("This should never be reached"); } -bool runcpp2::ResolveImports( Data::ScriptInfo& scriptInfo, - const ghc::filesystem::path& scriptPath, - const ghc::filesystem::path& buildDir) +DS::Result runcpp2::ResolveImports( Data::ScriptInfo& scriptInfo, + const ghc::filesystem::path& scriptPath, + const ghc::filesystem::path& buildDir) { ssLOG_FUNC_INFO(); - INTERNAL_RUNCPP2_SAFE_START(); //For each dependency, check if import path exists for(int i = 0; i < scriptInfo.Dependencies.size(); ++i) @@ -1110,38 +1086,29 @@ bool runcpp2::ResolveImports( Data::ScriptInfo& scriptInfo, continue; if(!source.ImportPath.is_relative()) - { - ssLOG_ERROR("Import path is not relative: " << source.ImportPath.string()); - return false; - } + return DS_ERROR_MSG("Import path is not relative: " + source.ImportPath.string()); ghc::filesystem::path copyPath; ghc::filesystem::path sourcePath; - - if(!GetDependencyPath(dependency, scriptPath, buildDir, copyPath, sourcePath)) - return false; + GetDependencyPath(dependency, scriptPath, buildDir, copyPath, sourcePath).DS_TRY(); bool prePopulated = false; - if(!PopulateLocalDependency(dependency, copyPath, sourcePath, buildDir, prePopulated)) - return false; + PopulateLocalDependency(dependency, copyPath, sourcePath, buildDir, prePopulated).DS_TRY(); //Parse the import file - if(!HandleImport(dependency, copyPath)) - return false; + HandleImport(dependency, copyPath).DS_TRY(); //Check do we still have import path in the dependency. If so, we need to parse it again if(!dependency.Source.ImportPath.empty()) --i; } - return true; - - INTERNAL_RUNCPP2_SAFE_CATCH_RETURN(false); + return {}; } -bool runcpp2::SyncLocalDependency( const Data::DependencyInfo& dependency, - const ghc::filesystem::path& sourcePath, - const ghc::filesystem::path& copyPath) +DS::Result runcpp2::SyncLocalDependency( const Data::DependencyInfo& dependency, + const ghc::filesystem::path& sourcePath, + const ghc::filesystem::path& copyPath) { ssLOG_FUNC_DEBUG(); std::error_code ec; @@ -1151,24 +1118,18 @@ bool runcpp2::SyncLocalDependency( const Data::DependencyInfo& dependency, if(!local) { ssLOG_DEBUG("Not a local dependency, skipping sync"); - return true; + return {}; } //Fail if source path doesn't exist if(!ghc::filesystem::exists(sourcePath, ec)) - { - ssLOG_ERROR("Source path does not exist: " << sourcePath.string()); - return false; - } + return DS_ERROR_MSG("Source path does not exist: " + sourcePath.string()); //Create target directory if it doesn't exist if(!ghc::filesystem::exists(copyPath, ec)) { if(!ghc::filesystem::create_directory(copyPath, ec)) - { - ssLOG_ERROR("Failed to create directory " << copyPath.string() << ": " << ec.message()); - return false; - } + return DS_ERROR_MSG("Failed to create directory " + copyPath.string() + ": " + ec.message()); } //Get list of files in source @@ -1248,10 +1209,7 @@ bool runcpp2::SyncLocalDependency( const Data::DependencyInfo& dependency, } if(ec) - { - ssLOG_ERROR("Failed to update target: " << ec.message()); - return false; - } + return DS_ERROR_MSG("Failed to update target: " + ec.message()); } sourceFiles.erase(targetPath.filename().string()); } @@ -1303,30 +1261,25 @@ bool runcpp2::SyncLocalDependency( const Data::DependencyInfo& dependency, } if(ec) - { - ssLOG_ERROR("Failed to add new file: " << ec.message()); - return false; - } + return DS_ERROR_MSG("Failed to add new file: " + ec.message()); } - return true; + return {}; } -bool runcpp2::SyncLocalDependencies(const std::vector& dependencies, - const std::vector& dependenciesSourcePaths, - const std::vector& dependenciesCopiesPaths) +DS::Result +runcpp2::SyncLocalDependencies( const std::vector& dependencies, + const std::vector& dependenciesSourcePaths, + const std::vector& dependenciesCopiesPaths) { ssLOG_FUNC_DEBUG(); for(size_t i = 0; i < dependencies.size(); ++i) { - if(!SyncLocalDependency(*dependencies.at(i), - ghc::filesystem::path(dependenciesSourcePaths.at(i)), - ghc::filesystem::path(dependenciesCopiesPaths.at(i)))) - { - return false; - } + SyncLocalDependency(*dependencies.at(i), + ghc::filesystem::path(dependenciesSourcePaths.at(i)), + ghc::filesystem::path(dependenciesCopiesPaths.at(i))).DS_TRY(); } - return true; + return {}; } diff --git a/Src/runcpp2/PipelineSteps.cpp b/Src/runcpp2/PipelineSteps.cpp index 2ad6faf..1df58c3 100644 --- a/Src/runcpp2/PipelineSteps.cpp +++ b/Src/runcpp2/PipelineSteps.cpp @@ -327,6 +327,7 @@ runcpp2::ParseAndValidateScriptInfo(const ghc::filesystem::path& absoluteScriptP outScriptInfo.LastWriteTime = ghc::filesystem::last_write_time(dedicatedYamlLoc, e); if(e) { + ssLOG_ERROR(e.message()); ssLOG_ERROR("Failed to get last write time for: " << dedicatedYamlLoc); return PipelineResult::INVALID_SCRIPT_INFO; } @@ -342,13 +343,14 @@ runcpp2::ParseAndValidateScriptInfo(const ghc::filesystem::path& absoluteScriptP outScriptInfo.LastWriteTime = ghc::filesystem::last_write_time(absoluteScriptPath, e); if(e) { + ssLOG_ERROR(e.message()); ssLOG_ERROR("Failed to get last write time for: " << absoluteScriptPath); return PipelineResult::INVALID_SCRIPT_INFO; } inputFile.open(absoluteScriptPath); - if (!inputFile) + if(!inputFile) { ssLOG_ERROR("Failed to open file: " << absoluteScriptPath); return PipelineResult::INVALID_SCRIPT_PATH; @@ -366,12 +368,10 @@ runcpp2::ParseAndValidateScriptInfo(const ghc::filesystem::path& absoluteScriptP } //Try to parse the runcpp2 info - if(!ParseScriptInfo(parsableInfo, outScriptInfo)) - { - ssLOG_ERROR("Failed to parse info"); - ssLOG_ERROR("Content trying to parse: " << "\n" << parsableInfo); - return PipelineResult::INVALID_SCRIPT_INFO; - } + ParseScriptInfo(parsableInfo, outScriptInfo) + .DS_TRY_ACT(ssLOG_ERROR("Failed to parse info: " << DS_TMP_ERROR.ToString()); + ssLOG_ERROR("Content trying to parse: " << "\n" << parsableInfo); + return PipelineResult::INVALID_SCRIPT_INFO); if(!parsableInfo.empty()) { @@ -520,11 +520,10 @@ runcpp2::ResolveScriptImports( Data::ScriptInfo& scriptInfo, INTERNAL_RUNCPP2_SAFE_START(); //Resolve all the script info imports first before evaluating it - if(!ResolveImports(scriptInfo, scriptPath, buildDir)) - { - ssLOG_ERROR("Failed to resolve imports"); - return PipelineResult::UNEXPECTED_FAILURE; - } + ResolveImports(scriptInfo, scriptPath, buildDir) + .DS_TRY_ACT(ssLOG_ERROR("Failed to resolve imports"); + ssLOG_ERROR(DS_TMP_ERROR.ToString()); + return PipelineResult::UNEXPECTED_FAILURE); return PipelineResult::SUCCESS; @@ -583,7 +582,7 @@ runcpp2::CheckScriptInfoChanges(const ghc::filesystem::path& buildDir, do { - if(!ParseScriptInfo(lastScriptInfoBuffer.str(), lastScriptInfoFromDisk)) + if(!ParseScriptInfo(lastScriptInfoBuffer.str(), lastScriptInfoFromDisk).HasValue()) break; //Resolve imports for last script info @@ -696,15 +695,14 @@ runcpp2::ProcessDependencies( Data::ScriptInfo& scriptInfo, std::vector dependenciesLocalCopiesPaths; std::vector dependenciesSourcePaths; - if(!GetDependenciesPaths( outAvailableDependencies, - dependenciesLocalCopiesPaths, - dependenciesSourcePaths, - absoluteScriptPath, - buildDir)) - { - ssLOG_ERROR("Failed to get dependencies paths"); - return PipelineResult::DEPENDENCIES_FAILED; - } + GetDependenciesPaths( outAvailableDependencies, + dependenciesLocalCopiesPaths, + dependenciesSourcePaths, + absoluteScriptPath, + buildDir) + .DS_TRY_ACT(ssLOG_ERROR("Failed to get dependencies paths"); + ssLOG_ERROR(DS_TMP_ERROR.ToString()); + return PipelineResult::DEPENDENCIES_FAILED); if(currentOptions.count(CmdOptions::RESET_DEPENDENCIES) > 0 || !changedDependencies.empty()) { @@ -723,65 +721,63 @@ runcpp2::ProcessDependencies( Data::ScriptInfo& scriptInfo, depsToReset += "," + changedDependencies[i]; } - if(!CleanupDependencies(profile, - scriptInfo, - outAvailableDependencies, - dependenciesLocalCopiesPaths, - currentOptions.count(CmdOptions::RESET_DEPENDENCIES) > 0 ? - currentOptions.at(CmdOptions::RESET_DEPENDENCIES) : - depsToReset)) - { - ssLOG_ERROR("Failed to cleanup dependencies"); - return PipelineResult::DEPENDENCIES_FAILED; - } + CleanupDependencies(profile, + scriptInfo, + outAvailableDependencies, + dependenciesLocalCopiesPaths, + currentOptions.count(CmdOptions::RESET_DEPENDENCIES) > 0 ? + currentOptions.at(CmdOptions::RESET_DEPENDENCIES) : + depsToReset) + .DS_TRY_ACT(ssLOG_ERROR("Failed to cleanup dependencies"); + ssLOG_ERROR(DS_TMP_ERROR.ToString()); + return PipelineResult::DEPENDENCIES_FAILED); } if(currentOptions.count(CmdOptions::RESET_DEPENDENCIES) > 0) return PipelineResult::SUCCESS; - if(!SetupDependenciesIfNeeded( profile, - buildDir, - scriptInfo, - outAvailableDependencies, - dependenciesLocalCopiesPaths, - dependenciesSourcePaths, - maxThreads)) - { - ssLOG_ERROR("Failed to setup script dependencies"); - return PipelineResult::DEPENDENCIES_FAILED; - } + SetupDependenciesIfNeeded( profile, + buildDir, + scriptInfo, + outAvailableDependencies, + dependenciesLocalCopiesPaths, + dependenciesSourcePaths, + maxThreads) + .DS_TRY_ACT(ssLOG_ERROR("Failed to setup script dependencies"); + ssLOG_ERROR(DS_TMP_ERROR.ToString()); + return PipelineResult::DEPENDENCIES_FAILED); //Sync local dependencies before building - if(!SyncLocalDependencies( outAvailableDependencies, - dependenciesSourcePaths, - dependenciesLocalCopiesPaths)) - { - ssLOG_ERROR("Failed to sync local dependencies"); - return PipelineResult::DEPENDENCIES_FAILED; - } + SyncLocalDependencies( outAvailableDependencies, + dependenciesSourcePaths, + dependenciesLocalCopiesPaths) + .DS_TRY_ACT(ssLOG_ERROR("Failed to sync local dependencies"); + ssLOG_ERROR(DS_TMP_ERROR.ToString()); + return PipelineResult::DEPENDENCIES_FAILED); if(currentOptions.count(CmdOptions::BUILD_SOURCE_ONLY) == 0) { - if(!BuildDependencies( profile, - scriptInfo, - outAvailableDependencies, - dependenciesLocalCopiesPaths, - maxThreads)) - { + BuildDependencies( profile, + scriptInfo, + outAvailableDependencies, + dependenciesLocalCopiesPaths, + maxThreads) + .DS_TRY_ACT + ( ssLOG_ERROR("Failed to build script dependencies. Maybe try resetting dependencies " "with \"-rd all\" and run again?"); - return PipelineResult::DEPENDENCIES_FAILED; - } + ssLOG_ERROR(DS_TMP_ERROR.ToString()); + return PipelineResult::DEPENDENCIES_FAILED + ); } - if(!GatherDependenciesBinaries( outAvailableDependencies, - dependenciesLocalCopiesPaths, - profile, - outGatheredBinariesPaths)) - { - ssLOG_ERROR("Failed to gather dependencies binaries"); - return PipelineResult::DEPENDENCIES_FAILED; - } + GatherDependenciesBinaries( outAvailableDependencies, + dependenciesLocalCopiesPaths, + profile, + outGatheredBinariesPaths) + .DS_TRY_ACT(ssLOG_ERROR("Failed to gather dependencies binaries"); + ssLOG_ERROR(DS_TMP_ERROR.ToString()); + return PipelineResult::DEPENDENCIES_FAILED); return PipelineResult::SUCCESS; diff --git a/Src/runcpp2/main.cpp b/Src/runcpp2/main.cpp index c64801c..73ca4a5 100644 --- a/Src/runcpp2/main.cpp +++ b/Src/runcpp2/main.cpp @@ -6,6 +6,8 @@ #include "ghc/filesystem.hpp" +#define OUTPUT_ERROR() ssLOG_ERROR(DS_TMP_ERROR.ToString()); + //TODO: Merge long and short options into a single structure int ParseArgs( const std::unordered_map& longOptionsMap, const std::unordered_map& shortOptionsMap, @@ -335,9 +337,10 @@ int main(int argc, char* argv[]) INTERNAL_RUNCPP2_SAFE_START(); //Show user config path + std::string configFilePath = runcpp2::GetConfigFilePath().DS_TRY_ACT(OUTPUT_ERROR(); return 1); if(currentOptions.count(runcpp2::CmdOptions::SHOW_USER_CONFIG)) { - ssLOG_BASE(runcpp2::GetConfigFilePath()); + ssLOG_BASE(configFilePath); return 0; } @@ -360,11 +363,7 @@ int main(int argc, char* argv[]) if(currentOptions.count(runcpp2::CmdOptions::RESET_USER_CONFIG)) { ssLOG_INFO("Resetting user config"); - if(!runcpp2::WriteDefaultConfigs(runcpp2::GetConfigFilePath(), true, true)) - { - ssLOG_ERROR("Failed reset user config"); - return -1; - } + runcpp2::WriteDefaultConfigs(configFilePath, true, true).DS_TRY_ACT(OUTPUT_ERROR(); return -1); ssLOG_BASE("User config reset successful"); return 0; } @@ -389,11 +388,9 @@ int main(int argc, char* argv[]) if(currentOptions.count(runcpp2::CmdOptions::CONFIG_FILE)) configPath = currentOptions.at(runcpp2::CmdOptions::CONFIG_FILE); - if(!runcpp2::ReadUserConfig(profiles, preferredProfile, configPath)) - { - ssLOG_ERROR("Failed read user config"); - return -1; - } + runcpp2::ReadUserConfig(profiles, + preferredProfile, + configPath).DS_TRY_ACT(OUTPUT_ERROR(); return -1); ssLOG_DEBUG("\nprofiles:"); for(int i = 0; i < profiles.size(); ++i) diff --git a/Src/runcpp2/runcpp2.cpp b/Src/runcpp2/runcpp2.cpp index d9c0c06..6ce122c 100644 --- a/Src/runcpp2/runcpp2.cpp +++ b/Src/runcpp2/runcpp2.cpp @@ -320,7 +320,10 @@ runcpp2::CheckSourcesNeedUpdate( const std::string& scriptPath, } //Initialize BuildsManager and IncludeManager - ghc::filesystem::path configDir = GetConfigFilePath(); + ghc::filesystem::path configDir = + GetConfigFilePath().DS_TRY_ACT( ssLOG_ERROR(DS_TMP_ERROR.ToString()); + return PipelineResult::INVALID_CONFIG_PATH); + configDir = configDir.parent_path(); if(!ghc::filesystem::is_directory(configDir, e)) { @@ -420,7 +423,9 @@ runcpp2::StartPipeline( const std::string& scriptPath, if(result != PipelineResult::SUCCESS) return result; - ghc::filesystem::path configDir = GetConfigFilePath(); + ghc::filesystem::path configDir = + GetConfigFilePath().DS_TRY_ACT( ssLOG_ERROR(DS_TMP_ERROR.ToString()); + PipelineResult::INVALID_CONFIG_PATH); ghc::filesystem::path buildDir; //Parse script info From a27a6b16eef148a1368d0fce79755c4bce8526cf Mon Sep 17 00:00:00 2001 From: anon Date: Thu, 22 Jan 2026 17:37:02 +0000 Subject: [PATCH 3/3] WIP --- Include/runcpp2/DependenciesHelper.hpp | 1 + Include/runcpp2/PipelineSteps.hpp | 21 ++- Src/runcpp2/PipelineSteps.cpp | 138 +++++++++---------- Src/runcpp2/runcpp2.cpp | 175 +++++++++++-------------- 4 files changed, 153 insertions(+), 182 deletions(-) diff --git a/Include/runcpp2/DependenciesHelper.hpp b/Include/runcpp2/DependenciesHelper.hpp index 6ef452d..eb37506 100644 --- a/Include/runcpp2/DependenciesHelper.hpp +++ b/Include/runcpp2/DependenciesHelper.hpp @@ -9,6 +9,7 @@ #define NOMINMAX 1 #endif +#include "DSResult/DSResult.hpp" #include "ghc/filesystem.hpp" #include diff --git a/Include/runcpp2/PipelineSteps.hpp b/Include/runcpp2/PipelineSteps.hpp index 30f0247..10daa43 100644 --- a/Include/runcpp2/PipelineSteps.hpp +++ b/Include/runcpp2/PipelineSteps.hpp @@ -21,27 +21,26 @@ namespace runcpp2 { - bool CopyFiles( const ghc::filesystem::path& destDir, - const std::vector& filePaths, - std::vector& outCopiedPaths); + DS::Result CopyFiles( const ghc::filesystem::path& destDir, + const std::vector& filePaths, + std::vector& outCopiedPaths); - PipelineResult RunProfileCommands( const Data::ProfilesCommands* commands, + DS::Result RunProfileCommands(const Data::ProfilesCommands* commands, const Data::Profile& profile, const std::string& workingDir, const std::string& commandType); - PipelineResult ValidateInputs( const std::string& scriptPath, + DS::Result ValidateInputs(const std::string& scriptPath, const std::vector& profiles, ghc::filesystem::path& outAbsoluteScriptPath, ghc::filesystem::path& outScriptDirectory, std::string& outScriptName); - PipelineResult - ParseAndValidateScriptInfo( const ghc::filesystem::path& absoluteScriptPath, - const ghc::filesystem::path& scriptDirectory, - const std::string& scriptName, - const bool buildExecutable, - Data::ScriptInfo& outScriptInfo); + DS::Result ParseAndValidateScriptInfo(const ghc::filesystem::path& absoluteScriptPath, + const ghc::filesystem::path& scriptDirectory, + const std::string& scriptName, + const bool buildExecutable, + Data::ScriptInfo& outScriptInfo); PipelineResult HandleCleanup( const Data::ScriptInfo& scriptInfo, const Data::Profile& profile, diff --git a/Src/runcpp2/PipelineSteps.cpp b/Src/runcpp2/PipelineSteps.cpp index 1df58c3..466a875 100644 --- a/Src/runcpp2/PipelineSteps.cpp +++ b/Src/runcpp2/PipelineSteps.cpp @@ -178,12 +178,11 @@ namespace } } -bool runcpp2::CopyFiles(const ghc::filesystem::path& destDir, - const std::vector& filePaths, - std::vector& outCopiedPaths) +DS::Result runcpp2::CopyFiles(const ghc::filesystem::path& destDir, + const std::vector& filePaths, + std::vector& outCopiedPaths) { ssLOG_FUNC_INFO(); - INTERNAL_RUNCPP2_SAFE_START(); std::error_code e; for (const std::string& srcPath : filePaths) @@ -199,35 +198,28 @@ bool runcpp2::CopyFiles(const ghc::filesystem::path& destDir, if(e) { - ssLOG_ERROR("Failed to copy file from " << srcPath << - " to " << destPath.string()); - ssLOG_ERROR("Error: " << e.message()); - return false; + std::string errorMsg = DS_STR("Failed to copy file from ") + srcPath + " to " + + destPath.string() + "\nError: " + e.message(); + return DS_ERROR_MSG(errorMsg); } ssLOG_INFO("Copied from " << srcPath << " to " << destPath.string()); outCopiedPaths.push_back(ProcessPath(destPath)); } else - { - ssLOG_ERROR("File to copy not found: " << srcPath); - return false; - } + return DS_ERROR_MSG("File to copy not found: " + srcPath); } - return true; - - INTERNAL_RUNCPP2_SAFE_CATCH_RETURN(false); + return {}; } -runcpp2::PipelineResult -runcpp2::RunProfileCommands(const Data::ProfilesCommands* commands, - const Data::Profile& profile, - const std::string& workingDir, - const std::string& commandType) + +DS::Result runcpp2::RunProfileCommands( const Data::ProfilesCommands* commands, + const Data::Profile& profile, + const std::string& workingDir, + const std::string& commandType) { ssLOG_FUNC_INFO(); - INTERNAL_RUNCPP2_SAFE_START(); if(commands != nullptr) { @@ -243,11 +235,11 @@ runcpp2::RunProfileCommands(const Data::ProfilesCommands* commands, if(!runcpp2::RunCommand(cmd, true, workingDir, output, returnCode)) { - ssLOG_ERROR(commandType << " command failed: " << cmd << - " with return code " << returnCode); - ssLOG_ERROR("Was trying to run: " << cmd); - ssLOG_ERROR("Output: \n" << output); - return PipelineResult::UNEXPECTED_FAILURE; + std::string errorMsg = commandType + " command failed: " + cmd + + " with return code " + DS_STR(returnCode) + "\n"; + errorMsg += "Was trying to run: " + cmd + "\n"; + errorMsg += "Output: \n" + output; + return DS_ERROR_MSG_EC(errorMsg, (int)PipelineResult::UNEXPECTED_FAILURE); } ssLOG_INFO(commandType << " command ran: \n" << cmd); @@ -255,38 +247,33 @@ runcpp2::RunProfileCommands(const Data::ProfilesCommands* commands, } } } - return PipelineResult::SUCCESS; - INTERNAL_RUNCPP2_SAFE_CATCH_RETURN(PipelineResult::UNEXPECTED_FAILURE); + return {}; } -runcpp2::PipelineResult runcpp2::ValidateInputs(const std::string& scriptPath, - const std::vector& profiles, - ghc::filesystem::path& outAbsoluteScriptPath, - ghc::filesystem::path& outScriptDirectory, - std::string& outScriptName) +DS::Result runcpp2::ValidateInputs( const std::string& scriptPath, + const std::vector& profiles, + ghc::filesystem::path& outAbsoluteScriptPath, + ghc::filesystem::path& outScriptDirectory, + std::string& outScriptName) { ssLOG_FUNC_INFO(); - INTERNAL_RUNCPP2_SAFE_START(); if(profiles.empty()) - { - ssLOG_ERROR("No compiler profiles found"); - return PipelineResult::EMPTY_PROFILES; - } + return DS_ERROR_MSG_EC("No compiler profiles found", (int)PipelineResult::EMPTY_PROFILES); //Check if input file exists std::error_code _; if(!ghc::filesystem::exists(scriptPath, _)) { - ssLOG_ERROR("File does not exist: " << scriptPath); - return PipelineResult::INVALID_SCRIPT_PATH; + return DS_ERROR_MSG_EC( "File does not exist: " + scriptPath, + (int)PipelineResult::INVALID_SCRIPT_PATH); } if(ghc::filesystem::is_directory(scriptPath, _)) { - ssLOG_ERROR("The input file must not be a directory: " << scriptPath); - return PipelineResult::INVALID_SCRIPT_PATH; + return DS_ERROR_MSG_EC( "The input file must not be a directory: " + scriptPath, + (int)PipelineResult::INVALID_SCRIPT_PATH); } outAbsoluteScriptPath = ghc::filesystem::absolute(ghc::filesystem::canonical(scriptPath, _)); @@ -299,20 +286,16 @@ runcpp2::PipelineResult runcpp2::ValidateInputs(const std::string& scriptPath, ssLOG_DEBUG("scriptName: " << outScriptName); ssLOG_DEBUG("is_directory: " << ghc::filesystem::is_directory(outScriptDirectory)); - return PipelineResult::SUCCESS; - - INTERNAL_RUNCPP2_SAFE_CATCH_RETURN(PipelineResult::UNEXPECTED_FAILURE); + return {}; } -runcpp2::PipelineResult -runcpp2::ParseAndValidateScriptInfo(const ghc::filesystem::path& absoluteScriptPath, - const ghc::filesystem::path& scriptDirectory, - const std::string& scriptName, - const bool buildExecutable, - Data::ScriptInfo& outScriptInfo) +DS::Result runcpp2::ParseAndValidateScriptInfo( const ghc::filesystem::path& absoluteScriptPath, + const ghc::filesystem::path& scriptDirectory, + const std::string& scriptName, + const bool buildExecutable, + Data::ScriptInfo& outScriptInfo) { ssLOG_FUNC_INFO(); - INTERNAL_RUNCPP2_SAFE_START(); //Check if there's script info as yaml file instead std::error_code e; @@ -327,9 +310,9 @@ runcpp2::ParseAndValidateScriptInfo(const ghc::filesystem::path& absoluteScriptP outScriptInfo.LastWriteTime = ghc::filesystem::last_write_time(dedicatedYamlLoc, e); if(e) { - ssLOG_ERROR(e.message()); - ssLOG_ERROR("Failed to get last write time for: " << dedicatedYamlLoc); - return PipelineResult::INVALID_SCRIPT_INFO; + std::string errorMsg = e.message(); + errorMsg += "\nFailed to get last write time for: " + dedicatedYamlLoc.string(); + return DS_ERROR_MSG_EC(errorMsg, (int)PipelineResult::INVALID_SCRIPT_INFO); } inputFile.open(dedicatedYamlLoc); @@ -343,17 +326,17 @@ runcpp2::ParseAndValidateScriptInfo(const ghc::filesystem::path& absoluteScriptP outScriptInfo.LastWriteTime = ghc::filesystem::last_write_time(absoluteScriptPath, e); if(e) { - ssLOG_ERROR(e.message()); - ssLOG_ERROR("Failed to get last write time for: " << absoluteScriptPath); - return PipelineResult::INVALID_SCRIPT_INFO; + std::string errorMsg = e.message(); + errorMsg += "\nFailed to get last write time for: " + absoluteScriptPath.string(); + return DS_ERROR_MSG_EC(errorMsg, (int)PipelineResult::INVALID_SCRIPT_INFO); } inputFile.open(absoluteScriptPath); if(!inputFile) { - ssLOG_ERROR("Failed to open file: " << absoluteScriptPath); - return PipelineResult::INVALID_SCRIPT_PATH; + return DS_ERROR_MSG_EC( "Failed to open file: " + absoluteScriptPath.string(), + (int)PipelineResult::INVALID_SCRIPT_PATH); } std::stringstream buffer; @@ -362,16 +345,18 @@ runcpp2::ParseAndValidateScriptInfo(const ghc::filesystem::path& absoluteScriptP if(!GetParsableInfo(source, parsableInfo)) { - ssLOG_ERROR("An error has been encountered when parsing info: " << absoluteScriptPath); - return PipelineResult::INVALID_SCRIPT_INFO; + return DS_ERROR_MSG_EC( "An error has been encountered when parsing info: " + + absoluteScriptPath.string(), + (int)PipelineResult::INVALID_SCRIPT_INFO); } } //Try to parse the runcpp2 info ParseScriptInfo(parsableInfo, outScriptInfo) - .DS_TRY_ACT(ssLOG_ERROR("Failed to parse info: " << DS_TMP_ERROR.ToString()); - ssLOG_ERROR("Content trying to parse: " << "\n" << parsableInfo); - return PipelineResult::INVALID_SCRIPT_INFO); + .DS_TRY_ACT(DS_APPEND_TRACE(DS_TMP_ERROR); + DS_TMP_ERROR.Message += "\nContent trying to parse: \n" + parsableInfo; + DS_TMP_ERROR.ErrorCode = (int)PipelineResult::INVALID_SCRIPT_INFO; + return DS::Error(DS_TMP_ERROR)); if(!parsableInfo.empty()) { @@ -388,9 +373,7 @@ runcpp2::ParseAndValidateScriptInfo(const ghc::filesystem::path& absoluteScriptP Data::BuildType::INTERNAL_EXECUTABLE_SHARED; } - return PipelineResult::SUCCESS; - - INTERNAL_RUNCPP2_SAFE_CATCH_RETURN(PipelineResult::UNEXPECTED_FAILURE); + return {}; } runcpp2::PipelineResult runcpp2::HandleCleanup( const Data::ScriptInfo& scriptInfo, @@ -558,12 +541,9 @@ runcpp2::CheckScriptInfoChanges(const ghc::filesystem::path& buildDir, if(setupCommands != nullptr) { - PipelineResult result = RunProfileCommands( setupCommands, - profile, - scriptDirectory.string(), - "Setup"); - if(result != PipelineResult::SUCCESS) - return result; + RunProfileCommands(setupCommands, profile, scriptDirectory.string(), "Setup") + .DS_TRY_ACT(ssLOG_ERROR(DS_TMP_ERROR.ToString()); + return (PipelineResult)DS_TMP_ERROR.ErrorCode); } } @@ -845,7 +825,10 @@ runcpp2::PipelineResult runcpp2::HandlePreBuild(const Data::ScriptInfo& scriptIn const Data::ProfilesCommands* preBuildCommands = runcpp2::GetValueFromPlatformMap(scriptInfo.PreBuild); - return RunProfileCommands(preBuildCommands, profile, buildDir.string(), "PreBuild"); + RunProfileCommands(preBuildCommands, profile, buildDir.string(), "PreBuild") + .DS_TRY_ACT(ssLOG_ERROR(DS_TMP_ERROR.ToString()); + return (PipelineResult)DS_TMP_ERROR.ErrorCode); + return {}; } runcpp2::PipelineResult runcpp2::HandlePostBuild( const Data::ScriptInfo& scriptInfo, @@ -857,7 +840,10 @@ runcpp2::PipelineResult runcpp2::HandlePostBuild( const Data::ScriptInfo& scri const Data::ProfilesCommands* postBuildCommands = GetValueFromPlatformMap(scriptInfo.PostBuild); - return RunProfileCommands(postBuildCommands, profile, buildDir.string(), "PostBuild"); + RunProfileCommands(postBuildCommands, profile, buildDir.string(), "PostBuild") + .DS_TRY_ACT(ssLOG_ERROR(DS_TMP_ERROR.ToString()); + return (PipelineResult)DS_TMP_ERROR.ErrorCode); + return {}; } runcpp2::PipelineResult diff --git a/Src/runcpp2/runcpp2.cpp b/Src/runcpp2/runcpp2.cpp index 6ce122c..a15f779 100644 --- a/Src/runcpp2/runcpp2.cpp +++ b/Src/runcpp2/runcpp2.cpp @@ -6,6 +6,7 @@ #include "runcpp2/ConfigParsing.hpp" #include "runcpp2/PlatformUtil.hpp" #include "runcpp2/Data/BuildTypeHelper.hpp" + #include "ssLogger/ssLog.hpp" #include "ghc/filesystem.hpp" @@ -28,16 +29,16 @@ extern "C" const size_t DefaultScriptInfo_size; namespace { - bool HasCompiledCache( const ghc::filesystem::path& scriptPath, - const std::vector& sourceFiles, - const ghc::filesystem::path& buildDir, - const runcpp2::Data::Profile& currentProfile, - runcpp2::IncludeManager& includeManager, - std::vector& outHasCache, - std::vector& outCachedObjectsFiles, - ghc::filesystem::file_time_type& outFinalObjectWriteTime, - ghc::filesystem::file_time_type& outFinalSourceWriteTime, - ghc::filesystem::file_time_type& outFinalIncludeWriteTime) + DS::Result HasCompiledCache( const ghc::filesystem::path& scriptPath, + const std::vector& sourceFiles, + const ghc::filesystem::path& buildDir, + const runcpp2::Data::Profile& currentProfile, + runcpp2::IncludeManager& includeManager, + std::vector& outHasCache, + std::vector& outCachedObjectsFiles, + ghc::filesystem::file_time_type& outFinalObjectWriteTime, + ghc::filesystem::file_time_type& outFinalSourceWriteTime, + ghc::filesystem::file_time_type& outFinalIncludeWriteTime) { ssLOG_FUNC_INFO(); @@ -49,14 +50,12 @@ namespace const std::string* rawObjectExt = runcpp2::GetValueFromPlatformMap(currentProfile.FilesTypes.ObjectLinkFile.Extension); - if(rawObjectExt == nullptr) - return false; + DS_ASSERT_FALSE(rawObjectExt == nullptr); const std::string& objectExt = *rawObjectExt; outFinalObjectWriteTime = ghc::filesystem::file_time_type(); std::error_code e; - for(int i = 0; i < sourceFiles.size(); ++i) { ghc::filesystem::path relativeSourcePath = @@ -64,9 +63,10 @@ namespace if(e) { - ssLOG_ERROR("Failed to get relative path for " << sourceFiles.at(i).string()); - ssLOG_ERROR("Failed with error: " << e.message()); - return false; + std::string retMsg = DS_STR("Failed to get relative path for ") + + sourceFiles.at(i).string() + "\n"; + retMsg += DS_STR("Failed with error: ") + e.message(); + return DS_ERROR_MSG(retMsg); } ghc::filesystem::path currentObjectFilePath = buildDir / @@ -143,7 +143,7 @@ namespace } } - return true; + return {}; } bool HasOutputCache( const std::vector& sourceHasCache, @@ -287,13 +287,9 @@ runcpp2::CheckSourcesNeedUpdate( const std::string& scriptPath, ghc::filesystem::path scriptDirectory; std::string scriptName; - PipelineResult result = ValidateInputs( scriptPath, - profiles, - absoluteScriptPath, - scriptDirectory, - scriptName); - if(result != PipelineResult::SUCCESS) - return result; + ValidateInputs(scriptPath, profiles, absoluteScriptPath, scriptDirectory, scriptName) + .DS_TRY_ACT(ssLOG_ERROR(DS_TMP_ERROR.ToString()); + return (PipelineResult)DS_TMP_ERROR.ErrorCode); //First check if script info file has changed std::error_code e; @@ -336,12 +332,12 @@ runcpp2::CheckSourcesNeedUpdate( const std::string& scriptPath, IncludeManager includeManager; const bool useLocalBuildDir = currentOptions.count(CmdOptions::LOCAL) > 0; - result = InitializeBuildDirectory( configDir, - absoluteScriptPath, - useLocalBuildDir, - buildsManager, - buildDir, - includeManager); + PipelineResult result = InitializeBuildDirectory( configDir, + absoluteScriptPath, + useLocalBuildDir, + buildsManager, + buildDir, + includeManager); if(result != PipelineResult::SUCCESS) return result; @@ -366,20 +362,18 @@ runcpp2::CheckSourcesNeedUpdate( const std::string& scriptPath, ghc::filesystem::file_time_type finalSourceWriteTime; ghc::filesystem::file_time_type finalIncludeWriteTime; - if(!HasCompiledCache( absoluteScriptPath, - sourceFiles, - buildDir, - currentProfile, - includeManager, - sourceHasCache, - cachedObjectsFiles, - finalObjectWriteTime, - finalSourceWriteTime, - finalIncludeWriteTime)) - { - //TODO: Maybe add a pipeline result for this? - return PipelineResult::UNEXPECTED_FAILURE; - } + HasCompiledCache( absoluteScriptPath, + sourceFiles, + buildDir, + currentProfile, + includeManager, + sourceHasCache, + cachedObjectsFiles, + finalObjectWriteTime, + finalSourceWriteTime, + finalIncludeWriteTime).DS_TRY_ACT( ssLOG_ERROR(DS_TMP_ERROR.ToString()); + //TODO: Maybe add a pipeline result for this? + return PipelineResult::UNEXPECTED_FAILURE); if( finalSourceWriteTime > prevFinalSourceWriteTime || finalIncludeWriteTime > prevFinalIncludeWriteTime) @@ -414,14 +408,9 @@ runcpp2::StartPipeline( const std::string& scriptPath, ghc::filesystem::path absoluteScriptPath; ghc::filesystem::path scriptDirectory; std::string scriptName; - - PipelineResult result = ValidateInputs( scriptPath, - profiles, - absoluteScriptPath, - scriptDirectory, - scriptName); - if(result != PipelineResult::SUCCESS) - return result; + ValidateInputs(scriptPath, profiles, absoluteScriptPath, scriptDirectory, scriptName) + .DS_TRY_ACT(ssLOG_ERROR(DS_TMP_ERROR.ToString()); + return (PipelineResult)DS_TMP_ERROR.ErrorCode); ghc::filesystem::path configDir = GetConfigFilePath().DS_TRY_ACT( ssLOG_ERROR(DS_TMP_ERROR.ToString()); @@ -430,14 +419,13 @@ runcpp2::StartPipeline( const std::string& scriptPath, //Parse script info Data::ScriptInfo scriptInfo; - result = ParseAndValidateScriptInfo(absoluteScriptPath, - scriptDirectory, - scriptName, - currentOptions.count(CmdOptions::EXECUTABLE) > 0, - scriptInfo); - - if(result != PipelineResult::SUCCESS) - return result; + ParseAndValidateScriptInfo( absoluteScriptPath, + scriptDirectory, + scriptName, + currentOptions.count(CmdOptions::EXECUTABLE) > 0, + scriptInfo) + .DS_TRY_ACT(ssLOG_ERROR(DS_TMP_ERROR.ToString()); + return (PipelineResult)DS_TMP_ERROR.ErrorCode); //Parse and get the config directory { @@ -575,19 +563,21 @@ runcpp2::StartPipeline( const std::string& scriptPath, if(currentOptions.count(CmdOptions::RESET_CACHE) > 0 || recompileNeeded) sourceHasCache = std::vector(sourceFiles.size(), false); - else if(!HasCompiledCache( absoluteScriptPath, - sourceFiles, - buildDir, - profiles.at(profileIndex), - includeManager, - sourceHasCache, - cachedObjectsFiles, - finalObjectWriteTime, - outFinalSourceWriteTime, - outFinalIncludeWriteTime)) + else { - //TODO: Maybe add a pipeline result for this? - return PipelineResult::UNEXPECTED_FAILURE; + HasCompiledCache( absoluteScriptPath, + sourceFiles, + buildDir, + profiles.at(profileIndex), + includeManager, + sourceHasCache, + cachedObjectsFiles, + finalObjectWriteTime, + outFinalSourceWriteTime, + outFinalIncludeWriteTime) + .DS_TRY_ACT(ssLOG_ERROR(DS_TMP_ERROR.ToString()); + //TODO: Maybe add a pipeline result for this? + return PipelineResult::UNEXPECTED_FAILURE); } runcpp2::SourceIncludeMap sourcesIncludes; @@ -601,22 +591,18 @@ runcpp2::StartPipeline( const std::string& scriptPath, ssLOG_DEBUG("Updating include record for " << sourceFiles.at(i).string()); if(sourcesIncludes.count(sourceFiles.at(i)) == 0) { - ssLOG_WARNING( "Includes not gathered for " << - sourceFiles.at(i).string()); + ssLOG_WARNING("Includes not gathered for " << sourceFiles.at(i).string()); continue; } - bool writeResult = - includeManager.WriteIncludeRecord - ( - sourceFiles.at(i), - sourcesIncludes.at(sourceFiles.at(i)) - ); - + bool writeResult = includeManager.WriteIncludeRecord + ( + sourceFiles.at(i), + sourcesIncludes.at(sourceFiles.at(i)) + ); if(!writeResult) { - ssLOG_ERROR("Failed to write include record for " << - sourceFiles.at(i).string()); + ssLOG_ERROR("Failed to write include record for " << sourceFiles.at(i).string()); return PipelineResult::UNEXPECTED_FAILURE; } } @@ -714,13 +700,13 @@ runcpp2::StartPipeline( const std::string& scriptPath, { std::vector targets; ghc::filesystem::path runnableTarget; - result = GetBuiltTargetPaths( buildDir, - scriptName, - profiles.at(profileIndex), - currentOptions, - scriptInfo, - targets, - &runnableTarget); + PipelineResult result = GetBuiltTargetPaths(buildDir, + scriptName, + profiles.at(profileIndex), + currentOptions, + scriptInfo, + targets, + &runnableTarget); if(result != PipelineResult::SUCCESS) return result; @@ -741,11 +727,10 @@ runcpp2::StartPipeline( const std::string& scriptPath, filesToCopyPaths.push_back(target.string()); } - if(!CopyFiles(buildDir, filesToCopyPaths, copiedPaths)) - { - ssLOG_ERROR("Failed to copy binaries before running the script"); - return PipelineResult::UNEXPECTED_FAILURE; - } + CopyFiles(buildDir, filesToCopyPaths, copiedPaths) + .DS_TRY_ACT(ssLOG_ERROR(DS_TMP_ERROR.ToString()); + ssLOG_ERROR("Failed to copy binaries before running the script"); + return PipelineResult::UNEXPECTED_FAILURE); //Run PostBuild commands after successful compilation result = HandlePostBuild(scriptInfo, profiles.at(profileIndex), buildDir.string());