Skip to content

Commit

Permalink
bug 1463425 - autopep8 on build/ r=gps
Browse files Browse the repository at this point in the history
MozReview-Commit-ID: ETzx4HsjbEF
  • Loading branch information
sylvestre committed May 21, 2018
1 parent 7b75fcc commit 9716032
Show file tree
Hide file tree
Showing 10 changed files with 374 additions and 318 deletions.
137 changes: 71 additions & 66 deletions build/clang-plugin/import_mozilla_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import ThirdPartyPaths


def copy_dir_contents(src, dest):
for f in glob.glob("%s/*" % src):
try:
Expand All @@ -32,11 +33,12 @@ def copy_dir_contents(src, dest):
else:
raise Exception('Directory not copied. Error: %s' % e)


def write_cmake(module_path):
names = map(lambda f: ' ' + os.path.basename(f),
glob.glob("%s/*.cpp" % module_path))
with open(os.path.join(module_path, 'CMakeLists.txt'), 'wb') as f:
f.write("""set(LLVM_LINK_COMPONENTS support)
names = map(lambda f: ' ' + os.path.basename(f),
glob.glob("%s/*.cpp" % module_path))
with open(os.path.join(module_path, 'CMakeLists.txt'), 'wb') as f:
f.write("""set(LLVM_LINK_COMPONENTS support)
add_definitions( -DCLANG_TIDY )
add_definitions( -DHAVE_NEW_ASTMATCHER_NAMES )
Expand All @@ -55,92 +57,95 @@ def write_cmake(module_path):
clangTidyUtils
)""" % {'names': "\n".join(names)})


def add_item_to_cmake_section(cmake_path, section, library):
with open(cmake_path, 'r') as f:
lines = f.readlines()
f.close()

libs = []
seen_target_libs = False
for line in lines:
if line.find(section) > -1:
seen_target_libs = True
elif seen_target_libs:
if line.find(')') > -1:
break
else:
libs.append(line.strip())
libs.append(library)
libs = sorted(libs, key = lambda s: s.lower())

with open(cmake_path, 'wb') as f:
with open(cmake_path, 'r') as f:
lines = f.readlines()
f.close()

libs = []
seen_target_libs = False
for line in lines:
if line.find(section) > -1:
seen_target_libs = True
f.write(line)
f.writelines(map(lambda p: ' ' + p + '\n', libs))
continue
elif seen_target_libs:
if line.find(')') > -1:
seen_target_libs = False
else:
continue
f.write(line)
if line.find(section) > -1:
seen_target_libs = True
elif seen_target_libs:
if line.find(')') > -1:
break
else:
libs.append(line.strip())
libs.append(library)
libs = sorted(libs, key=lambda s: s.lower())

with open(cmake_path, 'wb') as f:
seen_target_libs = False
for line in lines:
if line.find(section) > -1:
seen_target_libs = True
f.write(line)
f.writelines(map(lambda p: ' ' + p + '\n', libs))
continue
elif seen_target_libs:
if line.find(')') > -1:
seen_target_libs = False
else:
continue
f.write(line)

f.close()
f.close()


def write_third_party_paths(mozilla_path, module_path):
tpp_txt = os.path.join(mozilla_path, '../../tools/rewriting/ThirdPartyPaths.txt')
with open(os.path.join(module_path, 'ThirdPartyPaths.cpp'), 'w') as f:
ThirdPartyPaths.generate(f, tpp_txt)
tpp_txt = os.path.join(
mozilla_path, '../../tools/rewriting/ThirdPartyPaths.txt')
with open(os.path.join(module_path, 'ThirdPartyPaths.cpp'), 'w') as f:
ThirdPartyPaths.generate(f, tpp_txt)


def do_import(mozilla_path, clang_tidy_path):
module = 'mozilla'
module_path = os.path.join(clang_tidy_path, module)
if not os.path.isdir(module_path):
os.mkdir(module_path)

copy_dir_contents(mozilla_path, module_path)
write_third_party_paths(mozilla_path, module_path)
write_cmake(module_path)
add_item_to_cmake_section(os.path.join(module_path, '..', 'plugin',
'CMakeLists.txt'),
'LINK_LIBS', 'clangTidyMozillaModule')
add_item_to_cmake_section(os.path.join(module_path, '..', 'tool',
'CMakeLists.txt'),
'target_link_libraries', 'clangTidyMozillaModule')
with open(os.path.join(module_path, '..', 'CMakeLists.txt'), 'a') as f:
f.write('add_subdirectory(%s)\n' % module)
with open(os.path.join(module_path, '..', 'tool', 'ClangTidyMain.cpp'), 'a') as f:
f.write('''
module = 'mozilla'
module_path = os.path.join(clang_tidy_path, module)
if not os.path.isdir(module_path):
os.mkdir(module_path)

copy_dir_contents(mozilla_path, module_path)
write_third_party_paths(mozilla_path, module_path)
write_cmake(module_path)
add_item_to_cmake_section(os.path.join(module_path, '..', 'plugin',
'CMakeLists.txt'),
'LINK_LIBS', 'clangTidyMozillaModule')
add_item_to_cmake_section(os.path.join(module_path, '..', 'tool',
'CMakeLists.txt'),
'target_link_libraries', 'clangTidyMozillaModule')
with open(os.path.join(module_path, '..', 'CMakeLists.txt'), 'a') as f:
f.write('add_subdirectory(%s)\n' % module)
with open(os.path.join(module_path, '..', 'tool', 'ClangTidyMain.cpp'), 'a') as f:
f.write('''
// This anchor is used to force the linker to link the MozillaModule.
extern volatile int MozillaModuleAnchorSource;
static int LLVM_ATTRIBUTE_UNUSED MozillaModuleAnchorDestination =
MozillaModuleAnchorSource;
''')


def main():
if len(sys.argv) != 3:
print """\
if len(sys.argv) != 3:
print """\
Usage: import_mozilla_checks.py <mozilla-clang-plugin-path> <clang-tidy-path>
Imports the Mozilla static analysis checks into a clang-tidy source tree.
"""

