question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Seemingly duplicate labels

See original GitHub issue

Description of the problem / feature request:

Basically it is good that Bazel forbids duplicate labels. But it should not make false-positives. For example:

cc_binary(
    name = "hello",
    srcs = select({ "//conditions:default" : [], "//:x86_32_windows" : ["sources/hello.cpp"] })
        + [ "sources/common.cpp" ]
        + select({ "//conditions:default" : [], "//:x64_windows" : ["sources/hello.cpp"] })
)

This target looks good, but in reality it won’t compile:

ERROR: C:/users/chebotarev_v/documents/src/bazel-issues/seemingly-duplicate-labels/BUILD:17:1: Label '//:sources/hello.cpp' is duplicated in the 'srcs' attribute of rule 'hello'

Feature requests: what underlying problem are you trying to solve with this feature?

Label lists can be combined with (+) and come from different points of BUILD files, so these false-positives can be extremely hard to workaround in a project. I believe that should be fixed.

Bugs: what’s the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.

Please find an example here: https://github.com/excitoon/bazel-issues/tree/master/seemingly-duplicate-labels

What operating system are you running Bazel on?

Windows 10 x64

What’s the output of bazel info release?

Build label: 0.14.0
Build target: bazel-out/x64_windows-opt/bin/src/main/java/com/google/devtools/build/lib/bazel/BazelServer_deploy.jar
Build time: Fri Jun 1 13:06:29 2018 (1527858389)
Build timestamp: 1527858389
Build timestamp as int: 1527858389

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
cushoncommented, Jun 17, 2018

Consider using collections.uniq from https://github.com/bazelbuild/bazel-skylib to deduplicate the srcs of that target, e.g.:

Add this to your WORKSPACE:

git_repository(
    name = "bazel_skylib",
    remote = "https://github.com/bazelbuild/bazel-skylib.git",
    tag = "0.1.0",  # change this to use a different release
)

And then use:

load("@bazel_skylib//:lib.bzl", "collections")

cc_binary(
    name = "hello",
    srcs = collections.uniq(select({ "//conditions:default" : [], "//:x86_32_windows" : ["sources/hello.cpp"] })
        + [ "sources/common.cpp" ]
        + select({ "//conditions:default" : [], "//:x64_windows" : ["sources/hello.cpp"] }))
)
0reactions
FaBrandcommented, Jun 21, 2022

@gregestren Just came across the same issue after a bit of searching. I guess it would make sense to extend the docs with this information.

I created https://github.com/bazelbuild/bazel/pull/15714 to make this behavior easier to detect

Read more comments on GitHub >

github_iconTop Results From Across the Web

Avoiding Duplicate Labels When Including the Same Source ...
a duplicate of the original data is stored in a separate section of ... avoid it - since it involves a seemingly unavoidable...
Read more >
Question - - Duplicate Labels on map | RedGuides: EverQuest Multi ...
If the duplicate names happen to be your group you can unclick show group in the EQ map. That way you will only...
Read more >
I am getting unexpected duplicate labels when I print from ...
Bring up the record creating duplicates in Connexion client. Click F10 to open the Label printing settings. Correct the Copies of Each setting ......
Read more >
Duplicate labels for single parts : r/QGIS - Reddit
It is trying to place labels at other scales, but seemingly with no rhyme or reason. EDIT: I even ran a "multi-part to...
Read more >
How to Resolve Duplicate Data within Excel Pivot Tables
Excel 2003 and earlier: Drag these field names into the Row Labels and Data sections, respectively. You'll see in my case that account...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found