Skip to content

Commit afa138d

Browse files
committed
elisp_manual: Support additional input files.
Fixes #570.
1 parent 2fb4c53 commit afa138d

File tree

7 files changed

+43
-10
lines changed

7 files changed

+43
-10
lines changed

elisp/BUILD

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ load(
2828
"LAUNCHER_FEATURES",
2929
"LAUNCHER_LINKOPTS",
3030
"LINKOPTS",
31+
"MAX_MANUAL_ADDITIONAL_INPUTS",
3132
"PACKAGE_FEATURES",
3233
"UNDEFINED_ERROR",
3334
"bootstrap",
@@ -480,8 +481,11 @@ build_test(
480481
elisp_binary(
481482
name = "export_org",
482483
src = "export-org.el",
483-
input_args = [1],
484-
output_args = [2],
484+
input_args = range(
485+
2,
486+
3 + MAX_MANUAL_ADDITIONAL_INPUTS,
487+
),
488+
output_args = [1],
485489
visibility = [
486490
# FIXME: Make private once
487491
# https://github.com/bazelbuild/proposals/blob/main/designs/2019-10-15-tool-visibility.md

elisp/defs.bzl

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ load(
2424
"CcDefaultInfo",
2525
"LAUNCHER_ATTRS",
2626
"LAUNCHER_DEPS",
27+
"MAX_MANUAL_ADDITIONAL_INPUTS",
2728
"ModuleConfigInfo",
2829
"cc_launcher",
2930
"check_relative_filename",
@@ -738,11 +739,14 @@ def _elisp_manual_impl(ctx):
738739
out = ctx.outputs.out
739740
if out.extension != "texi":
740741
fail("Output filename {} doesn’t end in “.texi”".format(out.short_path))
742+
additional_inputs = ctx.files.additional_inputs
743+
if len(additional_inputs) > MAX_MANUAL_ADDITIONAL_INPUTS:
744+
fail("Got {} additional input files; at most {} are allowed".format(len(additional_inputs), MAX_MANUAL_ADDITIONAL_INPUTS))
741745
ctx.actions.run(
742746
outputs = [out],
743-
inputs = [src],
747+
inputs = [src] + additional_inputs,
744748
executable = ctx.executable._export,
745-
arguments = [ctx.actions.args().add(src).add(out)],
749+
arguments = [ctx.actions.args().add(out).add(src).add_all(additional_inputs, expand_directories = False)],
746750
mnemonic = "Export",
747751
progress_message = "Exporting %{input} into Texinfo file",
748752
toolchain = None,
@@ -759,6 +763,11 @@ elisp_manual = rule(
759763
doc = "Texinfo manual file to write; must end in `.texi`.",
760764
mandatory = True,
761765
),
766+
"additional_inputs": attr.label_list(
767+
doc = "List of additional files made available during export.",
768+
allow_files = True,
769+
cfg = "exec",
770+
),
762771
"_export": attr.label(
763772
allow_single_file = True,
764773
executable = True,

elisp/export-org.el

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

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

2323
;;; Code:
2424

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

3232
(pcase command-line-args-left
33-
(`(,input ,output)
33+
(`(,output ,input . ,_)
3434
(setq command-line-args-left nil)
3535
(cl-callf expand-file-name input)
3636
(cl-callf expand-file-name output)
@@ -48,6 +48,6 @@
4848
(insert-file-contents input :visit)
4949
(setq default-directory (file-name-directory input))
5050
(write-region (org-export-as 'texinfo) nil output))))
51-
(_ (user-error "Usage: elisp/export-org INPUT OUTPUT")))
51+
(_ (user-error "Usage: elisp/export-org OUTPUT INPUT ADDITIONAL-INPUTS")))
5252

5353
;;; export-org.el ends here

examples/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ elisp_manual(
104104
name = "doc",
105105
src = "doc.org",
106106
out = "doc.texi",
107+
additional_inputs = ["config.org"],
107108
)
108109

109110
genrule(

examples/config.org

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Copyright 2021, 2022, 2024 Philipp Stephani
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+
#+LANGUAGE: en
16+
#+OPTIONS: author:nil date:nil

examples/doc.org

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2021, 2022 Google LLC
1+
# Copyright 2021, 2022, 2024 Google LLC
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.
@@ -13,8 +13,7 @@
1313
# limitations under the License.
1414

1515
#+TITLE: Example documentation
16-
#+LANGUAGE: en
17-
#+OPTIONS: author:nil date:nil
16+
#+SETUPFILE: config.org
1817

1918
* Chapter
2019

private/defs.bzl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -720,6 +720,10 @@ UNDEFINED_ERROR = select({
720720
Label("//conditions:default"): [],
721721
})
722722

723+
# FIXME: This restriction is arbitrary; elisp_binary rules should accept any
724+
# number of input files if necessary.
725+
MAX_MANUAL_ADDITIONAL_INPUTS = 10
726+
723727
def _repository_name(file):
724728
# Skip empty string for main repository.
725729
return file.owner.workspace_name or None

0 commit comments

Comments
 (0)