Skip to content

Commit

Permalink
findpaths: Add '-r' option
Browse files Browse the repository at this point in the history
It allows finding a path for a resolvable expression.
  • Loading branch information
weinhold committed Nov 21, 2013
1 parent 62b164b commit 0122bbf
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 6 deletions.
6 changes: 5 additions & 1 deletion src/bin/Jamfile
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ if $(TARGET_PLATFORM) = libbe_test {
StdBinCommands
alert.cpp
eject.cpp
findpaths.cpp
getarch.cpp
hey.cpp
reindex.cpp
Expand Down Expand Up @@ -190,6 +189,11 @@ StdBinCommands
mail.cpp
: be libmail.so : $(haiku-utils_rsrc) ;

# standard commands that need libbe.so, libpackage.so, libsupc++.so
StdBinCommands
findpaths.cpp
: be package $(TARGET_LIBSUPC++) : $(haiku-utils_rsrc) ;

# standard commands that need libbe.so, libdevice.so
StdBinCommands
listusb.cpp
Expand Down
35 changes: 30 additions & 5 deletions src/bin/findpaths.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <stdlib.h>
#include <string.h>

#include <package/PackageResolvableExpression.h>
#include <Path.h>
#include <PathFinder.h>
#include <StringList.h>
Expand Down Expand Up @@ -115,6 +116,12 @@ static const char* kUsage =
" -p, --path <path>\n"
" Print only one path, the one for the installation location that\n"
" contains the path <path>.\n"
" -r, --resolvable <expression>\n"
" Print only one path, the one for the installation location for the\n"
" package providing the resolvable matching the expression\n"
" <expression>. The expressions can be a simple resolvable name or\n"
" a resolvable name with operator and version (e.g.\n"
" \"cmd:perl >= 5\"; must be one argument).\n"
;


Expand All @@ -132,6 +139,7 @@ main(int argc, const char* const* argv)
const char* architecture = NULL;
const char* dependency = NULL;
const char* referencePath = NULL;
const char* resolvable = NULL;
bool existingOnly = false;
const char* separator = NULL;

Expand All @@ -141,11 +149,12 @@ main(int argc, const char* const* argv)
{ "dependency", required_argument, 0, 'd' },
{ "help", no_argument, 0, 'h' },
{ "path", required_argument, 0, 'p' },
{ "resolvable", required_argument, 0, 'pr' },
{ 0, 0, 0, 0 }
};

opterr = 0; // don't print errors
int c = getopt_long(argc, (char**)argv, "+a:c:d:ehlp:",
int c = getopt_long(argc, (char**)argv, "+a:c:d:ehlp:r:",
sLongOptions, NULL);
if (c == -1)
break;
Expand Down Expand Up @@ -183,6 +192,10 @@ main(int argc, const char* const* argv)
referencePath = optarg;
break;

case 'r':
resolvable = optarg;
break;

default:
print_usage_and_exit(true);
break;
Expand All @@ -199,6 +212,10 @@ main(int argc, const char* const* argv)
if (optind >= argc)
subPath = argv[optind++];

// only one of path or resolvable may be specified
if (referencePath != NULL && resolvable != NULL)
print_usage_and_exit(true);

// resolve the directory constant
path_base_directory baseDirectory = B_FIND_PATH_IMAGE_PATH;
bool found = false;
Expand All @@ -217,11 +234,19 @@ main(int argc, const char* const* argv)
exit(1);
}

if (referencePath != NULL) {
if (referencePath != NULL || resolvable != NULL) {
BPathFinder pathFinder;
if (referencePath != NULL) {
pathFinder.SetTo(referencePath, dependency);
} else {
pathFinder.SetTo(
BPackageKit::BPackageResolvableExpression(resolvable),
dependency);
}

BPath path;
status_t error = BPathFinder(referencePath, dependency).FindPath(
architecture, baseDirectory, subPath,
existingOnly ? B_FIND_PATH_EXISTING_ONLY : 0, path);
status_t error =pathFinder.FindPath(architecture, baseDirectory,
subPath, existingOnly ? B_FIND_PATH_EXISTING_ONLY : 0, path);
if (error != B_OK) {
fprintf(stderr, "Error: Failed to find path: %s\n",
strerror(error));
Expand Down

0 comments on commit 0122bbf

Please sign in to comment.