コード例 #1
0
ファイル: mx_sigtest.py プロジェクト: timfel/mx
def _sigtest_generate(args, suite=None, projects=None):
    """run sigtest generator for Java projects with API"""
    sigtestlib = mx.library('SIGTEST').get_path(resolve=True)
    nonTestProjects = [p for p in mx.projects() if _should_test_project(p)]
    if not nonTestProjects:
        return 0
    javaCompliance = max([p.javaCompliance for p in nonTestProjects])

    for p in nonTestProjects:
        sigtestResults = p.dir + os.sep + 'snapshot.sigtest'
        jdk = mx.get_jdk(javaCompliance)
        cmd = [
            '-cp',
            mx._cygpathU2W(sigtestlib),
            'com.sun.tdk.signaturetest.Setup',
            '-Static',
            '-FileName',
            sigtestResults,
            '-ClassPath',
            mx.classpath(p, jdk=jdk) + os.pathsep + jdk.bootclasspath(),
        ]
        for pkg in mx._find_packages(p):
            cmd = cmd + ['-PackageWithoutSubpackages', pkg]
        exitcode = mx.run_java(cmd,
                               nonZeroIsFatal=False,
                               jdk=mx.get_jdk(javaCompliance))
        if exitcode != 95:
            mx.abort('Exit code was ' + str(exitcode) + ' while generating ' +
                     sigtestResults)
        if not exists(sigtestResults):
            mx.abort('Cannot generate ' + sigtestResults)
        mx.log("Sigtest snapshot generated to " + sigtestResults)
    return 0
コード例 #2
0
ファイル: mx_javamodules.py プロジェクト: tmysik/mx
def _expand_package_info(dep, packages):
    """
    Converts a list of package names to a unique set of package names,
    expanding any '<package-info>' entry in the list to the set of
    packages in the project that contain a ``package-info.java`` file.
    """
    if '<package-info>' in packages:
        result = set((e for e in packages if e != '<package-info>'))
        result.update(mx._find_packages(dep, onlyPublic=True))
    else:
        result = set(packages)
    return result
コード例 #3
0
ファイル: mx_sigtest.py プロジェクト: charig/mx
def _sigtest_check(checktype, args, suite=None, projects=None):
    """run sigtest against Java projects with API"""
    sigtestlib = mx.library('SIGTEST').get_path(resolve=True)
    nonTestProjects = [p for p in mx.projects() if _should_test_project(p)]
    if not nonTestProjects:
        return 1
    javaCompliance = max([p.javaCompliance for p in nonTestProjects])

    class OutputCapture:
        def __init__(self):
            self.data = ""
        def __call__(self, data):
            self.data += data
    failed = None
    for p in nonTestProjects:
        sigtestResults = p.dir + os.sep + 'snapshot.sigtest'
        if not os.path.exists(sigtestResults):
            continue
        jdk = mx.get_jdk(javaCompliance)
        cmd = ['-cp', mx._cygpathU2W(sigtestlib), 'com.sun.tdk.signaturetest.SignatureTest',
            '-Static', '-Mode', 'bin', '-FileName', sigtestResults,
            '-ClassPath', mx.classpath(p, jdk=jdk) + os.pathsep + jdk.bootclasspath(),
        ]
        if checktype != 'all':
            cmd.append('-b')
        for pkg in mx._find_packages(p):
            cmd = cmd + ['-PackageWithoutSubpackages', pkg]
        out = OutputCapture()
        print 'Checking ' + checktype + ' signature changes against ' + sigtestResults
        exitcode = mx.run_java(cmd, nonZeroIsFatal=False, jdk=mx.get_jdk(javaCompliance), out=out, err=out)
        mx.ensure_dir_exists(p.get_output_root())
        with open(p.get_output_root() + os.path.sep + 'sigtest-junit.xml', 'w') as f:
            f.write('<?xml version="1.0" encoding="UTF-8" ?>\n')
            f.write('<testsuite tests="1" name="' + p.name + '.sigtest.' + checktype + '">\n')
            f.write('<testcase classname="' + p.name + '" name="sigtest.' + checktype + '">\n')
            if exitcode != 95:
                print out.data
                failed = sigtestResults
                f.write('<failure type="SignatureCheck"><![CDATA[\n')
                f.write(out.data)
                f.write(']]></failure>')
            else:
                f.write('<system-err><![CDATA[\n')
                f.write(out.data)
                f.write(']]></system-err>')
            f.write('</testcase>\n')
            f.write('</testsuite>\n')
    if failed:
        mx.abort('Signature error in ' + failed)
    else:
        print 'OK.'
    return 0
