forked from angular/angular
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
build: support running compiler-cli tests on windows
In order to support running "compiler-cli" tests that use the "test_support.ts" utilities on Windows with Bazel, we need to imporve the logic that resolves NPM packages and symlinks them into a temporary directory. A more Bazel idiomatic and windows compatible way of resolving Bazel runfiles is to use the "RUNFILES_MANIFEST" if present. This ensures that the NPM packages can be also symlinked on Windows, and tests can execute properly on Windows. Read more about why this is needed here: * bazelbuild/bazel#3726 (comment)
- Loading branch information
1 parent
8d7eac0
commit 8ebb1ea
Showing
4 changed files
with
90 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/** | ||
* @license | ||
* Copyright Google Inc. All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.io/license | ||
*/ | ||
|
||
import * as fs from 'fs'; | ||
import * as path from 'path'; | ||
|
||
/** | ||
* Gets all built Angular NPM package artifacts by querying the Bazel runfiles. | ||
* In case there is a runfiles manifest (e.g. on Windows), the packages are resolved | ||
* through the manifest because the runfiles are not symlinked and cannot be searched | ||
* within the real filesystem. | ||
*/ | ||
export function getAngularPackagesFromRunfiles() { | ||
// Path to the Bazel runfiles manifest if present. This file is present if runfiles are | ||
// not symlinked into the runfiles directory. | ||
const runfilesManifestPath = process.env.RUNFILES_MANIFEST_FILE; | ||
|
||
if (!runfilesManifestPath) { | ||
const packageRunfilesDir = path.join(process.env.RUNFILES !, 'angular/packages'); | ||
|
||
return fs.readdirSync(packageRunfilesDir) | ||
.map(name => ({name, pkgPath: path.join(packageRunfilesDir, name, 'npm_package/')})) | ||
.filter(({pkgPath}) => fs.existsSync(pkgPath)); | ||
} | ||
|
||
return fs.readFileSync(runfilesManifestPath, 'utf8') | ||
.split('\n') | ||
.map(mapping => mapping.split(' ')) | ||
.filter(([runfilePath]) => runfilePath.match(/^angular\/packages\/[\w-]+\/npm_package$/)) | ||
.map(([runfilePath, realPath]) => ({ | ||
name: path.relative('angular/packages', runfilePath).split(path.sep)[0], | ||
pkgPath: realPath, | ||
})); | ||
} | ||
|
||
/** | ||
* Resolves a NPM package from the Bazel runfiles. We need to resolve the Bazel tree | ||
* artifacts using a "resolve file" because the NodeJS module resolution does not allow | ||
* resolving to directory paths. | ||
*/ | ||
export function resolveNpmTreeArtifact(manifestPath: string, resolveFile = 'package.json') { | ||
return path.dirname(require.resolve(path.posix.join(manifestPath, resolveFile))); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters