Skip to content

Commit

Permalink
fixup! feat(builtin): use linker for all generated :bin targets
Browse files Browse the repository at this point in the history
  • Loading branch information
gregmagolan authored and alexeagle committed Apr 11, 2020
1 parent ec5d67c commit 4d68be0
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 12 deletions.
38 changes: 32 additions & 6 deletions internal/linker/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,18 +142,44 @@ class Runfiles {
return runfilesEntries;
}
resolve(modulePath) {
if (this.manifest) {
const result = this.lookupDirectory(modulePath);
if (result)
return result;
if (path.isAbsolute(modulePath)) {
return modulePath;
}
if (exports.runfiles.dir && fs.existsSync(path.join(exports.runfiles.dir, modulePath))) {
return path.join(exports.runfiles.dir, modulePath);
const result = this._resolve(modulePath, '');
if (result) {
return result;
}
const e = new Error(`could not resolve modulePath ${modulePath}`);
e.code = 'MODULE_NOT_FOUND';
throw e;
}
_resolve(moduleBase, moduleTail) {
if (this.manifest) {
const result = this.lookupDirectory(moduleBase);
if (result) {
if (moduleTail) {
const maybe = path.join(result, moduleTail);
if (fs.existsSync(maybe)) {
return maybe;
}
}
else {
return result;
}
}
}
if (exports.runfiles.dir) {
const maybe = path.join(exports.runfiles.dir, moduleBase, moduleTail);
if (fs.existsSync(maybe)) {
return maybe;
}
}
const dirname = path.dirname(moduleBase);
if (dirname == '.') {
return undefined;
}
return this._resolve(dirname, path.join(path.basename(moduleBase), moduleTail));
}
resolveWorkspaceRelative(modulePath) {
if (!this.workspace) {
throw new Error('workspace could not be determined from the environment; make sure BAZEL_WORKSPACE is set');
Expand Down
39 changes: 33 additions & 6 deletions internal/linker/link_node_modules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,19 +243,46 @@ export class Runfiles {
}

resolve(modulePath: string) {
// Look in the runfiles first
if (this.manifest) {
const result = this.lookupDirectory(modulePath);
if (result) return result;
if (path.isAbsolute(modulePath)) {
return modulePath;
}
if (runfiles.dir && fs.existsSync(path.join(runfiles.dir, modulePath))) {
return path.join(runfiles.dir, modulePath);
const result = this._resolve(modulePath, '');
if (result) {
return result;
}
const e = new Error(`could not resolve modulePath ${modulePath}`);
(e as any).code = 'MODULE_NOT_FOUND';
throw e;
}

_resolve(moduleBase: string, moduleTail: string): string|undefined {
if (this.manifest) {
const result = this.lookupDirectory(moduleBase);
if (result) {
if (moduleTail) {
const maybe = path.join(result, moduleTail);
if (fs.existsSync(maybe)) {
return maybe;
}
} else {
return result;
}
}
}
if (runfiles.dir) {
const maybe = path.join(runfiles.dir, moduleBase, moduleTail);
if (fs.existsSync(maybe)) {
return maybe;
}
}
const dirname = path.dirname(moduleBase);
if (dirname == '.') {
// no match
return undefined;
}
return this._resolve(dirname, path.join(path.basename(moduleBase), moduleTail));
}

resolveWorkspaceRelative(modulePath: string) {
if (!this.workspace) {
throw new Error(
Expand Down

0 comments on commit 4d68be0

Please sign in to comment.