Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC

Commits:

1 changed file:

Changes:

  • testsuite/tests/linters/regex-linters/check-rts-includes.py
    ... ... @@ -12,12 +12,16 @@ import re
    12 12
     INCLUDE_RE = re.compile('# *include ([<"][^">]+[>"])')
    
    13 13
     
    
    14 14
     def get_includes(file: Path) -> List[Tuple[int, str]]:
    
    15
    -    txt = file.read_text()
    
    16
    -    return [ (line_no+1, m.group(1) )
    
    17
    -             for (line_no, line) in enumerate(txt.split('\n'))
    
    18
    -             for m in [INCLUDE_RE.match(line)]
    
    19
    -             if m is not None
    
    20
    -             if m.group(1) != "rts/PosixSource.h"]
    
    15
    +    try:
    
    16
    +        txt = file.read_text(encoding="utf-8")
    
    17
    +        return [ (line_no+1, m.group(1) )
    
    18
    +                 for (line_no, line) in enumerate(txt.split('\n'))
    
    19
    +                 for m in [INCLUDE_RE.match(line)]
    
    20
    +                 if m is not None
    
    21
    +                 if m.group(1) != "rts/PosixSource.h"]
    
    22
    +    except Exception as e:
    
    23
    +        e.add_note(f"While reading includes from {file}")
    
    24
    +        raise
    
    21 25
     
    
    22 26
     def in_rts_dir(path: Path) -> bool:
    
    23 27
         return len(path.parts) > 0 and path.parts[0] == 'rts'
    
    ... ... @@ -40,9 +44,14 @@ class RtsHIncludeOrderLinter(Linter):
    40 44
                 '"ghcplatform.h"',
    
    41 45
             }
    
    42 46
     
    
    43
    -        includes = get_includes(path)
    
    44
    -        headers = [x[1] for x in includes]
    
    45
    -        lines = path.read_text().split('\n')
    
    47
    +        try:
    
    48
    +            includes = get_includes(path)
    
    49
    +            headers = [x[1] for x in includes]
    
    50
    +            lines = path.read_text(encoding="utf-8").split('\n')
    
    51
    +        # #26850
    
    52
    +        except Exception as e:
    
    53
    +            e.add_note(f"Error while decoding path {path}")
    
    54
    +            raise e
    
    46 55
     
    
    47 56
             if '"PosixSource.h"' in headers:
    
    48 57
                 for line_no, header in includes:
    
    ... ... @@ -69,18 +78,22 @@ class PrivateIncludeLinter(Linter):
    69 78
     
    
    70 79
         def lint(self, path: Path):
    
    71 80
             private = False
    
    72
    -        lines = path.read_text().split('\n')
    
    73
    -        for line_no, include in get_includes(path):
    
    74
    -            if include == '"BeginPrivate.h"':
    
    75
    -                private = True
    
    76
    -            elif include == '"EndPrivate.h"':
    
    77
    -                private = False
    
    78
    -            elif private:
    
    79
    -                self.add_warning(Warning(
    
    80
    -                    path=path,
    
    81
    -                    line_no=line_no,
    
    82
    -                    line_content=lines[line_no-1],
    
    83
    -                    message='System header %s found inside of <BeginPrivate.h> block' % include))
    
    81
    +        try:
    
    82
    +            lines = path.read_text(encoding="utf-8").split('\n')
    
    83
    +            for line_no, include in get_includes(path):
    
    84
    +                if include == '"BeginPrivate.h"':
    
    85
    +                    private = True
    
    86
    +                elif include == '"EndPrivate.h"':
    
    87
    +                    private = False
    
    88
    +                elif private:
    
    89
    +                    self.add_warning(Warning(
    
    90
    +                        path=path,
    
    91
    +                        line_no=line_no,
    
    92
    +                        line_content=lines[line_no-1],
    
    93
    +                        message='System header %s found inside of <BeginPrivate.h> block' % include))
    
    94
    +        except Exception as e:
    
    95
    +            e.add_note(f"While handling {path}")
    
    96
    +            raise e
    
    84 97
     
    
    85 98
     linters = [
    
    86 99
         RtsHIncludeOrderLinter(),