Bug 784841 - Part 15: Produce moz.build files for dom imported tests; r=Ms2ger

--HG--
rename : dom/imptests/writeMakefile.py => dom/imptests/writeBuildFiles.py
This commit is contained in:
Gregory Szorc 2013-02-25 12:46:50 -08:00
parent 8612caaf5c
commit 4479cef096
5 changed files with 86 additions and 52 deletions

View File

@ -57,8 +57,8 @@ Source; Usage and purpose; License
by @ signs.
MPL
* writeMakefile.py
Helper functions to write out Makefiles.
* writeBuildFiles.py
Helper functions to write out automatically generated build files.
MPL
* Makefile.in

View File

@ -18,7 +18,7 @@ import subprocess
import sys
import parseManifest
import writeMakefile
import writeBuildFiles
HEADERS_SUFFIX = "^headers^"
@ -36,18 +36,17 @@ def getData(confFile):
dest = ""
directories = []
try:
fp = open(confFile, "r")
first = True
for line in fp:
if first:
idx = line.index("|")
repo = line[:idx].strip()
dest = line[idx + 1:].strip()
first = False
else:
directories.append(line.strip())
with open(confFile, 'r') as fp:
first = True
for line in fp:
if first:
idx = line.index("|")
repo = line[:idx].strip()
dest = line[idx + 1:].strip()
first = False
else:
directories.append(line.strip())
finally:
fp.close()
return repo, dest, directories
def makePath(a, b):
@ -86,23 +85,24 @@ def copy(thissrcdir, dest, directories):
# Empty directory, i.e., the repository root
importDirs(thissrcdir, dest, subdirs)
def printMakefile(dest, directories):
"""Create a .mk file to be included into the main Makefile.in, which lists the
directories with tests.
def printMozbuildFile(dest, directories):
"""Create a .mozbuild file to be included into the main moz.build, which
lists the directories with tests.
"""
print("Creating .mk...")
path = dest + ".mk"
fp = open(path, "w")
fp.write("DIRS += \\\n")
fp.write(writeMakefile.makefileString([makePath(dest, d) for d in directories]))
fp.write("\n")
fp.close()
print("Creating mozbuild...")
path = dest + ".mozbuild"
with open(path, 'w') as fh:
normalized = [makePath(dest, d) for d in directories]
result = writeBuildFiles.substMozbuild("importTestSuites.py",
normalized)
fh.write(result)
subprocess.check_call(["hg", "add", path])
def printMakefiles(thissrcdir, dest, directories):
def printBuildFiles(thissrcdir, dest, directories):
"""Create Makefile.in files for each directory that contains tests we import.
"""
print("Creating Makefile.ins...")
print("Creating build files...")
for d in directories:
path = makePath(dest, d)
print("Creating Makefile.in in %s..." % path)
@ -113,11 +113,16 @@ def printMakefiles(thissrcdir, dest, directories):
files.extend(supportfiles)
files.extend(f for f in os.listdir(path) if f.endswith(HEADERS_SUFFIX))
result = writeMakefile.substMakefile("importTestsuite.py", subdirs, files)
with open(path + "/Makefile.in", "w") as fh:
result = writeBuildFiles.substMakefile("importTestsuite.py", files)
fh.write(result)
print("Creating moz.build in %s..." % path)
with open(path + "/moz.build", "w") as fh:
result = writeBuildFiles.substMozbuild("importTestsuite.py",
subdirs)
fh.write(result)
fp = open(path + "/Makefile.in", "w")
fp.write(result)
fp.close()
def hgadd(dest, directories):
"""Inform hg of the files in |directories|."""
@ -127,7 +132,7 @@ def hgadd(dest, directories):
def importDirs(thissrcdir, dest, directories):
copy(thissrcdir, dest, directories)
printMakefiles(thissrcdir, dest, directories)
printBuildFiles(thissrcdir, dest, directories)
def importRepo(confFile, thissrcdir):
try:
@ -135,17 +140,17 @@ def importRepo(confFile, thissrcdir):
hgdest = "hg-%s" % (dest, )
print("Going to clone %s to %s..." % (repo, hgdest))
print("Removing %s..." % dest)
subprocess.check_call(["rm", "--recursive", "--force", dest])
subprocess.check_call(["rm", "-rf", dest])
print("Removing %s..." % hgdest)
subprocess.check_call(["rm", "--recursive", "--force", hgdest])
subprocess.check_call(["rm", "-rf", hgdest])
print("Cloning %s to %s..." % (repo, hgdest))
subprocess.check_call(["hg", "clone", repo, hgdest])
print("Going to import %s..." % directories)
importDirs(thissrcdir, dest, directories)
printMakefile(dest, directories)
printMozbuildFile(dest, directories)
hgadd(dest, directories)
print("Removing %s again..." % hgdest)
subprocess.check_call(["rm", "--recursive", "--force", hgdest])
subprocess.check_call(["rm", "-rf", hgdest])
except subprocess.CalledProcessError as e:
print(e.returncode)
finally:
@ -156,3 +161,4 @@ if __name__ == "__main__":
print("Need one argument.")
else:
importRepo(sys.argv[1], "dom/imptests")

View File

@ -9,7 +9,7 @@ import json
import os
import sys
import writeMakefile
import writeBuildFiles
def extractLines(fp):
lines = []
@ -52,19 +52,22 @@ def dumpFailures(lines):
fp.close()
return files
def writeMakefiles(files):
def writeFiles(files):
pathmap = {}
for path in files:
dirp, leaf = path.rsplit('/', 1)
pathmap.setdefault(dirp, []).append(leaf)
for k, v in pathmap.items():
resultstr = writeMakefile.substMakefile('parseFailures.py', [], v)
result = resultstr.encode('utf-8')
with open(k + '/Makefile.in', 'wb') as fh:
result = writeBuildFiles.substMakefile('parseFailures.py', v)
result = result.encode('utf-8')
fh.write(result)
fp = open(k + '/Makefile.in', 'wb')
fp.write(result)
fp.close()
with open(k + '/moz.build', 'wb') as fh:
result = writeBuildFiles.substMozbuild('parseFailures.py', [])
result = result.encode('utf-8')
fh.write(result)
def main(logPath):
fp = open(logPath, 'rb')
@ -72,9 +75,10 @@ def main(logPath):
fp.close()
files = dumpFailures(lines)
writeMakefiles(files)
writeFiles(files)
if __name__ == '__main__':
if len(sys.argv) < 2:
print("Please pass the path to the logfile from which failures should be extracted.")
main(sys.argv[1])

View File

@ -15,4 +15,5 @@ subprocess.check_call(["hg", "clone", repo, dest])
for f in files:
subprocess.check_call(["cp", "%s/%s" % (dest, f), f])
subprocess.check_call(["hg", "add", f])
subprocess.check_call(["rm", "--recursive", "--force", dest])
subprocess.check_call(["rm", "-rf", dest])

View File

@ -6,7 +6,7 @@ from __future__ import unicode_literals
import string
makefileTemplate = """# THIS FILE IS AUTOGENERATED BY ${caller} - DO NOT EDIT
makefile_template = """# THIS FILE IS AUTOGENERATED BY ${caller} - DO NOT EDIT
DEPTH := @DEPTH@
@ -17,24 +17,47 @@ relativesrcdir := @relativesrcdir@
include $$(DEPTH)/config/autoconf.mk
${dirs}
${files}
include $$(topsrcdir)/config/rules.mk
"""
mozbuild_template = """# THIS FILE IS AUTOGENERATED BY ${caller} - DO NOT EDIT
${dirs}
"""
def makefileString(entries):
if not len(entries):
return " $(NULL)"
return "\n".join([" %s \\" % (entry, ) for entry in entries]) + "\n $(NULL)"
def assignList(variable, entries):
return "%s := \\\n%s" % (variable, makefileString(entries))
def substMakefile(caller, subdirs, files):
return string.Template(makefileTemplate).substitute({
"caller": caller,
"dirs": assignList("DIRS", subdirs),
"files": assignList("MOCHITEST_FILES", files) if files else ""
def mozbuildDirs(dirs):
"""Obtain a DIRS assignment string for mozbuild files."""
parts = ['DIRS += [']
for d in dirs:
parts.append(" '%s'," % d)
parts.append(']')
return '\n'.join(parts)
def substMakefile(caller, files):
return string.Template(makefile_template).substitute({
"caller": caller,
"files": assignList("MOCHITEST_FILES", files) if files else ""
})
def substMozbuild(caller, dirs):
return string.Template(mozbuild_template).substitute({
"caller": caller,
"dirs": mozbuildDirs(dirs),
})