0
Files
src/tools/json_schema_compiler
Georg Neis a3b69ca3b1 Remove Lacros support from tools/json_schema_compiler
Lacros is gone. IS_CHROMEOS_LACROS is about to be removed
and IS_CHROMEOS_ASH is being replaced by the existing IS_CHROMEOS.

Bug: b:354842935
Change-Id: I27e1b52448f9d6ff99079624b6b3bc8ff519ea36
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6290186
Reviewed-by: Tim <tjudkins@chromium.org>
Commit-Queue: Georg Neis <neis@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1424272}
2025-02-24 18:17:59 -08:00
..

The JSON Schema Compiler is used by the chrome extensions system to generate various necessary files from the "schemas" in extensions. These include the C++ type representations for API types, string blobs for the files, feature availability information, and more. You can read more about these in our documentation on schemas and features.

Note that, despite its name, the JSON Schema Compiler does not just handle JSON files -- it also handles files written in IDL syntax.

The main entry point for generation is compiler.py, which then uses different "compilers" and "generators" to produce necessary types and files. These are used in gn actions in various files in the codebase, such as those in //chrome/common/extensions/api/ and //extensions/common/api.

The loading of the schema files by compiler.py differs slightly between JSON schema files and IDL schema files . For JSON schemas we first strip the "//" style comments from the JSON file and then parse the rest using standard python libraries. The resulting python object is then sent to the "compilers" and "generators". For IDL schemas the process is a bit more complicated. First we load the schema file with an IDL parser, which returns an AST (Abstract Syntax Tree) that represents the contents of the file. This AST is then passed to a "processor" that creates a python object based on it, mimicking the same structure as the output from JSON schema loading. The resulting python object is then passed to the "compilers" and "generators", just like the JSON schema path.

NOTE: Currently we use an old IDL parser, which means that the current format of our IDL files is not up to date with modern WebIDL. However https://crbug.com/340297705 is working on fixing that, by integrating the Blink maintained WebIDL parser and creating a new "processor" to transform the output to the format we expect.

For any questions, reach out to the OWNERS.