Skip to content

Implement bzl_mod compatible workaround for local_includes [IO-416] #161

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions cc/defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ def _common_cxx_opts(exceptions = False, rtti = False, standard = None):
}) + _common_cxx_standard_opts(standard)

# Handle various nuances of local include paths
def _construct_local_includes(local_includes):
return [construct_local_include(path) for path in local_includes]
def _construct_local_includes(target_name, local_includes):
return [construct_local_include(target_name, path) for path in local_includes]

# Handle whether to link statically
def _link_static(linkstatic = True):
Expand Down Expand Up @@ -232,7 +232,7 @@ def swift_c_library(**kwargs):
_create_srcs(**kwargs)
_create_hdrs(**kwargs)

local_includes = _construct_local_includes(kwargs.pop("local_includes", []))
local_includes = _construct_local_includes(kwargs.get("name", ""), kwargs.pop("local_includes", []))

nocopts = kwargs.pop("nocopts", []) # pop because nocopts is a deprecated cc* attr.

Expand Down Expand Up @@ -284,7 +284,7 @@ def swift_cc_library(**kwargs):
_create_srcs(**kwargs)
_create_hdrs(**kwargs)

local_includes = _construct_local_includes(kwargs.pop("local_includes", []))
local_includes = _construct_local_includes(kwargs.get("name", ""), kwargs.pop("local_includes", []))

nocopts = kwargs.pop("nocopts", []) # pop because nocopts is a deprecated cc* attr.

Expand Down Expand Up @@ -331,7 +331,7 @@ def swift_c_tool_library(**kwargs):
nocopts: List of flags to remove from the default compile
options. Use judiciously.
"""
local_includes = _construct_local_includes(kwargs.pop("local_includes", []))
local_includes = _construct_local_includes(kwargs.get("name", ""), kwargs.pop("local_includes", []))

nocopts = kwargs.pop("nocopts", [])

Expand Down Expand Up @@ -377,7 +377,7 @@ def swift_cc_tool_library(**kwargs):
nocopts: List of flags to remove from the default compile
options. Use judiciously.
"""
local_includes = _construct_local_includes(kwargs.pop("local_includes", []))
local_includes = _construct_local_includes(kwargs.get("name", ""), kwargs.pop("local_includes", []))

nocopts = kwargs.pop("nocopts", [])

Expand Down Expand Up @@ -421,7 +421,7 @@ def swift_c_binary(**kwargs):
nocopts: List of flags to remove from the default compile
options. Use judiciously.
"""
local_includes = _construct_local_includes(kwargs.pop("local_includes", []))
local_includes = _construct_local_includes(kwargs.get("name", ""), kwargs.pop("local_includes", []))

nocopts = kwargs.pop("nocopts", [])

Expand Down Expand Up @@ -471,7 +471,7 @@ def swift_cc_binary(**kwargs):
nocopts: List of flags to remove from the default compile
options. Use judiciously.
"""
local_includes = _construct_local_includes(kwargs.pop("local_includes", []))
local_includes = _construct_local_includes(kwargs.get("name", ""), kwargs.pop("local_includes", []))

nocopts = kwargs.pop("nocopts", [])

Expand Down Expand Up @@ -598,7 +598,7 @@ def swift_cc_test_library(**kwargs):

_ = kwargs.pop("nocopts", []) # To handle API compatibility.

local_includes = _construct_local_includes(kwargs.pop("local_includes", []))
local_includes = _construct_local_includes(kwargs.get("name", ""), kwargs.pop("local_includes", []))

kwargs["copts"] = local_includes + kwargs.get("copts", [])

Expand Down Expand Up @@ -650,7 +650,7 @@ def swift_cc_test(name, type, **kwargs):
if not (type == UNIT or type == INTEGRATION):
fail("The 'type' attribute must be either UNIT or INTEGRATION")

local_includes = _construct_local_includes(kwargs.pop("local_includes", []))
local_includes = _construct_local_includes(kwargs.get("name", ""), kwargs.pop("local_includes", []))

kwargs["copts"] = local_includes + kwargs.get("copts", []) + _tests_warn_deprecated_declarations() + _common_cxx_standard_opts(kwargs.pop("standard", []))
kwargs["data"] = kwargs.get("data", []) + _symbolizer_data()
Expand Down
9 changes: 7 additions & 2 deletions cc/utils.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.

def construct_local_include(path):
def construct_local_include(target_name, path):
"""Helper to correctly set up local (non-public) include paths.

When a bazel workspace is consumed externally, (i.e. via local_repository),
Expand All @@ -19,13 +19,18 @@ def construct_local_include(path):
building a workpace standalone, and externally.

Args:
name: The target, which calls this macro

path: The include path relative to the package this macro is called from

Use the special argument $(GENDIR) to construct an include path for
any generated files the build depends on. Assumes these files are
not generated into a subdirectory.
"""
root = Label(native.repository_name() + "//:WORKSPACE").workspace_root or "."
if target_name != "":
root = Label(target_name).workspace_root or "."
else:
root = "."
package = native.package_name()

# Generated files are placed in $(GENDIR)/external/<workspace_root>
Expand Down
Loading