Skip to content
This repository has been archived by the owner on Oct 19, 2023. It is now read-only.

Add support for relative paths to the Bazel build #41

Merged
merged 7 commits into from
Jun 7, 2018
Merged
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
11 changes: 10 additions & 1 deletion BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
load("@bazel_ios_warnings//:strict_warnings_objc_library.bzl", "strict_warnings_objc_library")
load("@build_bazel_rules_apple//apple:swift.bzl", "swift_library")
load("@build_bazel_rules_apple//apple:ios.bzl", "ios_unit_test")
load(":apple_framework_relative_headers.bzl", "apple_framework_relative_headers")

licenses(["notice"]) # Apache 2.0

Expand All @@ -38,12 +39,20 @@ strict_warnings_objc_library(
visibility = ["//visibility:public"],
)

apple_framework_relative_headers(
name = "MDFInternationalizationFrameworkHeaders",
hdrs = glob([
"Sources/*.h",
]),
framework_name = "MDFInternationalization",
)

objc_library(
name = "UnitTestsLib",
srcs = glob([
"Tests/*.m",
]),
deps = [":MDFInternationalization"],
deps = [":MDFInternationalization", ":MDFInternationalizationFrameworkHeaders"],
visibility = ["//visibility:private"],
)

Expand Down
15 changes: 15 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,21 @@
# See the License for the specific language governing permissions and
# limitations under the License.


#git_repository(
# name = "io_bazel",
# remote = "https://github.com/bazelbuild/bazel.git",
# tag = "0.14.0",
#)



git_repository(
name = "com_github_bazelbuild_buildtools",
remote = "https://github.com/bazelbuild/buildtools.git",
tag = "0.11.1",
)

git_repository(
name = "build_bazel_rules_apple",
remote = "https://github.com/bazelbuild/rules_apple.git",
Expand Down
60 changes: 60 additions & 0 deletions apple_framework_relative_headers.bzl
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.
"""