Skip to content

Commit 1ddca9a

Browse files
Ability to choose dependencies to reset
1 parent 03ea9ae commit 1ddca9a

File tree

5 files changed

+62
-11
lines changed

5 files changed

+62
-11
lines changed

Include/runcpp2/DependenciesHelper.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ namespace runcpp2
2121
bool CleanupDependencies( const runcpp2::Data::Profile& profile,
2222
const Data::ScriptInfo& scriptInfo,
2323
const std::vector<Data::DependencyInfo*>& availableDependencies,
24-
const std::vector<std::string>& dependenciesLocalCopiesPaths);
24+
const std::vector<std::string>& dependenciesLocalCopiesPaths,
25+
const std::string& dependenciesToReset);
2526

2627
bool SetupDependenciesIfNeeded( const runcpp2::Data::Profile& profile,
2728
const ghc::filesystem::path& buildDir,

Include/runcpp2/runcpp2.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ namespace runcpp2
1616
RESET_USER_CONFIG,
1717
EXECUTABLE,
1818
HELP,
19-
REMOVE_DEPENDENCIES,
19+
RESET_DEPENDENCIES,
2020
LOCAL,
2121
SHOW_USER_CONFIG,
2222
SCRIPT_TEMPLATE,

Src/runcpp2/DependenciesHelper.cpp

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "runcpp2/DependenciesHelper.hpp"
22
#include "ghc/filesystem.hpp"
33
#include "runcpp2/PlatformUtil.hpp"
4+
#include "runcpp2/StringUtil.hpp"
45
#include "ssLogger/ssLog.hpp"
56

67
#include <unordered_set>
@@ -345,7 +346,8 @@ bool runcpp2::IsDependencyAvailableForThisPlatform(const Data::DependencyInfo& d
345346
bool runcpp2::CleanupDependencies( const runcpp2::Data::Profile& profile,
346347
const Data::ScriptInfo& scriptInfo,
347348
const std::vector<Data::DependencyInfo*>& availableDependencies,
348-
const std::vector<std::string>& dependenciesLocalCopiesPaths)
349+
const std::vector<std::string>& dependenciesLocalCopiesPaths,
350+
const std::string& dependenciesToReset)
349351
{
350352
ssLOG_FUNC_DEBUG();
351353

@@ -354,8 +356,52 @@ bool runcpp2::CleanupDependencies( const runcpp2::Data::Profile& profile,
354356
return true;
355357

356358
assert(availableDependencies.size() == dependenciesLocalCopiesPaths.size());
359+
360+
//Split dependency names if not "all"
361+
std::unordered_set<std::string> dependencyNames;
362+
if(dependenciesToReset != "all")
363+
{
364+
std::string currentName;
365+
for(int i = 0; i < dependenciesToReset.size(); ++i)
366+
{
367+
if(dependenciesToReset[i] == ',' || i == dependenciesToReset.size() - 1)
368+
{
369+
if(dependenciesToReset[i] != ',')
370+
currentName += dependenciesToReset[i];
371+
372+
if(!currentName.empty())
373+
{
374+
runcpp2::Trim(currentName);
375+
//Convert to lowercase for case-insensitive comparison
376+
for(int j = 0; j < currentName.size(); ++j)
377+
currentName[j] = std::tolower(currentName[j]);
378+
379+
dependencyNames.insert(currentName);
380+
currentName.clear();
381+
}
382+
}
383+
else
384+
currentName += dependenciesToReset[i];
385+
}
386+
}
387+
357388
for(int i = 0; i < availableDependencies.size(); ++i)
358389
{
390+
//Skip if not in the list of dependencies to reset
391+
if(!dependencyNames.empty())
392+
{
393+
//Convert dependency name to lowercase for comparison
394+
std::string depName = availableDependencies.at(i)->Name;
395+
for(int j = 0; j < depName.size(); ++j)
396+
depName[j] = std::tolower(depName[j]);
397+
398+
if(dependencyNames.count(depName) == 0)
399+
{
400+
ssLOG_DEBUG(availableDependencies.at(i)->Name << " not in list to remove");
401+
continue;
402+
}
403+
}
404+
359405
std::error_code e;
360406
ssLOG_INFO("Running cleanup commands for " << availableDependencies.at(i)->Name);
361407

@@ -377,6 +423,8 @@ bool runcpp2::CleanupDependencies( const runcpp2::Data::Profile& profile,
377423

378424
return false;
379425
}
426+
427+
ssLOG_DEBUG(availableDependencies.at(i)->Name << " removed");
380428
}
381429

382430
return true;

Src/runcpp2/main.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,8 @@ int main(int argc, char* argv[])
195195
runcpp2::OptionInfo(runcpp2::CmdOptions::HELP, false)
196196
},
197197
{
198-
"--remove-dependencies",
199-
runcpp2::OptionInfo(runcpp2::CmdOptions::REMOVE_DEPENDENCIES, false)
198+
"--reset-dependencies",
199+
runcpp2::OptionInfo(runcpp2::CmdOptions::RESET_DEPENDENCIES, true)
200200
},
201201
{
202202
"--local",
@@ -235,7 +235,7 @@ int main(int argc, char* argv[])
235235
{"-c", longOptionsMap.at("--reset-user-config")},
236236
{"-e", longOptionsMap.at("--executable")},
237237
{"-h", longOptionsMap.at("--help")},
238-
{"-d", longOptionsMap.at("--remove-dependencies")},
238+
{"-d", longOptionsMap.at("--reset-dependencies")},
239239
{"-l", longOptionsMap.at("--local")},
240240
{"-s", longOptionsMap.at("--show-config-path")},
241241
{"-t", longOptionsMap.at("--create-script-template")},
@@ -265,7 +265,7 @@ int main(int argc, char* argv[])
265265
ssLOG_BASE(" -c, --reset-user-[c]onfig Replace current user config with the default one");
266266
ssLOG_BASE(" -e, --[e]xecutable Runs as executable instead of shared library");
267267
ssLOG_BASE(" -h, --[h]elp Show this help message");
268-
ssLOG_BASE(" -d, --remove-[d]ependencies Remove dependencies listed in the script");
268+
ssLOG_BASE(" -d, --reset-[d]ependencies <names> Reset dependencies (comma-separated names, or \"all\" for all)");
269269
ssLOG_BASE(" -l, --[l]ocal Build in the current working directory under .runcpp2 directory");
270270
ssLOG_BASE(" -s, --[s]how-config-path Show where runcpp2 is reading the config from");
271271
ssLOG_BASE(" -t, --create-script-[t]emplate <file> Creates/prepend runcpp2 script info template");

Src/runcpp2/runcpp2.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -683,7 +683,7 @@ runcpp2::StartPipeline( const std::string& scriptPath,
683683
if(!parsableInfo.empty())
684684
{
685685
ssLOG_INFO("Parsed script info YAML:");
686-
ssLOG_INFO(scriptInfo.ToString(""));
686+
ssLOG_INFO("\n" << scriptInfo.ToString(""));
687687
}
688688

689689
//Create build directory
@@ -787,19 +787,21 @@ runcpp2::StartPipeline( const std::string& scriptPath,
787787
return PipelineResult::DEPENDENCIES_FAILED;
788788
}
789789

790-
if(currentOptions.count(CmdOptions::REMOVE_DEPENDENCIES) > 0 || scriptInfoChanged)
790+
if(currentOptions.count(CmdOptions::RESET_DEPENDENCIES) > 0 || scriptInfoChanged)
791791
{
792792
if(!CleanupDependencies(profiles.at(profileIndex),
793793
scriptInfo,
794794
availableDependencies,
795-
dependenciesLocalCopiesPaths))
795+
dependenciesLocalCopiesPaths,
796+
currentOptions.count(CmdOptions::RESET_DEPENDENCIES) > 0 ?
797+
currentOptions.at(CmdOptions::RESET_DEPENDENCIES) : "all"))
796798
{
797799
ssLOG_ERROR("Failed to cleanup dependencies");
798800
return PipelineResult::DEPENDENCIES_FAILED;
799801
}
800802
}
801803

802-
if(currentOptions.count(CmdOptions::REMOVE_DEPENDENCIES) > 0)
804+
if(currentOptions.count(CmdOptions::RESET_DEPENDENCIES) > 0)
803805
{
804806
ssLOG_LINE("Removed script dependencies");
805807
return PipelineResult::SUCCESS;

0 commit comments

Comments
 (0)