Bug 786891: Refactor import script for css reftests and add support for auto-prefixing, DONTBUILD because NPOTB. [r=dbaron]
This commit is contained in:
@@ -2,6 +2,12 @@
|
||||
# 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 os
|
||||
from optparse import OptionParser
|
||||
from subprocess import Popen, PIPE
|
||||
import xml.dom.minidom
|
||||
import html5lib
|
||||
import shutil
|
||||
|
||||
# FIXME:
|
||||
# * Import more tests rather than just the very limited set currently
|
||||
@@ -12,94 +18,105 @@
|
||||
# for tests with multiple rel="match" references. (But still go
|
||||
# though all those references in case they, in turn, have references.)
|
||||
|
||||
import os
|
||||
from optparse import OptionParser
|
||||
from subprocess import Popen, PIPE
|
||||
import xml.dom.minidom
|
||||
import html5lib
|
||||
import shutil
|
||||
|
||||
op = OptionParser()
|
||||
(options, args) = op.parse_args()
|
||||
|
||||
if len(args) != 1:
|
||||
op.error("expected a single argument (path to CSS test repository clone)")
|
||||
|
||||
srcpath = args[0]
|
||||
if not os.path.isdir(srcpath) or \
|
||||
not os.path.isdir(os.path.join(srcpath, ".hg")):
|
||||
raise StandardError("source path does not appear to be a mercurial clone")
|
||||
|
||||
destpath = os.path.join(os.path.dirname(os.path.realpath(__file__)), "received")
|
||||
|
||||
# Since we're going to commit the tests, we should also commit
|
||||
# information about where they came from.
|
||||
log = open(os.path.join(destpath, "import.log"), "w")
|
||||
|
||||
def log_output_of(subprocess):
|
||||
subprocess.wait()
|
||||
if (subprocess.returncode != 0):
|
||||
raise StandardError("error while running subprocess")
|
||||
log.write(subprocess.stdout.readline().rstrip())
|
||||
log.write("Importing revision: ")
|
||||
log_output_of(Popen(["hg", "parent", "--template={node}"],
|
||||
stdout=PIPE, cwd=srcpath))
|
||||
log.write("\nfrom repository: ")
|
||||
log_output_of(Popen(["hg", "paths", "default"],
|
||||
stdout=PIPE, cwd=srcpath))
|
||||
log.write("\n")
|
||||
|
||||
# Remove existing directories that we're going to regenerate. This
|
||||
# is necessary so that we can give errors in cases where our import
|
||||
# might copy two files to the same location, which we do by giving
|
||||
# errors if a copy would overwrite a file.
|
||||
for dirname in os.listdir(destpath):
|
||||
fulldir = os.path.join(destpath, dirname)
|
||||
if not os.path.isdir(fulldir):
|
||||
continue
|
||||
shutil.rmtree(fulldir)
|
||||
|
||||
# Eventually we should import all the tests that have references. (At
|
||||
# least for a subset of secs. And we probably want to organize the
|
||||
# directory structure by spec to avoid constant file moves when files
|
||||
# move in the W3C repository. And we probably also want to import each
|
||||
# test only once, even if it covers more than one spec.)
|
||||
|
||||
# But for now, let's just import one set of tests.
|
||||
# But for now, let's just import a few sets of tests.
|
||||
|
||||
subtrees = [
|
||||
os.path.join(srcpath, "approved", "css3-namespace", "src"),
|
||||
os.path.join(srcpath, "contributors", "opera", "submitted", "css3-conditional")
|
||||
gSubtrees = [
|
||||
os.path.join("approved", "css3-namespace", "src"),
|
||||
os.path.join("approved", "css3-multicol", "src"),
|
||||
os.path.join("contributors", "opera", "submitted", "css3-conditional"),
|
||||
os.path.join("contributors", "opera", "submitted", "multicol")
|
||||
]
|
||||
testfiles = []
|
||||
for subtree in subtrees:
|
||||
for dirpath, dirnames, filenames in os.walk(subtree, topdown=True):
|
||||
if "support" in dirnames:
|
||||
dirnames.remove("support")
|
||||
if "reftest" in dirnames:
|
||||
dirnames.remove("reftest")
|
||||
for f in filenames:
|
||||
if f == "README" or \
|
||||
f.find("-ref.") != -1:
|
||||
continue
|
||||
testfiles.append(os.path.join(dirpath, f))
|
||||
|
||||
testfiles.sort()
|
||||
gLog = None
|
||||
gPrefixedProperties = [
|
||||
"column-count",
|
||||
"column-fill",
|
||||
"column-gap",
|
||||
"column-rule",
|
||||
"column-rule-color",
|
||||
"column-rule-style",
|
||||
"column-rule-width",
|
||||
"columns",
|
||||
"column-span",
|
||||
"column-width"
|
||||
]
|
||||
|
||||
gDestPath = None
|
||||
gSrcPath = None
|
||||
support_dirs_mapped = set()
|
||||
filemap = {}
|
||||
speclinkmap = {}
|
||||
propsaddedfor = []
|
||||
tests = []
|
||||
gOptions = None
|
||||
gArgs = None
|
||||
gTestfiles = []
|
||||
|
||||
def log_output_of(subprocess):
|
||||
global gLog
|
||||
subprocess.wait()
|
||||
if (subprocess.returncode != 0):
|
||||
raise StandardError("error while running subprocess")
|
||||
gLog.write(subprocess.stdout.readline().rstrip())
|
||||
|
||||
def write_log_header():
|
||||
global gLog, gSrcPath
|
||||
gLog.write("Importing revision: ")
|
||||
log_output_of(Popen(["hg", "parent", "--template={node}"],
|
||||
stdout=PIPE, cwd=gSrcPath))
|
||||
gLog.write("\nfrom repository: ")
|
||||
log_output_of(Popen(["hg", "paths", "default"],
|
||||
stdout=PIPE, cwd=gSrcPath))
|
||||
gLog.write("\n")
|
||||
|
||||
def remove_existing_dirs():
|
||||
global gDestPath
|
||||
# Remove existing directories that we're going to regenerate. This
|
||||
# is necessary so that we can give errors in cases where our import
|
||||
# might copy two files to the same location, which we do by giving
|
||||
# errors if a copy would overwrite a file.
|
||||
for dirname in os.listdir(gDestPath):
|
||||
fulldir = os.path.join(gDestPath, dirname)
|
||||
if not os.path.isdir(fulldir):
|
||||
continue
|
||||
shutil.rmtree(fulldir)
|
||||
|
||||
def populate_test_files():
|
||||
global gSubtrees, gTestfiles
|
||||
for subtree in gSubtrees:
|
||||
for dirpath, dirnames, filenames in os.walk(subtree, topdown=True):
|
||||
if "support" in dirnames:
|
||||
dirnames.remove("support")
|
||||
if "reftest" in dirnames:
|
||||
dirnames.remove("reftest")
|
||||
for f in filenames:
|
||||
if f == "README" or \
|
||||
f.find("-ref.") != -1:
|
||||
continue
|
||||
gTestfiles.append(os.path.join(dirpath, f))
|
||||
|
||||
gTestfiles.sort()
|
||||
|
||||
def copy_file(srcfile, destname):
|
||||
if not srcfile.startswith(srcpath):
|
||||
raise StandardError("Filename " + srcfile + " does not start with " + srcpath)
|
||||
logname = srcfile[len(srcpath):]
|
||||
log.write("Importing " + logname + " to " + destname + "\n")
|
||||
destfile = os.path.join(destpath, destname)
|
||||
global gDestPath, gLog, gSrcPath
|
||||
if not srcfile.startswith(gSrcPath):
|
||||
raise StandardError("Filename " + srcfile + " does not start with " + gSrcPath)
|
||||
logname = srcfile[len(gSrcPath):]
|
||||
gLog.write("Importing " + logname + " to " + destname + "\n")
|
||||
destfile = os.path.join(gDestPath, destname)
|
||||
destdir = os.path.dirname(destfile)
|
||||
if not os.path.exists(destdir):
|
||||
os.makedirs(destdir)
|
||||
if os.path.exists(destfile):
|
||||
raise StandardError("file " + destfile + " already exists")
|
||||
shutil.copyfile(srcfile, destfile)
|
||||
copy_and_prefix(srcfile, destfile, gPrefixedProperties)
|
||||
|
||||
support_dirs_mapped = set()
|
||||
def copy_support_files(dirname, spec):
|
||||
if dirname in support_dirs_mapped:
|
||||
return
|
||||
@@ -114,7 +131,6 @@ def copy_support_files(dirname, spec):
|
||||
full_fn = os.path.join(dirpath, fn)
|
||||
copy_file(full_fn, os.path.join(spec, "support", full_fn[len(support_dir)+1:]))
|
||||
|
||||
filemap = {}
|
||||
def map_file(fn, spec):
|
||||
if fn in filemap:
|
||||
return filemap[fn]
|
||||
@@ -124,7 +140,6 @@ def map_file(fn, spec):
|
||||
copy_support_files(os.path.dirname(fn), spec)
|
||||
return destname
|
||||
|
||||
tests = []
|
||||
def add_test_items(fn, spec):
|
||||
document = None # an xml.dom.minidom document
|
||||
if fn.endswith(".htm") or fn.endswith(".html"):
|
||||
@@ -169,12 +184,68 @@ def add_test_items(fn, spec):
|
||||
for notref in notrefs:
|
||||
add_test_items(notref, spec=spec)
|
||||
|
||||
for t in testfiles:
|
||||
add_test_items(t, spec=None)
|
||||
def copy_and_prefix(aSourceFileName, aDestFileName, props):
|
||||
newFile = open(aDestFileName, 'w')
|
||||
unPrefixedFile = open(aSourceFileName)
|
||||
|
||||
listfile = open(os.path.join(destpath, "reftest.list"), "w")
|
||||
for test in tests:
|
||||
listfile.write(" ".join(test) + "\n")
|
||||
listfile.close()
|
||||
for line in unPrefixedFile:
|
||||
replacementLine = line;
|
||||
for rule in props:
|
||||
replacementLine = replacementLine.replace(rule, "-moz-" + rule)
|
||||
newFile.write(replacementLine)
|
||||
|
||||
log.close()
|
||||
newFile.close()
|
||||
unPrefixedFile.close()
|
||||
|
||||
def read_options():
|
||||
global gArgs, gOptions
|
||||
op = OptionParser()
|
||||
op.usage = \
|
||||
'''%prog <clone of hg repository>
|
||||
Import reftests from a W3C hg repository clone. The location of
|
||||
the local clone of the hg repository must be given on the command
|
||||
line.'''
|
||||
(gOptions, gArgs) = op.parse_args()
|
||||
if len(gArgs) != 1:
|
||||
op.error("Too few arguments specified.")
|
||||
|
||||
def setup_paths():
|
||||
global gSubtrees, gDestPath, gSrcPath
|
||||
gSrcPath = gArgs[0]
|
||||
if not os.path.isdir(gSrcPath) or \
|
||||
not os.path.isdir(os.path.join(gSrcPath, ".hg")):
|
||||
raise StandardError("source path does not appear to be a mercurial clone")
|
||||
|
||||
gDestPath = os.path.join(os.path.dirname(os.path.realpath(__file__)), "received")
|
||||
newSubtrees = []
|
||||
for relPath in gSubtrees:
|
||||
newSubtrees[len(gSubtrees):] = [os.path.join(gSrcPath, relPath)]
|
||||
gSubtrees = newSubtrees
|
||||
|
||||
def setup_log():
|
||||
global gLog
|
||||
# Since we're going to commit the tests, we should also commit
|
||||
# information about where they came from.
|
||||
gLog = open(os.path.join(gDestPath, "import.log"), "w")
|
||||
|
||||
def main():
|
||||
global gDestPath, gLog, gTestfiles
|
||||
read_options()
|
||||
setup_paths()
|
||||
setup_log()
|
||||
write_log_header()
|
||||
remove_existing_dirs()
|
||||
populate_test_files()
|
||||
|
||||
for t in gTestfiles:
|
||||
add_test_items(t, spec=None)
|
||||
|
||||
listfile = open(os.path.join(gDestPath, "reftest.list"), "w")
|
||||
for test in tests:
|
||||
listfile.write(" ".join(test) + "\n")
|
||||
listfile.close()
|
||||
|
||||
gLog.close()
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user