Skip to content

Commit

Permalink
Copy module file instead of symlinking.
Browse files Browse the repository at this point in the history
This is primary to work around bazelbuild/bazel#20886,
but also helps on Windows if symbolic links aren’t supported.
  • Loading branch information
phst committed Jan 21, 2024
1 parent 79b09b6 commit 578ce77
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 4 deletions.
8 changes: 8 additions & 0 deletions elisp/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,14 @@ elisp_binary(
visibility = ["//visibility:public"],
)

py_binary(
name = "copy_file",
srcs = ["copy_file.py"],
python_version = "PY3",
srcs_version = "PY3",
visibility = [":__pkg__"],
)

cc_defaults(
name = "launcher_defaults",
copts = LAUNCHER_COPTS,
Expand Down
29 changes: 29 additions & 0 deletions elisp/copy_file.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Copyright 2024 Philipp Stephani
#
# 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.

import argparse
import pathlib
import shutil


def _main() -> None:
parser = argparse.ArgumentParser(allow_abbrev=False)
parser.add_argument('source', type=pathlib.Path)
parser.add_argument('dest', type=pathlib.Path)
args = parser.parse_args()
shutil.copyfile(args.source, args.dest)


if __name__ == '__main__':
_main()
16 changes: 12 additions & 4 deletions elisp/defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -527,10 +527,13 @@ def _elisp_cc_module_impl(ctx):
lib = out.library_to_link.dynamic_library
else:
lib = ctx.actions.declare_file(filename)
ctx.actions.symlink(
output = lib,
target_file = out.library_to_link.dynamic_library,
progress_message = "Creating symbolic link " + lib.short_path,
ctx.actions.run(
executable = ctx.executable._copy_file,
arguments = [ctx.actions.args().add("--").add(out.library_to_link.dynamic_library).add(lib)],
inputs = [out.library_to_link.dynamic_library],
outputs = [lib],
mnemonic = "Copy",
progress_message = "Copying %{input} to %{output}",
)

# Replicate some implementation details of cc_binary to make coverage work,
Expand Down Expand Up @@ -645,6 +648,11 @@ C/C++ compiler. See the [corresponding attribute for
default = Label("//elisp:module_config"),
providers = [CcDefaultInfo, ModuleConfigInfo],
),
"_copy_file": attr.label(
default = Label("//elisp:copy_file"),
executable = True,
cfg = "exec",
),
},
provides = [EmacsLispInfo],
fragments = ["cpp"],
Expand Down

0 comments on commit 578ce77

Please sign in to comment.