Skip to content
Merged
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
48 changes: 48 additions & 0 deletions swift_cc_defs.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Name for a unit test
UNIT = "unit"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bazel has a built in convention for splitting up tests that's similiar to how we distinguish unit vs integration tests.

The convention is small vs large tests: https://bazel.build/reference/test-encyclopedia#tag-conventions.

The you filter with bazel test --test_size_filters=small.

Putting this behind a constant means we can change this to the conventional way if we want without a big refactor.


# Name for a integration test
INTEGRATION = "integration"

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_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.

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)