return
return

mozilla_path = sys.argv[1]
if not os.path.isdir(mozilla_path):
print "Invalid path to mozilla clang plugin"
mozilla_path = sys.argv[1]
if not os.path.isdir(mozilla_path):
print "Invalid path to mozilla clang plugin"

clang_tidy_path = sys.argv[2]
if not os.path.isdir(mozilla_path):
print "Invalid path to clang-tidy source directory"
clang_tidy_path = sys.argv[2]
if not os.path.isdir(mozilla_path):
print "Invalid path to clang-tidy source directory"

do_import(mozilla_path, clang_tidy_path)
do_import(mozilla_path, clang_tidy_path)


if __name__ == '__main__':
main()
main()
53 changes: 32 additions & 21 deletions build/mobile/remoteautomation.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,20 @@
import mozcrash

# signatures for logcat messages that we don't care about much
fennecLogcatFilters = [ "The character encoding of the HTML document was not declared",
"Use of Mutation Events is deprecated. Use MutationObserver instead.",
"Unexpected value from nativeGetEnabledTags: 0" ]
fennecLogcatFilters = ["The character encoding of the HTML document was not declared",
"Use of Mutation Events is deprecated. Use MutationObserver instead.",
"Unexpected value from nativeGetEnabledTags: 0"]


class RemoteAutomation(Automation):

