Commit c85c6027 authored by Alexander Hendrich's avatar Alexander Hendrich Committed by Commit Bot

Revert "Run policy-presubmit when presubmit is changed"

This reverts commit 139c1efd.

Reason for revert: https://crbug.com/1047721

Original change's description:
> Run policy-presubmit when presubmit is changed
> 
> When policy templates are changed, syntax_check_policy_template_json.py is run as part of the presubmit checks. It should also be run when changes to the file itself were made.
> 
> Bug: 1045930
> Change-Id: Ic8870bd748d80d87b99b93889640cf2ebbbf0b27
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2022794
> Reviewed-by: Alexander Hendrich <hendrich@chromium.org>
> Commit-Queue: Anina Koehler <aninak@google.com>
> Cr-Commit-Position: refs/heads/master@{#737240}

TBR=hendrich@chromium.org,aninak@google.com

Change-Id: I9b1e9c6fc799516a5a7944706032ad5fc9cffd6f
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: 1045930, 1047721
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2031110Reviewed-by: default avatarAlexander Hendrich <hendrich@chromium.org>
Commit-Queue: Alexander Hendrich <hendrich@chromium.org>
Cr-Commit-Position: refs/heads/master@{#737543}
parent 7fb02064
...@@ -23,55 +23,58 @@ def _GetPolicyTemplates(template_path): ...@@ -23,55 +23,58 @@ def _GetPolicyTemplates(template_path):
def _CheckPolicyTemplatesSyntax(input_api, output_api): def _CheckPolicyTemplatesSyntax(input_api, output_api):
local_path = input_api.PresubmitLocalPath() local_path = input_api.PresubmitLocalPath()
filepath = input_api.os_path.join(local_path, 'policy_templates.json') filepath = input_api.os_path.join(local_path, 'policy_templates.json')
if any(f.AbsoluteLocalPath() == filepath
try: for f in input_api.AffectedFiles()):
template_affected_file = next(iter(f \ old_sys_path = sys.path
for f in input_api.change.AffectedFiles() \ try:
if f.AbsoluteLocalPath() == filepath)) tools_path = input_api.os_path.normpath(
except: input_api.os_path.join(local_path, input_api.os_path.pardir, 'tools'))
template_affected_file = None sys.path = [ tools_path ] + sys.path
# Optimization: only load this when it's needed.
old_sys_path = sys.path import syntax_check_policy_template_json
try: device_policy_proto_path = input_api.os_path.join(
tools_path = input_api.os_path.normpath( local_path, '../proto/chrome_device_policy.proto')
input_api.os_path.join(local_path, input_api.os_path.pardir, 'tools')) args = ["--device_policy_proto_path=" + device_policy_proto_path]
sys.path = [ tools_path ] + sys.path
# Optimization: only load this when it's needed. root = input_api.change.RepositoryRoot()
import syntax_check_policy_template_json
device_policy_proto_path = input_api.os_path.join( current_version = None
local_path, '../proto/chrome_device_policy.proto') original_file_contents = None
args = ["--device_policy_proto_path=" + device_policy_proto_path]
# Check if there is a tag that allows us to bypass compatibility checks.
root = input_api.change.RepositoryRoot() # This can be used in situations where there is a bug in the validation
# code or if a policy change needs to urgently be submitted.
current_version = None if not input_api.change.tags.get('BYPASS_POLICY_COMPATIBILITY_CHECK'):
original_file_contents = None # Get the current version from the VERSION file so that we can check
# which policies are un-released and thus can be changed at will.
# Check if there is a tag that allows us to bypass compatibility checks. try:
# This can be used in situations where there is a bug in the validation version_path = input_api.os_path.join(
# code or if a policy change needs to urgently be submitted. root, 'chrome', 'VERSION')
if not input_api.change.tags.get('BYPASS_POLICY_COMPATIBILITY_CHECK'): with open(version_path, "rb") as f:
# Get the current version from the VERSION file so that we can check current_version = int(f.readline().split("=")[1])
# which policies are un-released and thus can be changed at will. print ('Checking policies against current version: ' +
try: current_version)
version_path = input_api.os_path.join(root, 'chrome', 'VERSION') except:
with open(version_path, "rb") as f: pass
current_version = int(f.readline().split("=")[1])
print ('Checking policies against current version: ' + # Get the original file contents of the policy file so that we can check
current_version) # the compatibility of template changes in it
except: template_path = input_api.os_path.join(
pass root, 'components', 'policy', 'resources', 'policy_templates.json')
affected_files = input_api.change.AffectedFiles()
# Get the original file contents of the policy file so that we can check template_affected_file = next(iter(f \
# the compatibility of template changes in it for f in affected_files if f.AbsoluteLocalPath() == template_path))
if template_affected_file is not None: if template_affected_file is not None:
original_file_contents = '\n'.join(template_affected_file.OldContents()) original_file_contents = \
'\n'.join(template_affected_file.OldContents())
checker = syntax_check_policy_template_json.PolicyTemplateChecker()
if checker.Run(args, filepath, original_file_contents, current_version) > 0: checker = syntax_check_policy_template_json.PolicyTemplateChecker()
return [output_api.PresubmitError('Syntax error(s) in file:', [filepath])] if checker.Run(args, filepath,
finally: original_file_contents, current_version) > 0:
sys.path = old_sys_path return [output_api.PresubmitError('Syntax error(s) in file:',
[filepath])]
finally:
sys.path = old_sys_path
return [] return []
...@@ -207,14 +210,11 @@ def _CheckMissingPlaceholders(input_api, output_api, template_path): ...@@ -207,14 +210,11 @@ def _CheckMissingPlaceholders(input_api, output_api, template_path):
def _CommonChecks(input_api, output_api): def _CommonChecks(input_api, output_api):
results = [] results = []
root = input_api.change.RepositoryRoot() root = input_api.change.RepositoryRoot()
template_path = input_api.os_path.join( template_path = template_path = input_api.os_path.join(
root, 'components', 'policy', 'resources', 'policy_templates.json') root, 'components', 'policy', 'resources', 'policy_templates.json')
# policies in chrome/test/data/policy/policy_test_cases.json. # policies in chrome/test/data/policy/policy_test_cases.json.
test_cases_path = input_api.os_path.join( test_cases_path = input_api.os_path.join(
root, 'chrome', 'test', 'data', 'policy', 'policy_test_cases.json') root, 'chrome', 'test', 'data', 'policy', 'policy_test_cases.json')
syntax_check_path = input_api.os_path.join(
root, 'components', 'policy', 'tools',
'syntax_check_policy_template_json.py')
affected_files = input_api.change.AffectedFiles() affected_files = input_api.change.AffectedFiles()
results.extend(_CheckMissingPlaceholders(input_api, output_api, results.extend(_CheckMissingPlaceholders(input_api, output_api,
...@@ -223,17 +223,15 @@ def _CommonChecks(input_api, output_api): ...@@ -223,17 +223,15 @@ def _CommonChecks(input_api, output_api):
for f in affected_files) for f in affected_files)
tests_changed = any(f.AbsoluteLocalPath() == test_cases_path \ tests_changed = any(f.AbsoluteLocalPath() == test_cases_path \
for f in affected_files) for f in affected_files)
syntax_check_changed = any(f.AbsoluteLocalPath() == syntax_check_path \
for f in affected_files)
if template_changed or tests_changed or syntax_check_changed: if template_changed or tests_changed:
try: try:
policies = _GetPolicyTemplates(template_path) policies = _GetPolicyTemplates(template_path)
except: except:
results.append(output_api.PresubmitError('Invalid Python/JSON syntax.')) results.append(output_api.PresubmitError('Invalid Python/JSON syntax.'))
return results return results
results.extend(_CheckPolicyTestCases(input_api, output_api, policies)) results.extend(_CheckPolicyTestCases(input_api, output_api, policies))
if template_changed or syntax_check_changed: if template_changed:
results.extend(_CheckPolicyTemplatesSyntax(input_api, output_api)) results.extend(_CheckPolicyTemplatesSyntax(input_api, output_api))
results.extend(_CheckPolicyHistograms(input_api, output_api, policies)) results.extend(_CheckPolicyHistograms(input_api, output_api, policies))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment