Flutter Engine
The Flutter Engine
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
Classes | Functions | Variables
PRESUBMIT Namespace Reference

Classes

class  _WarningsAsErrors
 
class  CodeReview
 

Functions

def load_source (modname, filename)
 
def runSmokeTest (input_api, output_api)
 
def CheckChangeOnCommit (input_api, output_api)
 
def CheckChangeOnUpload (input_api, output_api)
 
def EnsurePubspecAndChangelogAltered (input_api, package_name)
 
def CheckChange (input_api, output_api)
 
def CheckNodeTextExpectationsCollectorUpdatingIsDisabled (input_api, output_api)
 
def is_cpp_file (path)
 
def is_dart_file (path)
 
def get_old_contents (input_api, path)
 
def files_to_check_for_format (input_api, extension, exclude_folders)
 
def CheckMemcpy (filename)
 
def RunLint (input_api, output_api)
 
def CheckGn (input_api, output_api)
 
def CheckFormatted (input_api, output_api)
 
def PostUploadHook (gerrit, change, output_api)
 

Variables

bool USE_PYTHON3 = True
 
string PRESUBMIT_VERSION = '2.0.0'
 
string RELEASE_NOTES_DIR = 'relnotes'
 
string RELEASE_NOTES_FILE_NAME = 'RELEASE_NOTES.md'
 
string RELEASE_NOTES_README = '//relnotes/README.md'
 
string GOLD_TRYBOT_URL = 'https://gold.skia.org/search?issue='
 
list SERVICE_ACCOUNT_SUFFIX
 

Function Documentation

◆ CheckChange()

def PRESUBMIT.CheckChange (   input_api,
  output_api 
)

Definition at line 41 of file PRESUBMIT.py.

41def CheckChange(input_api, output_api):
42 errors = []
43
44 # If the `lib` dir is altered, we also require a change to the pubspec.yaml
45 # of both this package and the `macros` package.
46 lib_changed = any(file.LocalPath().startswith('pkg/_macros/lib')
47 for file in input_api.AffectedFiles())
48 if lib_changed:
49 errors += EnsurePubspecAndChangelogAltered(input_api, '_macros')
50 errors += EnsurePubspecAndChangelogAltered(input_api, 'macros')
51
52 if errors:
53 return [
54 output_api.PresubmitError(
55 'pkg/_macros presubmit/PRESUBMIT.py failure(s):',
56 long_text='\n\n'.join(errors))
57 ]
58
59 return []
def CheckChange(input_api, output_api)
Definition: PRESUBMIT.py:41
def EnsurePubspecAndChangelogAltered(input_api, package_name)
Definition: PRESUBMIT.py:20
SIT bool any(const Vec< 1, T > &x)
Definition: SkVx.h:530
static SkString join(const CommandLineFlags::StringArray &)
Definition: skpbench.cpp:741

◆ CheckChangeOnCommit()

def PRESUBMIT.CheckChangeOnCommit ( input_api  ,
output_api   
)
Presubmit checks for the change on commit.

Definition at line 66 of file PRESUBMIT.py.

66def CheckChangeOnCommit(input_api, output_api):
67 return runSmokeTest(input_api, output_api)
68
69
def CheckChangeOnCommit(input_api, output_api)
Definition: PRESUBMIT.py:66
def runSmokeTest(input_api, output_api)
Definition: PRESUBMIT.py:32

◆ CheckChangeOnUpload()

def PRESUBMIT.CheckChangeOnUpload ( input_api  ,
output_api   
)
Presubmit checks for the change on upload.

Definition at line 70 of file PRESUBMIT.py.

70def CheckChangeOnUpload(input_api, output_api):
71 return runSmokeTest(input_api, output_api)
def CheckChangeOnUpload(input_api, output_api)
Definition: PRESUBMIT.py:70

◆ CheckFormatted()

def PRESUBMIT.CheckFormatted (   input_api,
  output_api 
)

Definition at line 62 of file PRESUBMIT.py.

62def CheckFormatted(input_api, output_api):
63
64 def convert_warning_to_error(presubmit_result):
65 if not presubmit_result.fatal:
66 # Convert this warning to an error.
67 result_json = presubmit_result.json_format()
68 return output_api.PresubmitError(
69 message=result_json['message'],
70 items=result_json['items'],
71 long_text=result_json['long_text'])
72 return presubmit_result
73
74 results = input_api.canned_checks.CheckPatchFormatted(input_api, output_api)
75 return [convert_warning_to_error(r) for r in results]
76
77
def CheckFormatted(input_api, output_api)
Definition: PRESUBMIT.py:62

