1# Copyright 2021 Code Intelligence GmbH 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); 4# you may not use this file except in compliance with the License. 5# You may obtain a copy of the License at 6# 7# http://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, 11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12# See the License for the specific language governing permissions and 13# limitations under the License. 14 15load("@io_bazel_rules_kotlin//kotlin:lint.bzl", "ktlint_fix", "ktlint_test") 16load("@io_bazel_rules_kotlin//kotlin:jvm.bzl", "kt_jvm_test") 17load("//bazel:compat.bzl", "SKIP_ON_WINDOWS") 18 19# A kt_jvm_test wrapped in a java_test for Windows compatibility. 20# Workaround for https://github.com/bazelbuild/rules_kotlin/issues/599: rules_kotlin can only create 21# a shell wrapper script for Java targets, no native executable as is required on Windows. 22def wrapped_kt_jvm_test( 23 name, 24 test_class, 25 size = None, 26 tags = None, 27 timeout = None, 28 visibility = None, 29 **kt_jvm_test_args): 30 kt_jvm_test_name = name + "_kt_" 31 32 # Modify a copy of the tags. 33 kt_jvm_test_tags = list(tags) if tags != None else [] 34 kt_jvm_test_tags.append("manual") 35 kt_jvm_test( 36 name = kt_jvm_test_name, 37 test_class = test_class, 38 visibility = ["//visibility:private"], 39 tags = kt_jvm_test_tags, 40 **kt_jvm_test_args 41 ) 42 43 native.java_test( 44 name = name, 45 size = size, 46 tags = tags, 47 test_class = test_class, 48 timeout = timeout, 49 visibility = visibility, 50 runtime_deps = [ 51 ":" + kt_jvm_test_name, 52 ], 53 ) 54 55def ktlint(name = "ktlint"): 56 ktlint_test( 57 name = name + "_test", 58 srcs = native.glob(["**/*.kt"]), 59 config = Label("//bazel/toolchains:ktlint_config"), 60 target_compatible_with = SKIP_ON_WINDOWS, 61 ) 62 63 ktlint_fix( 64 name = name + "_fix", 65 srcs = native.glob(["**/*.kt"]), 66 config = Label("//bazel/toolchains:ktlint_config"), 67 target_compatible_with = SKIP_ON_WINDOWS, 68 ) 69