xref: /aosp_15_r20/external/bazel-skylib/rules/private/copy_common.bzl (revision bcb5dc7965af6ee42bf2f21341a2ec00233a8c8a)
1# Copyright 2022 The Bazel Authors. 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"Helpers for copy rules"
16
17# Hints for Bazel spawn strategy
18COPY_EXECUTION_REQUIREMENTS = {
19    # ----------------+-----------------------------------------------------------------------------
20    # no-remote       | Prevents the action or test from being executed remotely or cached remotely.
21    #                 | This is equivalent to using both `no-remote-cache` and `no-remote-exec`.
22    # ----------------+-----------------------------------------------------------------------------
23    # no-cache        | Results in the action or test never being cached (remotely or locally)
24    # ----------------+-----------------------------------------------------------------------------
25    # See https://bazel.build/reference/be/common-definitions#common-attributes
26    #
27    # Copying file & directories is entirely IO-bound and there is no point doing this work
28    # remotely.
29    #
30    # Also, remote-execution does not allow source directory inputs, see
31    # https://github.com/bazelbuild/bazel/commit/c64421bc35214f0414e4f4226cc953e8c55fa0d2 So we must
32    # not attempt to execute remotely in that case.
33    #
34    # There is also no point pulling the output file or directory from the remote cache since the
35    # bytes to copy are already available locally. Conversely, no point in writing to the cache if
36    # no one has any reason to check it for this action.
37    #
38    # Read and writing to disk cache is disabled as well primarily to reduce disk usage on the local
39    # machine. A disk cache hit of a directory copy could be slghtly faster than a copy since the
40    # disk cache stores the directory artifact as a single entry, but the slight performance bump
41    # comes at the cost of heavy disk cache usage, which is an unmanaged directory that grow beyond
42    # the bounds of the physical disk.
43    "no-remote": "1",
44    "no-cache": "1",
45}
46