Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 62 additions & 6 deletions packages/runfiles/runfiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,19 +144,75 @@ export class Runfiles {
const repoMappings: RepoMappings = Object.create(null);
const mappings = fs.readFileSync(repoMappingPath, { encoding: "utf-8" });

// Each line of the repository mapping manifest has the form:
// canonical name of source repo,apparent name of target repo,target repo runfiles directory
// https://cs.opensource.google/bazel/bazel/+/1b073ac0a719a09c9b2d1a52680517ab22dc971e:src/main/java/com/google/devtools/build/lib/analysis/RepoMappingManifestAction.java;l=117
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this comment+link still relevant?

for (const line of mappings.split("\n")) {
if (!line) continue;

const [sourceRepo, targetRepoApparentName, targetRepoDirectory] = line.split(",");

(repoMappings[sourceRepo] ??= Object.create(null))[targetRepoApparentName] = targetRepoDirectory;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't the fix just defaulting one of the fields here? See #3797 (comment)

try {
const parsed = this.parseBzlmodRepoMappingLine(line) || this.parseLegacyRepoMappingLine(line);

if (parsed) {
const { sourceRepo, targetRepoApparentName, targetRepoDirectory } = parsed;
(repoMappings[sourceRepo] ??= Object.create(null))[targetRepoApparentName] = targetRepoDirectory;
}
} catch (error) {
console.warn(`Failed to parse repo mapping line: "${line}"`);
}
}
return repoMappings;
}

private parseBzlmodRepoMappingLine(line: string): {
sourceRepo: string;
targetRepoApparentName: string;
targetRepoDirectory: string;
} | null {
const trimmedLine = line.trim();
if (!trimmedLine || trimmedLine.startsWith('#')) {
return null;
}

const parts = trimmedLine.split(',');
if (parts.length < 3) {
return null;
}

const [sourceRepo, targetRepoApparentName, targetRepoDirectory] = parts;

if (!sourceRepo.trim() || !targetRepoApparentName.trim() || !targetRepoDirectory.trim()) {
return null;
}

return {
sourceRepo: sourceRepo.trim(),
targetRepoApparentName: targetRepoApparentName.trim(),
targetRepoDirectory: targetRepoDirectory.trim()
};
}

private parseLegacyRepoMappingLine(line: string): {
sourceRepo: string;
targetRepoApparentName: string;
targetRepoDirectory: string;
} | null {
const trimmedLine = line.trim();
if (!trimmedLine) {
return null;
}

const parts = trimmedLine.split(',');
if (parts.length !== 3) {
return null;
}

const [sourceRepo, targetRepoApparentName, targetRepoDirectory] = parts;

return {
sourceRepo,
targetRepoApparentName,
targetRepoDirectory
};
}

/** Resolves the given module path. */
resolve(modulePath: string, sourceRepo?: string): string {
this._assertRunfilesResolved();
Expand Down