From 0122bbf08b6b019a152c73d2fd8d7a7e1042cd69 Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Thu, 21 Nov 2013 13:07:17 +0100 Subject: [PATCH] findpaths: Add '-r' option It allows finding a path for a resolvable expression. --- src/bin/Jamfile | 6 +++++- src/bin/findpaths.cpp | 35 ++++++++++++++++++++++++++++++----- 2 files changed, 35 insertions(+), 6 deletions(-) diff --git a/src/bin/Jamfile b/src/bin/Jamfile index eb7c6b2e7d..5cb2794fa9 100644 --- a/src/bin/Jamfile +++ b/src/bin/Jamfile @@ -115,7 +115,6 @@ if $(TARGET_PLATFORM) = libbe_test { StdBinCommands alert.cpp eject.cpp - findpaths.cpp getarch.cpp hey.cpp reindex.cpp @@ -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 diff --git a/src/bin/findpaths.cpp b/src/bin/findpaths.cpp index 32c3c5fae1..b6a5bb59d3 100644 --- a/src/bin/findpaths.cpp +++ b/src/bin/findpaths.cpp @@ -9,6 +9,7 @@ #include #include +#include #include #include #include @@ -115,6 +116,12 @@ static const char* kUsage = " -p, --path \n" " Print only one path, the one for the installation location that\n" " contains the path .\n" + " -r, --resolvable \n" + " Print only one path, the one for the installation location for the\n" + " package providing the resolvable matching the expression\n" + " . 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" ; @@ -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; @@ -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; @@ -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; @@ -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; @@ -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));