示例#1
0
def computeApiChecksum(includeDir):
    """
    Computes a checksum of the header files found in the provided directory (recursively).
    The result is a SHA256 checksum (as string with hex digits) of all header files.
    """
    m = hashlib.sha256()
    rootDir = includeDir
    for root, _, files in os.walk(rootDir):
        mx.logvv("Visiting directory {0}".format(root))
        for f in files:
            fileName = join(root, f)
            if fileName.endswith('.h'):
                try:
                    mx.logvv("Including file {0}".format(fileName))
                    with open(fileName) as f:
                        m.update(f.read())
                except IOError as e:
                    # Ignore errors on broken symlinks
                    if not os.path.islink(fileName) or os.path.exists(fileName):
                        raise e


    hxdigest = m.hexdigest()
    mx.logv("Computed API version checksum {0}".format(hxdigest))
    return hxdigest
示例#2
0
def register_urlrewrite(urlrewrite, onError=None):
    """
    Appends a URL rewrite rule to the current rewrite rules.
    A URL rewrite rule is a dict where the key is a regex for matching a URL and the value describes
    how to rewrite.

    :Example:

    {
      "https://git.acme.com/(.*).git" : {
         "replacement" : "https://my.company.com/foo-git-cache/\1.git",
      }
    }

    :param urlrewrite: a URL rewrite rule
    :type urlrewrite: dict or URLRewrite
    :param function onError: called with error message argument if urlrewrite is badly formed
    """

    if onError is None:

        def _error(msg):
            raise Exception(msg)

        onError = _error

    if isinstance(urlrewrite, URLRewrite):
        _urlrewrites.append(urlrewrite)
        return
    if not isinstance(urlrewrite, dict) or len(urlrewrite) != 1:
        onError('A URL rewrite rule must be a dict with a single entry')
    for pattern, attrs in urlrewrite.items():
        replacement = attrs.pop('replacement', None)
        sha1 = attrs.pop('sha1', None)
        if replacement is None:
            raise Exception('URL rewrite for pattern "' + pattern +
                            '" is missing "replacement" entry')
        if len(attrs) != 0:
            raise Exception('Unsupported attributes found for URL rewrite "' +
                            pattern + '": ' + str(attrs))
        try:
            pattern = re.compile(pattern)
        except Exception as e:  # pylint: disable=broad-except
            onError('Error parsing URL rewrite pattern "' + pattern + '": ' +
                    str(e))
        urlrewrite = URLRewrite(pattern, replacement, sha1)
        mx.logvv("Registering url rewrite: " + str(urlrewrite))
        _urlrewrites.append(urlrewrite)
示例#3
0
def rewriteurl(url):
    """
    Finds the first registered URL rewrite rule that matches `url` and returns the replacement
    provided by the rule.

    :param str url: a URL to match against the registered rerwrite rules
    :return: the value of `url` rewritten according to the first matching rewrite URL or unmodified
             if no rules match
    :rtype: str
    """
    for urlrewrite in _urlrewrites:
        res = urlrewrite._rewrite(url)
        if res:
            mx.logvv("Rewrote '{}' to '{}'".format(url, res))
            return res
    return url
示例#4
0
def checkCFile(targetFile):
    mx.logvv("  checking file " + targetFile)
    """ Checks the formatting of a C file and returns True if the formatting is okay """
    clangFormat = mx_sulong.findBundledLLVMProgram('clang-format')
    formatCommand = [clangFormat, targetFile]
    formattedContent = mx_sulong._decode(subprocess.check_output(formatCommand)).splitlines()
    with open(targetFile) as f:
        originalContent = f.read().splitlines()
    if not formattedContent == originalContent:
        # modify the file to the right format
        subprocess.check_output(formatCommand + ['-i'])
        mx.log('\n'.join(formattedContent))
        mx.log('\nmodified formatting in {0} to the format above'.format(targetFile))
        mx.logv("command: " + " ".join(formatCommand))
        return False
    return True
示例#5
0
def _applyurlrewrite(urlrewrite, url):
    """
    Applies an URL rewrite rule to `url`.
    Handles JAR URL references.
    """
    if urlrewrite:
        # Rewrite rule exists, use it.
        jar_url = mx._JarURL.parse(url)
        if jar_url:
            jar_url.base_url = urlrewrite._rewrite(jar_url.base_url)
            res = str(jar_url)
        else:
            res = urlrewrite._rewrite(url)
        mx.logvv("Rewrote '{}' to '{}'".format(url, res))
        return res
    else:
        # Rewrite rule does not exist.
        return url
示例#6
0
def rewriteurl(url):
    """
    Finds the first registered URL rewrite rule that matches `url` and returns the replacement
    provided by the rule.

    :param str url: a URL to match against the registered rerwrite rules
    :return: the value of `url` rewritten according to the first matching rewrite URL or unmodified
             if no rules match
    :rtype: str
    """
    original_url = url
    jar_url = mx._JarURL.parse(url)
    if jar_url:
        url = jar_url.base_url

    for urlrewrite in _urlrewrites:
        res = urlrewrite._rewrite(url)
        if res:
            if jar_url is not None:
                jar_url.base_url = res
                res = str(jar_url)
            mx.logvv("Rewrote '{}' to '{}'".format(original_url, res))
            return res
    return original_url