2012-03-29 14:08:58 -07:00
|
|
|
#!/usr/bin/env 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/.
|
|
|
|
|
|
|
|
"""
|
|
|
|
Imports a test suite from a remote repository. Takes one argument, a file in
|
|
|
|
the format described in README.
|
|
|
|
Note: removes both source and destination directory before starting. Do not
|
|
|
|
use with outstanding changes in either directory.
|
|
|
|
"""
|
|
|
|
|
2012-11-04 01:00:06 -07:00
|
|
|
from __future__ import print_function, unicode_literals
|
|
|
|
|
2012-03-29 14:08:58 -07:00
|
|
|
import os
|
|
|
|
import shutil
|
|
|
|
import subprocess
|
|
|
|
import sys
|
|
|
|
|
|
|
|
import parseManifest
|
2013-02-25 12:46:50 -08:00
|
|
|
import writeBuildFiles
|
2012-03-29 14:08:58 -07:00
|
|
|
|
2013-05-10 00:12:13 -07:00
|
|
|
def readManifests(iden, dirs):
|
|
|
|
def parseManifestFile(iden, path):
|
|
|
|
pathstr = "hg-%s/%s/MANIFEST" % (iden, path)
|
2013-05-10 00:12:48 -07:00
|
|
|
subdirs, mochitests, reftests, _, supportfiles = parseManifest.parseManifestFile(pathstr)
|
|
|
|
return subdirs, mochitests, reftests, supportfiles
|
2013-05-10 00:12:13 -07:00
|
|
|
|
|
|
|
data = []
|
|
|
|
for path in dirs:
|
2013-05-10 00:12:48 -07:00
|
|
|
subdirs, mochitests, reftests, supportfiles = parseManifestFile(iden, path)
|
2013-05-10 00:12:13 -07:00
|
|
|
data.append({
|
|
|
|
"path": path,
|
|
|
|
"mochitests": mochitests,
|
2013-05-10 00:12:48 -07:00
|
|
|
"reftests": reftests,
|
2013-05-10 00:12:13 -07:00
|
|
|
"supportfiles": supportfiles,
|
|
|
|
})
|
|
|
|
data.extend(readManifests(iden, ["%s/%s" % (path, d) for d in subdirs]))
|
|
|
|
return data
|
|
|
|
|
2012-03-29 14:08:58 -07:00
|
|
|
|
|
|
|
def getData(confFile):
|
2013-02-21 10:56:48 -08:00
|
|
|
"""This function parses a file of the form
|
2013-05-10 00:11:35 -07:00
|
|
|
(hg or git)|URL of remote repository|identifier for the local directory
|
2013-02-21 10:56:48 -08:00
|
|
|
First directory of tests
|
|
|
|
...
|
|
|
|
Last directory of tests"""
|
2013-05-10 00:11:35 -07:00
|
|
|
vcs = ""
|
|
|
|
url = ""
|
|
|
|
iden = ""
|
2013-02-21 10:56:48 -08:00
|
|
|
directories = []
|
|
|
|
try:
|
2013-02-25 12:46:50 -08:00
|
|
|
with open(confFile, 'r') as fp:
|
|
|
|
first = True
|
|
|
|
for line in fp:
|
|
|
|
if first:
|
2013-05-10 00:11:35 -07:00
|
|
|
vcs, url, iden = line.strip().split("|")
|
2013-02-25 12:46:50 -08:00
|
|
|
first = False
|
|
|
|
else:
|
|
|
|
directories.append(line.strip())
|
2013-02-21 10:56:48 -08:00
|
|
|
finally:
|
2013-05-10 00:11:35 -07:00
|
|
|
return vcs, url, iden, directories
|
2012-03-29 14:08:58 -07:00
|
|
|
|
2013-05-10 00:12:29 -07:00
|
|
|
|
|
|
|
def makePathInternal(a, b):
|
2013-02-21 10:56:48 -08:00
|
|
|
if not b:
|
|
|
|
# Empty directory, i.e., the repository root.
|
|
|
|
return a
|
|
|
|
return "%s/%s" % (a, b)
|
2012-05-20 04:12:41 -07:00
|
|
|
|
2013-05-10 00:12:29 -07:00
|
|
|
|
|
|
|
def makeSourcePath(a, b):
|
|
|
|
"""Make a path in the source (upstream) directory."""
|
|
|
|
return makePathInternal("hg-%s" % a, b)
|
|
|
|
|
|
|
|
|
|
|
|
def makeDestPath(a, b):
|
|
|
|
"""Make a path in the destination (mozilla-central) directory, shortening as
|
|
|
|
appropriate."""
|
|
|
|
def shorten(path):
|
|
|
|
path = path.replace('dom-tree-accessors', 'dta')
|
|
|
|
path = path.replace('document.getElementsByName', 'doc.gEBN')
|
|
|
|
path = path.replace('requirements-for-implementations', 'implreq')
|
|
|
|
path = path.replace('other-elements-attributes-and-apis', 'oeaaa')
|
|
|
|
return path
|
|
|
|
|
|
|
|
return shorten(makePathInternal(a, b))
|
|
|
|
|
|
|
|
|
2013-05-10 00:12:48 -07:00
|
|
|
def extractReftestFiles(reftests):
|
|
|
|
"""Returns the set of files referenced in the reftests argument"""
|
|
|
|
files = set()
|
|
|
|
for line in reftests:
|
|
|
|
files.update([line[1], line[2]])
|
|
|
|
return files
|
|
|
|
|
|
|
|
|
2013-05-10 00:11:55 -07:00
|
|
|
def copy(dest, directories):
|
2013-02-21 10:56:48 -08:00
|
|
|
"""Copy mochitests and support files from the external HG directory to their
|
|
|
|
place in mozilla-central.
|
|
|
|
"""
|
2013-05-10 00:12:13 -07:00
|
|
|
print("Copying tests...")
|
2013-02-21 10:56:48 -08:00
|
|
|
for d in directories:
|
2013-05-10 00:12:29 -07:00
|
|
|
sourcedir = makeSourcePath(dest, d["path"])
|
|
|
|
destdir = makeDestPath(dest, d["path"])
|
2013-02-21 10:56:48 -08:00
|
|
|
os.makedirs(destdir)
|
|
|
|
|
2013-05-10 00:12:48 -07:00
|
|
|
reftestfiles = extractReftestFiles(d["reftests"])
|
|
|
|
|
2013-05-10 00:12:13 -07:00
|
|
|
for mochitest in d["mochitests"]:
|
2013-05-10 00:12:08 -07:00
|
|
|
shutil.copy("%s/%s" % (sourcedir, mochitest), "%s/test_%s" % (destdir, mochitest))
|
2013-05-10 00:12:48 -07:00
|
|
|
for reftest in sorted(reftestfiles):
|
|
|
|
shutil.copy("%s/%s" % (sourcedir, reftest), "%s/%s" % (destdir, reftest))
|
2013-05-10 00:12:13 -07:00
|
|
|
for support in d["supportfiles"]:
|
2013-05-10 00:12:08 -07:00
|
|
|
shutil.copy("%s/%s" % (sourcedir, support), "%s/%s" % (destdir, support))
|
2013-02-21 10:56:48 -08:00
|
|
|
|
2013-02-25 12:46:50 -08:00
|
|
|
def printMozbuildFile(dest, directories):
|
|
|
|
"""Create a .mozbuild file to be included into the main moz.build, which
|
|
|
|
lists the directories with tests.
|
2013-02-21 10:56:48 -08:00
|
|
|
"""
|
2013-02-25 12:46:50 -08:00
|
|
|
print("Creating mozbuild...")
|
|
|
|
path = dest + ".mozbuild"
|
|
|
|
with open(path, 'w') as fh:
|
2013-05-10 00:12:29 -07:00
|
|
|
normalized = [makeDestPath(dest, d["path"]) for d in directories]
|
2013-04-04 00:03:55 -07:00
|
|
|
result = writeBuildFiles.substMozbuild("importTestsuite.py",
|
2013-02-25 12:46:50 -08:00
|
|
|
normalized)
|
|
|
|
fh.write(result)
|
|
|
|
|
2013-02-21 10:56:48 -08:00
|
|
|
subprocess.check_call(["hg", "add", path])
|
2012-03-29 14:08:58 -07:00
|
|
|
|
2013-05-10 00:11:55 -07:00
|
|
|
def printBuildFiles(dest, directories):
|
2013-02-21 10:56:48 -08:00
|
|
|
"""Create Makefile.in files for each directory that contains tests we import.
|
|
|
|
"""
|
2013-02-25 12:46:50 -08:00
|
|
|
print("Creating build files...")
|
2013-02-21 10:56:48 -08:00
|
|
|
for d in directories:
|
2013-05-10 00:12:29 -07:00
|
|
|
path = makeDestPath(dest, d["path"])
|
2012-03-29 14:08:58 -07:00
|
|
|
|
2013-05-10 00:12:13 -07:00
|
|
|
files = ["test_%s" % (mochitest, ) for mochitest in d["mochitests"]]
|
|
|
|
files.extend(d["supportfiles"])
|
2012-07-18 03:36:07 -07:00
|
|
|
|
2013-02-25 12:46:50 -08:00
|
|
|
with open(path + "/Makefile.in", "w") as fh:
|
|
|
|
result = writeBuildFiles.substMakefile("importTestsuite.py", files)
|
|
|
|
fh.write(result)
|
|
|
|
|
|
|
|
with open(path + "/moz.build", "w") as fh:
|
2013-05-10 00:12:13 -07:00
|
|
|
result = writeBuildFiles.substMozbuild("importTestsuite.py", [])
|
2013-02-25 12:46:50 -08:00
|
|
|
fh.write(result)
|
2012-03-29 14:08:58 -07:00
|
|
|
|
2013-05-10 00:12:48 -07:00
|
|
|
if d["reftests"]:
|
|
|
|
with open(path + "/reftest.list", "w") as fh:
|
|
|
|
result = writeBuildFiles.substReftestList("importTestsuite.py",
|
|
|
|
d["reftests"])
|
|
|
|
fh.write(result)
|
|
|
|
|
2012-03-29 14:08:58 -07:00
|
|
|
|
|
|
|
def hgadd(dest, directories):
|
2013-02-21 10:56:48 -08:00
|
|
|
"""Inform hg of the files in |directories|."""
|
|
|
|
print("hg addremoving...")
|
|
|
|
for d in directories:
|
2013-05-10 00:12:29 -07:00
|
|
|
subprocess.check_call(["hg", "addremove", makeDestPath(dest, d)])
|
2012-03-29 14:08:58 -07:00
|
|
|
|
2013-05-10 00:11:35 -07:00
|
|
|
def removeAndCloneRepo(vcs, url, dest):
|
|
|
|
"""Replaces the repo at dest by a fresh clone from url using vcs"""
|
|
|
|
assert vcs in ('hg', 'git')
|
|
|
|
|
|
|
|
print("Removing %s..." % dest)
|
|
|
|
subprocess.check_call(["rm", "-rf", dest])
|
|
|
|
|
|
|
|
print("Cloning %s to %s with %s..." % (url, dest, vcs))
|
|
|
|
subprocess.check_call([vcs, "clone", url, dest])
|
|
|
|
|
2013-05-10 00:11:55 -07:00
|
|
|
def importRepo(confFile):
|
2013-02-21 10:56:48 -08:00
|
|
|
try:
|
2013-05-10 00:11:35 -07:00
|
|
|
vcs, url, iden, directories = getData(confFile)
|
|
|
|
dest = iden
|
|
|
|
hgdest = "hg-%s" % iden
|
|
|
|
|
2013-02-21 10:56:48 -08:00
|
|
|
print("Removing %s..." % dest)
|
2013-02-25 12:46:50 -08:00
|
|
|
subprocess.check_call(["rm", "-rf", dest])
|
2013-05-10 00:11:35 -07:00
|
|
|
|
|
|
|
removeAndCloneRepo(vcs, url, hgdest)
|
|
|
|
|
2013-05-10 00:12:13 -07:00
|
|
|
data = readManifests(iden, directories)
|
|
|
|
print("Going to import %s..." % [d["path"] for d in data])
|
|
|
|
|
|
|
|
copy(dest, data)
|
|
|
|
printBuildFiles(dest, data)
|
|
|
|
printMozbuildFile(dest, data)
|
2013-02-21 10:56:48 -08:00
|
|
|
hgadd(dest, directories)
|
|
|
|
print("Removing %s again..." % hgdest)
|
2013-02-25 12:46:50 -08:00
|
|
|
subprocess.check_call(["rm", "-rf", hgdest])
|
2013-02-21 10:56:48 -08:00
|
|
|
except subprocess.CalledProcessError as e:
|
|
|
|
print(e.returncode)
|
|
|
|
finally:
|
|
|
|
print("Done")
|
2012-03-29 14:08:58 -07:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2013-02-21 10:56:48 -08:00
|
|
|
if len(sys.argv) != 2:
|
|
|
|
print("Need one argument.")
|
|
|
|
else:
|
2013-05-10 00:11:55 -07:00
|
|
|
importRepo(sys.argv[1])
|
2013-02-25 12:46:50 -08:00
|
|
|
|