Skip to content

Commit

Permalink
add list-licenses and depends-licenses
Browse files Browse the repository at this point in the history
  • Loading branch information
k-okada committed Nov 25, 2020
1 parent 44c92b1 commit 49dcc19
Show file tree
Hide file tree
Showing 3 changed files with 134 additions and 0 deletions.
18 changes: 18 additions & 0 deletions include/rospack/rospack.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::pair<std::string, std::vector<std::string> > >& 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<std::string>& deps);
/**
* @brief Compute reverse dependencies of a stackage (i.e., stackages
Expand Down Expand Up @@ -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<std::pair<std::string, std::vector<std::string> > >& 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<std::string>& manifests);
/**
Expand Down
50 changes: 50 additions & 0 deletions src/rospack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,24 @@ Rosstackage::listDuplicatesWithPaths(std::map<std::string, std::vector<std::stri
}
}

void
Rosstackage::listLicenses(std::set<std::pair<std::string, std::vector<std::string> > >& list)
{
for(boost::unordered_map<std::string, Stackage*>::const_iterator it = stackages_.begin();
it != stackages_.end();
++it)
{
std::pair<std::string, std::vector<std::string> > item;
item.first = it->first;
for(std::vector<std::string>::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<std::string>& deps)
Expand Down Expand Up @@ -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<std::pair<std::string, std::vector<std::string> > >& deps)
{
std::vector<Stackage*> 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<Stackage*>::const_iterator it = stackages.begin();
it != stackages.end();
++it)
{
std::vector<std::string> licenses;
licenses.push_back("BSD");
deps.push_back(std::pair<std::string, std::vector<std::string> >((*it)->name_, licenses));
}
return result;
}

bool
Rosstackage::rosdeps(const std::string& name, bool direct,
std::set<std::string>& rosdeps)
Expand Down Expand Up @@ -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"
Expand All @@ -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=<attrib> [--top=<toppkg>] [package]\n"
" profile [--length=<length>] [--zombie-only]\n"
Expand Down
66 changes: 66 additions & 0 deletions src/rospack_cmdline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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")
Expand Down Expand Up @@ -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<std::pair<std::string, std::vector<std::string> > > dups;
rp.listLicenses(dups);
// if there are dups, list-duplicates prints them and returns non-zero
for(std::set<std::pair<std::string, std::vector<std::string> > >::const_iterator it = dups.begin();
it != dups.end();
++it)
{
output.append(it->first + " ");
for(std::vector<std::string>::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")
{
Expand Down Expand Up @@ -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<std::pair<std::string, std::vector<std::string> > >licenses;
bool result = rp.depsLicenses(package, false, licenses);
for(std::vector<std::pair<std::string, std::vector<std::string> > >::const_iterator it = licenses.begin();
it != licenses.end();
++it)
{
output.append(it->first + " ");
for(std::vector<std::string>::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"))
Expand Down

0 comments on commit 49dcc19

Please sign in to comment.