aboutsummaryrefslogtreecommitdiff
path: root/bazel/deploy_jar_freshness_golden_test.bzl
blob: 7c933ce09a37ad4436d02f9dceb76099000ba8a0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# Copyright 2022 Google LLC. All rights reserved.
#
# 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.

"""Test on *_deploy.jar freshness"""

load("//:visibility.bzl", "RULES_KOTLIN")

visibility(RULES_KOTLIN)

def _deploy_jar_freshness_golden_test_impl(ctx):
    test_command = """
      if ! cmp $1 $2 ; then
          echo "$1 needs to be rebuilt"
          echo "exit 1" > $3
          exit 0
      fi

      # Always passes
      echo "#!/bin/bash" > $3
    """

    dummy_test_script = ctx.actions.declare_file(ctx.label.name + ".sh")
    ctx.actions.run_shell(
        inputs = [ctx.file.current_jar, ctx.file.newly_built_jar],
        outputs = [dummy_test_script],
        arguments = [
            ctx.file.current_jar.path,
            ctx.file.newly_built_jar.path,
            dummy_test_script.path,
        ],
        command = test_command,
    )

    return [DefaultInfo(executable = dummy_test_script)]

deploy_jar_freshness_golden_test = rule(
    implementation = _deploy_jar_freshness_golden_test_impl,
    attrs = dict(
        newly_built_jar = attr.label(
            doc = "Newly built target deploy.jar",
            mandatory = True,
            allow_single_file = [".jar"],
        ),
        current_jar = attr.label(
            doc = "Prebuilt jar to verify",
            allow_single_file = [".jar"],
            mandatory = True,
        ),
    ),
    test = True,
)