From 700c2dd041743f9d71be81fd4c6a13e943dc0f14 Mon Sep 17 00:00:00 2001
From: Philipp Stephani
Date: Wed, 21 Aug 2024 18:35:23 +0200
Subject: [PATCH] elisp_manual: Support additional input files.
Fixes #570.
---
elisp/BUILD | 8 ++++++--
elisp/defs.bzl | 13 +++++++++++--
elisp/export-org.el | 6 +++---
examples/BUILD | 1 +
examples/config.org | 16 ++++++++++++++++
examples/doc.org | 5 ++---
private/defs.bzl | 4 ++++
7 files changed, 43 insertions(+), 10 deletions(-)
create mode 100644 examples/config.org
diff --git a/elisp/BUILD b/elisp/BUILD
index 0c45f04b..d1e69b43 100644
--- a/elisp/BUILD
+++ b/elisp/BUILD
@@ -28,6 +28,7 @@ load(
"LAUNCHER_FEATURES",
"LAUNCHER_LINKOPTS",
"LINKOPTS",
+ "MAX_MANUAL_ADDITIONAL_INPUTS",
"PACKAGE_FEATURES",
"UNDEFINED_ERROR",
"bootstrap",
@@ -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
diff --git a/elisp/defs.bzl b/elisp/defs.bzl
index 6a934b86..bc457213 100644
--- a/elisp/defs.bzl
+++ b/elisp/defs.bzl
@@ -24,6 +24,7 @@ load(
"CcDefaultInfo",
"LAUNCHER_ATTRS",
"LAUNCHER_DEPS",
+ "MAX_MANUAL_ADDITIONAL_INPUTS",
"ModuleConfigInfo",
"cc_launcher",
"check_relative_filename",
@@ -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,
@@ -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,
diff --git a/elisp/export-org.el b/elisp/export-org.el
index 029fde1e..d9c5e0a1 100644
--- a/elisp/export-org.el
+++ b/elisp/export-org.el
@@ -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:
@@ -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)
(cl-callf expand-file-name input)
(cl-callf expand-file-name output)
@@ -48,6 +48,6 @@
(insert-file-contents input :visit)
(setq default-directory (file-name-directory 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
diff --git a/examples/BUILD b/examples/BUILD
index 24a1f82c..5ad3e7f4 100644
--- a/examples/BUILD
+++ b/examples/BUILD
@@ -104,6 +104,7 @@ elisp_manual(
name = "doc",
src = "doc.org",
out = "doc.texi",
+ additional_inputs = ["config.org"],
)
genrule(
diff --git a/examples/config.org b/examples/config.org
new file mode 100644
index 00000000..6c482bf9
--- /dev/null
+++ b/examples/config.org
@@ -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
diff --git a/examples/doc.org b/examples/doc.org
index bc33dcae..b0f0061c 100644
--- a/examples/doc.org
+++ b/examples/doc.org
@@ -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.
@@ -13,8 +13,7 @@
# limitations under the License.
#+TITLE: Example documentation
-#+LANGUAGE: en
-#+OPTIONS: author:nil date:nil
+#+SETUPFILE: config.org
* Chapter
diff --git a/private/defs.bzl b/private/defs.bzl
index 056826d8..a266426b 100644
--- a/private/defs.bzl
+++ b/private/defs.bzl
@@ -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