Skip to content
Open
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
5 changes: 5 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ module(name = "rules_codechecker")
bazel_dep(name = "rules_cc", version = "0.2.3")
bazel_dep(name = "rules_python", version = "0.38.0")

bazel_dep(
name = "bazel_skylib",
version = "1.7.1",
dev_dependency = True,
)
bazel_dep(
name = "buildifier_prebuilt",
version = "7.3.1",
Expand Down
230 changes: 230 additions & 0 deletions test/unit/compile_commands/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,230 @@
# Copyright 2026 Ericsson AB
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

load("@rules_cc//cc:defs.bzl", "cc_library")
load(
":compile_commands_analysis_test.bzl",
"custom_ccinfo",
"get_compile_flags_defines_from_impl_deps_test",
"get_compile_flags_includes_from_impl_deps_test",
"get_compile_flags_local_defines_from_impl_deps_test",
"get_compile_flags_no_duplicates_test",
"get_compile_flags_quote_includes_from_deps_test",
"get_compile_flags_system_includes_from_impl_deps_test",
"get_compile_flags_test_suite",
)

# =============================================================================
# Analysis tests
# =============================================================================

# get_compile_flags
# -----------------

cc_library(
name = "compile_flags_tests_with_defines",
srcs = ["testdata/foo.cc"],
hdrs = ["testdata/foo.h"],
defines = ["MY_DEFINE=1"],
tags = ["manual"],
)

# BUG (manual): defines from implementation_deps are not collected.
cc_library(
name = "compile_flags_tests_impl_dep_with_defines",
srcs = ["testdata/bar.cc"],
hdrs = ["testdata/bar.h"],
defines = ["IMPL_DEP_DEFINE=1"],
tags = ["manual"],
)

cc_library(
name = "compile_flags_tests_with_impl_dep_defines",
srcs = ["testdata/foo.cc"],
hdrs = ["testdata/foo.h"],
implementation_deps = [":compile_flags_tests_impl_dep_with_defines"],
tags = ["manual"],
)

get_compile_flags_defines_from_impl_deps_test(
name = "get_compile_flags_defines_from_impl_deps",
tags = ["manual"],
target_under_test = ":compile_flags_tests_with_impl_dep_defines",
)

cc_library(
name = "compile_flags_tests_with_local_defines",
srcs = ["testdata/foo.cc"],
hdrs = ["testdata/foo.h"],
local_defines = ["LOCAL_DEF=1"],
tags = ["manual"],
)

# BUG (manual): local_defines from implementation_deps are not collected.
cc_library(
name = "compile_flags_tests_impl_dep_with_local_defines",
srcs = ["testdata/bar.cc"],
hdrs = ["testdata/bar.h"],
local_defines = ["IMPL_DEP_LOCAL_DEF=1"],
tags = ["manual"],
)

cc_library(
name = "compile_flags_tests_with_impl_dep_local_defines",
srcs = ["testdata/foo.cc"],
hdrs = ["testdata/foo.h"],
implementation_deps = [":compile_flags_tests_impl_dep_with_local_defines"],
tags = ["manual"],
)

get_compile_flags_local_defines_from_impl_deps_test(
name = "get_compile_flags_local_defines_from_impl_deps",
tags = ["manual"],
target_under_test = ":compile_flags_tests_with_impl_dep_local_defines",
)

cc_library(
name = "compile_flags_tests_with_includes",
srcs = ["testdata/foo.cc"],
hdrs = ["testdata/foo.h"],
includes = ["my/include/path"],
tags = ["manual"],
)

# includes from implementation_deps should be collected.
cc_library(
name = "compile_flags_tests_impl_dep_with_includes",
srcs = ["testdata/bar.cc"],
hdrs = ["testdata/bar.h"],
includes = ["impl_dep/include"],
tags = ["manual"],
)

cc_library(
name = "compile_flags_tests_with_impl_dep_includes",
srcs = ["testdata/foo.cc"],
hdrs = ["testdata/foo.h"],
implementation_deps = [":compile_flags_tests_impl_dep_with_includes"],
tags = ["manual"],
)

get_compile_flags_includes_from_impl_deps_test(
name = "get_compile_flags_includes_from_impl_deps",
target_under_test = ":compile_flags_tests_with_impl_dep_includes",
)

cc_library(
name = "compile_flags_tests_with_copts",
srcs = ["testdata/foo.cc"],
hdrs = ["testdata/foo.h"],
copts = [
"-Wall",
"-Wextra",
],
tags = ["manual"],
)

cc_library(
name = "compile_flags_tests_dep_with_includes",
srcs = ["testdata/bar.cc"],
hdrs = ["testdata/bar.h"],
includes = ["dep/include"],
tags = ["manual"],
)

cc_library(
name = "compile_flags_tests_with_dep_includes",
srcs = ["testdata/foo.cc"],
hdrs = ["testdata/foo.h"],
tags = ["manual"],
deps = [":compile_flags_tests_dep_with_includes"],
)

custom_ccinfo(
name = "compile_flags_tests_sys_include_provider",
system_includes = ["my/sys/include"],
tags = ["manual"],
)

cc_library(
name = "compile_flags_tests_with_system_includes",
srcs = ["testdata/foo.cc"],
hdrs = ["testdata/foo.h"],
tags = ["manual"],
deps = [":compile_flags_tests_sys_include_provider"],
)

# system_includes from implementation_deps should be collected.
custom_ccinfo(
name = "compile_flags_tests_impl_dep_sys_include_provider",
system_includes = ["impl_dep/sys/include"],
tags = ["manual"],
)

cc_library(
name = "compile_flags_tests_with_impl_dep_system_includes",
srcs = ["testdata/foo.cc"],
hdrs = ["testdata/foo.h"],
implementation_deps = [":compile_flags_tests_impl_dep_sys_include_provider"],
tags = ["manual"],
)

get_compile_flags_system_includes_from_impl_deps_test(
name = "get_compile_flags_system_includes_from_impl_deps",
target_under_test = ":compile_flags_tests_with_impl_dep_system_includes",
)

custom_ccinfo(
name = "compile_flags_tests_quote_include_provider",
quote_includes = ["my/quote/include"],
tags = ["manual"],
)

cc_library(
name = "compile_flags_tests_with_quote_includes",
srcs = ["testdata/foo.cc"],
hdrs = ["testdata/foo.h"],
tags = ["manual"],
deps = [":compile_flags_tests_quote_include_provider"],
)

# BUG (manual): quote_includes from implementation_deps are not collected.
custom_ccinfo(
name = "compile_flags_tests_dep_quote_include_provider",
quote_includes = ["dep/quote/path"],
tags = ["manual"],
)

cc_library(
name = "compile_flags_tests_with_dep_quote_includes",
srcs = ["testdata/foo.cc"],
hdrs = ["testdata/foo.h"],
implementation_deps = [":compile_flags_tests_dep_quote_include_provider"],
tags = ["manual"],
)

get_compile_flags_quote_includes_from_deps_test(
name = "get_compile_flags_quote_includes_from_deps",
tags = ["manual"],
target_under_test = ":compile_flags_tests_with_dep_quote_includes",
)

get_compile_flags_test_suite(name = "compile_flags_tests")

# BUG (manual): compile commands should not contain duplicate flags.
get_compile_flags_no_duplicates_test(
name = "get_compile_flags_no_duplicates",
tags = ["manual"],
target_under_test = ":compile_flags_tests_with_dep_includes",
)
Loading
Loading