コード例 #4
0
ファイル: mx_javamodules.py プロジェクト: neomatrix369/mx
 def _parse_packages_spec(packages_spec, available_packages, project_scope):
     """
     Parses a packages specification against a set of available packages:
       "org.graalvm.foo,org.graalvm.bar" -> set("org.graalvm.foo", "org.graalvm.bar")
       "<package-info>" -> set of all entries in `available_packages` denoting a package with a package-info.java file
       "org.graalvm.*" -> set of all entries in `available_packages` that start with "org.graalvm."
       "org.graalvm.compiler.code" -> set("org.graalvm.compiler.code")
     """
     if not packages_spec:
         mx.abort(
             'exports attribute cannot have entry with empty packages specification',
             context=dist)
     res = set()
     for spec in packages_spec.split(','):
         if spec.endswith('*'):
             prefix = spec[0:-1]
             selection = set(
                 (p for p in available_packages if p.startswith(prefix)))
             if not selection:
                 mx.abort(
                     'The export package specifier "{}" does not match any of {}'
                     .format(spec, available_packages),
                     context=dist)
             res.update(selection)
         elif spec == '<package-info>':
             if not project_scope:
                 mx.abort(
                     'The export package specifier "<package-info>" can only be used in a project, not a distribution',
                     context=dist)
             res.update(mx._find_packages(project_scope, onlyPublic=True))
         else:
             if spec not in module_packages:
                 mx.abort(
                     'Cannot export package {0} from {1} as it is not defined by any project in the module {1}'
                     .format(spec, moduleName),
                     context=dist)
             if project_scope and spec not in available_packages and project_scope.suite.requiredMxVersion >= mx.VersionSpec(
                     "5.226.1"):
                 mx.abort(
                     'Package {} in "exports" attribute not defined by project {}'
                     .format(spec, project_scope),
                     context=project_scope)
             res.add(spec)
     return res
コード例 #5
0
ファイル: mx_sigtest.py プロジェクト: charig/mx
def _sigtest_generate(args, suite=None, projects=None):
    """run sigtest generator for Java projects with API"""
    sigtestlib = mx.library('SIGTEST').get_path(resolve=True)
    nonTestProjects = [p for p in mx.projects() if _should_test_project(p)]
    if not nonTestProjects:
        return 0
    javaCompliance = max([p.javaCompliance for p in nonTestProjects])

    for p in nonTestProjects:
        sigtestResults = p.dir + os.sep + 'snapshot.sigtest'
        jdk = mx.get_jdk(javaCompliance)
        cmd = ['-cp', mx._cygpathU2W(sigtestlib), 'com.sun.tdk.signaturetest.Setup',
            '-Static', '-FileName', sigtestResults,
            '-ClassPath', mx.classpath(p, jdk=jdk) + os.pathsep + jdk.bootclasspath(),
        ]
        for pkg in mx._find_packages(p):
            cmd = cmd + ['-PackageWithoutSubpackages', pkg]
        exitcode = mx.run_java(cmd, nonZeroIsFatal=False, jdk=mx.get_jdk(javaCompliance))
        if exitcode != 95:
            mx.abort('Exit code was ' + str(exitcode) + ' while generating ' + sigtestResults)
        if not exists(sigtestResults):
            mx.abort('Cannot generate ' + sigtestResults)
        mx.log("Sigtest snapshot generated to " + sigtestResults)
    return 0