◆ CheckGn()

def PRESUBMIT.CheckGn (   input_api,
  output_api 
)

Definition at line 58 of file PRESUBMIT.py.

58def CheckGn(input_api, output_api):
59 return input_api.canned_checks.CheckGNFormatted(input_api, output_api)
60
61
def CheckGn(input_api, output_api)
Definition: PRESUBMIT.py:58

◆ CheckMemcpy()

def PRESUBMIT.CheckMemcpy (   filename)

Definition at line 17 of file PRESUBMIT.py.

17def CheckMemcpy(filename):
18 if filename.endswith(os.path.join('platform', 'globals.h')) or \
19 filename.find('third_party') != -1:
20 return 0
21 fh = open(filename, 'r')
22 content = fh.read()
23 match = re.search('\\bmemcpy\\b', content)
24 if match:
25 offset = match.start()
26 end_of_line = content.index('\n', offset)
27 # We allow explicit use of memcpy with an opt-in via NOLINT
28 if 'NOLINT' not in content[offset:end_of_line]:
29 line_number = content[0:match.start()].count('\n') + 1
30 print("%s:%d: use of memcpy is forbidden" % (filename, line_number))
31 return 1
32 return 0
33
34
int count
Definition: FontMgrTest.cpp:50
def CheckMemcpy(filename)
Definition: PRESUBMIT.py:17
def print(*args, **kwargs)
Definition: run_tests.py:49

◆ CheckNodeTextExpectationsCollectorUpdatingIsDisabled()

def PRESUBMIT.CheckNodeTextExpectationsCollectorUpdatingIsDisabled (   input_api,
  output_api 
)

Definition at line 18 of file PRESUBMIT.py.

19 local_root = input_api.change.RepositoryRoot()
20 node_text_expectations_file = os.path.join(local_root, 'pkg', 'analyzer',
21 'test', 'src', 'dart',
22 'resolution',
23 'node_text_expectations.dart')
24 for git_file in input_api.AffectedTestableFiles():
25 filename = git_file.AbsoluteLocalPath()
26 if (filename == node_text_expectations_file):
27 isEnabledLine = re.compile('static const updatingIsEnabled = (.*);')
28 for line in git_file.NewContents():
29 m = isEnabledLine.search(line)
30 if (m is not None):
31 value = m.group(1)
32 if (value == 'false'):
33 return []
34 else:
35 return [
36 output_api.PresubmitError(
37 'NodeTextExpectationsCollector.updatingIsEnabled '
38 'must be `false`')
39 ]
40 return [
41 output_api.PresubmitError(
42 'Could not validate '
43 'NodeTextExpectationsCollector.updatingIsEnabled')
44 ]
45 return []
def CheckNodeTextExpectationsCollectorUpdatingIsDisabled(input_api, output_api)
Definition: PRESUBMIT.py:18

◆ EnsurePubspecAndChangelogAltered()

def PRESUBMIT.EnsurePubspecAndChangelogAltered (   input_api,
  package_name 
)

Definition at line 20 of file PRESUBMIT.py.

20def EnsurePubspecAndChangelogAltered(input_api, package_name):
21 errors = []
22 package_path = 'pkg/%s' % package_name
23 pubspec_path = '%s/pubspec.yaml' % package_path
24 pubspec_changed = any(file.LocalPath() == pubspec_path
25 for file in input_api.change.AffectedFiles())
26 if not pubspec_changed:
27 errors.append(
28 ('The pkg/_macros/lib dir was altered but the version of %s was '
29 'not bumped. See pkg/_macros/CONTRIBUTING.md' % package_path))
30
31 changelog_path = '%s/CHANGELOG.md' % package_path
32 changelog_changed = any(file.LocalPath() == changelog_path
33 for file in input_api.change.AffectedFiles())
34 if not changelog_changed:
35 errors.append(
36 ('The pkg/_macros/lib dir was altered but the CHANGELOG.md of %s '
37 'was not edited. See pkg/_macros/CONTRIBUTING.md' % package_path))
38 return errors
39
40# Invoked on upload and commit.

◆ files_to_check_for_format()

def PRESUBMIT.files_to_check_for_format (   input_api,
  extension,
  exclude_folders 
)

