Skip to content

Commit

Permalink
Fix check_sql_modules on Windows
Browse files Browse the repository at this point in the history
In Chromium, these presubmit checks run on Windows as well. We need to use os.path.normpath to normalize the paths before checking the allowlist for this to work on Windows as well.

Bug: b/287233783
Change-Id: If5a495042394119aca95a24bdc8519e0f5b7ee02
  • Loading branch information
Rasika Navarange committed Nov 13, 2023
1 parent 11e588e commit e228d33
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions python/generators/sql_processing/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

from enum import Enum
import re
import os
from typing import Dict, List

NAME = r'[a-zA-Z_\d\{\}]+'
Expand Down Expand Up @@ -177,12 +178,16 @@ def check_banned_create_table_as(sql: str, filename: str,
errors = []
for _, matches in match_pattern(CREATE_TABLE_AS_PATTERN, sql).items():
name = matches[0]
if filename not in allowlist:
# Normalize paths before checking presence in the allowlist so it will
# work on Windows for the Chrome stdlib presubmit.
allowlist_normpath = dict(
(os.path.normpath(path), tables) for path, tables in allowlist.items())
if os.path.normpath(filename) not in allowlist_normpath:
errors.append(f"CREATE TABLE '{name}' is deprecated."
"Use CREATE PERFETTO TABLE instead.\n"
f"Offending file: {filename}\n")
continue
if name not in allowlist[filename]:
if name not in allowlist_normpath[os.path.normpath(filename)]:
errors.append(
f"Table '{name}' uses CREATE TABLE which is deprecated "
"and this table is not allowlisted. Use CREATE PERFETTO TABLE.\n"
Expand Down

0 comments on commit e228d33

Please sign in to comment.