コード例 #6
0
ファイル: mx_sigtest.py プロジェクト: timfel/mx
def _sigtest_check(checktype, args, suite=None, projects=None):
    """run sigtest against Java projects with API"""
    sigtestlib = mx.library('SIGTEST').get_path(resolve=True)
    nonTestProjects = [p for p in mx.projects() if _should_test_project(p)]
    if not nonTestProjects:
        return 1
    javaCompliance = max([p.javaCompliance for p in nonTestProjects])

    class OutputCapture:
        def __init__(self):
            self.data = ""

        def __call__(self, data):
            self.data += data

    failed = None
    for p in nonTestProjects:
        sigtestResults = p.dir + os.sep + 'snapshot.sigtest'
        if not os.path.exists(sigtestResults):
            continue
        jdk = mx.get_jdk(javaCompliance)
        cmd = [
            '-cp',
            mx._cygpathU2W(sigtestlib),
            'com.sun.tdk.signaturetest.SignatureTest',
            '-Static',
            '-Mode',
            'bin',
            '-FileName',
            sigtestResults,
            '-ClassPath',
            mx.classpath(p, jdk=jdk) + os.pathsep + jdk.bootclasspath(),
        ]
        if checktype != 'all':
            cmd.append('-b')
        for pkg in mx._find_packages(p):
            cmd = cmd + ['-PackageWithoutSubpackages', pkg]
        out = OutputCapture()
        print 'Checking ' + checktype + ' signature changes against ' + sigtestResults
        exitcode = mx.run_java(cmd,
                               nonZeroIsFatal=False,
                               jdk=mx.get_jdk(javaCompliance),
                               out=out,
                               err=out)
        mx.ensure_dir_exists(p.get_output_root())
        with open(p.get_output_root() + os.path.sep + 'sigtest-junit.xml',
                  'w') as f:
            f.write('<?xml version="1.0" encoding="UTF-8" ?>\n')
            f.write('<testsuite tests="1" name="' + p.name + '.sigtest.' +
                    checktype + '">\n')
            f.write('<testcase classname="' + p.name + '" name="sigtest.' +
                    checktype + '">\n')
            if exitcode != 95:
                print out.data
                failed = sigtestResults
                f.write('<failure type="SignatureCheck"><![CDATA[\n')
                f.write(out.data)
                f.write(']]></failure>')
            else:
                f.write('<system-err><![CDATA[\n')
                f.write(out.data)
                f.write(']]></system-err>')
            f.write('</testcase>\n')
            f.write('</testsuite>\n')
    if failed:
        mx.abort('Signature error in ' + failed)
    else:
        print 'OK.'
    return 0
コード例 #7
0
ファイル: mx_sigtest.py プロジェクト: timfel/mx
def _should_test_project(p):
    if not p.isJavaProject():
        return False
    return len(mx._find_packages(p)) > 0
コード例 #8
0
def _sigtest_generate(args, suite=None, projects=None):
    """run sigtest generator for Java projects with API"""
    nonTestProjects = [p for p in mx.projects() if _should_test_project(p)]
    if not nonTestProjects:
        return 0
    javaCompliance = max([p.javaCompliance for p in nonTestProjects])

    for p in nonTestProjects:
        sigtestlib = p.suite.getMxCompatibility().get_sigtest_jar()
        sigtestResults = p.dir + os.sep + 'snapshot.sigtest'
        jdk = mx.get_jdk(javaCompliance)
        cp = mx.classpath(p, jdk=jdk)
        cmd = [
            '-cp',
            mx._cygpathU2W(sigtestlib),
            'com.sun.tdk.signaturetest.Setup',
            '-BootCP',
            '-Static',
            '-FileName',
            sigtestResults,
            '-ClassPath',
            cp,
        ]
        if args.human:
            cmd.append('-H')

        infos = set()
        packages = mx._find_packages(p, packageInfos=infos)
        for pkg in packages:
            cmd = cmd + ['-PackageWithoutSubpackages', pkg]

        javapExe = jdk.javap
        if not exists(javapExe):
            mx.abort('The javap executable does not exist: ' + javapExe)

        class OutputCapture:
            def __init__(self):
                self.data = ""

            def __call__(self, data):
                self.data += data

        for pkg in infos:
            oc = OutputCapture()
            ignore = OutputCapture()
            code = mx.run([
                javapExe, '-private', '-verbose', '-classpath', cp,
                pkg + '.package-info'
            ],
                          out=oc,
                          err=ignore,
                          nonZeroIsFatal=False)
            if code == 0:
                if oc.data.find('\nRuntimeVisibleAnnotations:\n'
                                ) == -1 and oc.data.find(
                                    '\nRuntimeInvisibleAnnotations:\n') == -1:
                    mx.abort(
                        'GR-22788: ecj generated an empty {}.package-info: rebuild with javac!'
                        .format(pkg))
        exitcode = mx.run_java(cmd,
                               nonZeroIsFatal=False,
                               jdk=mx.get_jdk(javaCompliance))
        if exitcode != 95:
            mx.abort('Exit code was ' + str(exitcode) + ' while generating ' +
                     sigtestResults)
        if not exists(sigtestResults):
            mx.abort('Cannot generate ' + sigtestResults)
        mx.log("Sigtest snapshot generated to " + sigtestResults)
    return 0