Definition at line 41 of file PRESUBMIT.py.

41def files_to_check_for_format(input_api, extension, exclude_folders):
42 files = []
43 exclude_folders += [
44 "pkg/front_end/testcases/", "pkg/front_end/parser_testcases/"
45 ]
46 for git_file in input_api.AffectedTextFiles():
47 local_path = git_file.LocalPath()
48 if not local_path.endswith(extension):
49 continue
50 if any([local_path.startswith(f) for f in exclude_folders]):
51 continue
52 files.append(git_file)
53 return files
54
55
def files_to_check_for_format(input_api, extension, exclude_folders)
Definition: PRESUBMIT.py:41

◆ get_old_contents()

def PRESUBMIT.get_old_contents (   input_api,
  path 
)

Definition at line 33 of file PRESUBMIT.py.

33def get_old_contents(input_api, path):
34 local_root = input_api.change.RepositoryRoot()
35 upstream = input_api.change._upstream
36 return scm.GIT.Capture(['show', upstream + ':' + path],
37 cwd=local_root,
38 strip_out=False)
39
40
def get_old_contents(input_api, path)
Definition: PRESUBMIT.py:33

◆ is_cpp_file()

def PRESUBMIT.is_cpp_file (   path)

Definition at line 25 of file PRESUBMIT.py.

25def is_cpp_file(path):
26 return path.endswith('.cc') or path.endswith('.h')
27
28
def is_cpp_file(path)
Definition: PRESUBMIT.py:25

◆ is_dart_file()

def PRESUBMIT.is_dart_file (   path)

Definition at line 29 of file PRESUBMIT.py.

29def is_dart_file(path):
30 return path.endswith('.dart')
31
32
def is_dart_file(path)
Definition: PRESUBMIT.py:29

◆ load_source()

def PRESUBMIT.load_source (   modname,
  filename 
)

Definition at line 19 of file PRESUBMIT.py.

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
static SkString load_source(skiatest::Reporter *r, const char *testFile, const char *permutationSuffix)
Definition: SkSLTest.cpp:226

◆ PostUploadHook()

def PRESUBMIT.PostUploadHook (   gerrit,
  change,
  output_api 
)
git cl upload will call this hook after the issue is created/modified.

This hook does the following:
* Adds a link to preview docs changes if there are any docs changes in the CL.
* Adds 'No-Try: true' if the CL contains only docs changes.

Definition at line 658 of file PRESUBMIT.py.

658def PostUploadHook(gerrit, change, output_api):
659 """git cl upload will call this hook after the issue is created/modified.
660
661 This hook does the following:
662 * Adds a link to preview docs changes if there are any docs changes in the CL.
663 * Adds 'No-Try: true' if the CL contains only docs changes.
664 """
665 if not change.issue:
666 return []
667
668 # Skip PostUploadHooks for all auto-commit service account bots. New
669 # patchsets (caused due to PostUploadHooks) invalidates the CQ+2 vote from
670 # the "--use-commit-queue" flag to "git cl upload".
671 for suffix in SERVICE_ACCOUNT_SUFFIX:
672 if change.author_email.endswith(suffix):
673 return []
674
675 results = []
676 at_least_one_docs_change = False
677 all_docs_changes = True
678 for affected_file in change.AffectedFiles():
679 affected_file_path = affected_file.LocalPath()
680 file_path, _ = os.path.splitext(affected_file_path)
681 if 'site' == file_path.split(os.path.sep)[0]:
682 at_least_one_docs_change = True
683 else:
684 all_docs_changes = False
685 if at_least_one_docs_change and not all_docs_changes:
686 break
687
688 footers = change.GitFootersFromDescription()
689 description_changed = False
690
691 # If the change includes only doc changes then add No-Try: true in the
692 # CL's description if it does not exist yet.
693 if all_docs_changes and 'true' not in footers.get('No-Try', []):
694 description_changed = True
695 change.AddDescriptionFooter('No-Try', 'true')
696 results.append(
697 output_api.PresubmitNotifyResult(
698 'This change has only doc changes. Automatically added '
699 '\'No-Try: true\' to the CL\'s description'))
700
701 # If the description has changed update it.
702 if description_changed:
703 gerrit.UpdateDescription(
704 change.FullDescriptionText(), change.issue)
705
706 return results
707
708
def PostUploadHook(gerrit, change, output_api)
Definition: PRESUBMIT.py:658

