@@ -96,15 +96,13 @@ bool IsDirectory(const string& path) {
96
96
97
97
bool PathsFrom (const std::string& argv0, std::string runfiles_manifest_file,
98
98
std::string runfiles_dir, std::string* out_manifest,
99
- std::string* out_directory, std::string* out_repo_mapping );
99
+ std::string* out_directory);
100
100
101
101
bool PathsFrom (const std::string& argv0, std::string runfiles_manifest_file,
102
102
std::string runfiles_dir,
103
103
std::function<bool (const std::string&)> is_runfiles_manifest,
104
104
std::function<bool(const std::string&)> is_runfiles_directory,
105
- std::function<bool(const std::string&)> is_repo_mapping,
106
- std::string* out_manifest, std::string* out_directory,
107
- std::string* out_repo_mapping);
105
+ std::string* out_manifest, std::string* out_directory);
108
106
109
107
bool ParseManifest (const string& path, map<string, string>* result,
110
108
string* error);
@@ -117,9 +115,9 @@ Runfiles* Runfiles::Create(const string& argv0,
117
115
const string& runfiles_manifest_file,
118
116
const string& runfiles_dir,
119
117
const string& source_repository, string* error) {
120
- string manifest, directory, repo_mapping ;
118
+ string manifest, directory;
121
119
if (!PathsFrom (argv0, runfiles_manifest_file, runfiles_dir, &manifest,
122
- &directory, &repo_mapping )) {
120
+ &directory)) {
123
121
if (error) {
124
122
std::ostringstream err;
125
123
err << " ERROR: " << __FILE__ << " (" << __LINE__
@@ -144,10 +142,10 @@ Runfiles* Runfiles::Create(const string& argv0,
144
142
}
145
143
146
144
map<pair<string, string>, string> mapping;
147
- if (!repo_mapping. empty ()) {
148
- if (! ParseRepoMapping (repo_mapping, &mapping, error)) {
149
- return nullptr ;
150
- }
145
+ if (!ParseRepoMapping (
146
+ RlocationUnchecked ( " _repo_mapping " , runfiles, directory), &mapping,
147
+ error)) {
148
+ return nullptr ;
151
149
}
152
150
153
151
return new Runfiles (std::move (runfiles), std::move (directory),
@@ -196,28 +194,28 @@ string Runfiles::Rlocation(const string& path,
196
194
return path;
197
195
}
198
196
199
- if (repo_mapping_.empty ()) {
200
- return RlocationUnchecked (path);
201
- }
202
197
string::size_type first_slash = path.find_first_of (' /' );
203
198
if (first_slash == string::npos) {
204
- return RlocationUnchecked (path);
199
+ return RlocationUnchecked (path, runfiles_map_, directory_ );
205
200
}
206
201
string target_apparent = path.substr (0 , first_slash);
207
202
auto target =
208
203
repo_mapping_.find (std::make_pair (source_repo, target_apparent));
209
204
if (target == repo_mapping_.cend ()) {
210
- return RlocationUnchecked (path);
205
+ return RlocationUnchecked (path, runfiles_map_, directory_ );
211
206
}
212
- return RlocationUnchecked (target->second + path.substr (first_slash));
207
+ return RlocationUnchecked (target->second + path.substr (first_slash),
208
+ runfiles_map_, directory_);
213
209
}
214
210
215
- string Runfiles::RlocationUnchecked (const string& path) const {
216
- const auto exact_match = runfiles_map_.find (path);
217
- if (exact_match != runfiles_map_.end ()) {
211
+ string Runfiles::RlocationUnchecked (const string& path,
212
+ const map<string, string>& runfiles_map,
213
+ const string& directory) {
214
+ const auto exact_match = runfiles_map.find (path);
215
+ if (exact_match != runfiles_map.end ()) {
218
216
return exact_match->second ;
219
217
}
220
- if (!runfiles_map_ .empty ()) {
218
+ if (!runfiles_map .empty ()) {
221
219
// If path references a runfile that lies under a directory that itself is a
222
220
// runfile, then only the directory is listed in the manifest. Look up all
223
221
// prefixes of path in the manifest and append the relative path from the
@@ -226,14 +224,14 @@ string Runfiles::RlocationUnchecked(const string& path) const {
226
224
while ((prefix_end = path.find_last_of (' /' , prefix_end - 1 )) !=
227
225
string::npos) {
228
226
const string prefix = path.substr (0 , prefix_end);
229
- const auto prefix_match = runfiles_map_ .find (prefix);
230
- if (prefix_match != runfiles_map_ .end ()) {
227
+ const auto prefix_match = runfiles_map .find (prefix);
228
+ if (prefix_match != runfiles_map .end ()) {
231
229
return prefix_match->second + " /" + path.substr (prefix_end + 1 );
232
230
}
233
231
}
234
232
}
235
- if (!directory_ .empty ()) {
236
- return directory_ + " /" + path;
233
+ if (!directory .empty ()) {
234
+ return directory + " /" + path;
237
235
}
238
236
return " " ;
239
237
}
@@ -279,13 +277,7 @@ bool ParseRepoMapping(const string& path,
279
277
string* error) {
280
278
std::ifstream stm (path);
281
279
if (!stm.is_open ()) {
282
- if (error) {
283
- std::ostringstream err;
284
- err << " ERROR: " << __FILE__ << " (" << __LINE__
285
- << " ): cannot open repository mapping \" " << path << " \" " ;
286
- *error = err.str ();
287
- }
288
- return false ;
280
+ return true ;
289
281
}
290
282
string line;
291
283
std::getline (stm, line);
@@ -333,12 +325,9 @@ namespace testing {
333
325
bool TestOnly_PathsFrom (const string& argv0, string mf, string dir,
334
326
function<bool (const string&)> is_runfiles_manifest,
335
327
function<bool(const string&)> is_runfiles_directory,
336
- function<bool(const string&)> is_repo_mapping,
337
- string* out_manifest, string* out_directory,
338
- string* out_repo_mapping) {
328
+ string* out_manifest, string* out_directory) {
339
329
return PathsFrom (argv0, mf, dir, is_runfiles_manifest, is_runfiles_directory,
340
- is_repo_mapping, out_manifest, out_directory,
341
- out_repo_mapping);
330
+ out_manifest, out_directory);
342
331
}
343
332
344
333
bool TestOnly_IsAbsolute (const string& path) { return IsAbsolute (path); }
@@ -376,23 +365,19 @@ Runfiles* Runfiles::CreateForTest(std::string* error) {
376
365
namespace {
377
366
378
367
bool PathsFrom (const string& argv0, string mf, string dir, string* out_manifest,
379
- string* out_directory, string* out_repo_mapping ) {
368
+ string* out_directory) {
380
369
return PathsFrom (
381
370
argv0, mf, dir, [](const string& path) { return IsReadableFile (path); },
382
- [](const string& path) { return IsDirectory (path); },
383
- [](const string& path) { return IsReadableFile (path); }, out_manifest,
384
- out_directory, out_repo_mapping);
371
+ [](const string& path) { return IsDirectory (path); }, out_manifest,
372
+ out_directory);
385
373
}
386
374
387
375
bool PathsFrom (const string& argv0, string mf, string dir,
388
376
function<bool (const string&)> is_runfiles_manifest,
389
377
function<bool(const string&)> is_runfiles_directory,
390
- function<bool(const string&)> is_repo_mapping,
391
- string* out_manifest, string* out_directory,
392
- string* out_repo_mapping) {
378
+ string* out_manifest, string* out_directory) {
393
379
out_manifest->clear ();
394
380
out_directory->clear ();
395
- out_repo_mapping->clear ();
396
381
397
382
bool mfValid = is_runfiles_manifest (mf);
398
383
bool dirValid = is_runfiles_directory (dir);
@@ -428,21 +413,6 @@ bool PathsFrom(const string& argv0, string mf, string dir,
428
413
dirValid = is_runfiles_directory (dir);
429
414
}
430
415
431
- string rm;
432
- bool rmValid = false ;
433
-
434
- if (dirValid && ends_with (dir, " .runfiles" )) {
435
- rm = dir.substr (0 , dir.size () - 9 ) + " .repo_mapping" ;
436
- rmValid = is_repo_mapping (rm);
437
- }
438
-
439
- if (!rmValid && mfValid &&
440
- (ends_with (mf, " .runfiles_manifest" ) ||
441
- ends_with (mf, " .runfiles/MANIFEST" ))) {
442
- rm = mf.substr (0 , mf.size () - 18 ) + " .repo_mapping" ;
443
- rmValid = is_repo_mapping (rm);
444
- }
445
-
446
416
if (mfValid) {
447
417
*out_manifest = mf;
448
418
}
@@ -451,10 +421,6 @@ bool PathsFrom(const string& argv0, string mf, string dir,
451
421
*out_directory = dir;
452
422
}
453
423
454
- if (rmValid) {
455
- *out_repo_mapping = rm;
456
- }
457
-
458
424
return true ;
459
425
}
460
426
0 commit comments