mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-08 19:04:45 +00:00
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:
parent
8612caaf5c
commit
4479cef096
@ -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
|
||||
|
@ -18,7 +18,7 @@ import subprocess
|
||||
import sys
|
||||
|
||||
import parseManifest
|
||||
import writeMakefile
|
||||
import writeBuildFiles
|
||||
|
||||
HEADERS_SUFFIX = "^headers^"
|
||||
|
||||
@ -36,7 +36,7 @@ def getData(confFile):
|
||||
dest = ""
|
||||
directories = []
|
||||
try:
|
||||
fp = open(confFile, "r")
|
||||
with open(confFile, 'r') as fp:
|
||||
first = True
|
||||
for line in fp:
|
||||
if first:
|
||||
@ -47,7 +47,6 @@ def getData(confFile):
|
||||
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")
|
||||
|
||||
|
@ -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])
|
||||
|
||||
|
@ -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])
|
||||
|
||||
|
@ -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({
|
||||
|
||||
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,
|
||||
"dirs": assignList("DIRS", subdirs),
|
||||
"files": assignList("MOCHITEST_FILES", files) if files else ""
|
||||
})
|
||||
|
||||
|
||||
def substMozbuild(caller, dirs):
|
||||
return string.Template(mozbuild_template).substitute({
|
||||
"caller": caller,
|
||||
"dirs": mozbuildDirs(dirs),
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user