Skip to content
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
27 changes: 27 additions & 0 deletions test/unit/compile_commands/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ load("@rules_cc//cc:defs.bzl", "cc_library")
load("//:defs.bzl", "compile_commands")
load(
":analysis_test.bzl",
"c_only_has_conlyopt_flag_test",
"compile_flags_test_suite",
"custom_ccinfo",
"cxx_only_has_cxx_flag_test",
"defines_from_impl_deps_test",
"includes_from_impl_deps_test",
"local_defines_in_impl_deps_test",
Expand Down Expand Up @@ -264,3 +266,28 @@ no_duplicate_records_test(
name = "no_duplicate_records",
target_under_test = ":records",
)

# cxxopt / conlyopt filtering
# ----------------------------
# Verifies that --cxxopt flags only appear on C++ files and
# --conlyopt flags only appear on C files.

cc_library(
name = "target_with_c_and_cc",
srcs = [
"testdata/bar.c",
"testdata/bar.cc",
],
hdrs = ["testdata/bar.h"],
tags = ["manual"],
)

cxx_only_has_cxx_flag_test(
name = "cxx_only_has_cxx_flag",
target_under_test = ":target_with_c_and_cc",
)

c_only_has_conlyopt_flag_test(
name = "c_only_has_conlyopt_flag",
target_under_test = ":target_with_c_and_cc",
)
68 changes: 68 additions & 0 deletions test/unit/compile_commands/analysis_test.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,74 @@ quote_includes_from_deps_test = analysistest.make(
extra_target_under_test_aspects = [compile_commands_aspect],
)

def _cxx_only_has_cxx_flag_test_impl(ctx):
"""cxxopt flags must only appear in compile commands for c++ files."""
env = analysistest.begin(ctx)
commands = _get_compile_commands(analysistest.target_under_test(env)[SourceFilesInfo])

# Has cxx flags
cc_commands = [c for c in commands if "bar.cc" in c]
asserts.true(env, len(cc_commands) > 0, "Should have a command for bar.cc")
asserts.true(
env,
"__CXX__" in cc_commands[0],
"C++ file should contain cxxopt flag __CXX__, got: %s" % cc_commands[0],
)

# Doesn't have conly flags
cc_commands = [c for c in commands if "bar.cc" in c]
asserts.true(env, len(cc_commands) > 0, "Should have a command for bar.cc")
asserts.false(
env,
"__CONLY__" in cc_commands[0],
"C++ file should NOT contain conlyopt flag __CONLY__, got: %s" % cc_commands[0],
)

return analysistest.end(env)

cxx_only_has_cxx_flag_test = analysistest.make(
_cxx_only_has_cxx_flag_test_impl,
extra_target_under_test_aspects = [compile_commands_aspect],
config_settings = {
"//command_line_option:conlyopt": ["__CONLY__"],
"//command_line_option:cxxopt": ["__CXX__"],
},
)

def _c_only_has_conlyopt_flag_test_impl(ctx):
"""conlyopt flags must only appear in compile commands for .c files."""
env = analysistest.begin(ctx)
commands = _get_compile_commands(analysistest.target_under_test(env)[SourceFilesInfo])

# Has conly flags
c_commands = [c for c in commands if c.endswith("/bar.c")]
asserts.true(env, len(c_commands) > 0, "Should have a command for bar.c")
asserts.true(
env,
"__CONLY__" in c_commands[0],
"C file should contain conlyopt flag __CONLY__, got: %s" % c_commands[0],
)

# Doesn't have cxx flags
c_commands = [c for c in commands if c.endswith("/bar.c")]
asserts.true(env, len(c_commands) > 0, "Should have a command for bar.c")
asserts.false(
env,
"__CXX__" in c_commands[0],
"C file should NOT contain cxxopt flag __CXX__, got: %s" % c_commands[0],
)

return analysistest.end(env)

c_only_has_conlyopt_flag_test = analysistest.make(
_c_only_has_conlyopt_flag_test_impl,
extra_target_under_test_aspects = [compile_commands_aspect],
config_settings = {
"//command_line_option:conlyopt": ["__CONLY__"],
"//command_line_option:cxxopt": ["__CXX__"],
},
)

def _no_duplicates_test_impl(ctx):
"""Compile flags should not contain duplicates."""
env = analysistest.begin(ctx)
Expand Down
51 changes: 0 additions & 51 deletions test/unit/compile_flags/BUILD

This file was deleted.

18 changes: 0 additions & 18 deletions test/unit/compile_flags/simple_c.c

This file was deleted.

18 changes: 0 additions & 18 deletions test/unit/compile_flags/simple_cc.cc

This file was deleted.

115 changes: 0 additions & 115 deletions test/unit/compile_flags/test_compile_flags.py

This file was deleted.

Loading