Skip to content

Commit 0122bbf

Browse files
committed
findpaths: Add '-r' option
It allows finding a path for a resolvable expression.
1 parent 62b164b commit 0122bbf

File tree

2 files changed

+35
-6
lines changed

2 files changed

+35
-6
lines changed

src/bin/Jamfile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,6 @@ if $(TARGET_PLATFORM) = libbe_test {
115115
StdBinCommands
116116
alert.cpp
117117
eject.cpp
118-
findpaths.cpp
119118
getarch.cpp
120119
hey.cpp
121120
reindex.cpp
@@ -190,6 +189,11 @@ StdBinCommands
190189
mail.cpp
191190
: be libmail.so : $(haiku-utils_rsrc) ;
192191

192+
# standard commands that need libbe.so, libpackage.so, libsupc++.so
193+
StdBinCommands
194+
findpaths.cpp
195+
: be package $(TARGET_LIBSUPC++) : $(haiku-utils_rsrc) ;
196+
193197
# standard commands that need libbe.so, libdevice.so
194198
StdBinCommands
195199
listusb.cpp

src/bin/findpaths.cpp

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <stdlib.h>
1010
#include <string.h>
1111

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

120127

@@ -132,6 +139,7 @@ main(int argc, const char* const* argv)
132139
const char* architecture = NULL;
133140
const char* dependency = NULL;
134141
const char* referencePath = NULL;
142+
const char* resolvable = NULL;
135143
bool existingOnly = false;
136144
const char* separator = NULL;
137145

@@ -141,11 +149,12 @@ main(int argc, const char* const* argv)
141149
{ "dependency", required_argument, 0, 'd' },
142150
{ "help", no_argument, 0, 'h' },
143151
{ "path", required_argument, 0, 'p' },
152+
{ "resolvable", required_argument, 0, 'pr' },
144153
{ 0, 0, 0, 0 }
145154
};
146155

147156
opterr = 0; // don't print errors
148-
int c = getopt_long(argc, (char**)argv, "+a:c:d:ehlp:",
157+
int c = getopt_long(argc, (char**)argv, "+a:c:d:ehlp:r:",
149158
sLongOptions, NULL);
150159
if (c == -1)
151160
break;
@@ -183,6 +192,10 @@ main(int argc, const char* const* argv)
183192
referencePath = optarg;
184193
break;
185194

195+
case 'r':
196+
resolvable = optarg;
197+
break;
198+
186199
default:
187200
print_usage_and_exit(true);
188201
break;
@@ -199,6 +212,10 @@ main(int argc, const char* const* argv)
199212
if (optind >= argc)
200213
subPath = argv[optind++];
201214

215+
// only one of path or resolvable may be specified
216+
if (referencePath != NULL && resolvable != NULL)
217+
print_usage_and_exit(true);
218+
202219
// resolve the directory constant
203220
path_base_directory baseDirectory = B_FIND_PATH_IMAGE_PATH;
204221
bool found = false;
@@ -217,11 +234,19 @@ main(int argc, const char* const* argv)
217234
exit(1);
218235
}
219236

220-
if (referencePath != NULL) {
237+
if (referencePath != NULL || resolvable != NULL) {
238+
BPathFinder pathFinder;
239+
if (referencePath != NULL) {
240+
pathFinder.SetTo(referencePath, dependency);
241+
} else {
242+
pathFinder.SetTo(
243+
BPackageKit::BPackageResolvableExpression(resolvable),
244+
dependency);
245+
}
246+
221247
BPath path;
222-
status_t error = BPathFinder(referencePath, dependency).FindPath(
223-
architecture, baseDirectory, subPath,
224-
existingOnly ? B_FIND_PATH_EXISTING_ONLY : 0, path);
248+
status_t error =pathFinder.FindPath(architecture, baseDirectory,
249+
subPath, existingOnly ? B_FIND_PATH_EXISTING_ONLY : 0, path);
225250
if (error != B_OK) {
226251
fprintf(stderr, "Error: Failed to find path: %s\n",
227252
strerror(error));

0 commit comments

Comments
 (0)