Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing issue 218 #219

Merged
merged 1 commit into from
Aug 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 24 additions & 14 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,19 @@ ifndef PLANTUML_PATH
export PLANTUML_PATH = ./plantuml.jar
endif

models := tm.py
MODEL?=tm

libs := $(wildcard pytm/*.py) $(wildcard pytm/threatlib/*.json) $(wildcard pytm/images/*)
all: clean
all: $(models:.py=/report.html) $(models:.py=/dfd.png) $(models:.py=/seq.png) docs/pytm/index.html

all: clean docs/pytm/index.html
$(MAKE) $(MODEL)

safe_filename:
ifeq ($(suffix $(MODEL)), .py)
@echo "I think you mean MODEL=$(patsubst .py,,$(MODEL))"
exit 1
endif


docs/pytm/index.html: $(wildcard pytm/*.py)
PYTHONPATH=. pdoc --html --force --output-dir docs pytm
Expand All @@ -22,26 +31,27 @@ docs/threats.md: $(wildcard pytm/threatlib/*.json)
printf "# Threat database\n" > $@
jq -r ".[] | \"$$(cat docs/threats.jq)\"" $< >> $@

clean:
rm -rf dist/* build/* $(models:.py=/*)
clean: safe_filename
rm -rf dist/* build/* $(MODEL)

tm:
mkdir -p tm
$(MODEL): safe_filename
mkdir -p $(MODEL)
$(MAKE) MODEL=$(MODEL) report

%/dfd.png: %.py tm $(libs)
$(MODEL)/dfd.png: $(MODEL).py $(libs)
./$< --dfd | dot -Tpng -o $@

%/seq.png: %.py tm $(libs)
$(MODEL)/seq.png: $(MODEL).py $(libs)
./$< --seq | java -Djava.awt.headless=true -jar $$PLANTUML_PATH -tpng -pipe > $@

%/report.html: %.py tm $(libs) docs/template.md docs/Stylesheet.css
./$< --report docs/template.md | pandoc -f markdown -t html > $@
$(MODEL)/report.html: $(MODEL).py $(libs) docs/basic_template.md docs/Stylesheet.css
./$< --report docs/basic_template.md | pandoc -f markdown -t html > $@

dfd: $(models:.py=/dfd.png)
dfd: $(MODEL)/dfd.png

seq: $(models:.py=/seq.png)
seq: $(MODEL)/seq.png

report: $(models:.py=/report.html) seq dfd
report: $(MODEL)/report.html seq dfd

.PHONY: test
test:
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,11 @@ mkdir -p tm
There's also an example `Makefile` that wraps all these into targets that can be easily shared for multiple models. If you have [GNU make](https://www.gnu.org/software/make/) installed (available by default on Linux distros but not on OSX), simply run:

```
make
make MODEL=the_name_of_your_model_minus_.py
```

You should either have plantuml.jar on the same directory as your model, or set PLANTUML_PATH.

To avoid installing all the dependencies, like `pandoc` or `Java`, the script can be run inside a container:

```
Expand Down