Skip to content

Commit

Permalink
elisp_manual: Support additional input files.
Browse files Browse the repository at this point in the history
Fixes #570.
  • Loading branch information
phst committed Aug 29, 2024
1 parent 8f74d48 commit 9b31929
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 10 deletions.
8 changes: 6 additions & 2 deletions elisp/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ load(
"LAUNCHER_FEATURES",
"LAUNCHER_LINKOPTS",
"LINKOPTS",
"MAX_MANUAL_ADDITIONAL_INPUTS",
"PACKAGE_FEATURES",
"UNDEFINED_ERROR",
"bootstrap",
Expand Down Expand Up @@ -480,8 +481,11 @@ build_test(
elisp_binary(
name = "export_org",
src = "export-org.el",
input_args = [1],
output_args = [2],
input_args = range(
2,
3 + MAX_MANUAL_ADDITIONAL_INPUTS,
),
output_args = [1],
visibility = [
# FIXME: Make private once
# https://github.com/bazelbuild/proposals/blob/main/designs/2019-10-15-tool-visibility.md
Expand Down
13 changes: 11 additions & 2 deletions elisp/defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ load(
"CcDefaultInfo",
"LAUNCHER_ATTRS",
"LAUNCHER_DEPS",
"MAX_MANUAL_ADDITIONAL_INPUTS",
"ModuleConfigInfo",
"cc_launcher",
"check_relative_filename",
Expand Down Expand Up @@ -738,11 +739,14 @@ def _elisp_manual_impl(ctx):
out = ctx.outputs.out
if out.extension != "texi":
fail("Output filename {} doesn’t end in “.texi”".format(out.short_path))
additional_inputs = ctx.files.additional_inputs
if len(additional_inputs) > MAX_MANUAL_ADDITIONAL_INPUTS:
fail("Got {} additional input files; at most {} are allowed".format(len(additional_inputs), MAX_MANUAL_ADDITIONAL_INPUTS))
ctx.actions.run(
outputs = [out],
inputs = [src],
inputs = [src] + additional_inputs,
executable = ctx.executable._export,
arguments = [ctx.actions.args().add(src).add(out)],
arguments = [ctx.actions.args().add(out).add(src).add_all(additional_inputs, expand_directories = False)],
mnemonic = "Export",
progress_message = "Exporting %{input} into Texinfo file",
toolchain = None,
Expand All @@ -759,6 +763,11 @@ elisp_manual = rule(
doc = "Texinfo manual file to write; must end in `.texi`.",
mandatory = True,
),
"additional_inputs": attr.label_list(
doc = "List of additional files made available during export.",
allow_files = True,
cfg = "exec",
),
"_export": attr.label(
allow_single_file = True,
executable = True,
Expand Down
6 changes: 3 additions & 3 deletions elisp/export-org.el
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

;; Internal implementation of the ‘elisp_manual’ Bazel rule.
;; Usage:
;; emacs export-org.el INPUT.org OUTPUT.texi
;; emacs export-org.el OUTPUT.texi INPUT.org 〈ADDITIONAL-INPUTS〉

;;; Code:

Expand All @@ -30,7 +30,7 @@
(unless noninteractive (user-error "This file works only in batch mode"))

(pcase command-line-args-left
(`(,input ,output)
(`(,output ,input . ,_)
(setq command-line-args-left nil)
(let ((warning-fill-column 1000) ; https://debbugs.gnu.org/52281
(coding-system-for-read 'utf-8-unix)
Expand All @@ -45,6 +45,6 @@
(with-temp-buffer
(insert-file-contents input)
(write-region (org-export-as 'texinfo) nil output))))
(_ (user-error "Usage: elisp/export-org INPUT OUTPUT")))
(_ (user-error "Usage: elisp/export-org OUTPUT INPUT ADDITIONAL-INPUTS")))

;;; export-org.el ends here
1 change: 1 addition & 0 deletions examples/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ elisp_manual(
name = "doc",
src = "doc.org",
out = "doc.texi",
additional_inputs = ["config.org"],
)

genrule(
Expand Down
16 changes: 16 additions & 0 deletions examples/config.org
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Copyright 2021, 2022, 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.

#+LANGUAGE: en
#+OPTIONS: author:nil date:nil
5 changes: 2 additions & 3 deletions examples/doc.org
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2021, 2022 Google LLC
# Copyright 2021, 2022, 2024 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -13,8 +13,7 @@
# limitations under the License.

#+TITLE: Example documentation
#+LANGUAGE: en
#+OPTIONS: author:nil date:nil
#+SETUPFILE: examples/config.org

* Chapter

Expand Down
4 changes: 4 additions & 0 deletions private/defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -720,6 +720,10 @@ UNDEFINED_ERROR = select({
Label("//conditions:default"): [],
})

# FIXME: This restriction is arbitrary; elisp_binary rules should accept any
# number of input files if necessary.
MAX_MANUAL_ADDITIONAL_INPUTS = 10

def _repository_name(file):
# Skip empty string for main repository.
return file.owner.workspace_name or None
Expand Down

1 comment on commit 9b31929

@gutron
Copy link
Collaborator

@gutron gutron commented on 9b31929 Aug 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. This works for me locally.

Please sign in to comment.