コード例 #9
0
def _sigtest_check(checktype, args, suite=None, projects=None):
    """run sigtest against Java projects with API"""
    nonTestProjects = [p for p in mx.projects() if _should_test_project(p)]
    if not nonTestProjects:
        return 1
    javaCompliance = max([p.javaCompliance for p in nonTestProjects])

    class OutputCapture:
        def __init__(self):
            self.data = ""

        def __call__(self, data):
            self.data += data

    failed = None
    for p in nonTestProjects:
        sigtestlib = p.suite.getMxCompatibility().get_sigtest_jar()
        sigtestResults = p.dir + os.sep + 'snapshot.sigtest'
        if not os.path.exists(sigtestResults):
            continue
        jdk = mx.get_jdk(javaCompliance)
        cmd = [
            '-cp',
            mx._cygpathU2W(sigtestlib),
            'com.sun.tdk.signaturetest.SignatureTest',
            '-BootCP',
            '-Static',
            '-Mode',
            'bin',
            '-FileName',
            sigtestResults,
            '-ClassPath',
            mx.classpath(p, jdk=jdk),
        ]
        if args.human:
            cmd.append('-H')
        if checktype != 'all':
            cmd.append('-b')
        for pkg in mx._find_packages(p):
            cmd = cmd + ['-PackageWithoutSubpackages', pkg]
        out = OutputCapture()
        print('Checking ' + checktype + ' signature changes against ' +
              sigtestResults)
        exitcode = mx.run_java(cmd,
                               nonZeroIsFatal=False,
                               jdk=mx.get_jdk(javaCompliance),
                               out=out,
                               err=out)
        mx.ensure_dir_exists(p.get_output_root())
        with open(p.get_output_root() + os.path.sep + 'sigtest-junit.xml',
                  'w') as f:
            f.write('<?xml version="1.0" encoding="UTF-8" ?>\n')
            f.write('<testsuite tests="1" name="' + p.name + '.sigtest.' +
                    checktype + '">\n')
            f.write('<testcase classname="' + p.name + '" name="sigtest.' +
                    checktype + '">\n')
            if exitcode != 95:
                print(out.data)
                failed = sigtestResults
                f.write('<failure type="SignatureCheck"><![CDATA[\n')
                f.write(out.data)
                f.write(']]></failure>')
            else:
                f.write('<system-err><![CDATA[\n')
                f.write(out.data)
                f.write(']]></system-err>')
            f.write('</testcase>\n')
            f.write('</testsuite>\n')
    if failed:
        print(
            '\nThe signature check detected changes in the API by comparing it with previous signature files.'
        )
        print(
            'To fix this restore the original API or regenerate the signature files with:'
        )
        print('mx sigtest --generate')
        mx.abort('Signature error in ' + failed)
    else:
        print('OK.')
    return 0
コード例 #10
0
ファイル: mx_sigtest.py プロジェクト: charig/mx
def _should_test_project(p):
    if not p.isJavaProject():
        return False
    return len(mx._find_packages(p)) > 0