From a1492a73ce657b61c3bb293b873166f1fb02a7a9 Mon Sep 17 00:00:00 2001 From: Alex Eagle Date: Tue, 19 Dec 2017 15:03:29 -0800 Subject: [PATCH] build: Remove angular_src nested workspace (#21096) PR Close #21096 --- .circleci/config.yml | 2 +- WORKSPACE | 7 +------ build.sh | 4 ++++ packages/bazel/WORKSPACE | 9 --------- packages/bazel/src/ng_module.bzl | 4 ++-- packages/bazel/src/ngc-wrapped/BUILD.bazel | 16 ++++++---------- packages/bazel/src/ngc-wrapped/index.ts | 8 +++++++- packages/bazel/test/ngc-wrapped/BUILD.bazel | 10 +++++----- .../bazel/test/ngc-wrapped/empty/BUILD.bazel | 6 +++--- packages/bazel/test/ngc-wrapped/test_support.ts | 5 +++-- .../bazel/test/ngc-wrapped/tsconfig_template.ts | 4 ++-- packages/common/test/BUILD.bazel | 2 +- packages/compiler/test/BUILD.bazel | 2 +- packages/core/test/BUILD.bazel | 2 +- packages/core/test/render3/BUILD.bazel | 2 +- packages/forms/test/BUILD.bazel | 2 +- packages/http/test/BUILD.bazel | 2 +- packages/language-service/test/BUILD.bazel | 2 +- .../platform-browser-dynamic/test/BUILD.bazel | 2 +- packages/platform-browser/test/BUILD.bazel | 2 +- packages/platform-server/test/BUILD.bazel | 2 +- packages/platform-webworker/test/BUILD.bazel | 2 +- packages/router/test/BUILD.bazel | 2 +- packages/service-worker/test/BUILD.bazel | 2 +- tools/defaults.bzl | 2 +- 25 files changed, 48 insertions(+), 55 deletions(-) delete mode 100644 packages/bazel/WORKSPACE diff --git a/.circleci/config.yml b/.circleci/config.yml index 35efc0845a..461504d1b1 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -62,7 +62,7 @@ jobs: # Use bazel query so that we explicitly ask for all buildable targets to be built as well # This avoids waiting for a build command to finish before running the first test # See https://github.com/bazelbuild/bazel/issues/4257 - - run: bazel query --output=label '//modules/... union //packages/... union //tools/... union @angular//...' | xargs bazel test --config=ci + - run: bazel query --output=label '//modules/... union //packages/... union //tools/...' | xargs bazel test --config=ci - save_cache: key: *cache_key diff --git a/WORKSPACE b/WORKSPACE index c40194f91c..62c4341dfd 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -1,4 +1,4 @@ -workspace(name = "angular_src") +workspace(name = "angular") load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository") @@ -24,11 +24,6 @@ load("@build_bazel_rules_typescript//:setup.bzl", "ts_setup_workspace") ts_setup_workspace() -local_repository( - name = "angular", - path = "packages/bazel", -) - local_repository( name = "rxjs", path = "node_modules/rxjs/src", diff --git a/build.sh b/build.sh index 9709b8ec4f..07f9cb0d41 100755 --- a/build.sh +++ b/build.sh @@ -416,9 +416,13 @@ if [[ ${BUILD_TOOLS} == true || ${BUILD_ALL} == true ]]; then mkdir -p ./dist/packages-dist rsync -a packages/bazel/ ./dist/packages-dist/bazel + echo "workspace(name=\"angular\")" > ./dist/packages-dist/bazel/WORKSPACE # Remove BEGIN-INTERNAL...END-INTERAL blocks # https://stackoverflow.com/questions/24175271/how-can-i-match-multi-line-patterns-in-the-command-line-with-perl-style-regex perl -0777 -n -i -e "s/(?m)^.*BEGIN-INTERNAL[\w\W]*END-INTERNAL.*\n//g; print" $(grep -ril BEGIN-INTERNAL dist/packages-dist/bazel) < /dev/null 2> /dev/null + # Re-host //packages/bazel/ which is just // in the public distro + perl -0777 -n -i -e "s#//packages/bazel/#//#g; print" $(grep -ril packages/bazel dist/packages-dist/bazel) < /dev/null 2> /dev/null + perl -0777 -n -i -e "s#angular/packages/bazel/#angular/#g; print" $(grep -ril packages/bazel dist/packages-dist/bazel) < /dev/null 2> /dev/null updateVersionReferences dist/packages-dist/bazel fi diff --git a/packages/bazel/WORKSPACE b/packages/bazel/WORKSPACE deleted file mode 100644 index 0951b51139..0000000000 --- a/packages/bazel/WORKSPACE +++ /dev/null @@ -1,9 +0,0 @@ -# By convention, the name should "describe the project in reverse-DNS form" -# https://docs.bazel.build/versions/master/be/functions.html#workspace -# But if we use "io_angular" then the loads used in BUILD files will -# be unfamiliar to Angular users who import from '@angular/pkg' in -# TypeScript files. We want to reduce the impedance between the Bazel -# and node naming schemes. -# We take the name "angular" so that users can write -# load("@angular//:index.bzl", "ng_module") -workspace(name = "angular") diff --git a/packages/bazel/src/ng_module.bzl b/packages/bazel/src/ng_module.bzl index e88a6c7028..16655cc09f 100644 --- a/packages/bazel/src/ng_module.bzl +++ b/packages/bazel/src/ng_module.bzl @@ -268,13 +268,13 @@ NG_MODULE_ATTRIBUTES = { "no_i18n": attr.bool(default = False), "compiler": attr.label( - default = Label("//src/ngc-wrapped"), + default = Label("//packages/bazel/src/ngc-wrapped"), executable = True, cfg = "host", ), "_ng_xi18n": attr.label( - default = Label("//src/ngc-wrapped:xi18n"), + default = Label("//packages/bazel/src/ngc-wrapped:xi18n"), executable = True, cfg = "host", ), diff --git a/packages/bazel/src/ngc-wrapped/BUILD.bazel b/packages/bazel/src/ngc-wrapped/BUILD.bazel index 56a1557524..3414c44833 100644 --- a/packages/bazel/src/ngc-wrapped/BUILD.bazel +++ b/packages/bazel/src/ngc-wrapped/BUILD.bazel @@ -9,12 +9,12 @@ ts_library( ], module_name = "@angular/bazel", tsconfig = ":tsconfig.json", - visibility = ["//test/ngc-wrapped:__subpackages__"], + visibility = ["//packages/bazel/test/ngc-wrapped:__subpackages__"], deps = [ # BEGIN-INTERNAL - # Only needed when compiling within the Angular repo. - # Users will get this dependency from node_modules. - "@//packages/compiler-cli", + # Only needed when compiling Angular from sources. + # Users with an npm depnedency will get this dependency from node_modules. + "//packages/compiler-cli", # END-INTERNAL "@build_bazel_rules_typescript//internal/tsc_wrapped", ], @@ -26,9 +26,7 @@ nodejs_binary( ":ngc_lib", "@build_bazel_rules_typescript//internal:worker_protocol.proto", ], - # Entry point assumes the user is outside this WORKSPACE, - # and references our rules with @angular//src/ngc-wrapped - entry_point = "angular/src/ngc-wrapped/index.js", + entry_point = "angular/packages/bazel/src/ngc-wrapped/index.js", node_modules = "@build_bazel_rules_typescript_deps//:node_modules", visibility = ["//visibility:public"], ) @@ -38,8 +36,6 @@ nodejs_binary( data = [ ":ngc_lib", ], - # Entry point assumes the user is outside this WORKSPACE, - # and references our rules with @angular//src/ngc-wrapped - entry_point = "angular/src/ngc-wrapped/index.js/extract_i18n.js", + entry_point = "angular/packages/bazel/src/ngc-wrapped/index.js/extract_i18n.js", visibility = ["//visibility:public"], ) diff --git a/packages/bazel/src/ngc-wrapped/index.ts b/packages/bazel/src/ngc-wrapped/index.ts index 4db274dd41..1b5dde203c 100644 --- a/packages/bazel/src/ngc-wrapped/index.ts +++ b/packages/bazel/src/ngc-wrapped/index.ts @@ -45,7 +45,13 @@ export function runOneBuild(args: string[], inputs?: {[path: string]: string}): if (args[0] === '-p') args.shift(); // Strip leading at-signs, used to indicate a params file const project = args[0].replace(/^@+/, ''); - const [{options: tsOptions, bazelOpts, files, config}] = parseTsconfig(project); + + const [parsedOptions, errors] = parseTsconfig(project); + if (errors && errors.length) { + console.error(ng.formatDiagnostics(errors)); + return false; + } + const {options: tsOptions, bazelOpts, files, config} = parsedOptions; const expectedOuts = config['angularCompilerOptions']['expectedOut']; const {basePath} = ng.calcProjectFileAndBasePath(project); diff --git a/packages/bazel/test/ngc-wrapped/BUILD.bazel b/packages/bazel/test/ngc-wrapped/BUILD.bazel index 6e0b79c0fa..36cc00696b 100644 --- a/packages/bazel/test/ngc-wrapped/BUILD.bazel +++ b/packages/bazel/test/ngc-wrapped/BUILD.bazel @@ -13,9 +13,9 @@ ts_library( # BEGIN-INTERNAL # Only needed when compiling within the Angular repo. # Users will get this dependency from node_modules. - "@//packages/compiler-cli", + "//packages/compiler-cli", # END-INTERNAL - "//src/ngc-wrapped:ngc_lib", + "//packages/bazel/src/ngc-wrapped:ngc_lib", ], ) @@ -23,7 +23,7 @@ ts_library( # .d.ts files (by default, jasmine_node_test would get the .js files). filegroup( name = "angular_core", - srcs = ["@//packages/core"], + srcs = ["//packages/core"], ) jasmine_node_test( @@ -32,8 +32,8 @@ jasmine_node_test( srcs = [":ngc_test_lib"], data = [ ":angular_core", - "//test/ngc-wrapped/empty:empty_tsconfig.json", - "//test/ngc-wrapped/empty:tsconfig.json", + "//packages/bazel/test/ngc-wrapped/empty:empty_tsconfig.json", + "//packages/bazel/test/ngc-wrapped/empty:tsconfig.json", "@build_bazel_rules_typescript//internal:worker_protocol.proto", ], ) diff --git a/packages/bazel/test/ngc-wrapped/empty/BUILD.bazel b/packages/bazel/test/ngc-wrapped/empty/BUILD.bazel index ee912d1090..48925e5a18 100644 --- a/packages/bazel/test/ngc-wrapped/empty/BUILD.bazel +++ b/packages/bazel/test/ngc-wrapped/empty/BUILD.bazel @@ -1,10 +1,10 @@ -load("@angular//:index.bzl", "ng_module") +load("//tools:defaults.bzl", "ng_module") -package(default_visibility = ["//test:__subpackages__"]) +package(default_visibility = ["//packages/bazel/test:__subpackages__"]) ng_module( name = "empty", srcs = ["empty.ts"], tsconfig = ":tsconfig.json", - deps = ["@//packages/core"], + deps = ["//packages/core"], ) diff --git a/packages/bazel/test/ngc-wrapped/test_support.ts b/packages/bazel/test/ngc-wrapped/test_support.ts index b18ed80c0c..9246d57efb 100644 --- a/packages/bazel/test/ngc-wrapped/test_support.ts +++ b/packages/bazel/test/ngc-wrapped/test_support.ts @@ -47,7 +47,7 @@ export function setup( const bazelBinPath = path.resolve(basePath, bazelBin); fs.mkdirSync(bazelBinPath); - const angularCorePath = path.resolve(runfilesPath, 'angular_src', 'packages', 'core'); + const angularCorePath = path.resolve(runfilesPath, 'angular', 'packages', 'core'); const ngFiles = listFilesRecursive(angularCorePath); const tsConfigJsonPath = path.resolve(basePath, tsconfig); @@ -113,7 +113,8 @@ export function setup( const emptyTsConfig = ts.readConfigFile( path.resolve( - runfilesPath, 'angular', 'test', 'ngc-wrapped', 'empty', 'empty_tsconfig.json'), + runfilesPath, 'angular', 'packages', 'bazel', 'test', 'ngc-wrapped', 'empty', + 'empty_tsconfig.json'), read); const tsconfig = createTsConfig({ diff --git a/packages/bazel/test/ngc-wrapped/tsconfig_template.ts b/packages/bazel/test/ngc-wrapped/tsconfig_template.ts index ace06601a0..05a8ee90b4 100644 --- a/packages/bazel/test/ngc-wrapped/tsconfig_template.ts +++ b/packages/bazel/test/ngc-wrapped/tsconfig_template.ts @@ -32,7 +32,7 @@ export function createTsConfig(options: TsConfigOptions) { const result = options.defaultTsConfig; return { - 'extends': '../angular/test/ngc-wrapped/empty/tsconfig', + 'extends': '../angular/packages/bazel/test/ngc-wrapped/empty/tsconfig', 'compilerOptions': { ...result.compilerOptions, 'outDir': options.outDir, @@ -70,7 +70,7 @@ export function createTsConfig(options: TsConfigOptions) { 'tsickleExternsPath': '', // we don't copy the node_modules into our tmp dir, so we should look in // the original workspace directory for it - 'nodeModulesPrefix': '../angular_src/node_modules', + 'nodeModulesPrefix': '../angular/node_modules', }, 'files': options.files, 'angularCompilerOptions': { diff --git a/packages/common/test/BUILD.bazel b/packages/common/test/BUILD.bazel index 4f3aa6a590..1b02d02123 100644 --- a/packages/common/test/BUILD.bazel +++ b/packages/common/test/BUILD.bazel @@ -23,7 +23,7 @@ ts_library( jasmine_node_test( name = "test", - bootstrap = ["angular_src/tools/testing/init_node_spec.js"], + bootstrap = ["angular/tools/testing/init_node_spec.js"], deps = [ ":test_lib", "//tools/testing:node", diff --git a/packages/compiler/test/BUILD.bazel b/packages/compiler/test/BUILD.bazel index b64042d089..d89ade47a4 100644 --- a/packages/compiler/test/BUILD.bazel +++ b/packages/compiler/test/BUILD.bazel @@ -36,7 +36,7 @@ ts_library( jasmine_node_test( name = "test", - bootstrap = ["angular_src/tools/testing/init_node_spec.js"], + bootstrap = ["angular/tools/testing/init_node_spec.js"], # dissable since tests are running but not yet passing tags = ["manual"], deps = [ diff --git a/packages/core/test/BUILD.bazel b/packages/core/test/BUILD.bazel index 7cbe649ebd..18cb4501c5 100644 --- a/packages/core/test/BUILD.bazel +++ b/packages/core/test/BUILD.bazel @@ -50,7 +50,7 @@ ts_library( jasmine_node_test( name = "test", - bootstrap = ["angular_src/tools/testing/init_node_spec.js"], + bootstrap = ["angular/tools/testing/init_node_spec.js"], deps = [ ":test_lib", ":test_node_only_lib", diff --git a/packages/core/test/render3/BUILD.bazel b/packages/core/test/render3/BUILD.bazel index 7a2b7839ac..cb62372f78 100644 --- a/packages/core/test/render3/BUILD.bazel +++ b/packages/core/test/render3/BUILD.bazel @@ -46,7 +46,7 @@ ts_library( jasmine_node_test( name = "render3", bootstrap = [ - "angular_src/packages/core/test/render3/load_domino", + "angular/packages/core/test/render3/load_domino", ], deps = [ ":render3_node_lib", diff --git a/packages/forms/test/BUILD.bazel b/packages/forms/test/BUILD.bazel index 3ae89405a1..9d0598a498 100644 --- a/packages/forms/test/BUILD.bazel +++ b/packages/forms/test/BUILD.bazel @@ -18,7 +18,7 @@ ts_library( jasmine_node_test( name = "test", - bootstrap = ["angular_src/tools/testing/init_node_spec.js"], + bootstrap = ["angular/tools/testing/init_node_spec.js"], deps = [ ":test_lib", "//tools/testing:node", diff --git a/packages/http/test/BUILD.bazel b/packages/http/test/BUILD.bazel index 2d0cf76545..48b01584b8 100644 --- a/packages/http/test/BUILD.bazel +++ b/packages/http/test/BUILD.bazel @@ -19,7 +19,7 @@ ts_library( jasmine_node_test( name = "test", - bootstrap = ["angular_src/tools/testing/init_node_spec.js"], + bootstrap = ["angular/tools/testing/init_node_spec.js"], deps = [ ":test_lib", "//tools/testing:node", diff --git a/packages/language-service/test/BUILD.bazel b/packages/language-service/test/BUILD.bazel index 3e92cadb9b..3a8ea6e7ed 100644 --- a/packages/language-service/test/BUILD.bazel +++ b/packages/language-service/test/BUILD.bazel @@ -15,7 +15,7 @@ ts_library( jasmine_node_test( name = "test", - bootstrap = ["angular_src/tools/testing/init_node_spec.js"], + bootstrap = ["angular/tools/testing/init_node_spec.js"], # dissable since tests are running but not yet passing tags = ["manual"], deps = [ diff --git a/packages/platform-browser-dynamic/test/BUILD.bazel b/packages/platform-browser-dynamic/test/BUILD.bazel index 4b416cd2d3..110ac64637 100644 --- a/packages/platform-browser-dynamic/test/BUILD.bazel +++ b/packages/platform-browser-dynamic/test/BUILD.bazel @@ -19,7 +19,7 @@ ts_library( jasmine_node_test( name = "test", - bootstrap = ["angular_src/tools/testing/init_node_spec.js"], + bootstrap = ["angular/tools/testing/init_node_spec.js"], # dissable since tests are running but not yet passing tags = ["manual"], deps = [ diff --git a/packages/platform-browser/test/BUILD.bazel b/packages/platform-browser/test/BUILD.bazel index 01354f6930..2f8cb4427b 100644 --- a/packages/platform-browser/test/BUILD.bazel +++ b/packages/platform-browser/test/BUILD.bazel @@ -25,7 +25,7 @@ ts_library( jasmine_node_test( name = "test", - bootstrap = ["angular_src/tools/testing/init_node_spec.js"], + bootstrap = ["angular/tools/testing/init_node_spec.js"], # dissable since tests are running but not yet passing tags = ["manual"], deps = [ diff --git a/packages/platform-server/test/BUILD.bazel b/packages/platform-server/test/BUILD.bazel index b852cca401..eff4d9b01f 100644 --- a/packages/platform-server/test/BUILD.bazel +++ b/packages/platform-server/test/BUILD.bazel @@ -25,7 +25,7 @@ ts_library( jasmine_node_test( name = "test", - bootstrap = ["angular_src/tools/testing/init_node_spec.js"], + bootstrap = ["angular/tools/testing/init_node_spec.js"], deps = [ ":test_lib", "//tools/testing:node", diff --git a/packages/platform-webworker/test/BUILD.bazel b/packages/platform-webworker/test/BUILD.bazel index 0e243b7983..fc51dc54e9 100644 --- a/packages/platform-webworker/test/BUILD.bazel +++ b/packages/platform-webworker/test/BUILD.bazel @@ -21,7 +21,7 @@ ts_library( jasmine_node_test( name = "test", - bootstrap = ["angular_src/tools/testing/init_node_spec.js"], + bootstrap = ["angular/tools/testing/init_node_spec.js"], deps = [ ":test_lib", "//tools/testing:node", diff --git a/packages/router/test/BUILD.bazel b/packages/router/test/BUILD.bazel index f1bb648575..a75b15d5b2 100644 --- a/packages/router/test/BUILD.bazel +++ b/packages/router/test/BUILD.bazel @@ -22,7 +22,7 @@ ts_library( jasmine_node_test( name = "test", - bootstrap = ["angular_src/tools/testing/init_node_spec.js"], + bootstrap = ["angular/tools/testing/init_node_spec.js"], deps = [ ":test_lib", "//tools/testing:node", diff --git a/packages/service-worker/test/BUILD.bazel b/packages/service-worker/test/BUILD.bazel index f3a6d5f242..296d7d6792 100644 --- a/packages/service-worker/test/BUILD.bazel +++ b/packages/service-worker/test/BUILD.bazel @@ -20,7 +20,7 @@ ts_library( jasmine_node_test( name = "test", - bootstrap = ["angular_src/tools/testing/init_node_spec.js"], + bootstrap = ["angular/tools/testing/init_node_spec.js"], deps = [ ":test_lib", "//tools/testing:node", diff --git a/tools/defaults.bzl b/tools/defaults.bzl index 328a9d456d..88ebffcebc 100644 --- a/tools/defaults.bzl +++ b/tools/defaults.bzl @@ -1,6 +1,6 @@ """Re-export of some bazel rules with repository-wide defaults.""" load("@build_bazel_rules_typescript//:defs.bzl", _ts_library = "ts_library") -load("@angular//:index.bzl", _ng_module = "ng_module") +load("//packages/bazel/src:ng_module.bzl", _ng_module = "ng_module") DEFAULT_TSCONFIG = "//packages:tsconfig-build.json"