xref: /aosp_15_r20/external/bazel-skylib/tests/copy_directory/empty_directory.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"""Creates an empty directory."""
16
17def _empty_directory_impl(ctx):
18    out = ctx.actions.declare_directory(ctx.attr.name)
19    ctx.actions.run_shell(
20        outputs = [out],
21        command = "mkdir -p $@",
22        arguments = [out.path],
23        mnemonic = "EmptyDirectory",
24        progress_message = "Creating empty directory %s" % out.path,
25        use_default_shell_env = True,
26        execution_requirements = {"no-remote": "1"},  # see rules/private/copy_directory_private.bzl
27    )
28    return [DefaultInfo(files = depset(direct = [out]))]
29
30empty_directory = rule(
31    implementation = _empty_directory_impl,
32    provides = [DefaultInfo],
33    doc = "Creates an empty directory with the same name as the target",
34)
35