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"""Test on *_deploy.jar freshness""" 16 17load("//:visibility.bzl", "RULES_KOTLIN") 18 19def _deploy_jar_freshness_golden_test_impl(ctx): 20 test_command = """ 21 if ! cmp $1 $2 ; then 22 echo "$1 needs to be rebuilt" 23 echo "exit 1" > $3 24 exit 0 25 fi 26 27 # Always passes 28 echo "#!/bin/bash" > $3 29 """ 30 31 dummy_test_script = ctx.actions.declare_file(ctx.label.name + ".sh") 32 ctx.actions.run_shell( 33 inputs = [ctx.file.current_jar, ctx.file.newly_built_jar], 34 outputs = [dummy_test_script], 35 arguments = [ 36 ctx.file.current_jar.path, 37 ctx.file.newly_built_jar.path, 38 dummy_test_script.path, 39 ], 40 command = test_command, 41 ) 42 43 return [DefaultInfo(executable = dummy_test_script)] 44 45deploy_jar_freshness_golden_test = rule( 46 implementation = _deploy_jar_freshness_golden_test_impl, 47 attrs = dict( 48 newly_built_jar = attr.label( 49 doc = "Newly built target deploy.jar", 50 mandatory = True, 51 allow_single_file = [".jar"], 52 ), 53 current_jar = attr.label( 54 doc = "Prebuilt jar to verify", 55 allow_single_file = [".jar"], 56 mandatory = True, 57 ), 58 ), 59 test = True, 60) 61