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 34
/
apple_framework_relative_headers.bzl
65 lines (54 loc) · 1.99 KB
/
apple_framework_relative_headers.bzl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
"""Bazel rules for supporting framework-relative header imports."""
load(
"@build_bazel_rules_apple//apple/internal:file_support.bzl",
"file_support",
)
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_support.symlink(ctx, f, framework_header_file)
outputs.append(framework_header_file)
# Documentation of these implicit types can be found here:
# ctx: https://docs.bazel.build/versions/master/skylark/lib/ctx.html
# ctx.label: https://docs.bazel.build/versions/master/skylark/lib/Label.html
include_dir = "/".join([
ctx.configuration.bin_dir.path, ctx.label.workspace_root, 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_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.
"""