Skip to content

Commit

Permalink
feat[install command]: provide option "--invert-remote-order" to inve…
Browse files Browse the repository at this point in the history
…rt main and alternate remote search order for remaken dependencies. When the option is provided, the alternate remote is searched before the declared remote.
  • Loading branch information
Firefly35 committed Sep 23, 2021
1 parent 3bbfaa1 commit 549e8fc
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/CmdOptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ CmdOptions::CmdOptions()
CLI::App * installCommand = m_cliApp.add_subcommand("install", "install dependencies for a package from its packagedependencies file(s)");
installCommand->add_option("--alternate-remote-type,-l", m_altRepoType, "alternate remote type: " + getOptionString("--alternate-remote-type"));
installCommand->add_option("--alternate-remote-url,-u", m_altRepoUrl, "alternate remote url to use when the declared remote fails to provide a dependency");
installCommand->add_option("--invert-remote-order", m_invertRepositoryOrder, "invert alternate and base remote search order : alternate remote is searched before packagedependencies declared remote", true);
installCommand->add_option("--apiKey,-k", m_apiKey, "Artifactory api key");
installCommand->add_option("file", m_dependenciesFile, "Remaken dependencies files", true);
installCommand->add_option("--conan_profile", m_conanProfile, "force conan profile name to use (overrides detected profile)",true);
Expand Down
5 changes: 5 additions & 0 deletions src/CmdOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@ class CmdOptions
return m_moduleSubfolderPath;
}

bool invertRepositoryOrder () const {
return m_invertRepositoryOrder;
}

bool useCache() const {
return !m_ignoreCache;
}
Expand Down Expand Up @@ -252,6 +256,7 @@ class CmdOptions
std::string m_conanProfile = "default";
fs::path m_moduleSubfolderPath;
bool m_ignoreCache;
bool m_invertRepositoryOrder = false;
bool m_verbose;
bool m_recurse;
bool m_regex = false;
Expand Down
1 change: 1 addition & 0 deletions src/Dependency.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ Dependency::Dependency(const std::string & rawFormat, const std::string & mainMo
m_bHasOptions = true;
}
}
m_originalBaseRepository = m_baseRepository;
}


Expand Down
6 changes: 6 additions & 0 deletions src/Dependency.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ class Dependency
m_baseRepository = otherRepo;
}

inline void resetBaseRepository() {
m_baseRepository = m_originalBaseRepository;
}


inline const std::string & getMode() const {
return m_mode;
}
Expand Down Expand Up @@ -122,6 +127,7 @@ class Dependency
std::string m_name;
std::string m_version;
std::string m_baseRepository;
std::string m_originalBaseRepository;
std::string m_identifier;
std::string m_repositoryType;
std::string m_mode;
Expand Down
16 changes: 15 additions & 1 deletion src/managers/DependencyManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,14 @@ void DependencyManager::retrieveDependency(Dependency & dependency)
{
fs::detail::utf8_codecvt_facet utf8;
shared_ptr<IFileRetriever> fileRetriever = FileHandlerFactory::instance()->getFileHandler(dependency, m_options);
if (m_options.invertRepositoryOrder() && dependency.getType() == Dependency::Type::REMAKEN) {// what about cache management in this case ?
fileRetriever = FileHandlerFactory::instance()->getAlternateHandler(dependency.getType(),m_options);
if (!fileRetriever) { // no alternate repository found
BOOST_LOG_TRIVIAL(error)<<"==> No alternate repository defined for '"<<dependency.getPackageName()<<":"<<dependency.getVersion()<<"'";
throw std::runtime_error("No alternate repository defined for '" + dependency.getPackageName() +":" +dependency.getVersion() + "'");
}
dependency.changeBaseRepository(m_options.getAlternateRepoUrl());
}
std::string source = fileRetriever->computeSourcePath(dependency);
fs::path outputDirectory = fileRetriever->computeLocalDependencyRootDir(dependency);
fs::path libDirectory = fileRetriever->computeRootLibDir(dependency);
Expand All @@ -186,14 +194,20 @@ void DependencyManager::retrieveDependency(Dependency & dependency)
try {
outputDirectory = fileRetriever->installArtefact(dependency);
}
catch (std::runtime_error & e) { // try alternate repository
catch (std::runtime_error & e) { // try alternate/primary repository
shared_ptr<IFileRetriever> fileRetriever = FileHandlerFactory::instance()->getAlternateHandler(dependency.getType(),m_options);
if (m_options.invertRepositoryOrder() && dependency.getType() == Dependency::Type::REMAKEN) {// what about cache management in this case ?
fileRetriever = FileHandlerFactory::instance()->getFileHandler(dependency, m_options);
}
if (!fileRetriever) { // no alternate repository found
BOOST_LOG_TRIVIAL(error)<<"==> Unable to find '"<<dependency.getPackageName()<<":"<<dependency.getVersion()<<"' on "<<dependency.getRepositoryType()<<"('"<<dependency.getBaseRepository()<<"')";
throw std::runtime_error(e.what());
}
else {
dependency.changeBaseRepository(m_options.getAlternateRepoUrl());
if (m_options.invertRepositoryOrder() && dependency.getType() == Dependency::Type::REMAKEN) {
dependency.resetBaseRepository();
}
source = fileRetriever->computeSourcePath(dependency);
try {
std::cout<<"==> Trying to find '"<<dependency.getPackageName()<<":"<<dependency.getVersion()<<"' on alternate repository "<<dependency.getBaseRepository()<<"('"<<source<<"')"<<std::endl;
Expand Down
2 changes: 1 addition & 1 deletion src/utils/OsUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ const std::string_view & OsUtils::sharedSuffix(const std::string_view & osStr)
const std::string_view & OsUtils::sharedLibraryPathEnvName(const std::string_view & osStr)
{
if (os2sharedPathEnv.find(osStr) == os2sharedPathEnv.end()) {
return os2sharedSuffix.at("unix");
return os2sharedPathEnv.at("unix");
}
return os2sharedPathEnv.at(osStr);
}
Expand Down

0 comments on commit 549e8fc

Please sign in to comment.