◆ RunLint()

def PRESUBMIT.RunLint (   input_api,
  output_api 
)

Definition at line 35 of file PRESUBMIT.py.

35def RunLint(input_api, output_api):
36 result = []
37 cpplint._cpplint_state.ResetErrorCounts()
38 memcpy_match_count = 0
39 # Find all .cc and .h files in the change list.
40 for git_file in input_api.AffectedTextFiles():
41 filename = git_file.AbsoluteLocalPath()
42 if filename.endswith('.cc') or (
43 # cpplint complains about the style of #ifndefs in our .pbzero.h
44 # files, but they are generated by the protozero compiler, so we
45 # can't fix this.
46 not filename.endswith('.pbzero.h') and filename.endswith('.h')):
47 # Run cpplint on the file.
48 cpplint.ProcessFile(filename, 1)
49 # Check for memcpy use.
50 memcpy_match_count += CheckMemcpy(filename)
51
52 # Report a presubmit error if any of the files had an error.
53 if cpplint._cpplint_state.error_count > 0 or memcpy_match_count > 0:
54 result = [output_api.PresubmitError('Failed cpplint check.')]
55 return result
56
57
def RunLint(input_api, output_api)
Definition: PRESUBMIT.py:35

◆ runSmokeTest()

def PRESUBMIT.runSmokeTest (   input_api,
  output_api 
)

Definition at line 32 of file PRESUBMIT.py.

32def runSmokeTest(input_api, output_api):
33 local_root = input_api.change.RepositoryRoot()
34 utils = load_source('utils', os.path.join(local_root, 'tools', 'utils.py'))
35 dart = os.path.join(utils.CheckedInSdkPath(), 'bin', 'dart')
36 test_helper = os.path.join(local_root, 'pkg', 'front_end',
37 'presubmit_helper.dart')
38
39 windows = utils.GuessOS() == 'win32'
40 if windows:
41 dart += '.exe'
42
43 if not os.path.isfile(dart):
44 print('WARNING: dart not found: %s' % dart)
45 return []
46
47 if not os.path.isfile(test_helper):
48 print('WARNING: CFE et al presubmit_helper not found: %s' % test_helper)
49 return []
50
51 args = [dart, test_helper, input_api.PresubmitLocalPath()]
52 process = subprocess.Popen(args,
53 stdout=subprocess.PIPE,
54 stdin=subprocess.PIPE)
55 outs, _ = process.communicate()
56
57 if process.returncode != 0:
58 return [
59 output_api.PresubmitError('CFE et al presubmit script failure(s):',
60 long_text=outs)
61 ]
62
63 return []
64
65
def GuessOS()
Definition: utils.py:21
def CheckedInSdkPath()
Definition: utils.py:499

Variable Documentation

◆ GOLD_TRYBOT_URL

string PRESUBMIT.GOLD_TRYBOT_URL = 'https://gold.skia.org/search?issue='

Definition at line 25 of file PRESUBMIT.py.

◆ PRESUBMIT_VERSION

string PRESUBMIT.PRESUBMIT_VERSION = '2.0.0'

Definition at line 11 of file PRESUBMIT.py.

◆ RELEASE_NOTES_DIR

string PRESUBMIT.RELEASE_NOTES_DIR = 'relnotes'

Definition at line 21 of file PRESUBMIT.py.

◆ RELEASE_NOTES_FILE_NAME

string PRESUBMIT.RELEASE_NOTES_FILE_NAME = 'RELEASE_NOTES.md'

Definition at line 22 of file PRESUBMIT.py.

◆ RELEASE_NOTES_README

string PRESUBMIT.RELEASE_NOTES_README = '//relnotes/README.md'

Definition at line 23 of file PRESUBMIT.py.

◆ SERVICE_ACCOUNT_SUFFIX

list PRESUBMIT.SERVICE_ACCOUNT_SUFFIX
Initial value:
1= [
2 '@%s.iam.gserviceaccount.com' % project for project in [
3 'skia-buildbots.google.com', 'skia-swarming-bots', 'skia-public',
4 'skia-corp.google.com', 'chops-service-accounts']]

Definition at line 27 of file PRESUBMIT.py.

◆ USE_PYTHON3

bool PRESUBMIT.USE_PYTHON3 = True

Definition at line 16 of file PRESUBMIT.py.