def __init__(self, device, appName = '', remoteProfile = None, remoteLog = None,
def __init__(self, device, appName='', remoteProfile=None, remoteLog=None,
processArgs=None):
self._device = device
self._appName = appName
self._remoteProfile = remoteProfile
self._remoteLog = remoteLog
self._processArgs = processArgs or {};
self._processArgs = processArgs or {}

self.lastTestSeen = "remoteautomation.py"
Automation.__init__(self)
Expand Down Expand Up @@ -79,7 +80,7 @@ def waitForFinish(self, proc, utilityPath, timeout, maxTime, startTime, debugger
"""
proc.utilityPath = utilityPath
# maxTime is used to override the default timeout, we should honor that
status = proc.wait(timeout = maxTime, noOutputTimeout = timeout)
status = proc.wait(timeout=maxTime, noOutputTimeout=timeout)
self.lastTestSeen = proc.getLastTestSeen

topActivity = self._device.get_top_activity(timeout=60)
Expand All @@ -89,7 +90,8 @@ def waitForFinish(self, proc, utilityPath, timeout, maxTime, startTime, debugger
if status == 1:
if maxTime:
print "TEST-UNEXPECTED-FAIL | %s | application ran for longer than " \
"allowed maximum time of %s seconds" % (self.lastTestSeen, maxTime)
"allowed maximum time of %s seconds" % (
self.lastTestSeen, maxTime)
else:
print "TEST-UNEXPECTED-FAIL | %s | application ran for longer than " \
"allowed maximum time" % (self.lastTestSeen)
Expand Down Expand Up @@ -128,7 +130,8 @@ def checkForANRs(self):

def deleteTombstones(self):
# delete any tombstone files from device
self._device.rm("/data/tombstones", force=True, recursive=True, root=True)
self._device.rm("/data/tombstones", force=True,
recursive=True, root=True)

def checkForTombstones(self):
# pull any tombstones from device and move to MOZ_UPLOAD_DIR
Expand Down Expand Up @@ -160,9 +163,11 @@ def checkForCrashes(self, directory, symbolsPath):
self.checkForANRs()
self.checkForTombstones()

logcat = self._device.get_logcat(filter_out_regexps=fennecLogcatFilters)
logcat = self._device.get_logcat(
filter_out_regexps=fennecLogcatFilters)

javaException = mozcrash.check_for_java_exception(logcat, test_name=self.lastTestSeen)
javaException = mozcrash.check_for_java_exception(
logcat, test_name=self.lastTestSeen)
if javaException:
return True

Expand All @@ -184,13 +189,15 @@ def checkForCrashes(self, directory, symbolsPath):
self._device.pull(remoteCrashDir, dumpDir)

logger = get_default_logger()
crashed = mozcrash.log_crashes(logger, dumpDir, symbolsPath, test=self.lastTestSeen)
crashed = mozcrash.log_crashes(
logger, dumpDir, symbolsPath, test=self.lastTestSeen)

finally:
try:
shutil.rmtree(dumpDir)
except Exception as e:
print "WARNING: unable to remove directory %s: %s" % (dumpDir, str(e))
print "WARNING: unable to remove directory %s: %s" % (
dumpDir, str(e))
return crashed

def buildCommandLine(self, app, debuggerInfo, profileDir, testURL, extraArgs):
Expand All @@ -203,14 +210,15 @@ def buildCommandLine(self, app, debuggerInfo, profileDir, testURL, extraArgs):
if app == "am" and extraArgs[0] in ('instrument', 'start'):
return app, extraArgs

cmd, args = Automation.buildCommandLine(self, app, debuggerInfo, profileDir, testURL, extraArgs)
cmd, args = Automation.buildCommandLine(
self, app, debuggerInfo, profileDir, testURL, extraArgs)
try:
args.remove('-foreground')
except:
pass
return app, args

def Process(self, cmd, stdout = None, stderr = None, env = None, cwd = None):
def Process(self, cmd, stdout=None, stderr=None, env=None, cwd=None):
return self.RProcess(self._device, cmd, self._remoteLog, env, cwd, self._appName,
**self._processArgs)

Expand All @@ -220,7 +228,7 @@ def __init__(self, device, cmd, stdout=None, env=None, cwd=None, app=None,
self.device = device
self.lastTestSeen = "remoteautomation.py"
self.messageLogger = messageLogger
self.proc = stdout
self.proc = stdout
self.procName = cmd[0].split(posixpath.sep)[-1]
self.stdoutlen = 0
self.utilityPath = None
Expand Down Expand Up @@ -251,7 +259,8 @@ def __init__(self, device, cmd, stdout=None, env=None, cwd=None, app=None,
self.device.launch_activity(app, activity, e10s=True, moz_env=env,
extra_args=args, url=url)
else:
self.device.launch_fennec(app, moz_env=env, extra_args=args, url=url)
self.device.launch_fennec(
app, moz_env=env, extra_args=args, url=url)

# Setting timeout at 1 hour since on a remote device this takes much longer.
# Temporarily increased to 90 minutes because no more chunks can be created.
Expand Down Expand Up @@ -279,7 +288,8 @@ def read_stdout(self):
if not self.device.is_file(self.proc):
return False
try:
newLogContent = self.device.get_file(self.proc, offset=self.stdoutlen)
newLogContent = self.device.get_file(
self.proc, offset=self.stdoutlen)
except Exception:
return False
if not newLogContent:
Expand All @@ -288,7 +298,8 @@ def read_stdout(self):
self.stdoutlen += len(newLogContent)

if self.messageLogger is None:
testStartFilenames = re.findall(r"TEST-START \| ([^\s]*)", newLogContent)
testStartFilenames = re.findall(
r"TEST-START \| ([^\s]*)", newLogContent)
if testStartFilenames:
self.lastTestSeen = testStartFilenames[-1]
print newLogContent
Expand Down Expand Up @@ -344,7 +355,7 @@ def getLastTestSeen(self):
# If the process is still running but no output is received in *noOutputTimeout*
# seconds, return 2;
# Else, once the process exits/goes to background, return 0.
def wait(self, timeout = None, noOutputTimeout = None):
def wait(self, timeout=None, noOutputTimeout=None):
timer = 0
noOutputTimer = 0
interval = 10
Expand All @@ -353,7 +364,7 @@ def wait(self, timeout = None, noOutputTimeout = None):
status = 0
top = self.procName
slowLog = False
endTime = datetime.datetime.now() + datetime.timedelta(seconds = timeout)
endTime = datetime.datetime.now() + datetime.timedelta(seconds=timeout)
while top == self.procName:
# Get log updates on each interval, but if it is taking
# too long, only do it every 60 seconds
Expand Down Expand Up @@ -385,7 +396,7 @@ def wait(self, timeout = None, noOutputTimeout = None):
self.read_stdout()
return status

def kill(self, stagedShutdown = False):
def kill(self, stagedShutdown=False):
if self.utilityPath:
# Take a screenshot to capture the screen state just before
# the application is killed. There are on-device screenshot
Expand Down
Loading

0 comments on commit 9716032

Please sign in to comment.