2012-03-30 01:08:58 +04: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 12:00:06 +04:00
|
|
|
from __future__ import print_function, unicode_literals
|
|
|
|
|
2012-03-30 01:08:58 +04:00
|
|
|
import os
|
|
|
|
import shutil
|
|
|
|
import subprocess
|
|
|
|
import sys
|
|
|
|
|
|
|
|
import parseManifest
|
2013-02-26 00:46:50 +04:00
|
|
|
import writeBuildFiles
|
2012-03-30 01:08:58 +04:00
|
|
|
|
2013-05-10 11:12:13 +04:00
|
|
|
def readManifests(iden, dirs):
|
|
|
|
def parseManifestFile(iden, path):
|
|
|
|
pathstr = "hg-%s/%s/MANIFEST" % (iden, path)
|
2013-05-10 11:12:48 +04:00
|
|
|
subdirs, mochitests, reftests, _, supportfiles = parseManifest.parseManifestFile(pathstr)
|
|
|
|
return subdirs, mochitests, reftests, supportfiles
|
2013-05-10 11:12:13 +04:00
|
|
|
|
|
|
|
data = []
|
|
|
|
for path in dirs:
|
2013-05-10 11:12:48 +04:00
|
|
|
subdirs, mochitests, reftests, supportfiles = parseManifestFile(iden, path)
|
2013-05-10 11:12:13 +04:00
|
|
|
data.append({
|
|
|
|
"path": path,
|
|
|
|
"mochitests": mochitests,
|
2013-05-10 11:12:48 +04:00
|
|
|
"reftests": reftests,
|
2013-05-10 11:12:13 +04:00
|
|
|
"supportfiles": supportfiles,
|
|
|
|
})
|
|
|
|
data.extend(readManifests(iden, ["%s/%s" % (path, d) for d in subdirs]))
|
|
|
|
return data
|
|
|
|
|
2012-03-30 01:08:58 +04:00
|
|
|
|
|
|
|
def getData(confFile):
|
2013-02-21 22:56:48 +04:00
|
|
|
"""This function parses a file of the form
|
2013-05-10 11:11:35 +04:00
|
|
|
(hg or git)|URL of remote repository|identifier for the local directory
|
2013-02-21 22:56:48 +04:00
|
|
|
First directory of tests
|
|
|
|
...
|
|
|
|
Last directory of tests"""
|
2013-05-10 11:11:35 +04:00
|
|
|
vcs = ""
|
|
|
|
url = ""
|
|
|
|
iden = ""
|
2013-02-21 22:56:48 +04:00
|
|
|
directories = []
|
|
|
|
try:
|
2013-02-26 00:46:50 +04:00
|
|
|
with open(confFile, 'r') as fp:
|
|
|
|
first = True
|
|
|
|
for line in fp:
|
|
|
|
if first:
|
2013-05-10 11:11:35 +04:00
|
|
|
vcs, url, iden = line.strip().split("|")
|
2013-02-26 00:46:50 +04:00
|
|
|
first = False
|
|
|
|
else:
|
|
|
|
directories.append(line.strip())
|
2013-02-21 22:56:48 +04:00
|
|
|
finally:
|
2013-05-10 11:11:35 +04:00
|
|
|
return vcs, url, iden, directories
|
2012-03-30 01:08:58 +04:00
|
|
|
|
2013-05-10 11:12:29 +04:00
|
|
|
|
|
|
|
def makePathInternal(a, b):
|
2013-02-21 22:56:48 +04:00
|
|
|
if not b:
|
|
|
|
# Empty directory, i.e., the repository root.
|
|
|
|
return a
|
|
|
|
return "%s/%s" % (a, b)
|
2012-05-20 15:12:41 +04:00
|
|
|
|
2013-05-10 11:12:29 +04: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 11:12:48 +04: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 11:11:55 +04:00
|
|
|
def copy(dest, directories):
|
2013-02-21 22:56:48 +04:00
|
|
|
"""Copy mochitests and support files from the external HG directory to their
|
|
|
|
place in mozilla-central.
|
|
|
|
"""
|
2013-05-10 11:12:13 +04:00
|
|
|
print("Copying tests...")
|
2013-02-21 22:56:48 +04:00
|
|
|
for d in directories:
|
2013-05-10 11:12:29 +04:00
|
|
|
sourcedir = makeSourcePath(dest, d["path"])
|
|
|
|
destdir = makeDestPath(dest, d["path"])
|
2013-02-21 22:56:48 +04:00
|
|
|
os.makedirs(destdir)
|
|
|
|
|
2013-05-10 11:12:48 +04:00
|
|
|
reftestfiles = extractReftestFiles(d["reftests"])
|
|
|
|
|
2013-05-10 11:12:13 +04:00
|
|
|
for mochitest in d["mochitests"]:
|
2013-05-10 11:12:08 +04:00
|
|
|
shutil.copy("%s/%s" % (sourcedir, mochitest), "%s/test_%s" % (destdir, mochitest))
|
2013-05-10 11:12:48 +04:00
|
|
|
for reftest in sorted(reftestfiles):
|
|
|
|
shutil.copy("%s/%s" % (sourcedir, reftest), "%s/%s" % (destdir, reftest))
|
2013-05-10 11:12:13 +04:00
|
|
|
for support in d["supportfiles"]:
|
2013-05-10 11:12:08 +04:00
|
|
|
shutil.copy("%s/%s" % (sourcedir, support), "%s/%s" % (destdir, support))
|
2013-02-21 22:56:48 +04:00
|
|
|
|
2013-02-26 00:46:50 +04: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 22:56:48 +04:00
|
|
|
"""
|
2013-02-26 00:46:50 +04:00
|
|
|
print("Creating mozbuild...")
|
|
|
|
path = dest + ".mozbuild"
|
|
|
|
with open(path, 'w') as fh:
|
2013-05-10 11:12:29 +04:00
|
|
|
normalized = [makeDestPath(dest, d["path"]) for d in directories]
|
2013-04-04 11:03:55 +04:00
|
|
|
result = writeBuildFiles.substMozbuild("importTestsuite.py",
|
2013-02-26 00:46:50 +04:00
|
|
|
normalized)
|
|
|
|
fh.write(result)
|
|
|
|
|
2013-02-21 22:56:48 +04:00
|
|
|
subprocess.check_call(["hg", "add", path])
|
2012-03-30 01:08:58 +04:00
|
|
|
|
2013-05-10 11:11:55 +04:00
|
|
|
def printBuildFiles(dest, directories):
|
2013-02-21 22:56:48 +04:00
|
|
|
"""Create Makefile.in files for each directory that contains tests we import.
|
|
|
|
"""
|
2013-02-26 00:46:50 +04:00
|
|
|
print("Creating build files...")
|
2013-02-21 22:56:48 +04:00
|
|
|
for d in directories:
|
2013-05-10 11:12:29 +04:00
|
|
|
path = makeDestPath(dest, d["path"])
|
2012-03-30 01:08:58 +04:00
|
|
|
|
2013-05-10 11:12:13 +04:00
|
|
|
files = ["test_%s" % (mochitest, ) for mochitest in d["mochitests"]]
|
|
|
|
files.extend(d["supportfiles"])
|
2012-07-18 14:36:07 +04:00
|
|
|
|
2013-02-26 00:46:50 +04: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 11:12:13 +04:00
|
|
|
result = writeBuildFiles.substMozbuild("importTestsuite.py", [])
|
2013-02-26 00:46:50 +04:00
|
|
|
fh.write(result)
|
2012-03-30 01:08:58 +04:00
|
|
|
|
2013-05-10 11:12:48 +04:00
|
|
|
if d["reftests"]:
|
|
|
|
with open(path + "/reftest.list", "w") as fh:
|
|
|
|
result = writeBuildFiles.substReftestList("importTestsuite.py",
|
|
|
|
d["reftests"])
|
|
|
|
fh.write(result)
|
|
|
|
|
2012-03-30 01:08:58 +04:00
|
|
|
|
|
|
|
def hgadd(dest, directories):
|
2013-02-21 22:56:48 +04:00
|
|
|
"""Inform hg of the files in |directories|."""
|
|
|
|
print("hg addremoving...")
|
|
|
|
for d in directories:
|
2013-05-10 11:12:29 +04:00
|
|
|
subprocess.check_call(["hg", "addremove", makeDestPath(dest, d)])
|
2012-03-30 01:08:58 +04:00
|
|
|
|
2013-05-10 11:11:35 +04: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 11:11:55 +04:00
|
|
|
def importRepo(confFile):
|
2013-02-21 22:56:48 +04:00
|
|
|
try:
|
2013-05-10 11:11:35 +04:00
|
|
|
vcs, url, iden, directories = getData(confFile)
|
|
|
|
dest = iden
|
|
|
|
hgdest = "hg-%s" % iden
|
|
|
|
|
2013-02-21 22:56:48 +04:00
|
|
|
print("Removing %s..." % dest)
|
2013-02-26 00:46:50 +04:00
|
|
|
subprocess.check_call(["rm", "-rf", dest])
|
2013-05-10 11:11:35 +04:00
|
|
|
|
|
|
|
removeAndCloneRepo(vcs, url, hgdest)
|
|
|
|
|
2013-05-10 11:12:13 +04: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 22:56:48 +04:00
|
|
|
hgadd(dest, directories)
|
|
|
|
print("Removing %s again..." % hgdest)
|
2013-02-26 00:46:50 +04:00
|
|
|
subprocess.check_call(["rm", "-rf", hgdest])
|
2013-02-21 22:56:48 +04:00
|
|
|
except subprocess.CalledProcessError as e:
|
|
|
|
print(e.returncode)
|
|
|
|
finally:
|
|
|
|
print("Done")
|
2012-03-30 01:08:58 +04:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2013-02-21 22:56:48 +04:00
|
|
|
if len(sys.argv) != 2:
|
|
|
|
print("Need one argument.")
|
|
|
|
else:
|
2013-05-10 11:11:55 +04:00
|
|
|
importRepo(sys.argv[1])
|
2013-02-26 00:46:50 +04:00
|
|
|
|