-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(docs) Clean up and reorganise build:
- docs build is now pure and doesn't require breaking the sandbox, yay! - passthru attributes are now all in their own files - add docs.figures which builds svgs from draw.io diagrams - Added graphviz dependency for diagram generation - Added docs.fetch-inventories script for updating Intersphinx inventory files - Intersphinx inventories use ROS distro specified in flake.nix if provided
- Loading branch information
1 parent
713f90b
commit ba0eacc
Showing
10 changed files
with
243 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,8 +12,6 @@ build/ | |
public/ | ||
# draw.io stuff | ||
.$* | ||
# generated figures | ||
figures-output/ | ||
|
||
# Prerequisites | ||
*.d | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ writeShellScript }: | ||
writeShellScript "roar-docs-inventory" '' | ||
# cd to docs/source assuming they exist (we're not already there) | ||
if [ -d docs ]; then | ||
cd docs | ||
fi | ||
if [ -d source ]; then | ||
cd source | ||
fi | ||
'' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
stdenv, | ||
p7zip, | ||
docs, | ||
}: | ||
stdenv.mkDerivation { | ||
name = "roar-docs-compressed"; | ||
buildInputs = [ | ||
docs | ||
p7zip | ||
]; | ||
src = docs; | ||
installPhase = '' | ||
mkdir -p $out | ||
7z a -t7z -m0=lzma -mx=9 -mfb=64 -md=32m -ms=on $out/docs.7z . | ||
''; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
lib, | ||
p7zip, | ||
writeShellScriptBin, | ||
}: | ||
writeShellScriptBin "decompress" '' | ||
${lib.getExe p7zip} x $1 -o$2 | ||
'' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# Fetches intersphinx inventory files | ||
{ | ||
rosDistro, | ||
writeShellScriptBin, | ||
cd-docs-source, | ||
}: | ||
writeShellScriptBin "roar-docs-fetch-inventories" '' | ||
set -e | ||
INVENTORY_LOCATION="intersphinx" | ||
source ${cd-docs-source} | ||
# get intersphinx inventories | ||
# clear existing | ||
rm -rf "$INVENTORY_LOCATION" | ||
# get the files | ||
echo "Fetching intersphinx inventories" | ||
curl --parallel \ | ||
--create-dirs --output-dir "$INVENTORY_LOCATION" \ | ||
--output python.inv https://docs.python.org/3/objects.inv \ | ||
--variable rosDistro="${rosDistro}" \ | ||
--output ros.inv --expand-url https://docs.ros.org/en/{{rosDistro:trim:url}}/objects.inv | ||
if [[ "$*" == *--no-commit* ]]; then | ||
echo "Will not commit changes" | ||
exit 0 | ||
fi | ||
if ! git diff --cached --quiet >/dev/null; then | ||
HAS_GIT_STAGING=1 | ||
echo "Stashing staged changes" | ||
git stash push -S >/dev/null | ||
fi | ||
cleanup() { | ||
if [[ -v HAS_GIT_STAGING ]]; then | ||
echo "Restoring git stash" | ||
git stash pop >/dev/null | ||
fi | ||
} | ||
trap cleanup EXIT | ||
echo "Staging changes" | ||
git add "$INVENTORY_LOCATION" | ||
echo "Committing changes" | ||
git commit -m "$(date +%Y-%m-%dT%H:%M:%S) Intersphinx inventory fetch" >/dev/null | ||
'' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
{ | ||
stdenv, | ||
lib, | ||
writeShellScript, | ||
drawio, | ||
parallel, | ||
xvfb-run, | ||
}: | ||
# Partly a ripoff of the drawio-headless package at: | ||
# https://github.com/NixOS/nixpkgs/blob/nixpkgs-unstable/pkgs/applications/graphics/drawio/headless.nix | ||
# Except highly specialised for our use case, and with no --auto-display because that breaks everything somehow. | ||
# With that flag, xvfb-run doesn't work - it doesn't actually run any commands. | ||
# Perhaps because it's in a Wayland environment not X11, and thus there's no pre-existing X server to talk to? | ||
# -a works, but supposedly it's deprecated. Very strange. Running it with no flags works too, so that's what we do. | ||
let | ||
output-dir = "generated"; | ||
|
||
figures = stdenv.mkDerivation { | ||
name = "roar-docs-figures"; | ||
src = lib.cleanSource ../figures-source; | ||
# after making the temp output dir, this finds all .drawio files in the source directory, | ||
# and parallel processes them using parallel with draw-io-convert, all run through xvfb-run so electron is happy | ||
buildPhase = '' | ||
mkdir ${output-dir} | ||
find ${../figures-source} -type f -name "*.drawio" -print0 | ${lib.getExe xvfb-run} ${lib.getExe parallel} -0 -j $(nproc) ${draw-io-convert} | ||
''; | ||
installPhase = '' | ||
mkdir -p $out | ||
cp -a ${output-dir}/. $out | ||
''; | ||
}; | ||
|
||
# script to convert .drawio files to .svg in both light and dark themes | ||
# note that there's a whole bunch of cache/dbus errors: since they don't stop draw.io from running, | ||
# we can just ignore them! | ||
draw-io-convert = writeShellScript "draw-io-convert" '' | ||
set -e | ||
BASENAME=$(basename "$1") | ||
OUTPUT_BASE="${output-dir}"/"$BASENAME" | ||
convert() { | ||
INPUT_FILE="$1" | ||
OUTPUT_FILE="$2" | ||
shift 2 | ||
${lib.getExe drawio} -x "$INPUT_FILE" -o "$OUTPUT_FILE" --disable-gpu "$@" | ||
} | ||
# Electron really wants a configuration directory to not die with: | ||
# "Error: Failed to get 'appData' path" | ||
# so we give it some temp dir as XDG_CONFIG_HOME | ||
tmpdir=$(mktemp -d) | ||
function cleanup { | ||
rm -rf "$tmpdir" | ||
} | ||
trap cleanup EXIT | ||
# Drawio needs to run in a virtual X session, because Electron | ||
# refuses to work and dies with an unhelpful error message otherwise: | ||
# "The futex facility returned an unexpected error code." | ||
export XDG_CONFIG_HOME="$tmpdir" | ||
convert "$1" "$OUTPUT_BASE"".svg" --svg-theme light | ||
convert "$1" "$OUTPUT_BASE""-dark.svg" --svg-theme dark | ||
''; | ||
in | ||
figures |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
writeShellScriptBin, | ||
cd-docs-source, | ||
figures, | ||
}: | ||
let | ||
output-dir = "generated"; | ||
in | ||
writeShellScriptBin "roar-docs-setup" '' | ||
set -e | ||
source ${cd-docs-source} | ||
mkdir -p "${output-dir}" | ||
cp -a ${figures}/. "${output-dir}" | ||
# nix store is read-only by default, so fix that after copying | ||
chmod -R +w "${output-dir}" | ||
'' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
rosDistro, | ||
mkShell, | ||
env, | ||
uv, | ||
drawio, | ||
}: | ||
let | ||
shell = mkShell { | ||
ROS_DISTRO = rosDistro; | ||
buildInputs = [ | ||
env | ||
uv # uv added to manage python dependencies | ||
drawio | ||
]; | ||
shellHook = '' | ||
# Undo dependency propagation by nixpkgs. | ||
unset PYTHONPATH | ||
''; | ||
}; | ||
in | ||
shell |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters