Bug 1452542 part 6 - Replace uses of PythonCSSProps.h with the data file generated from Servo. r?froydnj draft
authorXidorn Quan <me@upsuper.org>
Tue, 17 Apr 2018 14:40:12 +1000
changeset 784862 6e61821560e87f3c23ea9ee57085bb25ec9e10b8
parent 784861 dd8953d0b3d0ada24f6d8064377895c17a1635ab
child 784863 4a2029bedb9990393927a86fdbb610f5f8eafa23
push id107060
push userxquan@mozilla.com
push dateThu, 19 Apr 2018 08:17:21 +0000
reviewersfroydnj
bugs1452542
milestone61.0a1
Bug 1452542 part 6 - Replace uses of PythonCSSProps.h with the data file generated from Servo. r?froydnj Some content in Makefile.in is removed because after this change, the scripts no longer invoke the preprocessor and thus don't have unknown dependencies anymore outside what is provided in their inputs array. The order of exports.PREFERENCES in properties-db changes because the data file has shorthands placed after longhands. The only usage of it is in test_css-properties-db.js which doesn't care about the order. MozReview-Commit-ID: AMjzTRf2HYN
config/recurse.mk
devtools/shared/css/generated/mach_commands.py
devtools/shared/css/generated/properties-db.js
dom/bindings/GenerateCSS2PropertiesWebIDL.py
dom/bindings/Makefile.in
dom/bindings/moz.build
layout/style/GenerateCSSPropsGenerated.py
layout/style/Makefile.in
layout/style/PythonCSSProps.h
layout/style/moz.build
--- a/config/recurse.mk
+++ b/config/recurse.mk
@@ -166,16 +166,19 @@ js/xpconnect/src/export: dom/bindings/ex
 accessible/xpcom/export: xpcom/xpidl/export
 
 # The widget binding generator code is part of the annotationProcessors.
 widget/android/bindings/export: build/annotationProcessors/export
 
 # .xpt generation needs the xpidl lex/yacc files
 xpcom/xpidl/export: xpcom/idl-parser/xpidl/export
 
+# CSS2Properties.webidl needs ServoCSSPropList.py from layout/style
+dom/bindings/export: layout/style/export
+
 ifdef ENABLE_CLANG_PLUGIN
 $(filter-out config/host build/unix/stdc++compat/% build/clang-plugin/%,$(compile_targets)): build/clang-plugin/target build/clang-plugin/tests/target
 build/clang-plugin/tests/target: build/clang-plugin/target
 endif
 
 # Interdependencies that moz.build world don't know about yet for compilation.
 # Note some others are hardcoded or "guessed" in recursivemake.py and emitter.py
 ifeq ($(MOZ_WIDGET_TOOLKIT),gtk3)
--- a/devtools/shared/css/generated/mach_commands.py
+++ b/devtools/shared/css/generated/mach_commands.py
@@ -45,42 +45,27 @@ class MachCommands(MachCommandBase):
 
         self.output_template({
             'preferences': stringify(preferences),
             'cssProperties': stringify(db['cssProperties']),
             'pseudoElements': stringify(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, nonartifact")
-            print("build and try this again.")
-            sys.exit(1)
-
-        if type(cpp) is list:
-            cmd = cpp
-        else:
-            cmd = shellutil.split(cpp)
-        cmd += shellutil.split(self.substs['ACDEFINES'])
-        cmd.append(headerPath)
-
-        # The preprocessed list takes the following form:
+        # The data takes the following form:
         # [ (name, prop, id, flags, pref, proptype), ... ]
-        preprocessed = eval(subprocess.check_output(cmd))
+        dataPath = resolve_path(self.topobjdir, 'layout/style/ServoCSSPropList.py')
+        with open(dataPath, "r") as f:
+            data = eval(f.read())
 
         # Map this list
         # (name, prop, id, flags, pref, proptype) => (name, pref)
         preferences = [
             (name, pref)
-            for name, prop, id, flags, pref, proptype in preprocessed
+            for name, prop, id, flags, pref, proptype in data
             if 'CSS_PROPERTY_INTERNAL' not in flags and pref]
 
         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()
 
--- a/devtools/shared/css/generated/properties-db.js
+++ b/devtools/shared/css/generated/properties-db.js
@@ -9475,20 +9475,16 @@ exports.PSEUDO_ELEMENTS = [
 ];
 
 /**
  * A list of the preferences keys for whether a CSS property is enabled or not. This is
  * exposed for testing purposes.
  */
 exports.PREFERENCES = [
   [
-    "all",
-    "layout.css.all-shorthand.enabled"
-  ],
-  [
     "background-blend-mode",
     "layout.css.background-blend-mode.enabled"
   ],
   [
     "box-decoration-break",
     "layout.css.box-decoration-break.enabled"
   ],
   [
@@ -9527,32 +9523,24 @@ exports.PREFERENCES = [
     "mix-blend-mode",
     "layout.css.mix-blend-mode.enabled"
   ],
   [
     "-moz-osx-font-smoothing",
     "layout.css.osx-font-smoothing.enabled"
   ],
   [
-    "overflow-clip-box",
-    "layout.css.overflow-clip-box.enabled"
-  ],
-  [
     "overflow-clip-box-block",
     "layout.css.overflow-clip-box.enabled"
   ],
   [
     "overflow-clip-box-inline",
     "layout.css.overflow-clip-box.enabled"
   ],
   [
-    "overscroll-behavior",
-    "layout.css.overscroll-behavior.enabled"
-  ],
-  [
     "overscroll-behavior-x",
     "layout.css.overscroll-behavior.enabled"
   ],
   [
     "overscroll-behavior-y",
     "layout.css.overscroll-behavior.enabled"
   ],
   [
@@ -9579,20 +9567,16 @@ exports.PREFERENCES = [
     "scroll-snap-points-x",
     "layout.css.scroll-snap.enabled"
   ],
   [
     "scroll-snap-points-y",
     "layout.css.scroll-snap.enabled"
   ],
   [
-    "scroll-snap-type",
-    "layout.css.scroll-snap.enabled"
-  ],
-  [
     "scroll-snap-type-x",
     "layout.css.scroll-snap.enabled"
   ],
   [
     "scroll-snap-type-y",
     "layout.css.scroll-snap.enabled"
   ],
   [
@@ -9611,20 +9595,16 @@ exports.PREFERENCES = [
     "-webkit-text-fill-color",
     "layout.css.prefixes.webkit"
   ],
   [
     "text-justify",
     "layout.css.text-justify.enabled"
   ],
   [
-    "-webkit-text-stroke",
-    "layout.css.prefixes.webkit"
-  ],
-  [
     "-webkit-text-stroke-color",
     "layout.css.prefixes.webkit"
   ],
   [
     "-webkit-text-stroke-width",
     "layout.css.prefixes.webkit"
   ],
   [
@@ -9635,16 +9615,36 @@ exports.PREFERENCES = [
     "transform-box",
     "svg.transform-box.enabled"
   ],
   [
     "translate",
     "layout.css.individual-transform.enabled"
   ],
   [
+    "all",
+    "layout.css.all-shorthand.enabled"
+  ],
+  [
+    "overflow-clip-box",
+    "layout.css.overflow-clip-box.enabled"
+  ],
+  [
+    "overscroll-behavior",
+    "layout.css.overscroll-behavior.enabled"
+  ],
+  [
+    "scroll-snap-type",
+    "layout.css.scroll-snap.enabled"
+  ],
+  [
+    "-webkit-text-stroke",
+    "layout.css.prefixes.webkit"
+  ],
+  [
     "-moz-animation",
     "layout.css.prefixes.animations"
   ],
   [
     "-moz-animation-delay",
     "layout.css.prefixes.animations"
   ],
   [
--- a/dom/bindings/GenerateCSS2PropertiesWebIDL.py
+++ b/dom/bindings/GenerateCSS2PropertiesWebIDL.py
@@ -1,34 +1,27 @@
 # 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/.
 
 import sys
 import string
 import argparse
-import subprocess
-import buildconfig
-from mozbuild import shellutil
 
 # Generates a line of WebIDL with the given spelling of the property name
 # (whether camelCase, _underscorePrefixed, etc.) and the given array of
 # extended attributes.
 def generateLine(propName, extendedAttrs):
     return "  [%s] attribute DOMString %s;\n" % (", ".join(extendedAttrs),
                                                  propName)
-def generate(output, idlFilename, preprocessorHeader):
-    cpp = list(buildconfig.substs['CPP'])
-    cpp += shellutil.split(buildconfig.substs['ACDEFINES'])
-    cpp.append(preprocessorHeader)
-    preprocessed = subprocess.check_output(cpp)
-
-    propList = eval(preprocessed)
+def generate(output, idlFilename, dataFile):
+    with open(dataFile, "r") as f:
+        propList = eval(f.read())
     props = ""
-    for [name, prop, id, flags, pref, proptype] in propList:
+    for name, prop, id, flags, pref, proptype in propList:
         if "CSS_PROPERTY_INTERNAL" in flags:
             continue
         # Unfortunately, even some of the getters here are fallible
         # (e.g. on nsComputedDOMStyle).
         extendedAttrs = ["CEReactions", "Throws", "TreatNullAs=EmptyString",
                          "SetterNeedsSubjectPrincipal=NonSystem"]
         if pref is not "":
             extendedAttrs.append('Pref="%s"' % pref)
--- a/dom/bindings/Makefile.in
+++ b/dom/bindings/Makefile.in
@@ -10,29 +10,16 @@ ifdef COMPILE_ENVIRONMENT
 include webidlsrcs.mk
 
 # These come from webidlsrcs.mk.
 # TODO Write directly into backend.mk (bug 1281618)
 CPPSRCS += $(globalgen_sources) $(unified_binding_cpp_files)
 
 include $(topsrcdir)/config/rules.mk
 
-# TODO This list should be emitted to a .pp file via
-# GenerateCSS2PropertiesWebIDL.py (bug 1281614)
-css2properties_dependencies = \
-  $(topsrcdir)/layout/style/nsCSSPropList.h \
-  $(topsrcdir)/layout/style/nsCSSPropAliasList.h \
-  $(webidl_base)/CSS2Properties.webidl.in \
-  $(topsrcdir)/layout/style/PythonCSSProps.h \
-  $(srcdir)/GenerateCSS2PropertiesWebIDL.py \
-  $(GLOBAL_DEPS) \
-  $(NULL)
-
-CSS2Properties.webidl: $(css2properties_dependencies)
-
 # Most of the logic for dependencies lives inside Python so it can be
 # used by multiple build backends. We simply have rules to generate
 # and include the .pp file.
 #
 # The generated .pp file contains all the important dependencies such as
 # changes to .webidl or .py files should result in code generation being
 # performed. But we do pull in file-lists.jon to catch file additions.
 codegen_dependencies := \
--- a/dom/bindings/moz.build
+++ b/dom/bindings/moz.build
@@ -174,10 +174,10 @@ if CONFIG['CC_TYPE'] in ('clang', 'gcc')
     ]
 
 if CONFIG['COMPILE_ENVIRONMENT']:
     GENERATED_FILES += ['CSS2Properties.webidl']
     css_props = GENERATED_FILES['CSS2Properties.webidl']
     css_props.script = 'GenerateCSS2PropertiesWebIDL.py:generate'
     css_props.inputs = [
         '/dom/webidl/CSS2Properties.webidl.in',
-        '/layout/style/PythonCSSProps.h',
+        '!/layout/style/ServoCSSPropList.py',
     ]
--- a/layout/style/GenerateCSSPropsGenerated.py
+++ b/layout/style/GenerateCSSPropsGenerated.py
@@ -1,27 +1,22 @@
 # 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/.
 
 import sys
 import string
 import argparse
-import subprocess
-import buildconfig
-from mozbuild import shellutil
 
-def get_properties(preprocessorHeader):
-    cpp = list(buildconfig.substs['CPP'])
-    cpp += shellutil.split(buildconfig.substs['ACDEFINES'])
-    cpp.append(preprocessorHeader)
-    preprocessed = subprocess.check_output(cpp)
+def get_properties(dataFile):
+    with open(dataFile, "r") as f:
+        properties = eval(f.read())
     properties = [{"name":p[0], "prop":p[1], "id":p[2],
                    "flags":p[3], "pref":p[4], "proptype":p[5]}
-                  for (i, p) in enumerate(eval(preprocessed))]
+                  for (i, p) in enumerate(properties)]
 
     # Sort the list so that longhand properties are intermingled first,
     # shorthand properties follow, then aliases appear last.
     # This matches the order of the nsCSSPropertyID enum.
 
     def property_compare(x, y):
         property_order = {"longhand": 0, "shorthand": 1, "alias": 2}
         return property_order[x["proptype"]] - property_order[y["proptype"]]
@@ -52,17 +47,17 @@ def generate_idl_names(properties):
             names.append("  nullptr,  // %s" % p["name"])
         else:
             names.append('  "%s",' % p["idlname"])
     return "\n".join(names)
 
 def generate_assertions(properties):
     def enum(p):
         if p["proptype"] is "alias":
-            return "eCSSPropertyAlias_%s" % p["id"]
+            return "eCSSPropertyAlias_%s" % p["id"][0]
         else:
             return "eCSSProperty_%s" % p["id"]
     msg = ('static_assert(%s == %d, "GenerateCSSPropsGenerated.py did not list '
            'properties in nsCSSPropertyID order");')
     return "\n".join(map(lambda p: msg % (enum(p), p["index"]), properties))
 
 def generate_idl_name_positions(properties):
     # Skip aliases.
@@ -74,22 +69,22 @@ def generate_idl_name_positions(properti
     # Annotate entries with the sorted position.
     ps = [(p, position) for position, p in enumerate(ps)]
 
     # Sort back to nsCSSPropertyID order.
     ps = sorted(ps, key=lambda (p, position): p["index"])
 
     return ",\n".join(map(lambda (p, position): "  %d" % position, ps))
 
-def generate(output, cppTemplate, preprocessorHeader):
+def generate(output, cppTemplate, dataFile):
     cppFile = open(cppTemplate, "r")
     cppTemplate = cppFile.read()
     cppFile.close()
 
-    properties = get_properties(preprocessorHeader)
+    properties = get_properties(dataFile)
     substitutions = {
         "idl_names": generate_idl_names(properties),
         "assertions": generate_assertions(properties),
         "idl_name_positions": generate_idl_name_positions(properties),
     }
     output.write("/* THIS IS AN AUTOGENERATED FILE.  DO NOT EDIT */\n\n" +
                  string.Template(cppTemplate).substitute(substitutions) + "\n")
 
deleted file mode 100644
--- a/layout/style/Makefile.in
+++ /dev/null
@@ -1,16 +0,0 @@
-# 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/.
-
-# TODO This list should be emitted to a .pp file via
-# GenerateCSSPropsGenerated.py (bug 1281614)
-csspropsidlnames_dependencies = \
-  $(srcdir)/nsCSSPropList.h \
-  $(srcdir)/nsCSSPropAliasList.h \
-  $(srcdir)/nsCSSPropsGenerated.inc.in \
-  $(srcdir)/PythonCSSProps.h \
-  $(srcdir)/GenerateCSSPropsGenerated.py \
-  $(GLOBAL_DEPS) \
-  $(NULL)
-
-nsCSSPropsGenerated.inc : $(csspropsidlnames_dependencies)
deleted file mode 100644
--- a/layout/style/PythonCSSProps.h
+++ /dev/null
@@ -1,42 +0,0 @@
-/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* vim: set ts=8 sts=2 et sw=2 tw=80: */
-/* 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/. */
-
-/* A file meant as input to the preprocessor only */
-
-/* DO_PROP serves as an extra level of indirection to allow expansion
-   of CSS_PROP_DOMPROP_PREFIXED */
-
-[
-
-#define PROP_STRINGIFY_INTERNAL(X) #X
-#define PROP_STRINGIFY(X) PROP_STRINGIFY_INTERNAL(X)
-
-#define DO_PROP(name, method, id, flags, pref, proptype) \
-  [ #name, #method, #id, PROP_STRINGIFY(flags), pref, proptype ],
-#define CSS_PROP(name, id, method, flags, pref, ...) \
-  DO_PROP(name, method, id, flags, pref, "longhand")
-#define CSS_PROP_SHORTHAND(name, id, method, flags, pref) \
-  DO_PROP(name, method, id, flags, pref, "shorthand")
-#define CSS_PROP_PUBLIC_OR_PRIVATE(publicname_, privatename_) publicname_
-
-#include "nsCSSPropList.h"
-
-#undef CSS_PROP_PUBLIC_OR_PRIVATE
-#undef CSS_PROP_SHORTHAND
-#undef CSS_PROP
-
-#define CSS_PROP_ALIAS(name, aliasid, id, method, pref) \
-  DO_PROP(name, method, aliasid, 0, pref, "alias")
-
-#include "nsCSSPropAliasList.h"
-
-#undef CSS_PROP_ALIAS
-
-#undef DO_PROP
-#undef PROP_STRINGIFY
-#undef PROP_STRINGIFY_INTERNAL
-
-]
--- a/layout/style/moz.build
+++ b/layout/style/moz.build
@@ -296,14 +296,14 @@ if CONFIG['COMPILE_ENVIRONMENT']:
     GENERATED_FILES += [
         'nsCSSPropsGenerated.inc',
     ]
 
     css_props = GENERATED_FILES['nsCSSPropsGenerated.inc']
     css_props.script = 'GenerateCSSPropsGenerated.py:generate'
     css_props.inputs = [
         'nsCSSPropsGenerated.inc.in',
-        'PythonCSSProps.h',
+        '!ServoCSSPropList.py',
     ]
 
     CONFIGURE_SUBST_FILES += [
         'bindgen.toml',
     ]