bazelbuild / bazel

a fast, scalable, multi-language and extensible build system
https://bazel.build
Apache License 2.0
23.2k stars 4.06k forks source link

Build event protocol has incomplete output names #17193

Open sushain97 opened 1 year ago

sushain97 commented 1 year ago

Description of the bug:

Within a BEP stream, the namedSetOfFiles corresponding to a target contains entries with the identical (incomplete) name field when the files meet the following criteria:

  1. Exist within external repositories
  2. Created by a repository rule (e.g. repository_ctx.file not actions.write)
  3. Have the same basename

This makes it impossible to associate a particular output of a rule with a given file, especially when using --remote_download_minimal and the uri fields are opaque. Being able to associate outputs is useful if e.g. a rule outputs a manifest of its outputs that describes how to post-process them (e.g. "upload with these names").

Here's an example stream:

{
  "id": {
    "namedSet": {
      "id": "0"
    }
  },
  "namedSetOfFiles": {
    "files": [
      {
        "name": "food",
        "uri": "file:///private/var/tmp/_bazel/7bec43c1891cc58634d2eb9970f47206/external/monkey/food",
        "digest": "e49295702f7da8670778e9b95a281b72b41b31cb16afa376034b45f59a18ea3f",
        "length": "8"
      },
      {
        "name": "food",
        "uri": "file:///private/var/tmp/_bazel/7bec43c1891cc58634d2eb9970f47206/external/cheetah/food",
        "digest": "a84458ba7e2e5db7dc92760bef6c7aa29eb93488d069d53599cf23dfcfaf0bbe",
        "length": "5"
      },
      {
        "name": "food",
        "uri": "file:///private/var/tmp/_bazel/7bec43c1891cc58634d2eb9970f47206/execroot/root/bazel-out/darwin_arm64-fastbuild/bin/food",
        "pathPrefix": [
          "bazel-out",
          "darwin_arm64-fastbuild",
          "bin"
        ],
        "digest": "19fa068c43e98b6c92ac725ce20431fbdf9dfb995152f982fffb2203a7ea328d",
        "length": "13"
      }
    ]
  }
}

If File.path is invoked on the generated file corresponding to file:///private/var/tmp/_bazel/7bec43c1891cc58634d2eb9970f47206/external/monkey/food, it would output external/monkey/food. Thus, the BEP should also have "name": "external/monkey/food". Alternatively, the name field can stay ambiguous but pathPrefix should be set to disambiguate the entries.

Note that this works as expected if the file is generated by a standard build rule within the external repository. It only behaves this way when the file is created by a repository rule.

We suspect the issue may lie somewhere in this block: https://github.com/bazelbuild/bazel/blob/ccfeeff06cdc0266b92781213bbdf33c4288b1c5/src/main/java/com/google/devtools/build/lib/analysis/TargetCompleteEvent.java#L361-L389

cc @clint-stripe @sushain-stripe @qaisjp

What's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.

This bug is reproduced in https://github.com/sushain97/bazel-ambig-name-repro:

$ git clone https://github.com/sushain97/bazel-ambig-name-repro
$ cd bazel-ambig-name-repro/
$ ./repro.sh

Which operating system are you running Bazel on?

macOS

What is the output of bazel info release?

release 6.0.0

If bazel info release returns development version or (@non-git), tell us how you built Bazel.

No response

What's the output of git remote get-url origin; git rev-parse master; git rev-parse HEAD ?

No response

Have you found anything relevant by searching the web?

No response

Any other information, logs, or outputs that you want to share?

No response

github-actions[bot] commented 1 year ago

Thank you for contributing to the Bazel repository! This issue has been marked as stale since it has not had any activity in the last 30 days. It will be closed in the next 7 days unless any other activity occurs or the "not stale" label is added.

sushain97 commented 1 year ago

This issue is not stale.