<commit_before>#!/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/.

from __future__ import with_statement

import os
import platform
import subprocess
import sys

path0 = os.path.dirname(os.path.abspath(__file__))
path1 = os.path.abspath(os.path.join(path0, os.pardir, 'util'))
sys.path.append(path1)
from subprocesses import captureStdout, verbose, vdump

def archOfBinary(b):
    '''
    This function tests if a binary is 32-bit or 64-bit.
    '''
    unsplitFiletype = captureStdout(['file', b])[0]
    filetype = unsplitFiletype.split(':', 1)[1]
    if platform.system() == 'Windows':
        assert 'PE executable for MS Windows (console)' in filetype
        return '32' if 'Intel 80386 32-bit' in filetype else '64'
    else:
        if 'universal binary' in filetype:
            raise Exception("I don't know how to deal with multiple-architecture binaries")
        if '386' in filetype or '32-bit' in filetype:
            assert '64-bit' not in filetype
            return '32'
        if '64-bit' in filetype:
            assert '32-bit' not in filetype
            return '64'

def exitCodeDbgOptOrJsShellXpcshell(shell, dbgOptOrJsShellXpcshell):
    '''
    This function returns the exit code after testing the shell.
    '''
    cmdList = []

    cmdList.append(shell)
    if dbgOptOrJsShellXpcshell == 'dbgOpt':
        script = 'gczeal()'
    elif dbgOptOrJsShellXpcshell == 'jsShellXpcshell':
        script = 'Components'
        # To run xpcshell, command is `./run-mozilla.sh ./xpcshell testcase.js`
        # js shells do not have the middle parameter, so they will mis-understand and think that
        # ./xpcshell is the testcase they should run instead.
        if 'run-mozilla' in shell:
            cmdList.append('./xpcshell')
            assert len(cmdList) == 2
        else:
            assert len(cmdList) == 1

    cmdList.append("-e")
    cmdList.append(script)

    vdump(' '.join(cmdList))
    if verbose:
        retCode = subprocess.call(cmdList, stderr=subprocess.STDOUT)
    else:
        fnull = open(os.devnull, 'w')
        retCode = subprocess.call(cmdList, stdout=fnull, stderr=subprocess.STDOUT)
        fnull.close()

    vdump('The return code is: ' + str(retCode))
    return retCode

def testJsShellOrXpcshell(sname):<commit_msg>Remove xpcshell hack. If we need to do something in future, let's just unconditionally set LD_LIBRARY_PATH to the directory containing the shell.<commit_after>#!/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/.

from __future__ import with_statement

import os
import platform
import subprocess
import sys

path0 = os.path.dirname(os.path.abspath(__file__))
path1 = os.path.abspath(os.path.join(path0, os.pardir, 'util'))
sys.path.append(path1)
from subprocesses import captureStdout, verbose, vdump

def archOfBinary(b):
    '''
    This function tests if a binary is 32-bit or 64-bit.
    '''
    unsplitFiletype = captureStdout(['file', b])[0]
    filetype = unsplitFiletype.split(':', 1)[1]
    if platform.system() == 'Windows':
        assert 'PE executable for MS Windows (console)' in filetype
        return '32' if 'Intel 80386 32-bit' in filetype else '64'
    else:
        if 'universal binary' in filetype:
            raise Exception("I don't know how to deal with multiple-architecture binaries")
        if '386' in filetype or '32-bit' in filetype:
            assert '64-bit' not in filetype
            return '32'
        if '64-bit' in filetype:
            assert '32-bit' not in filetype
            return '64'

def exitCodeDbgOptOrJsShellXpcshell(shell, dbgOptOrJsShellXpcshell):
    '''
    This function returns the exit code after testing the shell.
    '''
    cmdList = []

    cmdList.append(shell)
    if dbgOptOrJsShellXpcshell == 'dbgOpt':
        script = 'gczeal()'
    elif dbgOptOrJsShellXpcshell == 'jsShellXpcshell':
        script = 'Components'

    cmdList.append("-e")
    cmdList.append(script)

    vdump(' '.join(cmdList))
    if verbose:
        retCode = subprocess.call(cmdList, stderr=subprocess.STDOUT)
    else:
        fnull = open(os.devnull, 'w')
        retCode = subprocess.call(cmdList, stdout=fnull, stderr=subprocess.STDOUT)
        fnull.close()

    vdump('The return code is: ' + str(retCode))
    return retCode

def testJsShellOrXpcshell(sname):
{'fraction_non_alphanumeric': 0.10653439723959457, 'fraction_numerical': 0.018115160664222557, 'mean_word_length': 2.9338422391857506, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5959578', 'n_tokens_mistral': 1555, 'n_tokens_neox': 1453, 'n_words': 453}