Flutter Engine
The Flutter Engine
PRESUBMIT.py
Go to the documentation of this file.
1#!/usr/bin/env python3
2# Copyright (c) 2022, the Dart project authors. Please see the AUTHORS file
3# for details. All rights reserved. Use of this source code is governed by a
4# BSD-style license that can be found in the LICENSE file.
5"""sdk/lib specific presubmit script.
6
7See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts
8for more details about the presubmit API built into gcl.
9"""
10
11import importlib.util
12import importlib.machinery
13import os.path
14import subprocess
15
16USE_PYTHON3 = True
17
18
19def load_source(modname, filename):
20 loader = importlib.machinery.SourceFileLoader(modname, filename)
21 spec = importlib.util.spec_from_file_location(modname,
22 filename,
23 loader=loader)
24 module = importlib.util.module_from_spec(spec)
25 # The module is always executed and not cached in sys.modules.
26 # Uncomment the following line to cache the module.
27 # sys.modules[module.__name__] = module
28 loader.exec_module(module)
29 return module
30
31
32def runSmokeTest(input_api, output_api):
33 hasChangedFiles = False
34 for git_file in input_api.AffectedTextFiles():
35 filename = git_file.AbsoluteLocalPath()
36 if filename.endswith('libraries.yaml') or filename.endswith(
37 'libraries.json'):
38 hasChangedFiles = True
39 break
40
41 if hasChangedFiles:
42 local_root = input_api.change.RepositoryRoot()
43 utils = load_source('utils',
44 os.path.join(local_root, 'tools', 'utils.py'))
45 dart = os.path.join(utils.CheckedInSdkPath(), 'bin', 'dart')
46 yaml2json = os.path.join(local_root, 'tools', 'yaml2json.dart')
47 libYaml = os.path.join(local_root, 'sdk', 'lib', 'libraries.yaml')
48 libJson = os.path.join(local_root, 'sdk', 'lib', 'libraries.json')
49
50 windows = utils.GuessOS() == 'win32'
51 if windows:
52 dart += '.exe'
53
54 if not os.path.isfile(dart):
55 print('WARNING: dart not found: %s' % dart)
56 return []
57
58 if not os.path.isfile(yaml2json):
59 print('WARNING: yaml2json not found: %s' % yaml2json)
60 return []
61
62 args = [
63 dart, yaml2json, libYaml, libJson, '--check',
64 '--relative=' + local_root + '/'
65 ]
66 process = subprocess.Popen(args,
67 stdout=subprocess.PIPE,
68 stdin=subprocess.PIPE)
69 outs, _ = process.communicate()
70
71 if process.returncode != 0:
72 return [
73 output_api.PresubmitError('lib/sdk smoketest failure(s)',
74 long_text=outs)
75 ]
76
77 return []
78
79
80def CheckChangeOnCommit(input_api, output_api):
81 return runSmokeTest(input_api, output_api)
82
83
84def CheckChangeOnUpload(input_api, output_api):
85 return runSmokeTest(input_api, output_api)
static SkString load_source(skiatest::Reporter *r, const char *testFile, const char *permutationSuffix)
Definition: SkSLTest.cpp:226
def CheckChangeOnCommit(input_api, output_api)
Definition: PRESUBMIT.py:66
def CheckChangeOnUpload(input_api, output_api)
Definition: PRESUBMIT.py:70
def runSmokeTest(input_api, output_api)
Definition: PRESUBMIT.py:32
def print(*args, **kwargs)
Definition: run_tests.py:49
def GuessOS()
Definition: utils.py:21
def CheckedInSdkPath()
Definition: utils.py:499