From 24fbe71a5e8be8f1de20a77d3ca49bd040215f53 Mon Sep 17 00:00:00 2001 From: Isaac Torres Date: Thu, 29 Sep 2022 13:02:02 -0600 Subject: [PATCH 1/4] Init swift_cc rules --- swift_cc_defs.bzl | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 swift_cc_defs.bzl diff --git a/swift_cc_defs.bzl b/swift_cc_defs.bzl new file mode 100644 index 00000000..b181d1c7 --- /dev/null +++ b/swift_cc_defs.bzl @@ -0,0 +1,24 @@ +def swift_cc_library(**kwargs): + """Wraps cc_library to enforce standards for a production library. + """ + native.cc_library(**kwargs) + +def swift_cc_tool_library(**kwargs): + """Wraps cc_library to enforce standards for a non-production library. + """ + native.cc_library(**kwargs) + +def swift_cc_binary(**kwargs): + """Wraps cc_binary to enforce standards for a production library. + """ + native.cc_binary(**kwargs) + +def swift_cc_tool(**kwargs): + """Wraps cc_binary to enforce standards for a non-production library. + """ + native.cc_binary(**kwargs) + +def swift_cc_test(**kwargs): + """Wraps cc_test to enforce Swift testing conventions. + """ + native.cc_test(**kwargs) From 4929d9445a8c4f539d184756bad4139bee496c11 Mon Sep 17 00:00:00 2001 From: Isaac Torres Date: Thu, 29 Sep 2022 13:36:44 -0600 Subject: [PATCH 2/4] Fix formatting --- swift_cc_defs.bzl | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/swift_cc_defs.bzl b/swift_cc_defs.bzl index b181d1c7..b7b6cba5 100644 --- a/swift_cc_defs.bzl +++ b/swift_cc_defs.bzl @@ -1,24 +1,24 @@ def swift_cc_library(**kwargs): - """Wraps cc_library to enforce standards for a production library. - """ + """Wraps cc_library to enforce standards for a production library. + """ native.cc_library(**kwargs) def swift_cc_tool_library(**kwargs): - """Wraps cc_library to enforce standards for a non-production library. - """ + """Wraps cc_library to enforce standards for a non-production library. + """ native.cc_library(**kwargs) def swift_cc_binary(**kwargs): - """Wraps cc_binary to enforce standards for a production library. - """ + """Wraps cc_binary to enforce standards for a production library. + """ native.cc_binary(**kwargs) def swift_cc_tool(**kwargs): - """Wraps cc_binary to enforce standards for a non-production library. - """ + """Wraps cc_binary to enforce standards for a non-production library. + """ native.cc_binary(**kwargs) def swift_cc_test(**kwargs): - """Wraps cc_test to enforce Swift testing conventions. - """ + """Wraps cc_test to enforce Swift testing conventions. + """ native.cc_test(**kwargs) From fb0a3b246531a58cf803a377e913ad098dc8f505 Mon Sep 17 00:00:00 2001 From: Isaac Torres Date: Thu, 29 Sep 2022 14:56:45 -0600 Subject: [PATCH 3/4] Implement test suites --- swift_cc_defs.bzl | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/swift_cc_defs.bzl b/swift_cc_defs.bzl index b7b6cba5..b24bb22b 100644 --- a/swift_cc_defs.bzl +++ b/swift_cc_defs.bzl @@ -1,3 +1,9 @@ +# Name for a unit test +UNIT = "unit" + +# Name for a integration test +INTEGRATION = "integration" + def swift_cc_library(**kwargs): """Wraps cc_library to enforce standards for a production library. """ @@ -18,7 +24,20 @@ def swift_cc_tool(**kwargs): """ native.cc_binary(**kwargs) -def swift_cc_test(**kwargs): +def swift_cc_test(name, type, **kwargs): """Wraps cc_test to enforce Swift testing conventions. + + Args: + name: A unique name for this rule. + type: Specifies whether the test is a unit or integration test. + + These are passed to cc_test as tags which enables running + these test types seperately: `bazel test --test_tag_filters=unit //...` """ + + if not (type == UNIT or type == INTEGRATION): + fail("The 'type' attribute must be either UNIT or INTEGRATION") + + kwargs["name"] = name + kwargs["tags"] = [type] native.cc_test(**kwargs) From 55851a9b1f034b6def665e6b63f71e7348d8bb7f Mon Sep 17 00:00:00 2001 From: Isaac Torres Date: Thu, 29 Sep 2022 17:40:09 -0600 Subject: [PATCH 4/4] Add test library wrapper --- swift_cc_defs.bzl | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/swift_cc_defs.bzl b/swift_cc_defs.bzl index b24bb22b..154532f5 100644 --- a/swift_cc_defs.bzl +++ b/swift_cc_defs.bzl @@ -24,6 +24,11 @@ def swift_cc_tool(**kwargs): """ native.cc_binary(**kwargs) +def swift_cc_test_library(**kwargs): + """Wraps cc_library to enforce Swift test library conventions. + """ + native.cc_library(**kwargs) + def swift_cc_test(name, type, **kwargs): """Wraps cc_test to enforce Swift testing conventions.