Mercurial > hg > graal-jvmci-8
comparison mx/commands.py @ 5762:b30cced39597
generalized functionality for finding classes based on searching for patterns in source code and moved it from commands.py to mx.py
used above functionality to find classes manually excluded from JaCoCo processing
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Wed, 04 Jul 2012 21:56:48 +0200 |
parents | dab877fe7c31 |
children | 66ec0bc36a37 |
comparison
equal
deleted
inserted
replaced
5761:856a54bae703 | 5762:b30cced39597 |
---|---|
585 if _jacoco == 'on' or _jacoco == 'append': | 585 if _jacoco == 'on' or _jacoco == 'append': |
586 jacocoagent = mx.library("JACOCOAGENT", True) | 586 jacocoagent = mx.library("JACOCOAGENT", True) |
587 # Exclude all compiler tests and snippets | 587 # Exclude all compiler tests and snippets |
588 excludes = ['com.oracle.graal.compiler.tests.*'] | 588 excludes = ['com.oracle.graal.compiler.tests.*'] |
589 for p in mx.projects(): | 589 for p in mx.projects(): |
590 _find_classes_with_annotations(excludes, p, None, ['@Snippet', '@ClassSubstitution'], includeInnerClasses=True) | 590 excludes += _find_classes_with_annotations(p, None, ['@Snippet', '@ClassSubstitution'], includeInnerClasses=True) |
591 excludes += p.find_classes_with_matching_source_line(None, lambda line: 'JaCoCo Exclude' in line, includeInnerClasses=True) | |
592 | |
591 agentOptions = { | 593 agentOptions = { |
592 'append' : 'true' if _jacoco == 'append' else 'false', | 594 'append' : 'true' if _jacoco == 'append' else 'false', |
593 'bootclasspath' : 'true', | 595 'bootclasspath' : 'true', |
594 'includes' : 'com.oracle.*', | 596 'includes' : 'com.oracle.*', |
595 'excludes' : ':'.join(excludes) | 597 'excludes' : ':'.join(excludes) |
596 } | 598 } |
597 args = ['-javaagent:' + jacocoagent.get_path(True) + '=' + ','.join([k + '=' + v for k, v in agentOptions.items()])] + args | 599 args = ['-javaagent:' + jacocoagent.get_path(True) + '=' + ','.join([k + '=' + v for k, v in agentOptions.items()])] + args |
598 exe = join(jdk, 'bin', mx.exe_suffix('java')) | 600 exe = join(jdk, 'bin', mx.exe_suffix('java')) |
599 return mx.run([exe, '-' + vm] + args, nonZeroIsFatal=nonZeroIsFatal, out=out, err=err, cwd=cwd, timeout=timeout) | 601 return mx.run([exe, '-' + vm] + args, nonZeroIsFatal=nonZeroIsFatal, out=out, err=err, cwd=cwd, timeout=timeout) |
600 | 602 |
601 def _find_classes_with_annotations(classes, p, pkgRoot, annotations, includeInnerClasses=False): | 603 def _find_classes_with_annotations(p, pkgRoot, annotations, includeInnerClasses=False): |
602 """ | 604 """ |
603 Scan the sources of project 'p' for Java source files containing a line starting with 'annotation' | 605 Scan the sources of project 'p' for Java source files containing a line starting with 'annotation' |
604 (ignoring preceding whitespace) and add the fully qualified class name | 606 (ignoring preceding whitespace) and return the fully qualified class name for each Java |
605 to 'classes' for each Java source file matched. | 607 source file matched in a list. |
606 """ | 608 """ |
607 for a in annotations: | 609 |
608 assert a.startswith('@') | 610 matches = lambda line : len([a for a in annotations if line == a or line.startswith(a + '(')]) != 0 |
609 pkgDecl = re.compile(r"^package\s+([a-zA-Z_][\w\.]*)\s*;$") | 611 return p.find_classes_with_matching_source_line(pkgRoot, matches, includeInnerClasses) |
610 for srcDir in p.source_dirs(): | |
611 outputDir = p.output_dir() | |
612 for root, _, files in os.walk(srcDir): | |
613 for name in files: | |
614 if name.endswith('.java') and name != 'package-info.java': | |
615 annotationFound = False | |
616 with open(join(root, name)) as f: | |
617 pkg = None | |
618 for line in f: | |
619 if line.startswith("package "): | |
620 match = pkgDecl.match(line) | |
621 if match: | |
622 pkg = match.group(1) | |
623 else: | |
624 stripped = line.strip() | |
625 for a in annotations: | |
626 if stripped == a or stripped.startswith(a + '('): | |
627 annotationFound = True | |
628 break | |
629 if annotationFound: | |
630 break | |
631 if annotationFound: | |
632 basename = name[:-len('.java')] | |
633 assert pkg is not None | |
634 if pkgRoot is None or pkg.startswith(pkgRoot): | |
635 pkgOutputDir = join(outputDir, pkg.replace('.', os.path.sep)) | |
636 for e in os.listdir(pkgOutputDir): | |
637 if includeInnerClasses: | |
638 if e.endswith('.class') and (e.startswith(basename) or e.startswith(basename + '$')): | |
639 classes.append(pkg + '.' + e[:-len('.class')]) | |
640 elif e == basename + '.class': | |
641 classes.append(pkg + '.' + basename) | |
642 | 612 |
643 def _run_tests(args, harnessName, harness): | 613 def _run_tests(args, harnessName, harness): |
644 pos = [a for a in args if a[0] != '-' and a[0] != '@' ] | 614 pos = [a for a in args if a[0] != '-' and a[0] != '@' ] |
645 neg = [a[1:] for a in args if a[0] == '-'] | 615 neg = [a[1:] for a in args if a[0] == '-'] |
646 vmArgs = [a[1:] for a in args if a[0] == '@'] | 616 vmArgs = [a[1:] for a in args if a[0] == '@'] |
651 return True | 621 return True |
652 return False | 622 return False |
653 | 623 |
654 for p in mx.projects(): | 624 for p in mx.projects(): |
655 if getattr(p, 'testHarness', None) == harnessName: | 625 if getattr(p, 'testHarness', None) == harnessName: |
656 classes = [] | 626 classes = _find_classes_with_annotations(p, None, ['@Test']) |
657 _find_classes_with_annotations(classes, p, None, ['@Test']) | |
658 | 627 |
659 if len(pos) != 0: | 628 if len(pos) != 0: |
660 classes = [c for c in classes if containsAny(c, pos)] | 629 classes = [c for c in classes if containsAny(c, pos)] |
661 if len(neg) != 0: | 630 if len(neg) != 0: |
662 classes = [c for c in classes if not containsAny(c, neg)] | 631 classes = [c for c in classes if not containsAny(c, neg)] |