Example #1
0
 def run(self, tasks, extraVMarguments=None):
     with Task(self.name + ': hosted-product ', tasks, tags=self.tags) as t:
         if t: mx_microbench.get_microbenchmark_executor().microbench(_noneAsEmptyList(extraVMarguments) + ['--', '-foe', 'true'] + self.args)
Example #2
0
def _run_gate(cleanArgs, args, tasks):
    global _jacoco
    with Task('Versions', tasks, tags=[Tags.always]) as t:
        if t:
            mx.command_function('version')(['--oneline'])
            mx.command_function('sversions')([])

    with Task('JDKReleaseInfo', tasks, tags=[Tags.always]) as t:
        if t:
            jdkDirs = os.pathsep.join([
                mx.get_env('JAVA_HOME', ''),
                mx.get_env('EXTRA_JAVA_HOMES', '')
            ])
            for jdkDir in jdkDirs.split(os.pathsep):
                release = join(jdkDir, 'release')
                if exists(release):
                    mx.log('==== ' + jdkDir + ' ====')
                    with open(release) as fp:
                        mx.log(fp.read().strip())

    for suiteRunner in _pre_gate_runners:
        suite, runner = suiteRunner
        if args.all_suites or suite is mx.primary_suite():
            runner(args, tasks)

    with Task('Pylint', tasks, tags=[Tags.style]) as t:
        if t:
            if mx.command_function('pylint')(['--primary']) != 0:
                _warn_or_abort(
                    'Pylint not configured correctly. Cannot execute Pylint task.',
                    args.strict_mode)

    gate_clean(cleanArgs,
               tasks,
               tags=[Tags.build, Tags.fullbuild, Tags.ecjbuild])

    with Task('Distribution Overlap Check', tasks, tags=[Tags.style]) as t:
        if t:
            if mx.command_function('checkoverlap')([]) != 0:
                t.abort('Found overlapping distributions.')

    with Task('Canonicalization Check', tasks, tags=[Tags.style]) as t:
        if t:
            mx.log(
                time.strftime(
                    '%d %b %Y %H:%M:%S - Ensuring mx/projects files are canonicalized...'
                ))
            if mx.command_function('canonicalizeprojects')([]) != 0:
                t.abort(
                    'Rerun "mx canonicalizeprojects" and modify the suite.py files as suggested.'
                )

    with Task('Verify Java Sources in Project', tasks, tags=[Tags.style]) as t:
        if t:
            mx.log(
                time.strftime(
                    '%d %b %Y %H:%M:%S - Ensuring all Java sources are in a Java project directory...'
                ))
            if mx.command_function('verifysourceinproject')([]) != 0:
                t.abort(
                    'Move or delete the Java sources that are not in a Java project directory.'
                )

    if mx._is_supported_by_jdt(mx.DEFAULT_JDK_TAG):
        with Task('BuildWithEcj',
                  tasks,
                  tags=[Tags.fullbuild, Tags.ecjbuild],
                  legacyTitles=['BuildJavaWithEcj']) as t:
            if t:
                defaultBuildArgs = ['-p']
                fullbuild = True if Task.tags is None else Tags.fullbuild in Task.tags
                # Using ecj alone is not compatible with --warning-as-error (see GR-3969)
                if not args.no_warning_as_error and fullbuild:
                    defaultBuildArgs += ['--warning-as-error']
                if mx.get_env('JDT'):
                    mx.command_function('build')(defaultBuildArgs +
                                                 args.extra_build_args)
                    if fullbuild:
                        gate_clean(cleanArgs,
                                   tasks,
                                   name='CleanAfterEcjBuild',
                                   tags=[Tags.fullbuild])
                else:
                    _warn_or_abort(
                        'JDT environment variable not set. Cannot execute BuildWithEcj task.',
                        args.strict_mode)

    with Task('BuildWithJavac',
              tasks,
              tags=[Tags.build, Tags.fullbuild],
              legacyTitles=['BuildJavaWithJavac']) as t:
        if t:
            defaultBuildArgs = ['-p']
            if not args.no_warning_as_error:
                defaultBuildArgs += ['--warning-as-error']
            mx.command_function('build')(defaultBuildArgs + ['--force-javac'] +
                                         args.extra_build_args)

    with Task('IDEConfigCheck', tasks, tags=[Tags.fullbuild]) as t:
        if t:
            if args.cleanIDE:
                mx.command_function('ideclean')([])
                mx.command_function('ideinit')([])

    with Task('CodeFormatCheck', tasks, tags=[Tags.style]) as t:
        if t:
            eclipse_exe = mx.get_env('ECLIPSE_EXE')
            if eclipse_exe is not None:
                if mx.command_function('eclipseformat')(
                    ['-e', eclipse_exe, '--primary']) != 0:
                    t.abort(
                        'Formatter modified files - run "mx eclipseformat", check in changes and repush'
                    )
            else:
                _warn_or_abort(
                    'ECLIPSE_EXE environment variable not set. Cannot execute CodeFormatCheck task.',
                    args.strict_mode)

    with Task('Checkstyle', tasks, tags=[Tags.style]) as t:
        if t and mx.command_function('checkstyle')(['--primary']) != 0:
            t.abort('Checkstyle warnings were found')

    with Task('FindBugs', tasks, tags=[Tags.fullbuild]) as t:
        if t and mx.command_function('findbugs')([]) != 0:
            t.abort('FindBugs warnings were found')

    with Task('VerifyLibraryURLs', tasks, tags=[Tags.fullbuild]) as t:
        if t:
            mx.command_function('verifylibraryurls')([])

    if mx._primary_suite is mx._mx_suite:
        with Task('TestJMH', tasks, tags=[Tags.fullbuild]) as t:
            if t:
                mx_microbench.get_microbenchmark_executor().microbench(
                    ['--', '-foe', 'true', 'com.oracle.mxtool.bench.TestJMH'])

    if exists('jacoco.exec'):
        os.unlink('jacoco.exec')

    if args.jacocout is not None:
        _jacoco = 'append'
    else:
        _jacoco = 'off'

    for suiteRunner in _gate_runners:
        suite, runner = suiteRunner
        if args.all_suites or suite is mx.primary_suite():
            runner(args, tasks)

    if args.jacocout is not None:
        mx.command_function('jacocoreport')([args.jacocout])
        _jacoco = 'off'
Example #3
0
def gate(args):
    """run the tests used to validate a push

    If this command exits with a 0 exit code, then the gate passed."""

    parser = ArgumentParser(prog='mx gate')
    add_omit_clean_args(parser)
    parser.add_argument('--all-suites', action='store_true', help='run gate tasks for all suites, not just the primary suite')
    parser.add_argument('--dry-run', action='store_true', help='just show the tasks that will be run without running them')
    parser.add_argument('-x', action='store_true', help='makes --task-filter or --tags an exclusion instead of inclusion filter')
    parser.add_argument('--jacocout', help='specify the output directory for jacoco report')
    parser.add_argument('--strict-mode', action='store_true', help='abort if a task cannot be executed due to missing tool configuration')
    filtering = parser.add_mutually_exclusive_group()
    filtering.add_argument('-t', '--task-filter', help='comma separated list of substrings to select subset of tasks to be run')
    filtering.add_argument('-s', '--start-at', help='substring to select starting task')
    filtering.add_argument('--tags', help='comma separated list of tags to select subset of tasks to be run')
    for a, k in _extra_gate_arguments:
        parser.add_argument(*a, **k)

    args = parser.parse_args(args)
    cleanArgs = check_gate_noclean_arg(args)

    global _jacoco
    if args.dry_run:
        Task.dryRun = True
    if args.start_at:
        Task.startAtFilter = args.start_at
    elif args.task_filter:
        Task.filters = args.task_filter.split(',')
        Task.filtersExclude = args.x
    elif args.tags:
        Task.tags = args.tags.split(',')
        Task.tagsExclude = args.x
        if not Task.tagsExclude:
            # implicitly include 'always'
            Task.tags += [Tags.always]
    elif args.x:
        mx.abort('-x option cannot be used without --task-filter or the --tags option')

    tasks = []
    total = Task('Gate')
    try:
        with Task('Versions', tasks, tags=[Tags.always]) as t:
            if t:
                mx.command_function('version')(['--oneline'])
                mx.command_function('sversions')([])

        with Task('JDKReleaseInfo', tasks, tags=[Tags.always]) as t:
            if t:
                jdkDirs = os.pathsep.join([mx.get_env('JAVA_HOME', ''), mx.get_env('EXTRA_JAVA_HOMES', '')])
                for jdkDir in jdkDirs.split(os.pathsep):
                    release = join(jdkDir, 'release')
                    if exists(release):
                        mx.log('==== ' + jdkDir + ' ====')
                        with open(release) as fp:
                            mx.log(fp.read().strip())

        with Task('Pylint', tasks, tags=[Tags.style]) as t:
            if t:
                if mx.command_function('pylint')(['--primary']) != 0:
                    _warn_or_abort('Pylint not configured correctly. Cannot execute Pylint task.', args.strict_mode)

        gate_clean(cleanArgs, tasks, tags=[Tags.build, Tags.fullbuild])

        with Task('Distribution Overlap Check', tasks, tags=[Tags.style]) as t:
            if t:
                if mx.command_function('checkoverlap')([]) != 0:
                    t.abort('Found overlapping distributions.')

        with Task('Canonicalization Check', tasks, tags=[Tags.style]) as t:
            if t:
                mx.log(time.strftime('%d %b %Y %H:%M:%S - Ensuring mx/projects files are canonicalized...'))
                if mx.command_function('canonicalizeprojects')([]) != 0:
                    t.abort('Rerun "mx canonicalizeprojects" and check-in the modified mx/suite*.py files.')

        if mx._is_supported_by_jdt(mx.DEFAULT_JDK_TAG):
            with Task('BuildJavaWithEcj', tasks, tags=[Tags.fullbuild]) as t:
                if t:
                    if mx.get_env('JDT'):
                        mx.command_function('build')(['-p', '--no-native', '--warning-as-error'])
                        gate_clean(cleanArgs, tasks, name='CleanAfterEcjBuild', tags=[Tags.fullbuild])
                    else:
                        _warn_or_abort('JDT environment variable not set. Cannot execute BuildJavaWithEcj task.', args.strict_mode)

        with Task('BuildJavaWithJavac', tasks, tags=[Tags.build, Tags.fullbuild]) as t:
            if t: mx.command_function('build')(['-p', '--warning-as-error', '--force-javac'])

        with Task('IDEConfigCheck', tasks, tags=[Tags.fullbuild]) as t:
            if t:
                if args.cleanIDE:
                    mx.command_function('ideclean')([])
                    mx.command_function('ideinit')([])

        with Task('CodeFormatCheck', tasks, tags=[Tags.style]) as t:
            if t:
                eclipse_exe = mx.get_env('ECLIPSE_EXE')
                if eclipse_exe is not None:
                    if mx.command_function('eclipseformat')(['-e', eclipse_exe, '--primary']) != 0:
                        t.abort('Formatter modified files - run "mx eclipseformat", check in changes and repush')
                else:
                    _warn_or_abort('ECLIPSE_EXE environment variable not set. Cannot execute CodeFormatCheck task.', args.strict_mode)

        with Task('Checkstyle', tasks, tags=[Tags.style]) as t:
            if t and mx.command_function('checkstyle')(['--primary']) != 0:
                t.abort('Checkstyle warnings were found')

        with Task('Checkheaders', tasks, tags=[Tags.style]) as t:
            if t and mx.command_function('checkheaders')([]) != 0:
                t.abort('Checkheaders warnings were found')

        with Task('FindBugs', tasks, tags=[Tags.fullbuild]) as t:
            if t and mx.command_function('findbugs')([]) != 0:
                t.abort('FindBugs warnings were found')

        if mx._primary_suite is mx._mx_suite:
            with Task('TestJMH', tasks, tags=[Tags.fullbuild]) as t:
                if t: mx_microbench.get_microbenchmark_executor().microbench(['--', '-foe', 'true', 'com.oracle.mxtool.bench.TestJMH'])

        if exists('jacoco.exec'):
            os.unlink('jacoco.exec')

        if args.jacocout is not None:
            _jacoco = 'append'
        else:
            _jacoco = 'off'

        for suiteRunner in _gate_runners:
            suite, runner = suiteRunner
            if args.all_suites or suite is mx.primary_suite():
                runner(args, tasks)

        if args.jacocout is not None:
            mx.command_function('jacocoreport')([args.jacocout])
            _jacoco = 'off'

    except KeyboardInterrupt:
        total.abort(1)

    except BaseException as e:
        import traceback
        traceback.print_exc()
        total.abort(str(e))

    total.stop()

    mx.log('Gate task times:')
    for t in tasks:
        mx.log('  ' + str(t.duration) + '\t' + t.title + ("" if not (Task.verbose and t.tags) else (' [' + ','.join(t.tags) + ']')))
    mx.log('  =======')
    mx.log('  ' + str(total.duration))

    if args.task_filter:
        Task.filters = None
