Generate apis.html and css-properties.json for docs as part of crates’ build scripts

… rather than as an extra step after `cargo doc`.
This helps always using the correct set of CSS properties
(for layout 2013 v.s. 2020).
This commit is contained in:
Simon Sapin 2019-07-29 18:57:20 +02:00
parent ddb4e369dd
commit 0215d09ccb
8 changed files with 67 additions and 173 deletions

View file

@ -41,7 +41,6 @@ set(globalgen_deps
${bindings_src}/Configuration.py
${bindings_src}/CodegenRust.py
${bindings_src}/parser/WebIDL.py
${PROJECT_BINARY_DIR}/css_properties.json
)
set(bindinggen_deps
${globalgen_deps}
@ -69,28 +68,12 @@ add_custom_command(
${bindings_src}/Bindings.conf
.
${PROJECT_SOURCE_DIR}
${PROJECT_BINARY_DIR}/css_properties.json
DEPENDS Bindings _cache ${globalgen_deps} ${webidls}
${PROJECT_BINARY_DIR}/../css-properties.json
${PROJECT_SOURCE_DIR}/../../target/doc/servo
DEPENDS Bindings _cache ${globalgen_deps} ${webidls} ${PROJECT_BINARY_DIR}/../css-properties.json
VERBATIM
)
add_custom_command(
OUTPUT apis.html
COMMAND ${PYTHON_EXECUTABLE} -B ${bindings_src}/pythonpath.py -I ${bindings_src}/parser -I ${bindings_src}/ply
${bindings_src}/GlobalGen.py
--cachedir=_cache
--filelist=webidls.list
--only-html
${bindings_src}/Bindings.conf
.
${PROJECT_SOURCE_DIR}
${PROJECT_BINARY_DIR}/css_properties.json
DEPENDS _cache ${globalgen_deps} ${webidls}
VERBATIM
)
add_custom_target(supported-apis DEPENDS apis.html)
# We need an intermediate custom target for this, due to this misfeature:
# > If any dependency is an OUTPUT of another custom command in the same
# > directory CMake automatically brings the other custom command into the

View file

@ -17,10 +17,8 @@ fn main() {
let style_out_dir = PathBuf::from(env::var_os("DEP_SERVO_STYLE_CRATE_OUT_DIR").unwrap());
let out_dir = PathBuf::from(env::var_os("OUT_DIR").unwrap());
let build_dir = out_dir.join("build");
let json = "css_properties.json";
let _ = std::fs::create_dir(&build_dir); // Ignore errors: they most likely indicate it already exists
std::fs::copy(style_out_dir.join(json), build_dir.join(json)).unwrap();
let json = "css-properties.json";
std::fs::copy(style_out_dir.join(json), out_dir.join(json)).unwrap();
// This must use the Ninja generator -- it's the only one that
// parallelizes cmake's output properly. (Cmake generates

View file

@ -7550,7 +7550,7 @@ impl %(base)s {
def SupportedDomApis(config):
descriptors = config.getDescriptors(isExposedConditionally=False)
base_path = os.path.join('dom', 'bindings', 'codegen')
base_path = os.path.dirname(__file__)
with open(os.path.join(base_path, 'apis.html.template')) as f:
base_template = f.read()
with open(os.path.join(base_path, 'api.html.template')) as f:

View file

@ -29,12 +29,10 @@ def generate_file(config, name, filename):
def main():
# Parse arguments.
from optparse import OptionParser
usageString = "usage: %prog [options] configFile outputdir webidldir cssProperties.json [files]"
usageString = "usage: %prog [options] configFile outputdir webidldir cssProperties.json docServoDir [files]"
o = OptionParser(usage=usageString)
o.add_option("--cachedir", dest='cachedir', default=None,
help="Directory in which to cache lex/parse tables.")
o.add_option("--only-html", dest='only_html', action="store_true",
help="Only generate HTML from WebIDL inputs")
o.add_option("--filelist", dest='filelist', default=None,
help="A file containing the list (one per line) of webidl files to process.")
(options, args) = o.parse_args()
@ -46,6 +44,7 @@ def main():
outputdir = args[1]
baseDir = args[2]
css_properties_json = args[3]
doc_servo = args[4]
if options.filelist is not None:
fileList = [l.strip() for l in open(options.filelist).xreadlines()]
else:
@ -63,34 +62,30 @@ def main():
parserResults = parser.finish()
if not options.only_html:
# Write the parser results out to a pickle.
resultsPath = os.path.join(outputdir, 'ParserResults.pkl')
with open(resultsPath, 'wb') as resultsFile:
cPickle.dump(parserResults, resultsFile, -1)
# Write the parser results out to a pickle.
resultsPath = os.path.join(outputdir, 'ParserResults.pkl')
with open(resultsPath, 'wb') as resultsFile:
cPickle.dump(parserResults, resultsFile, -1)
# Load the configuration.
config = Configuration(configFile, parserResults)
to_generate = [
('SupportedDomApis', 'apis.html'),
('PrototypeList', 'PrototypeList.rs'),
('RegisterBindings', 'RegisterBindings.rs'),
('InterfaceObjectMap', 'InterfaceObjectMap.rs'),
('InterfaceObjectMapData', 'InterfaceObjectMapData.json'),
('InterfaceTypes', 'InterfaceTypes.rs'),
('InheritTypes', 'InheritTypes.rs'),
('Bindings', os.path.join('Bindings', 'mod.rs')),
('UnionTypes', 'UnionTypes.rs'),
]
if not options.only_html:
to_generate = [
('PrototypeList', 'PrototypeList.rs'),
('RegisterBindings', 'RegisterBindings.rs'),
('InterfaceObjectMap', 'InterfaceObjectMap.rs'),
('InterfaceObjectMapData', 'InterfaceObjectMapData.json'),
('InterfaceTypes', 'InterfaceTypes.rs'),
('InheritTypes', 'InheritTypes.rs'),
('Bindings', os.path.join('Bindings', 'mod.rs')),
('UnionTypes', 'UnionTypes.rs'),
]
for name, filename in to_generate:
generate_file(config, name, os.path.join(outputdir, filename))
generate_file(config, 'SupportedDomApis', os.path.join(doc_servo, 'apis.html'))
def add_css_properties_attributes(webidl_files, css_properties_json, parser):
for filename in webidl_files:
@ -102,10 +97,11 @@ def add_css_properties_attributes(webidl_files, css_properties_json, parser):
css_properties = json.load(open(css_properties_json, "rb"))
idl = "partial interface CSSStyleDeclaration {\n%s\n};\n" % "\n".join(
" [%sCEReactions, SetterThrows] attribute [TreatNullAs=EmptyString] DOMString %s;" % (
('Pref="%s", ' % pref if pref else ""),
('Pref="%s", ' % data["pref"] if data["pref"] else ""),
attribute_name
)
for (property_name, pref) in css_properties
for (kind, properties_list) in sorted(css_properties.items())
for (property_name, data) in sorted(properties_list.items())
for attribute_name in attribute_names(property_name)
)
parser.parse(idl.encode("utf-8"), "CSSStyleDeclaration_generated.webidl")