Skip to content

Commit 317b88f

Browse files
authoredMay 26, 2024
Add iOs Swift example and fix missing remote_coverage_tools in main MODULE.bazel (#30)
1 parent 76f03d0 commit 317b88f

33 files changed

+3474
-5
lines changed
 

‎.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
.idea/
33
*.iml
44
bazel-*
5+
.DS_Store

‎MODULE.bazel

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
module(
22
name = "bazel_sonarqube",
3-
version = "1.0.1",
3+
version = "1.0.2",
44
compatibility_level = 1,
55
repo_name = "bazel_sonarqube",
66
)
77

8-
bazel_dep(name = "bazel_skylib", version = "1.0.3", repo_name = "bazel_skylib")
8+
bazel_dep(name = "bazel_skylib", version = "1.6.1", repo_name = "bazel_skylib")
99

1010
bazel_dep(
1111
name = "stardoc",
@@ -15,4 +15,7 @@ bazel_dep(
1515
)
1616

1717
non_module_dependencies = use_extension("//:extensions.bzl", "non_module_dependencies")
18-
use_repo(non_module_dependencies, "bazel_version", "org_sonarsource_scanner_cli_sonar_scanner_cli")
18+
use_repo(non_module_dependencies, "bazel_version", "org_sonarsource_scanner_cli_sonar_scanner_cli")
19+
20+
remote_coverage_tools_extension = use_extension("@bazel_tools//tools/test:extensions.bzl", "remote_coverage_tools_extension")
21+
use_repo(remote_coverage_tools_extension, "remote_coverage_tools")

‎examples/README.md

+4
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,7 @@ The usage pattern is similar to the single case except it limits the scope of th
2929

3030
1. `bazel coverage //subproject-with-separate-sonarqube/...`
3131
2. `bazel run //subproject-with-separate-sonarqube:sonarqube`
32+
33+
# Example integrating bazel_sonarqube with bzlmod
34+
35+
There is also a very simple iOS app example written in swift which demonstrates how to use bazel_sonarqube with [bzlmod](https://docs.bazel.build/versions/5.1.0/bzlmod.html).

‎examples/swift/.bazelignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.git

‎examples/swift/.bazelrc

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Enable Bzlmod for every Bazel command
2+
common --enable_bzlmod
3+
4+
## BUILD
5+
6+
# https://bazel.build/reference/command-line-reference#flag--incompatible_strict_action_env
7+
build --incompatible_strict_action_env
8+
9+
# Disable the worker, which has sandboxing disabled by default, which can hide
10+
# issues with non-hermetic bugs.
11+
build --spawn_strategy=sandboxed,local
12+
build --worker_sandboxing=true
13+
14+
#build --incompatible_disallow_empty_glob
15+
16+
build --features=swift.use_global_module_cache
17+
18+
# Enable indexing while building.
19+
build --features swift.use_global_index_store
20+
build --features swift.index_while_building
21+
22+
## TEST
23+
24+
# `bazel test` tries to build everything also by default, so skip that so the
25+
# *_library targets in examples/... aren't built (and fail since they are
26+
# platform specific).
27+
test --build_tests_only
28+
29+
# Show detailed errors for test failures
30+
test --test_output=errors
31+
32+
# We only want source files in test coverage reports, not tests themselves.
33+
test --instrumentation_filter="^//modules/API:APILib"
34+
35+
# Use llvm-cov instead of gcov (default).
36+
coverage --experimental_use_llvm_covmap
37+
coverage --collect_code_coverage
38+
coverage --combined_report=lcov
39+
coverage --coverage_report_generator=@bazel_sonarqube//:sonarqube_coverage_generator
40+
# Work around the Bazel issue with paths that contain whitespaces.
41+
coverage --experimental_inprocess_symlink_creation

‎examples/swift/.bazelversion

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
7.1.2

‎examples/swift/BUILD.bazel

+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
load("@bazel_sonarqube//:defs.bzl", "sonarqube")
2+
3+
# Generating Sonar coverage report
4+
filegroup(
5+
name = "test_reports",
6+
srcs = glob(["bazel-testlogs/**/test.xml"], allow_empty = True),
7+
tags = ["manual"],
8+
)
9+
10+
filegroup(
11+
name = "coverage_report",
12+
srcs = ["bazel-out/_coverage/_coverage_report.dat"],
13+
tags = ["manual"],
14+
)
15+
16+
filegroup(
17+
name = "git",
18+
srcs = glob([".git/**"], exclude = [".git/**/*[*]"]),
19+
tags = ["manial"],
20+
)
21+
22+
sonarqube(
23+
name = "sq",
24+
srcs = ["//modules/API:sources"],
25+
project_key = "your_sonar_project_key",
26+
project_name = "Bazel-SwiftUI-template",
27+
test_srcs = ["//modules/API:testSources"],
28+
test_targets = ["//modules/API:APITestsLib"],
29+
sq_properties_template = "sonar-project.properties.tpl",
30+
test_reports = [":test_reports"],
31+
coverage_report = ":coverage_report",
32+
scm_info = [":git"],
33+
testonly = True,
34+
)
35+
36+
load(
37+
"@rules_xcodeproj//xcodeproj:defs.bzl",
38+
"top_level_target",
39+
"xcodeproj",
40+
)
41+
42+
# Xcode
43+
44+
xcodeproj(
45+
name = "xcodeproj",
46+
project_name = "App",
47+
top_level_targets = [
48+
top_level_target(
49+
"//app",
50+
target_environments = ["simulator"],
51+
),
52+
top_level_target(
53+
"//modules/API:APITests",
54+
target_environments = ["simulator"],
55+
),
56+
top_level_target(
57+
"//modules/Models:ModelsTests",
58+
target_environments = ["simulator"],
59+
),
60+
],
61+
)
62+
63+
# tools
64+
65+
genrule(
66+
name = "lint",
67+
srcs = [],
68+
outs = ["lint.sh"],
69+
cmd = """
70+
echo "set -e" > "$@"
71+
echo "./$(location @buildifier_prebuilt//:buildifier) -lint fix -mode fix -r \\$$BUILD_WORKSPACE_DIRECTORY" >> "$@"
72+
echo "./$(location @SwiftLint//:swiftlint) --fix \\$$BUILD_WORKSPACE_DIRECTORY" >> "$@"
73+
""",
74+
executable = True,
75+
tools = [
76+
"@SwiftLint//:swiftlint",
77+
"@buildifier_prebuilt//:buildifier",
78+
],
79+
)

‎examples/swift/MODULE.bazel

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
bazel_dep(name = "bazel_skylib", version = "1.6.1")
2+
bazel_dep(name = "rules_xcodeproj", version = "2.3.1")
3+
bazel_dep(
4+
name = "apple_support",
5+
version = "1.15.1",
6+
repo_name = "build_bazel_apple_support",
7+
)
8+
bazel_dep(
9+
name = "rules_swift",
10+
version = "1.18.0",
11+
repo_name = "build_bazel_rules_swift",
12+
)
13+
bazel_dep(
14+
name = "rules_apple",
15+
version = "3.5.1",
16+
repo_name = "build_bazel_rules_apple",
17+
)
18+
bazel_dep(
19+
name = "buildifier_prebuilt",
20+
version = "6.3.3",
21+
dev_dependency = True,
22+
)
23+
24+
bazel_dep(
25+
name = "bazel_sonarqube",
26+
version = "1.0.1",
27+
repo_name = "bazel_sonarqube",
28+
)
29+
local_path_override(
30+
module_name = "bazel_sonarqube",
31+
path = "../../",
32+
)
33+
34+
non_module_dependencies = use_extension("//tools:extensions.bzl", "non_module_dependencies")
35+
use_repo(non_module_dependencies, "SwiftLint")

0 commit comments

Comments
 (0)
Please sign in to comment.