Skip to content

Make private headers for cc_library "just work" for external and generated files #4463

@drigz

Description

@drigz

Add a way of including private headers (ie, headers included by files in srcs that should not be available to targets that depend on this cc_library) that works the same when the cc_library is in an external repo and when the headers are generated files.

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

Currently, the only way I'm aware of including a private header is with copts = ["-Ipath/to/hdr/dir"]. However, this needs a different path when the target is used from an external repository, resulting in code like this (from ceres):

    # The path to internal/ depends on whether Ceres is the main workspace or
    # an external repository.
    if native.repository_name() != '@':
        internal = 'external/%s/internal' % native.repository_name().lstrip('@')
    else:
        internal = 'internal'
    copts = ["-I" + internal],

or if the header is generated, like this (from glog):

    if native.repository_name() != '@':
        gendir = '$(GENDIR)/external/' + native.repository_name().lstrip('@')
    else:
        gendir = '$(GENDIR)'
    copts = ["-I%s/glog_internal" % gendir],

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

  1. Download and extract private_headers.tar.gz
  2. cd private_headers/ws1
  3. bazel build :lib (works)
  4. cd ../ws2
  5. bazel build :exthdr_lib (fails)
  6. bazel build :genhdr_lib (also fails)

What operating system are you running Bazel on?

Ubuntu 14.04

What's the output of bazel info release?

release 0.9.0

Have you found anything relevant by searching the web?

It is related to #2172, but that is specifically about platform independence.
#1950 concerns the difficulty of using private generated headers, but (a) is closed due to inactivity and (b) doesn't mention the complexity of use from external repos.
#2476 might also have been avoided, since it appears to stem from the use of includes = ["$(GENDIR)"] (source).

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3We're not considering working on this, but happy to review a PR. (No assignee)team-Rules-CPPIssues for C++ rulestype: feature request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions