-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile
165 lines (152 loc) · 4.89 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# this is a shell monster that will fail with exit(125) if a command produces
# stderr output
FAILIF_STDERR=bash -c 'fail_if_stderr() (rc=$$({("$$@" 2>&1 >&3 3>&- 4>&-; echo "$$?" >&4) | grep '^' >&2 3>&- 4>&-; } 4>&1); err=$$?; [ "$$rc" -eq 0 ] || exit "$$rc"; [ "$$err" -ne 0 ] || exit 125 ) 3>&1; fail_if_stderr $$@' FAILIF_STDERR
# no execution when only command printed is wanted
ifneq (,$(filter n,$(MAKEFLAGS)))
FAILIF_STDERR=: FAILIF_STDERR
endif
try:
${FAILIF_STDERR} bash -c 'exit 12'
all: build/mkdocs-site
build/linkml-docs: \
build/linkml-docs/s/properties/unreleased \
build/linkml-docs/s/thing/unreleased \
build/linkml-docs/s/roles/unreleased \
build/linkml-docs/s/spatial/unreleased \
build/linkml-docs/s/temporal/unreleased \
build/linkml-docs/s/prov/unreleased \
build/linkml-docs/s/identifiers/unreleased \
build/linkml-docs/s/distribution/unreleased \
build/linkml-docs/s/datalad-dataset/unreleased \
build/linkml-docs/s/sdd/unreleased
build/linkml-docs/s/%: src/%.yaml src/%/extra-docs
gen-doc \
--hierarchical-class-view \
--include-top-level-diagram \
--diagram-type er_diagram \
--metadata \
--format markdown \
--example-directory src/$*/examples/ \
-d $@ \
$< \
&& (cp -r src/$*/extra-docs/*.md $@ || true) \
&& cp $< $@.yaml
# try to inject any extra-docs (if any exist)
# generate OWL
gen-owl \
-f owl \
--mergeimports \
$< > $@.owl.ttl
# jsonld context
gen-jsonld-context \
--mergeimports \
$< > $@.jsonld
build/mkdocs-site: build/linkml-docs extra-docs/*.md
# top-level content
cp -r extra-docs/*.md $<
mkdocs build
check: check-models check-validation
# add additional schemas to lint here
check-models: \
checkmodel/properties/unreleased \
checkmodel/thing/unreleased \
checkmodel/roles/unreleased \
checkmodel/spatial/unreleased \
checkmodel/temporal/unreleased \
checkmodel/prov/unreleased \
checkmodel/identifiers/unreleased \
checkmodel/distribution/unreleased \
checkmodel/datalad-dataset/unreleased \
checkmodel/sdd/unreleased
checkmodel/%: src/%.yaml
@echo [Check $<]
@echo "Run linter"
@linkml-lint \
--config .linkmllint.yaml \
--max-warnings 0 \
--validate \
$<
# generate various output formats, they all have the potential to
# reveal "hidden" issues
@echo Generate a JSON-LD context
@${FAILIF_STDERR} gen-jsonld-context \
--prefixes \
--model \
--mergeimports \
$< > /dev/null
@echo Generate JSON schema
@${FAILIF_STDERR} gen-json-schema $< > /dev/null
@echo Generate OWL
@${FAILIF_STDERR} gen-owl $< > /dev/null
@echo Generate Python classes
@${FAILIF_STDERR} gen-python $< | python
# within check-validation, conversion targets must come before the
# respective validation targets, because some tests rely on these
# converted formats
check-validation: \
convertexamples/thing/unreleased \
checkvalidation/thing/unreleased \
convertexamples/roles/unreleased \
checkvalidation/roles/unreleased \
convertexamples/spatial/unreleased \
checkvalidation/spatial/unreleased \
convertexamples/temporal/unreleased \
checkvalidation/temporal/unreleased \
convertexamples/prov/unreleased \
checkvalidation/prov/unreleased \
convertexamples/identifiers/unreleased \
checkvalidation/identifiers/unreleased \
convertexamples/distribution/unreleased \
checkvalidation/distribution/unreleased \
convertexamples/datalad-dataset/unreleased \
checkvalidation/datalad-dataset/unreleased
# convertexamples/sdd/unreleased \
# checkvalidation/sdd/unreleased
checkvalidation/%:
$(MAKE) checkvalid/$* checkinvalid/$*
checkvalid/%: src/%/validation src/%.yaml
@for ex in $</*.valid.cfg.yaml; do \
echo "Validate $$ex" ; \
linkml-validate --config "$$ex" || exit 5 ; \
done
checkinvalid/%: src/%/validation src/%.yaml
@for ex in $</*.invalid.cfg.yaml; do \
echo "(In)validate $$ex" ; \
linkml-validate --config "$$ex" && exit 5 || true; \
done
convert-examples: \
convertexamples/thing/unreleased \
convertexamples/roles/unreleased \
convertexamples/spatial/unreleased \
convertexamples/temporal/unreleased \
convertexamples/prov/unreleased \
convertexamples/identifiers/unreleased \
convertexamples/distribution/unreleased \
convertexamples/datalad-dataset/unreleased \
convertexamples/sdd/unreleased
convertexamples/%: src/%.yaml src/%/examples
# loop over all examples, skip the schema file itself
for ex in $^/*.yaml; do \
[ "$$ex" = "$<" ] && continue; \
echo "Converting $$ex" ; \
for outf in json rdf; do \
linkml-convert \
-s "$<" \
--target-class-from-path \
--infer \
-t "$$outf" \
"$$ex" \
> $${ex%.yaml}.$${outf}.tmp && \
mv $${ex%.yaml}.$${outf}.tmp $${ex%.yaml}.$${outf} ; \
done \
done
@git --no-pager diff -- $^
@if [ -n "$$(git diff -- $^)" ]; then \
echo -n 'ERROR: Unexpected modification of example output. ' ; \
echo 'Inspect and commit changes shown above!' ; \
exit 22 ; \
fi
clean:
rm -rf build
rm -f *-stamp
.PHONY: clean check check-models check-validation convert-examples