This repository has been archived by the owner on Oct 19, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for relative paths to the Bazel build (#41)
Pull in apple_relative_framework.bzl. bazel test now works as expected.
- Loading branch information
ianegordon
committed
Jun 7, 2018
1 parent
e32da49
commit f71a090
Showing
3 changed files
with
85 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
"""Bazel rules for supporting framework-relative header imports.""" | ||
|
||
load("@build_bazel_rules_apple//apple/bundling:file_actions.bzl", "file_actions") | ||
|
||
|
||
def _apple_framework_relative_headers_impl(ctx): | ||
"""Implementation for apple_framework_relative_headers rule.""" | ||
output_dir = ctx.attr.framework_name + "_apple_framework_relative_headers" | ||
|
||
outputs = [] | ||
for f in ctx.files.hdrs: | ||
framework_path = "/".join([output_dir, ctx.attr.framework_name, f.basename]) | ||
framework_header_file = ctx.actions.declare_file(framework_path) | ||
file_actions.symlink(ctx, f, framework_header_file) | ||
outputs.append(framework_header_file) | ||
|
||
include_dir = "/".join([ | ||
ctx.configuration.bin_dir.path, ctx.label.package, output_dir]) | ||
return [ | ||
apple_common.new_objc_provider( | ||
header=depset(outputs), | ||
include=depset([include_dir]), | ||
), | ||
DefaultInfo(files=depset(outputs)), | ||
] | ||
|
||
|
||
apple_framework_relative_headers = rule( | ||
_apple_framework_relative_headers_impl, | ||
attrs = { | ||
"hdrs": attr.label_list(allow_files=[".h"], allow_empty=False), | ||
"framework_name": attr.string(mandatory=True), | ||
"_realpath": attr.label( | ||
cfg="host", | ||
allow_files=True, | ||
single_file=True, | ||
default=Label("@bazel_tools//tools/objc:realpath"), | ||
), | ||
}, | ||
) | ||
"""Creates a directory structure suitable for framework-relative import | ||
statements. | ||
For example, one would be able to #import <Foo/Bar.h> given the following rules: | ||
apple_framework_relative_headers( | ||
name = "FooFrameworkHeaders", | ||
hdrs = ["Source/Bar.h"], | ||
framework_name = "Foo", | ||
) | ||
objc_library( | ||
... | ||
deps = [":FooFrameworkHeaders"], | ||
) | ||
Args: | ||
hdrs: The list of header files. | ||
framework_name: The name of the framework. | ||
""" |