Skip to content

Commit

Permalink
CMAKE: Add rule for generating options file for doc.
Browse files Browse the repository at this point in the history
  • Loading branch information
jamievlin committed Aug 12, 2024
1 parent eb0418f commit 2aec573
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
10 changes: 10 additions & 0 deletions cmake-scripts/docgen.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,13 @@ foreach(ASY_DOC_FILE_PREFIX ${ASY_DOC_FILE_PREFIXES})
)
list(APPEND ASY_DOC_PDF_FILES ${ASY_DOC_FILE_OUTPUT})
endforeach()


# options file
add_custom_command(
OUTPUT ${ASY_TEX_BUILD_ROOT}/options
DEPENDS asy ${ASY_DOC_ROOT}/gen-asy-options-file.py
COMMAND ${PY3_INTERPRETER} ${ASY_DOC_ROOT}/gen-asy-options-file.py
--asy-executable=$<TARGET_FILE:asy>
--output-file=${ASY_TEX_BUILD_ROOT}/options
)
38 changes: 38 additions & 0 deletions doc/gen-asy-options-file.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/usr/bin/env python3
import argparse
import subprocess
import subprocess as sp


def parse_args():
parser = argparse.ArgumentParser()
parser.add_argument("--asy-executable", type=str, default="asy")
parser.add_argument("--output-file", type=str, required=True)
return parser.parse_args()


def main():
args = parse_args()
asy_output = sp.run(
[args.asy_executable, "-h"],
check=True,
stderr=subprocess.STDOUT,
stdout=subprocess.PIPE,
text=True,
)

with open(args.output_file, "w", encoding="utf-8") as f:
for line in asy_output.stdout.splitlines():
stripped_lines = line.strip()
if (
stripped_lines.startswith("Asymptote")
or stripped_lines.startswith("http")
or stripped_lines.startswith("Usage:")
):
continue
f.write(line)
f.write("\n")


if __name__ == "__main__":
main()

0 comments on commit 2aec573

Please sign in to comment.