Skip to content

Commit

Permalink
Allow generated headers with path separators (#439)
Browse files Browse the repository at this point in the history
Co-authored-by: Michael Eisel <meisel@spotify.com>
Co-authored-by: Keith Smiley <keithbsmiley@gmail.com>
  • Loading branch information
3 people authored Aug 13, 2020
1 parent 49de7e5 commit fc74b43
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 15 deletions.
9 changes: 1 addition & 8 deletions swift/internal/compiling.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -1588,8 +1588,7 @@ def _declare_multiple_outputs_and_write_output_file_map(
def _declare_validated_generated_header(actions, generated_header_name):
"""Validates and declares the explicitly named generated header.
If the file does not have a `.h` extension or conatins path separators, the
build will fail.
If the file does not have a `.h` extension, the build will fail.
Args:
actions: The context's `actions` object.
Expand All @@ -1598,12 +1597,6 @@ def _declare_validated_generated_header(actions, generated_header_name):
Returns:
A `File` that should be used as the output for the generated header.
"""
if "/" in generated_header_name:
fail(
"The generated header for a Swift module may not contain " +
"directory components (got '{}').".format(generated_header_name),
)

extension = paths.split_extension(generated_header_name)[1]
if extension != ".h":
fail(
Expand Down
4 changes: 2 additions & 2 deletions test/fixtures/generated_header/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ swift_library(
)

swift_library(
name = "invalid_path_separator",
name = "valid_path_separator",
srcs = ["Empty.swift"],
generated_header_name = "Invalid/Separator.h",
generated_header_name = "Valid/Separator.h",
tags = FIXTURE_TAGS,
)
15 changes: 10 additions & 5 deletions test/generated_header_tests.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,17 @@ def generated_header_test_suite(name = "generated_header"):
target_under_test = "@build_bazel_rules_swift//test/fixtures/generated_header:invalid_extension",
)

# Verify that the build fails to analyze if a path separator is used.
generate_header_and_module_map_failure_test(
name = "{}_invalid_path_separator".format(name),
expected_message = "The generated header for a Swift module may not contain directory components",
# Verify that the build analyzes if a path separator is used.
generate_header_and_module_map_provider_test(
name = "{}_valid_path_separator".format(name),
expected_files = [
"test/fixtures/generated_header/Valid/Separator.h",
"*",
],
field = "files",
provider = "DefaultInfo",
tags = [name],
target_under_test = "@build_bazel_rules_swift//test/fixtures/generated_header:invalid_path_separator",
target_under_test = "@build_bazel_rules_swift//test/fixtures/generated_header:valid_path_separator",
)

# Verify that the header is not generated if the feature
Expand Down

0 comments on commit fc74b43

Please sign in to comment.