feat(all-apis): build all apis, were possible

Now there is a blacklist feature, allowing to list apis we can't yet
handle for whichever reason.
This commit is contained in:
Sebastian Thiel
2015-03-10 14:34:26 +01:00
parent 2531011fc5
commit 2d036b6623
7 changed files with 375 additions and 158 deletions

View File

@@ -3,31 +3,36 @@
# DO NOT EDIT !
<%api_info=[]%>\
% for a in api.list:
% for an, versions in api.list.iteritems():
% if an in api.blacklist:
<% continue %>\
% endif
% for version in versions:
<%
import util
gen_root = directories.output + '/' + a.name + util.to_api_version(a.version)
gen_root = directories.output + '/' + an + util.to_api_version(version)
gen_root_stamp = gen_root + '/.timestamp'
api_name = util.library_name(a.name, a.version)
api_name = util.library_name(an, version)
api_common = gen_root + '/src/cmn.rs'
api_clean = api_name + '-clean'
api_cargo = api_name + '-cargo'
# source, destination of individual output files
sds = [(directories.mako_src + '/' + i.source + '.mako', gen_root + '/' + i.get('output_dir', '') + '/' + i.source)
for i in api.templates]
api_json = directories.api_base + '/' + a.name + '/' + a.version + '/' + a.name + '-api.json'
api_json = directories.api_base + '/' + an + '/' + version + '/' + an + '-api.json'
api_json_inputs = api_json + " $(API_SHARED_INFO)"
api_info.append((api_name, api_clean, api_cargo, gen_root))
space_join = lambda i: ' '.join(a[i] for a in api_info)
%>\
${api_common}: $(RUST_SRC)/cmn.rs $(lastword $(MAKEFILE_LIST))
${api_common}: $(RUST_SRC)/cmn.rs $(lastword $(MAKEFILE_LIST)) ${gen_root_stamp}
@ echo "// COPY OF '$<'" > $@
@ echo "// DO NOT EDIT" >> $@
@cat $< >> $@
${gen_root_stamp}: ${' '.join(i[0] for i in sds)} ${api_json_inputs} $(MAKO_LIB_FILES) $(MAKO_RENDER)
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}
@echo Generating ${api_name}
@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}
@touch $@
${api_name}: ${gen_root_stamp} ${api_common}
@@ -38,6 +43,7 @@ ${api_cargo}: ${api_name}
${api_clean}:
-rm -Rf ${gen_root}
% endfor
% endfor
.PHONY += $(.PHONY) help-api clean-apis apis ${space_join(0)} ${space_join(1)} ${space_join(2)}

View File

@@ -3,7 +3,7 @@ import os
from random import (randint, random, choice, seed)
import collections
seed(7337)
seed(1337)
re_linestart = re.compile('^', flags=re.MULTILINE)
re_first_4_spaces = re.compile('^ {1,4}', flags=re.MULTILINE)
@@ -17,6 +17,7 @@ TYPE_MAP = {'boolean' : 'bool',
'double' : 'f64',
'float' : 'f32',
'int32' : 'i32',
'any' : 'String', # TODO: Figure out how to handle it. It's 'interface' in Go ...
'int64' : 'i64',
'uint64' : 'u64',
'array' : 'Vec',
@@ -483,7 +484,7 @@ def method_media_params(m):
res = list()
for pn, proto in mu.protocols.iteritems():
# the pi (proto-info) dict can be shown to the user
pi = {'multipart': proto.multipart and 'yes' or 'no', 'maxSize': mu.maxSize, 'validMimeTypes': mu.accept}
pi = {'multipart': proto.multipart and 'yes' or 'no', 'maxSize': mu.get('maxSize', '0kb'), 'validMimeTypes': mu.accept}
try:
ti = type(m)(PROTOCOL_TYPE_INFO[pn])
except KeyError:
@@ -493,7 +494,7 @@ def method_media_params(m):
'path': proto.path,
'type': ti,
'description': ti.description,
'max_size': size_to_bytes(mu.maxSize)})
'max_size': size_to_bytes(mu.get('maxSize', '0kb'))})
res.append(p)
# end for each proto
@@ -581,8 +582,10 @@ def new_context(resources):
# Expects v to be 'v\d+', throws otherwise
def to_api_version(v):
assert len(v) >= 2 and v[0] == 'v'
return v[1:].replace('.', 'p')
assert len(v) >= 2
if v.startswith('v'):
v = v[1:]
return v.replace('.', 'p')
# build a full library name (non-canonical)
def library_name(name, version):