Skip to content

Commit

Permalink
[build] Add headers attr to cc_library()
Browse files Browse the repository at this point in the history
So we can declare headers, and not have the ad hoc globs.

Right now we are inconsistent because we include cpp/* , mycpp/*,
prebuilt/*/*, etc.
  • Loading branch information
Andy C committed Jan 6, 2024
1 parent 6772c74 commit 8ba2024
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
10 changes: 8 additions & 2 deletions build/ninja_lib.py
Expand Up @@ -122,11 +122,12 @@ class CcLibrary(object):
4. The tarball needs the list of sources for binary
"""

def __init__(self, label, srcs, implicit, deps, generated_headers):
def __init__(self, label, srcs, implicit, deps, headers, generated_headers):
self.label = label
self.srcs = srcs # queried by SourcesForBinary
self.implicit = implicit
self.deps = deps
self.headers = headers
# TODO: asdl() rule should add to this.
# Generated headers are different than regular headers. The former need an
# implicit dep in Ninja, while the latter can rely on the .d mechanism.
Expand Down Expand Up @@ -285,6 +286,8 @@ def cc_library(self, label,
srcs = None,
implicit = None,
deps = None,
# note: headers is only used for tarball manifest, not compiler command line
headers = None,
generated_headers = None):

# srcs = [] is allowed for _gen/asdl/hnode.asdl.h
Expand All @@ -293,12 +296,14 @@ def cc_library(self, label,

implicit = implicit or []
deps = deps or []
headers = headers or []
generated_headers = generated_headers or []

if label in self.cc_libs:
raise RuntimeError('%s was already defined' % label)

self.cc_libs[label] = CcLibrary(label, srcs, implicit, deps, generated_headers)
self.cc_libs[label] = CcLibrary(label, srcs, implicit, deps,
generated_headers, headers)

def _TransitiveClosure(self, name, deps, unique_out):
"""
Expand Down Expand Up @@ -420,6 +425,7 @@ def HeadersForBinary(self, main_cc):
deps = self.cc_binary_deps[main_cc]
headers = []
for label in deps:
headers.extend(self.cc_libs[label].headers)
headers.extend(self.cc_libs[label].generated_headers)
return headers

Expand Down
1 change: 1 addition & 0 deletions build/ninja_main.py
Expand Up @@ -73,6 +73,7 @@ def TarballManifest(cc_h_files):
names.extend(glob('build/detect-*.c'))

# TODO: crawl headers
# We can now use the headers=[] attribute
names.extend(glob('mycpp/*.h'))
names.extend(glob('cpp/*.h'))

Expand Down
4 changes: 4 additions & 0 deletions cpp/NINJA_subgraph.py
Expand Up @@ -88,6 +88,10 @@ def NinjaGraph(ru):
deps=[
'//mycpp/runtime',
],
# This ensures its included in the release tarball
headers=[
'data_lang/utf8_impls/bjoern_dfa.h',
],
)

ru.cc_binary('cpp/data_lang_test.cc',
Expand Down

0 comments on commit 8ba2024

Please sign in to comment.