Skip to content

Commit

Permalink
Added plantuml Diagra support
Browse files Browse the repository at this point in the history
This commit patches the build tools and adds support to compile plantuml
diagrams from wsd files in the Diagrams folder. This works for single specs
that are located in the root folder as well as for nested structures in the
specs folder.
Note that nesting with sub-folders inside the Diagrams folder is not supported.
  • Loading branch information
thasso committed Sep 19, 2024
1 parent 09ee65c commit 9956d84
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 24 deletions.
2 changes: 1 addition & 1 deletion build-tools/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ RUN apk add --no-cache \
chromium-swiftshader \
git \
make \
# plantuml \
plantuml \
py-pip \
&& pip install --break-system-packages bikeshed \
&& bikeshed update
Expand Down
58 changes: 35 additions & 23 deletions build-tools/tools/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ SPECS = $(patsubst %.bs, %, $(shell if [ -d "specs" ]; then ls specs; fi))
# This is our target folder
OUT = dist

#DIAGRAM_IMAGES = $(subst $(OUT),$(OUT),$(patsubst %.wsd, %.png, $(shell find specs/ -type f -iname '*.wsd')))
# DIAGRAM_IMAGES = $(subst $(OUT),$(OUT),$(patsubst %.wsd, %.png, $(shell find specs/ -type f -iname '*.wsd')))
DIAGRAMS_SPEC = $(patsubst %.wsd, %, $(shell if [ -d "Diagrams" ]; then ls Diagrams/*.wsd; fi))

DIAGRAMS_SPEC_SOURCES := $(wildcard Diagrams/*.wsd)
DIAGRAMS_SPEC_IMAGES := $(addprefix $(OUT)/, $(DIAGRAMS_SPEC_SOURCES:.wsd=.png))

# default target to build everything
all: $(SPECS)
Expand Down Expand Up @@ -39,6 +43,14 @@ $(SPECS:%=%.pdf): %: $(OUT)/%
# This assumes that $* evaluates to the name of the spec
spec-sources = $(shell find specs/$*/ -type f -iname \*.md)

# This helper is used to find all the plantuml diagrams per spec
# and transforms the results to the target files that should match that
spec-diagrams = $(patsubst specs/%,$(OUT)/%,$(patsubst %.wsd,%.png,$(shell find specs/$*/ -type f -iname \*.wsd)))

# This helper finds the spec files for a single spec and then transforms them to
# the respective output path
single-spec-diagrams = $(addprefix ${OUT}/,$(patsubst %.wsd, %.png, $(shell if [ -d "Diagrams" ]; then ls Diagrams/*.wsd; fi)))

# This is a helper that we use in the prerequisits with SECONDEXPANSION
# to extract the name of the spec folder
spec-name = $(shell echo "$*" | cut -d/ -f1 )
Expand All @@ -47,10 +59,6 @@ spec-name = $(shell echo "$*" | cut -d/ -f1 )
# to find the spec file
spec-file = $(shell find specs/$*/ -type f -iname \*.bs | head -n 1)

# This is a helper that we use in the prerequisits with SECONDEXPANSION
# to find all diagram files
#spec-diagrams = $(subst .wsd,.png,$(shell find specs/$*/Diagrams -type f -iname \*.wsd))

# This is a helper that we use in the prerequisits with SECONDEXPANSION
# to find all diagram files
#spec-diagram-source = $(subst $(OUT),specs,$*).wsd
Expand All @@ -66,16 +74,16 @@ spec-file = $(shell find specs/$*/ -type f -iname \*.bs | head -n 1)
# - the Images are available in the output folder (order matters)
# - the .bs file that we pass to bikeshed
# - all .inc.md files that belong to this spec
$(OUT)/%/index.html: $${spec-file} $${spec-sources} $(OUT)/%/Images
@echo "Compile $< -> $(OUT)/$*/index.html. Deps $^ to $@"
$(OUT)/%/index.html: $${spec-file} $${spec-sources} $(OUT)/%/Images $${spec-diagrams}
@echo "Compile $< -> $(OUT)/$*/index.html"
@[ -d $(OUT)/$* ] || mkdir -p $(OUT)/$*
bikeshed --allow-nonlocal-files spec $< $@
@bikeshed --allow-nonlocal-files spec $< $@

.PHONY: $(OUT)/%-watch
$(OUT)/%-watch: $${spec-file} $${spec-sources} $(OUT)/%/Images
@echo "Watch $< -> $(OUT)/$*/index.html. Deps $^"
@[ -d $(OUT)/$* ] || mkdir -p $(OUT)/$*
bikeshed --allow-nonlocal-files watch $< $(OUT)/$*/index.html
@bikeshed --allow-nonlocal-files watch $< $(OUT)/$*/index.html

# Run chromium to create a PDF from the already generated html page
$(OUT)/%.pdf: $(OUT)/$${spec-name}/index.html
Expand All @@ -92,6 +100,12 @@ $(OUT)/%.pdf: $(OUT)/$${spec-name}/index.html
--virtual-time-budget=20000 \
$< 2>&1 | grep -v "bus.cc"

# Target that compiles the plantuml diagrams on a per spec bases
$(OUT)/%.png: specs/%.wsd
@echo "Compile $< -> $@"
@[ -d $(shell dirname $@) ] || mkdir -p $(shell dirname $@)
@plantuml $< -o $(shell pwd)/$(shell dirname $@);

# This one could maybe be done in a different way, but for now
# we are linking the Images folder to the outout folder
$(OUT)/%/Images:
Expand All @@ -101,15 +115,6 @@ $(OUT)/%/Images:
cp -r specs/$*/Images $(OUT)/$*/Images; \
fi

# $(DIAGRAM_IMAGES): %.png: %.wsd
# @echo "Compile Diagram $< -> $@"
# @plantuml $<

# $(OUT)/%/Diagrams: $${spec-diagrams}
# @echo "Move Diagrams $? -> $@"
# @[ -d $@ ] || mkdir -p $@
# @mv $? $@

SRC =
NAME=

Expand All @@ -122,10 +127,10 @@ spec.html: ${OUT}/index.html
.PHONY: spec.pdf
spec.pdf: ${OUT}/${NAME}.pdf

$(OUT)/index.html: ${SRC} $(OUT)/Images
@echo "Compile $< -> $(OUT)/index.html. Deps $^ to $@"
$(OUT)/index.html: ${SRC} ${OUT}/Images $${single-spec-diagrams}
@echo "Compile $< -> $(OUT)/index.html"
@[ -d $(OUT) ] || mkdir -p $(OUT)
bikeshed --allow-nonlocal-files spec $< $@
@bikeshed --allow-nonlocal-files spec $< $@

$(OUT)/Images: Images/
@[ -d $(OUT) ] || mkdir -p $(OUT)
Expand All @@ -134,6 +139,13 @@ $(OUT)/Images: Images/
cp -r Images $(OUT)/Images; \
fi

# Target to create the diagrams from plantUML files for a single
# spec that resides in the root folder.
$(OUT)/Diagrams/%.png: Diagrams/%.wsd
@echo "Compile $< -> $@"
@[ -d $(shell dirname $@) ] || mkdir -p $(shell dirname $@)
@plantuml $< -o $(shell pwd)/$(shell dirname $@);

$(OUT)/${NAME}.pdf: $(OUT)/index.html
@echo "Compile $< -> $@"
@chromium \
Expand All @@ -151,12 +163,12 @@ $(OUT)/${NAME}.pdf: $(OUT)/index.html
.PHONY: spec-watch
spec-watch: ${SRC} $(OUT)/Images
@[ -d $(OUT) ] || mkdir -p $(OUT)
bikeshed --allow-nonlocal-files watch $< $(OUT)/index.html
@bikeshed --allow-nonlocal-files watch $< $(OUT)/index.html

.PHONY: spec-serve
spec-serve: ${SRC} $(OUT)/Images
@[ -d $(OUT) ] || mkdir -p $(OUT)
bikeshed --allow-nonlocal-files serve $< $(OUT)/index.html
@bikeshed --allow-nonlocal-files serve $< $(OUT)/index.html

# Helper to clean up
.PHONY: clean
Expand Down

0 comments on commit 9956d84

Please sign in to comment.