Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4e5f2c0

Browse files
committed
feat(mako): mako-render generates output dirs
That way, the makefile doesn't need to know that much anymore, and gets simpler/less verbose. \# Also * Added filters for rust doc string * fixed .PHONY
1 parent 11b6fe2 commit 4e5f2c0

6 files changed

Lines changed: 22 additions & 8 deletions

File tree

.gitignore

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
.pyenv
22
*.pyc
3-
generated/
4-
target
3+
**target/
54
.api.deps
6-
Cargo.lock
5+
**Cargo.lock
76
*.sublime-workspace
8-
*.xml

Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.PHONY: json-to-xml clean help api-deps
1+
.PHONY: json-to-xml clean help api-deps rebuild-apis
22
.SUFFIXES:
33

44
include Makefile.helpers
@@ -24,6 +24,7 @@ help:
2424
$(info Targets)
2525
$(info help - print this help)
2626
$(info api-deps - generate a file to tell make what API file dependencies will be)
27+
$(info rebuild-apis - clear out all generated apis, and regenerate them)
2728
$(info help-api - show all api targets to build individually)
2829

2930
$(PYTHON):
@@ -39,6 +40,8 @@ api-deps: $(API_DEPS)
3940

4041
include $(API_DEPS)
4142

43+
rebuild-apis: clean-apis apis
44+
4245
clean: clean-apis
4346
-rm -Rf $(VENV_DIR)
4447
-rm $(API_DEPS)

etc/api/shared.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Contains values shared among all API implementations
22
directories:
33
# directory under which all generated sources should reside
4-
output: generated
4+
output: lib
55
# how to get from `output` back to common library
66
common: ../
77
# where are all the API meta files
@@ -15,6 +15,7 @@ api:
1515
base_path: "etc/api"
1616
templates:
1717
# all output directories are relative to the one set for the respective API
18+
- source: README.md
1819
- source: cargo.toml
1920
# output_dir: optional - not there if unset
2021
cargo:

etc/bin/mako-render

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
# the MIT License: http://www.opensource.org/licenses/mit-license.php
66
from argparse import ArgumentParser
77
from os.path import isfile, dirname
8+
import os
89
import sys
910
from mako.template import Template
1011
from mako.lookup import TemplateLookup
@@ -307,6 +308,8 @@ def cmdline(argv=None):
307308
try:
308309
result = template.render(**data_converted)
309310
if output_file:
311+
if not os.path.isdir(dirname(output_file)):
312+
os.makedirs(dirname(output_file))
310313
fh = open(output_file, "wb")
311314
fh.write(result)
312315
fh.close()

src/mako/deps.mako

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
api_info.append((api_name, api_clean, gen_root))
2020
%>\
2121
${gen_root}: ${' '.join(i[0] for i in sds)} ${api_json_inputs} $(MAKO_LIB_FILES) $(MAKO_RENDER)
22-
@mkdir -p $@
2322
PYTHONPATH=$(MAKO_LIB_DIR) $(TPL) --template-dir '.' --var OUTPUT_DIR=$@ -io ${' '.join("%s=%s" % (s, d) for s, d in sds)} --data-files ${api_json_inputs}
2423
2524
${api_name}: ${gen_root}
@@ -28,7 +27,7 @@ ${api_clean}:
2827
-rm -Rf ${gen_root}
2928
% endfor
3029
31-
.PHONY += $(.PHONY) ${' '.join(a[0] for a in api_info)} ${' '.join(a[1] for a in api_info)}
30+
.PHONY += $(.PHONY) help-api clean-apis apis ${' '.join(a[0] for a in api_info)} ${' '.join(a[1] for a in api_info)}
3231
3332
help-api:
3433
$(info apis - make all APIs)

src/mako/lib/util.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
2+
# rust module doc comment filter
3+
def rmdc(s):
4+
return '//! ' + s
5+
6+
# rust doc comment filter
7+
def rdc(s):
8+
return '/// ' + s
9+
10+
# Expects v to be 'v\d+', throws otherwise
111
def to_api_version(v):
212
assert len(v) >= 2 and v[0] == 'v'
313
return v[1:]

0 commit comments

Comments
 (0)