From 49dcc19b966d979c312e3aceff96da734315e461 Mon Sep 17 00:00:00 2001 From: Kei Okada Date: Wed, 25 Nov 2020 19:57:44 +0900 Subject: [PATCH] add list-licenses and depends-licenses --- include/rospack/rospack.h | 18 +++++++++++ src/rospack.cpp | 50 +++++++++++++++++++++++++++++ src/rospack_cmdline.cpp | 66 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 134 insertions(+) diff --git a/include/rospack/rospack.h b/include/rospack/rospack.h index 062fa50..bd21b10 100644 --- a/include/rospack/rospack.h +++ b/include/rospack/rospack.h @@ -307,6 +307,12 @@ class ROSPACK_DECL Rosstackage * @param deps If dependencies are computed, then they're written here. * @return True if dependencies were computed, false otherwise. */ + void listLicenses(std::set > >& list); + /** + * @brief Identify duplicate stackages. Forces crawl. + * @param dups Names of stackages and its licenses that are found more + * than once whilecrawling are written here. + */ bool deps(const std::string& name, bool direct, std::vector& deps); /** * @brief Compute reverse dependencies of a stackage (i.e., stackages @@ -351,6 +357,18 @@ class ROSPACK_DECL Rosstackage * that the given stackage depends on is written here. * @return True if the manifest list was computed, false otherwise. */ + bool depsLicenses(const std::string& name, bool direct, + std::vector > >& deps); + /** + * @brief Compute reverse dependencies of a stackage (i.e., stackages + * that depend on this stackage). Forces crawl. + * @param name The stackage to work on. + * @param direct If true, then compute only direct dependencies. If + * false, then compute full (including indirect) + * dependencies. + * @param deps If dependencies with licenses are computed, then they're written here. + * @return True if dependencies were computed, false otherwise. + */ bool depsManifests(const std::string& name, bool direct, std::vector& manifests); /** diff --git a/src/rospack.cpp b/src/rospack.cpp index 3a83fce..874854b 100644 --- a/src/rospack.cpp +++ b/src/rospack.cpp @@ -551,6 +551,24 @@ Rosstackage::listDuplicatesWithPaths(std::map > >& list) +{ + for(boost::unordered_map::const_iterator it = stackages_.begin(); + it != stackages_.end(); + ++it) + { + std::pair > item; + item.first = it->first; + for(std::vector::const_iterator jt = it->second->licenses_.begin(); + jt != it->second->licenses_.end(); + ++jt) { + item.second.push_back(*jt); + } + list.insert(item); + } +} + bool Rosstackage::deps(const std::string& name, bool direct, std::vector& deps) @@ -687,6 +705,36 @@ Rosstackage::depsManifests(const std::string& name, bool direct, return result; } +bool +Rosstackage::depsLicenses(const std::string& name, bool direct, + std::vector > >& deps) +{ + std::vector stackages; + // Disable errors for the first try + bool old_quiet = quiet_; + bool result = true; + setQuiet(true); + if(!depsDetail(name, direct, stackages)) + { + // Recrawl + crawl(search_paths_, true); + stackages.clear(); + setQuiet(old_quiet); + if(!depsDetail(name, direct, stackages)) + result = false; + } + setQuiet(old_quiet); + for(std::vector::const_iterator it = stackages.begin(); + it != stackages.end(); + ++it) + { + std::vector licenses; + licenses.push_back("BSD"); + deps.push_back(std::pair >((*it)->name_, licenses)); + } + return result; +} + bool Rosstackage::rosdeps(const std::string& name, bool direct, std::set& rosdeps) @@ -2293,6 +2341,7 @@ Rospack::usage() " cflags-only-other [--deps-only] [package]\n" " depends [package] (alias: deps)\n" " depends-indent [package] (alias: deps-indent)\n" + " depends-licenses [package] (alias: deps-licenses)\n" " depends-manifests [package] (alias: deps-manifests)\n" " depends-msgsrv [package] (alias: deps-msgsrv)\n" " depends-on [package]\n" @@ -2307,6 +2356,7 @@ Rospack::usage() " libs-only-other [--deps-only] [package]\n" " list\n" " list-duplicates\n" + " list-licenses\n" " list-names\n" " plugins --attrib= [--top=] [package]\n" " profile [--length=] [--zombie-only]\n" diff --git a/src/rospack_cmdline.cpp b/src/rospack_cmdline.cpp index 47ecea1..8fdddf6 100644 --- a/src/rospack_cmdline.cpp +++ b/src/rospack_cmdline.cpp @@ -142,6 +142,8 @@ rospack_run(int argc, char** argv, rospack::Rosstackage& rp, std::string& output output.append("\n\nPrint newline-separated list of packages names for all packages."); else if(command == "list-duplicates") output.append("\n\nPrint newline-separated list of names of packages that are found more than once during the search."); + else if(command == "list-licenses") + output.append("\n\nPrint newline-separated list of packages names and licenses for all packages."); else if(command == "langs") output.append("\n\nPrint space-separated list of available language-specific client libraries."); else if(command == "depends" || command == "deps") @@ -152,6 +154,8 @@ rospack_run(int argc, char** argv, rospack::Rosstackage& rp, std::string& output output.append("[package]\n\nPrint space-separated, ordered list of manifest.xml files for all dependencies of the package. Used internally by rosbuild."); else if(command == "depends-indent" || command == "deps-indent") output.append("[package]\n\nPrint newline-separated, indented list of the entire dependency chain for the package."); + else if(command == "depends-licenses" || command == "deps-licenses") + output.append("[package]\n\nPrint newline-separated, ordered list of all dependencies of the package with licenses."); else if(command == "depends-why" || command == "deps-why") output.append("--target=TARGET [package]\n\nPrint newline-separated presentation of all dependency chains from the package to TARGET. "); else if(command == "depends-msgsrv" || command == "deps-msgsrv") @@ -301,6 +305,35 @@ rospack_run(int argc, char** argv, rospack::Rosstackage& rp, std::string& output } return true; } + // COMMAND: list-lisenses + else if(command == "list-licenses") + { + if(package_given || target.size() || top.size() || length_str.size() || + zombie_only || deps_only || lang.size() || attrib.size()) + { + rp.logError( "invalid option(s) given"); + return false; + } + std::set > > dups; + rp.listLicenses(dups); + // if there are dups, list-duplicates prints them and returns non-zero + for(std::set > >::const_iterator it = dups.begin(); + it != dups.end(); + ++it) + { + output.append(it->first + " "); + for(std::vector::const_iterator jt = it->second.begin(); + jt != it->second.end(); + ++jt) + { + if(jt != it->second.begin()) + output.append(", "); + output.append(*jt); + } + output.append("\n"); + } + return true; + } // COMMAND: langs else if(rp.getName() == ROSPACK_NAME && command == "langs") { @@ -397,6 +430,39 @@ rospack_run(int argc, char** argv, rospack::Rosstackage& rp, std::string& output output.append("\n"); return result; } + // COMMAND: depends-licenses [package] (alias: deps-licenses) + else if(command == "depends-licenses" || command == "deps-licenses") + { + if(!package.size()) + { + rp.logError(std::string("no ") + rp.get_manifest_type() + " given"); + return false; + } + if(target.size() || top.size() || length_str.size() || + zombie_only || deps_only || lang.size() || attrib.size()) + { + rp.logError( "invalid option(s) given"); + return false; + } + std::vector > >licenses; + bool result = rp.depsLicenses(package, false, licenses); + for(std::vector > >::const_iterator it = licenses.begin(); + it != licenses.end(); + ++it) + { + output.append(it->first + " "); + for(std::vector::const_iterator jt = it->second.begin(); + jt != it->second.end(); + ++jt) + { + if(jt != it->second.begin()) + output.append(", "); + output.append(*jt); + } + output.append("\n"); + } + return result; + } // COMMAND: depends-msgsrv [package] (alias: deps-msgsrv) else if(rp.getName() == ROSPACK_NAME && (command == "depends-msgsrv" || command == "deps-msgsrv"))