Example #4
0
def gate(args):
    """run the tests used to validate a push

    If this command exits with a 0 exit code, then the gate passed."""

    parser = ArgumentParser(prog='mx gate')
    add_omit_clean_args(parser)
    parser.add_argument(
        '--all-suites',
        action='store_true',
        help='run gate tasks for all suites, not just the primary suite')
    parser.add_argument(
        '--dry-run',
        action='store_true',
        help='just show the tasks that will be run without running them')
    parser.add_argument(
        '-x',
        action='store_true',
        help=
        'makes --task-filter or --tags an exclusion instead of inclusion filter'
    )
    parser.add_argument('--jacocout',
                        help='specify the output directory for jacoco report')
    parser.add_argument(
        '--strict-mode',
        action='store_true',
        help=
        'abort if a task cannot be executed due to missing tool configuration')
    filtering = parser.add_mutually_exclusive_group()
    filtering.add_argument(
        '-t',
        '--task-filter',
        help=
        'comma separated list of substrings to select subset of tasks to be run'
    )
    filtering.add_argument('-s',
                           '--start-at',
                           help='substring to select starting task')
    filtering.add_argument(
        '--tags',
        help='comma separated list of tags to select subset of tasks to be run'
    )
    for a, k in _extra_gate_arguments:
        parser.add_argument(*a, **k)

    args = parser.parse_args(args)
    cleanArgs = check_gate_noclean_arg(args)

    global _jacoco
    if args.dry_run:
        Task.dryRun = True
    if args.start_at:
        Task.startAtFilter = args.start_at
    elif args.task_filter:
        Task.filters = args.task_filter.split(',')
        Task.filtersExclude = args.x
    elif args.tags:
        Task.tags = args.tags.split(',')
        Task.tagsExclude = args.x
        if not Task.tagsExclude:
            # implicitly include 'always'
            Task.tags += [Tags.always]
    elif args.x:
        mx.abort(
            '-x option cannot be used without --task-filter or the --tags option'
        )

    tasks = []
    total = Task('Gate')
    try:
        with Task('Versions', tasks, tags=[Tags.always]) as t:
            if t:
                mx.command_function('version')(['--oneline'])
                mx.command_function('sversions')([])

        with Task('JDKReleaseInfo', tasks, tags=[Tags.always]) as t:
            if t:
                jdkDirs = os.pathsep.join([
                    mx.get_env('JAVA_HOME', ''),
                    mx.get_env('EXTRA_JAVA_HOMES', '')
                ])
                for jdkDir in jdkDirs.split(os.pathsep):
                    release = join(jdkDir, 'release')
                    if exists(release):
                        mx.log('==== ' + jdkDir + ' ====')
                        with open(release) as fp:
                            mx.log(fp.read().strip())

        with Task('Pylint', tasks, tags=[Tags.style]) as t:
            if t:
                if mx.command_function('pylint')(['--primary']) != 0:
                    _warn_or_abort(
                        'Pylint not configured correctly. Cannot execute Pylint task.',
                        args.strict_mode)

        gate_clean(cleanArgs, tasks, tags=[Tags.build, Tags.fullbuild])

        with Task('Distribution Overlap Check', tasks, tags=[Tags.style]) as t:
            if t:
                if mx.command_function('checkoverlap')([]) != 0:
                    t.abort('Found overlapping distributions.')

        with Task('Canonicalization Check', tasks, tags=[Tags.style]) as t:
            if t:
                mx.log(
                    time.strftime(
                        '%d %b %Y %H:%M:%S - Ensuring mx/projects files are canonicalized...'
                    ))
                if mx.command_function('canonicalizeprojects')([]) != 0:
                    t.abort(
                        'Rerun "mx canonicalizeprojects" and check-in the modified mx/suite*.py files.'
                    )

        if mx._is_supported_by_jdt(mx.DEFAULT_JDK_TAG):
            with Task('BuildJavaWithEcj', tasks, tags=[Tags.fullbuild]) as t:
                if t:
                    if mx.get_env('JDT'):
                        mx.command_function('build')(
                            ['-p', '--no-native', '--warning-as-error'])
                        gate_clean(cleanArgs,
                                   tasks,
                                   name='CleanAfterEcjBuild',
                                   tags=[Tags.fullbuild])
                    else:
                        _warn_or_abort(
                            'JDT environment variable not set. Cannot execute BuildJavaWithEcj task.',
                            args.strict_mode)

        with Task('BuildJavaWithJavac',
                  tasks,
                  tags=[Tags.build, Tags.fullbuild]) as t:
            if t:
                mx.command_function('build')(
                    ['-p', '--warning-as-error', '--force-javac'])

        with Task('IDEConfigCheck', tasks, tags=[Tags.fullbuild]) as t:
            if t:
                if args.cleanIDE:
                    mx.command_function('ideclean')([])
                    mx.command_function('ideinit')([])

        with Task('CodeFormatCheck', tasks, tags=[Tags.style]) as t:
            if t:
                eclipse_exe = mx.get_env('ECLIPSE_EXE')
                if eclipse_exe is not None:
                    if mx.command_function('eclipseformat')(
                        ['-e', eclipse_exe, '--primary']) != 0:
                        t.abort(
                            'Formatter modified files - run "mx eclipseformat", check in changes and repush'
                        )
                else:
                    _warn_or_abort(
                        'ECLIPSE_EXE environment variable not set. Cannot execute CodeFormatCheck task.',
                        args.strict_mode)

        with Task('Checkstyle', tasks, tags=[Tags.style]) as t:
            if t and mx.command_function('checkstyle')(['--primary']) != 0:
                t.abort('Checkstyle warnings were found')

        with Task('Checkheaders', tasks, tags=[Tags.style]) as t:
            if t and mx.command_function('checkheaders')([]) != 0:
                t.abort('Checkheaders warnings were found')

        with Task('FindBugs', tasks, tags=[Tags.fullbuild]) as t:
            if t and mx.command_function('findbugs')([]) != 0:
                t.abort('FindBugs warnings were found')

        if mx._primary_suite is mx._mx_suite:
            with Task('TestJMH', tasks, tags=[Tags.fullbuild]) as t:
                if t:
                    mx_microbench.get_microbenchmark_executor().microbench([
                        '--', '-foe', 'true', 'com.oracle.mxtool.bench.TestJMH'
                    ])

        if exists('jacoco.exec'):
            os.unlink('jacoco.exec')

        if args.jacocout is not None:
            _jacoco = 'append'
        else:
            _jacoco = 'off'

        for suiteRunner in _gate_runners:
            suite, runner = suiteRunner
            if args.all_suites or suite is mx.primary_suite():
                runner(args, tasks)

        if args.jacocout is not None:
            mx.command_function('jacocoreport')([args.jacocout])
            _jacoco = 'off'

    except KeyboardInterrupt:
        total.abort(1)

    except BaseException as e:
        import traceback
        traceback.print_exc()
        total.abort(str(e))

    total.stop()

    mx.log('Gate task times:')
    for t in tasks:
        mx.log('  ' + str(t.duration) + '\t' + t.title +
               ("" if not (Task.verbose and t.tags) else
                (' [' + ','.join(t.tags) + ']')))
    mx.log('  =======')
    mx.log('  ' + str(total.duration))

    if args.task_filter:
        Task.filters = None