Bug 1290988 - Add the mach generate-css-db command. r=tromey, r=chmanchester

Provide a single mach command to automatically generate the static
database of CSS properties that devtools uses for the inspector
and various editors.

MozReview-Commit-ID: 8E2jwxF0KbM

--HG--
rename : devtools/shared/css/moz.build => devtools/shared/css/generated/moz.build
extra : rebase_source : ab1815f321d460886168d95ddb739a579599b8c7
extra : histedit_source : f2bfecdcc128a87abcf3c0284a54c53bdeff1c87
This commit is contained in:
Greg Tatum 2016-09-14 10:00:27 -05:00
Родитель 1e5a5a50e2
Коммит af2fa2e8ab
8 изменённых файлов: 244 добавлений и 34 удалений

Просмотреть файл

@ -103,6 +103,7 @@ SEARCH_PATHS = [
MACH_MODULES = [ MACH_MODULES = [
'addon-sdk/mach_commands.py', 'addon-sdk/mach_commands.py',
'build/valgrind/mach_commands.py', 'build/valgrind/mach_commands.py',
'devtools/shared/css/generated/mach_commands.py',
'dom/bindings/mach_commands.py', 'dom/bindings/mach_commands.py',
'dom/media/test/external/mach_commands.py', 'dom/media/test/external/mach_commands.py',
'layout/tools/reftest/mach_commands.py', 'layout/tools/reftest/mach_commands.py',

Просмотреть файл

@ -0,0 +1,49 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";
/*
* This is an xpcshell script that runs to generate a static list of CSS properties
* as known by the platform. It is run from ./mach_commands.py by running
* `mach devtools-css-db`.
*/
var {require} = Components.utils.import("resource://devtools/shared/Loader.jsm", {});
var {generateCssProperties} = require("devtools/server/actors/css-properties");
// Output JSON
dump(JSON.stringify({
cssProperties: cssProperties(),
pseudoElements: pseudoElements()
}));
/*
* A list of CSS Properties and their various characteristics. This is used on the
* client-side when the CssPropertiesActor is not found, or when the client and server
* are the same version. A single property takes the form:
*
* "animation": {
* "isInherited": false,
* "supports": [ 7, 9, 10 ]
* }
*/
function cssProperties() {
const properties = generateCssProperties();
for (let key in properties) {
// Ignore OS-specific properties
if (key.indexOf("-moz-osx-") !== -1) {
properties[key] = undefined;
}
}
return properties;
}
/**
* The list of all CSS Pseudo Elements.
*/
function pseudoElements() {
const {classes: Cc, interfaces: Ci} = Components;
const domUtils = Cc["@mozilla.org/inspector/dom-utils;1"]
.getService(Ci.inIDOMUtils);
return domUtils.getCSSPseudoElementNames();
}

Просмотреть файл

@ -0,0 +1,111 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
"""
This script implements the `mach devtools-css-db` command. It runs the C preprocessor
on the CSS properties header file to get the list of preferences associated with
a specific property, and it runs an xpcshell script that uses inIDOMUtils to query
the CSS properties used by the browser. This information is used to generate the
properties-db.js file.
"""
import json
import os
import sys
import string
import subprocess
from mozbuild import shellutil
from mozbuild.base import (
MozbuildObject,
MachCommandBase,
)
from mach.decorators import (
CommandProvider,
Command,
)
def resolve_path(start, relativePath):
"""Helper to resolve a path from a start, and a relative path"""
return os.path.normpath(os.path.join(start, relativePath))
@CommandProvider
class MachCommands(MachCommandBase):
@Command(
'devtools-css-db', category='post-build',
description='Rebuild the devtool\'s static css properties database.')
def generate_css_db(self):
"""Generate the static css properties database for devtools and write it to file."""
print("Re-generating the css properties database...")
preferences = self.get_preferences()
db = self.get_properties_db_from_xpcshell()
self.output_template({
'preferences': json.dumps(preferences),
'cssProperties': json.dumps(db['cssProperties']),
'pseudoElements': json.dumps(db['pseudoElements'])})
def get_preferences(self):
"""Get all of the preferences associated with enabling and disabling a property."""
# Build the command to run the preprocessor on PythonCSSProps.h
headerPath = resolve_path(self.topsrcdir, 'layout/style/PythonCSSProps.h')
cpp = self.substs['CPP']
if not cpp:
print("Unable to find the cpp program. Please do a full, non-artifact")
print("build and try this again.")
sys.exit(1)
cmd = shellutil.split(cpp)
cmd += shellutil.split(self.substs['ACDEFINES'])
cmd.append(headerPath)
# The preprocessed list takes the following form:
# [ (name, prop, id, flags, pref, proptype), ... ]
preprocessed = eval(subprocess.check_output(cmd))
# Map this list
# (name, prop, id, flags, pref, proptype) => (name, pref)
preferences = [
(name, pref)
for name, prop, id, flags, pref, proptype in preprocessed
if 'CSS_PROPERTY_INTERNAL' not in flags]
return preferences
def get_properties_db_from_xpcshell(self):
"""Generate the static css properties db for devtools from an xpcshell script."""
build = MozbuildObject.from_environment()
# Get the paths
script_path = resolve_path(self.topsrcdir,
'devtools/shared/css/generated/generate-properties-db.js')
browser_path = resolve_path(self.topobjdir, 'dist/bin/browser')
xpcshell_path = build.get_binary_path(what='xpcshell')
print(browser_path)
# Run the xcpshell script, and set the appdir flag to the browser path so that
# we have the proper dependencies for requiring the loader.
contents = subprocess.check_output([xpcshell_path, '-a', browser_path,
script_path])
return json.loads(contents)
def output_template(self, substitutions):
"""Output a the properties-db.js from a template."""
js_template_path = resolve_path(self.topsrcdir,
'devtools/shared/css/generated/properties-db.js.in')
destination_path = resolve_path(self.topsrcdir,
'devtools/shared/css/generated/properties-db.js')
with open(js_template_path, 'r') as handle:
js_template = handle.read()
preamble = '/* THIS IS AN AUTOGENERATED FILE. DO NOT EDIT */\n\n'
contents = string.Template(js_template).substitute(substitutions)
with open(destination_path, 'w') as destination:
destination.write(preamble + contents)
print('The database was successfully generated at ' + destination_path)

Просмотреть файл

@ -0,0 +1,9 @@
# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
# vim: set filetype=python:
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
DevToolsModules(
'properties-db.js',
)

Различия файлов скрыты, потому что одна или несколько строк слишком длинны

Просмотреть файл

@ -0,0 +1,30 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";
/**
* This file is automatically generated by `mach devtools-css-db`. It contains
* a static list of CSS properties that can be computed by Gecko. The actual script
* to generate these files can be found at devtools/shared/css/generate-properties-db.js.
*/
/* eslint-disable max-len */
/**
* A list of CSS Properties and their various characteristics.
*/
exports.CSS_PROPERTIES = ${cssProperties};
/**
* A list of the pseudo elements.
*/
exports.PSEUDO_ELEMENTS = ${pseudoElements};
/**
* A list of the preferences keys for whether a CSS property is enabled or not. This is
* exposed for testing purposes.
*/
exports.PREFERENCES = ${preferences};
/* eslint-enable max-len */

Просмотреть файл

@ -4,6 +4,10 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this # License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/. # file, You can obtain one at http://mozilla.org/MPL/2.0/.
DIRS += [
'generated',
]
DevToolsModules( DevToolsModules(
'color-db.js', 'color-db.js',
'color.js', 'color.js',

Различия файлов скрыты, потому что одна или несколько строк слишком длинны