1# Copyright 2022 Google LLC. All rights reserved. 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 15"""kt_run_deploy_jar""" 16 17# go/keep-sorted start 18load("//:visibility.bzl", "RULES_KOTLIN") 19load("//bazel:stubs.bzl", "BASE_JVMOPTS") 20# go/keep-sorted end 21 22visibility(RULES_KOTLIN) 23 24def kt_run_deploy_jar( 25 ctx, 26 java_runtime, 27 deploy_jar, 28 inputs, 29 args = [], 30 deploy_jsa = None, 31 **kwargs): 32 """An analogue to ctx.actions.run for _deploy.jar executables.""" 33 34 java_args = ctx.actions.args() 35 java_inputs = [] 36 if deploy_jsa: 37 java_args.add("-Xshare:auto") 38 java_args.add(deploy_jsa, format = "-XX:SharedArchiveFile=%s") 39 java_args.add("-XX:-VerifySharedSpaces") 40 java_args.add("-XX:-ValidateSharedClassPaths") 41 java_inputs.append(deploy_jsa) 42 java_args.add("-jar", deploy_jar) 43 java_inputs.append(deploy_jar) 44 45 java_depset = depset(direct = java_inputs, transitive = [java_runtime[DefaultInfo].files]) 46 if type(inputs) == "depset": 47 all_inputs = depset(transitive = [java_depset, inputs]) 48 else: 49 all_inputs = depset(direct = inputs, transitive = [java_depset]) 50 51 ctx.actions.run( 52 executable = str(java_runtime[java_common.JavaRuntimeInfo].java_executable_exec_path), 53 inputs = all_inputs, 54 arguments = BASE_JVMOPTS + [java_args] + args, 55 **kwargs 56 ) 57