【问题标题】:Referring angular.json in bazel workspace when supplying it in the root workspace is not an option在根工作区中提供 angular.json 时在 bazel 工作区中引用它不是一个选项
【发布时间】:2021-07-29 10:54:06
【问题描述】:

我正在尝试将 Angular 项目集成到现有的 Bazel 构建系统中。当我尝试运行 angular build 时,出现以下错误。

Workspace configuration file (angular.json, .angular.json, workspace.json, .workspace.json) cannot be found in '/home/build/.cache/bazel/_bazel_build/46b74a3c1f9a666f55591a5719d9f2ba/sandbox/linux-sandbox/1/execroot/root' or in parent directories.

现在我的 angular 项目位于根工作区的子文件夹中,因此 angular 无法找到 angular json 文件。当我使用 angular devkit 的架构师包运行 angular build 时,也没有选项可以使用 args 指定 angular json 的确切位置,这可能会解决问题。

一种方法,我可以考虑在运行构建命令之前将 angular json 文件复制到工作区的根目录。我还有其他选择吗?

【问题讨论】:

    标签: angular bazel angular-json


    【解决方案1】:

    如果有人尝试使用架构师构建 Angular 库,则不允许使用 outputPath。我关注了this example

    正如@Cameron @Birju 所说,其中chdir = package_name(), 行肯定是需要的。代码中的 args $(@D) 需要更改到正确的位置。否则,它位于沙盒中,将被删除。

    在示例中,一切运行良好。但就我而言,我的 GUI 项目位于 WORKSPACE 目录的 subdir1/subdir2 中,而我的库位于 subdir1/subdir2/projects/mylib 中。我没有示例中的.bazelrc 文件。所以我最终不得不更改${@D} 以添加大量../ 以退出沙箱目录,例如“../../../../../../. ./../../execroot/bla/$(@D)"

    【讨论】:

      【解决方案2】:

      Birju 的回答是肯定的。但我觉得它值得一些代码。

      我还要补充一点,在使用chdir 之后设置输出目录真的很重要,否则你会摸不着头脑,因为构建声称成功,但是当你检查你的 bazel 输出时,什么都不会出现(某种无声的失败)。请注意,在我的示例中,它是 outputPath,但这个变量实际上取决于您使用的工具,而不是 Bazel 本身。

      foo/BUILD.bazel

      load("@npm//@angular-devkit/architect-cli:index.bzl", "architect") # architect ruleset being generated by bazel itself. (I.e. `foo/`)
      
      architect(
          name = "build",
          args = [
              "frontend:build",
              "--outputPath=../$(@D)", # This output argument needs to point to the wherever the workspace directory is. Otherwise, your bazel build will succeed but nothing will appear.
                                     
          ],
          chdir = package_name(),      # package_name() gets the path of wherever the current build file is
      
          # any other arguments...
      )
      

      【讨论】:

        【解决方案3】:

        您可以使用chdir

        您基本上会将路径传递到该子文件夹,并且该工具将在运行 ng build 之前更改为该目录。我还必须通过将级别上移到根目录来更改 outDir 以使构建成功。

        例如,如果 chdir 是 lib/sub/angular,那么 outDir 将是 ../../../$(@D)

        【讨论】:

        • 谢谢,我在为 bazel 生成的 architect 规则设置目录时遇到了麻烦,但我可以将 chdir = package_name(), 传递到我的规则中。我猜很多 bazel 节点规则继承自 nodejs_binary 规则,否则我不知道为什么 chdir 会被我的 architect 规则接受。
        猜你喜欢
        • 2014-05-25
        • 2018-11-20
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-10-01
        相关资源
        最近更新 更多