[build] Python 3.12 compatibility.

Bug: https://github.com/dart-lang/sdk/issues/54306
Change-Id: I974e5e70c6c1cbb87343139a26052996d8df858f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/341023
Reviewed-by: Brian Quinlan <bquinlan@google.com>
Reviewed-by: Siva Annamalai <asiva@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
This commit is contained in:
Ryan Macnak
2023-12-12 18:19:35 +00:00
committed by Commit Queue
parent d65b47846b
commit 1256db2277
7 changed files with 122 additions and 26 deletions
+19 -7
View File
@@ -9,7 +9,8 @@ for more details about the presubmit API built into gcl.
"""
import datetime
import imp
import importlib.util
import importlib.machinery
import os
import os.path
from typing import Callable
@@ -70,10 +71,22 @@ def _CheckFormat(input_api,
return unformatted_files
def load_source(modname, filename):
loader = importlib.machinery.SourceFileLoader(modname, filename)
spec = importlib.util.spec_from_file_location(modname,
filename,
loader=loader)
module = importlib.util.module_from_spec(spec)
# The module is always executed and not cached in sys.modules.
# Uncomment the following line to cache the module.
# sys.modules[module.__name__] = module
loader.exec_module(module)
return module
def _CheckDartFormat(input_api, output_api):
local_root = input_api.change.RepositoryRoot()
utils = imp.load_source('utils',
os.path.join(local_root, 'tools', 'utils.py'))
utils = load_source('utils', os.path.join(local_root, 'tools', 'utils.py'))
dart = os.path.join(utils.CheckedInSdkPath(), 'bin', 'dart')
@@ -155,8 +168,7 @@ def _CheckDartFormat(input_api, output_api):
def _CheckStatusFiles(input_api, output_api):
local_root = input_api.change.RepositoryRoot()
utils = imp.load_source('utils',
os.path.join(local_root, 'tools', 'utils.py'))
utils = load_source('utils', os.path.join(local_root, 'tools', 'utils.py'))
dart = os.path.join(utils.CheckedInSdkPath(), 'bin', 'dart')
lint = os.path.join(local_root, 'pkg', 'status_file', 'bin', 'lint.dart')
@@ -231,12 +243,12 @@ def _CheckLayering(input_api, output_api):
return []
local_root = input_api.change.RepositoryRoot()
compiler_layering_check = imp.load_source(
compiler_layering_check = load_source(
'compiler_layering_check',
os.path.join(local_root, 'runtime', 'tools',
'compiler_layering_check.py'))
errors = compiler_layering_check.DoCheck(local_root)
embedder_layering_check = imp.load_source(
embedder_layering_check = load_source(
'embedder_layering_check',
os.path.join(local_root, 'runtime', 'tools',
'embedder_layering_check.py'))
+17 -3
View File
@@ -8,13 +8,27 @@ See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts
for more details about the presubmit API built into gcl.
"""
import imp
import importlib.util
import importlib.machinery
import os.path
import subprocess
USE_PYTHON3 = True
def load_source(modname, filename):
loader = importlib.machinery.SourceFileLoader(modname, filename)
spec = importlib.util.spec_from_file_location(modname,
filename,
loader=loader)
module = importlib.util.module_from_spec(spec)
# The module is always executed and not cached in sys.modules.
# Uncomment the following line to cache the module.
# sys.modules[module.__name__] = module
loader.exec_module(module)
return module
def runSmokeTest(input_api, output_api):
hasChangedFiles = False
for git_file in input_api.AffectedTextFiles():
@@ -25,8 +39,8 @@ def runSmokeTest(input_api, output_api):
if hasChangedFiles:
local_root = input_api.change.RepositoryRoot()
utils = imp.load_source('utils',
os.path.join(local_root, 'tools', 'utils.py'))
utils = load_source('utils',
os.path.join(local_root, 'tools', 'utils.py'))
dart = os.path.join(utils.CheckedInSdkPath(), 'bin', 'dart')
smoke_test = os.path.join(local_root, 'pkg', '_fe_analyzer_shared',
'tool', 'smoke_test_quick.dart')
+17 -3
View File
@@ -8,13 +8,27 @@ See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts
for more details about the presubmit API built into gcl.
"""
import imp
import importlib.util
import importlib.machinery
import os.path
import subprocess
USE_PYTHON3 = True
def load_source(modname, filename):
loader = importlib.machinery.SourceFileLoader(modname, filename)
spec = importlib.util.spec_from_file_location(modname,
filename,
loader=loader)
module = importlib.util.module_from_spec(spec)
# The module is always executed and not cached in sys.modules.
# Uncomment the following line to cache the module.
# sys.modules[module.__name__] = module
loader.exec_module(module)
return module
def runSmokeTest(input_api, output_api):
hasChangedFiles = False
for git_file in input_api.AffectedTextFiles():
@@ -25,8 +39,8 @@ def runSmokeTest(input_api, output_api):
if hasChangedFiles:
local_root = input_api.change.RepositoryRoot()
utils = imp.load_source('utils',
os.path.join(local_root, 'tools', 'utils.py'))
utils = load_source('utils',
os.path.join(local_root, 'tools', 'utils.py'))
dart = os.path.join(utils.CheckedInSdkPath(), 'bin', 'dart')
smoke_test = os.path.join(local_root, 'pkg', 'front_end', 'tool',
'smoke_test_quick.dart')
+17 -3
View File
@@ -8,13 +8,27 @@ See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts
for more details about the presubmit API built into gcl.
"""
import imp
import importlib.util
import importlib.machinery
import os.path
import subprocess
USE_PYTHON3 = True
def load_source(modname, filename):
loader = importlib.machinery.SourceFileLoader(modname, filename)
spec = importlib.util.spec_from_file_location(modname,
filename,
loader=loader)
module = importlib.util.module_from_spec(spec)
# The module is always executed and not cached in sys.modules.
# Uncomment the following line to cache the module.
# sys.modules[module.__name__] = module
loader.exec_module(module)
return module
def runSmokeTest(input_api, output_api):
hasChangedFiles = False
for git_file in input_api.AffectedTextFiles():
@@ -25,8 +39,8 @@ def runSmokeTest(input_api, output_api):
if hasChangedFiles:
local_root = input_api.change.RepositoryRoot()
utils = imp.load_source('utils',
os.path.join(local_root, 'tools', 'utils.py'))
utils = load_source('utils',
os.path.join(local_root, 'tools', 'utils.py'))
dart = os.path.join(utils.CheckedInSdkPath(), 'bin', 'dart')
smoke_test = os.path.join(local_root, 'pkg', 'kernel', 'tool',
'smoke_test_quick.dart')
+17 -3
View File
@@ -8,13 +8,27 @@ See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts
for more details about the presubmit API built into gcl.
"""
import imp
import importlib.util
import importlib.machinery
import os.path
import subprocess
USE_PYTHON3 = True
def load_source(modname, filename):
loader = importlib.machinery.SourceFileLoader(modname, filename)
spec = importlib.util.spec_from_file_location(modname,
filename,
loader=loader)
module = importlib.util.module_from_spec(spec)
# The module is always executed and not cached in sys.modules.
# Uncomment the following line to cache the module.
# sys.modules[module.__name__] = module
loader.exec_module(module)
return module
def runSmokeTest(input_api, output_api):
hasChangedFiles = False
for git_file in input_api.AffectedTextFiles():
@@ -26,8 +40,8 @@ def runSmokeTest(input_api, output_api):
if hasChangedFiles:
local_root = input_api.change.RepositoryRoot()
utils = imp.load_source('utils',
os.path.join(local_root, 'tools', 'utils.py'))
utils = load_source('utils',
os.path.join(local_root, 'tools', 'utils.py'))
dart = os.path.join(utils.CheckedInSdkPath(), 'bin', 'dart')
yaml2json = os.path.join(local_root, 'tools', 'yaml2json.dart')
libYaml = os.path.join(local_root, 'sdk', 'lib', 'libraries.yaml')
+16 -2
View File
@@ -5,7 +5,8 @@
# BSD-style license that can be found in the LICENSE file.
import hashlib
import imp
import importlib.util
import importlib.machinery
import os
import subprocess
import sys
@@ -14,9 +15,22 @@ DART_DIR = os.path.abspath(
os.path.normpath(os.path.join(__file__, '..', '..', '..')))
def load_source(modname, filename):
loader = importlib.machinery.SourceFileLoader(modname, filename)
spec = importlib.util.spec_from_file_location(modname,
filename,
loader=loader)
module = importlib.util.module_from_spec(spec)
# The module is always executed and not cached in sys.modules.
# Uncomment the following line to cache the module.
# sys.modules[module.__name__] = module
loader.exec_module(module)
return module
def GetUtils():
'''Dynamically load the tools/utils.py python module.'''
return imp.load_source('utils', os.path.join(DART_DIR, 'tools', 'utils.py'))
return load_source('utils', os.path.join(DART_DIR, 'tools', 'utils.py'))
def run(command, env=None, shell=False, throw_on_error=True):
+19 -5
View File
@@ -11,7 +11,8 @@ import contextlib
import datetime
from functools import total_ordering
import glob
import imp
import importlib.util
import importlib.machinery
import json
import os
import platform
@@ -111,16 +112,29 @@ def GetBaseDir():
return BASE_DIR
def load_source(modname, filename):
loader = importlib.machinery.SourceFileLoader(modname, filename)
spec = importlib.util.spec_from_file_location(modname,
filename,
loader=loader)
module = importlib.util.module_from_spec(spec)
# The module is always executed and not cached in sys.modules.
# Uncomment the following line to cache the module.
# sys.modules[module.__name__] = module
loader.exec_module(module)
return module
def GetBotUtils(repo_path=DART_DIR):
'''Dynamically load the tools/bots/bot_utils.py python module.'''
return imp.load_source(
'bot_utils', os.path.join(repo_path, 'tools', 'bots', 'bot_utils.py'))
return load_source('bot_utils',
os.path.join(repo_path, 'tools', 'bots', 'bot_utils.py'))
def GetMinidumpUtils(repo_path=DART_DIR):
'''Dynamically load the tools/minidump.py python module.'''
return imp.load_source('minidump',
os.path.join(repo_path, 'tools', 'minidump.py'))
return load_source('minidump',
os.path.join(repo_path, 'tools', 'minidump.py'))
@total_ordering