aboutsummaryrefslogtreecommitdiffhomepage
path: root/tools
diff options
context:
space:
mode:
authorGravatar Dmitry Shevchenko <dmishe@google.com>2016-10-05 20:16:39 +0000
committerGravatar Damien Martin-Guillerez <dmarting@google.com>2016-10-06 07:41:17 +0000
commit559aad78cae61f194e0bd5d880e60fb64f7ddb50 (patch)
tree48ac5f1d7822bf493732b091e5017c34721b8bc5 /tools
parent6a29202422f56cdce70c3827755011bbd1707338 (diff)
Validate swift_library names
* This prevents a target from building if its name or any name in its dependencies is not a valid Swift module name. -- MOS_MIGRATED_REVID=135270299
Diffstat (limited to 'tools')
-rw-r--r--tools/build_defs/apple/swift.bzl33
1 files changed, 33 insertions, 0 deletions
diff --git a/tools/build_defs/apple/swift.bzl b/tools/build_defs/apple/swift.bzl
index 3cc22fe44b..37fd4facb8 100644
--- a/tools/build_defs/apple/swift.bzl
+++ b/tools/build_defs/apple/swift.bzl
@@ -111,8 +111,41 @@ def _swift_xcrun_args(ctx):
return args
+
+def _is_valid_swift_module_name(string):
+ """Returns True if the string is a valid Swift module name."""
+ if not string:
+ return False
+
+ for char in string:
+ # Check that the character is in [a-zA-Z0-9_]
+ if not (char.isalnum() or char == "_"):
+ return False
+
+ return True
+
+
+def _validate_rule_and_deps(ctx):
+ """Validates the target and its dependencies."""
+
+ name_error_str = ("Error in target '%s', Swift target and its dependencies' "+
+ "names can only contain characters in [a-zA-Z0-9_].")
+
+ # Validate the name of the target
+ if not _is_valid_swift_module_name(ctx.label.name):
+ fail(name_error_str % ctx.label)
+
+ # Validate names of the dependencies
+ for dep in ctx.attr.deps:
+ if not _is_valid_swift_module_name(dep.label.name):
+ fail(name_error_str % dep.label)
+
+
def _swift_library_impl(ctx):
"""Implementation for swift_library Skylark rule."""
+
+ _validate_rule_and_deps(ctx)
+
# TODO(b/29772303): Assert xcode version.
apple_fragment = ctx.fragments.apple