Skip to content

Commit

Permalink
Exit with code 1 on logging of error. Only parse files in exclude_path
Browse files Browse the repository at this point in the history
  • Loading branch information
jiekang committed Nov 28, 2024
1 parent b7a3fba commit d99ef63
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions scripts/disabled_tests/exclude_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,21 @@
from common.models import Scheme, JdkInfo
from common.utils import to_shallow_dict, DEFAULT_TARGET

class ErrorTrackingHandler(logging.Handler):
def __init__(self):
super().__init__()
self.error_logged = False

def emit(self, record):
if record.levelno >= logging.ERROR:
self.error_logged = True

logging.basicConfig(
format="%(levelname)s - %(message)s"
)
LOG = logging.getLogger()
ERROR_TRACKER = ErrorTrackingHandler()
LOG.addHandler(ERROR_TRACKER)

OS_EXCEPTIONS = {
"macosx": "mac",
Expand All @@ -26,8 +37,6 @@
"x86": "x86-32",
}

ERROR_FOUND = False

class ExclusionFileProcessingException(Exception):
pass

Expand Down Expand Up @@ -190,10 +199,9 @@ def validate_platforms(split: TestExclusionSplitLine):
# the platform exclusion list must be comma-delimited with no spaces
platforms = split.raw_platform
if ' ' in platforms.strip():
LOG.error(f'{split.origin_file.path}:{split.line_number} : '
f'Space found in platform exclusion text. Please remove')
global ERROR_FOUND
ERROR_FOUND = True
raise TestExclusionProcessingException(
f'{split.origin_file.path}:{split.line_number} : '
f'Space found in platform exclusion text. Please remove', platforms)

def resolve_platforms(split: TestExclusionSplitLine) -> List[str]:
revolved_platforms = []
Expand Down Expand Up @@ -263,8 +271,8 @@ def main():
# if the dir containing the exclude ProblemList*.txt is not passed, the attempt to use openjdk/excludes/ dir instead
if args.exclude_dir:
LOG.debug("Taking file list from directory")
exclude_files = [os.path.join(args.exclude_dir, file_name)
for file_name in os.listdir(args.exclude_dir)]
exclude_files = [os.path.join(args.exclude_dir, f) for f in os.listdir(args.exclude_dir) if os.path.isfile(os.path.join(args.exclude_dir, f))]
LOG.debug(exclude_files)
else:
LOG.debug("Taking file list from stdin")
exclude_files = [line.rstrip() for line in sys.stdin.readlines()] # remove the \n from each lines
Expand Down Expand Up @@ -293,10 +301,9 @@ def main():
fp=fp,
indent=2,
)
if ERROR_FOUND:
if ERROR_TRACKER.error_logged:
LOG.debug(f"Error found. Exiting with code 1")
sys.exit(1)


if __name__ == '__main__':
main()

0 comments on commit d99ef63

Please sign in to comment.