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):
def _CheckPolicyTemplatesSyntax(input_api, output_api):
local_path = input_api.PresubmitLocalPath()
filepath = input_api.os_path.join(local_path, 'policy_templates.json')
try:
template_affected_file = next(iter(f \
for f in input_api.change.AffectedFiles() \
if f.AbsoluteLocalPath() == filepath))
except:
template_affected_file = None
old_sys_path = sys.path
try:
tools_path = input_api.os_path.normpath(
input_api.os_path.join(local_path, input_api.os_path.pardir, 'tools'))
sys.path = [ tools_path ] + sys.path
# Optimization: only load this when it's needed.
import syntax_check_policy_template_json
device_policy_proto_path = input_api.os_path.join(
local_path, '../proto/chrome_device_policy.proto')
args = ["--device_policy_proto_path=" + device_policy_proto_path]
root = input_api.change.RepositoryRoot()
current_version = None
original_file_contents = None
# Check if there is a tag that allows us to bypass compatibility checks.
# 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.
if not input_api.change.tags.get('BYPASS_POLICY_COMPATIBILITY_CHECK'):
# 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.
try:
version_path = input_api.os_path.join(root, 'chrome', 'VERSION')
with open(version_path, "rb") as f:
current_version = int(f.readline().split("=")[1])
print ('Checking policies against current version: ' +
current_version)
except:
pass
# Get the original file contents of the policy file so that we can check
# the compatibility of template changes in it
if template_affected_file is not None:
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:
return [output_api.PresubmitError('Syntax error(s) in file:', [filepath])]
finally:
sys.path = old_sys_path
if any(f.AbsoluteLocalPath() == filepath
for f in input_api.AffectedFiles()):
old_sys_path = sys.path
try:
tools_path = input_api.os_path.normpath(
input_api.os_path.join(local_path, input_api.os_path.pardir, 'tools'))
sys.path = [ tools_path ] + sys.path
# Optimization: only load this when it's needed.
import syntax_check_policy_template_json
device_policy_proto_path = input_api.os_path.join(
local_path, '../proto/chrome_device_policy.proto')
args = ["--device_policy_proto_path=" + device_policy_proto_path]
root = input_api.change.RepositoryRoot()
current_version = None
original_file_contents = None
# Check if there is a tag that allows us to bypass compatibility checks.
# 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.
if not input_api.change.tags.get('BYPASS_POLICY_COMPATIBILITY_CHECK'):
# 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.
try:
version_path = input_api.os_path.join(
root, 'chrome', 'VERSION')
with open(version_path, "rb") as f:
current_version = int(f.readline().split("=")[1])
print ('Checking policies against current version: ' +
current_version)
except:
pass
# Get the original file contents of the policy file so that we can check
# the compatibility of template changes in it
template_path = input_api.os_path.join(
root, 'components', 'policy', 'resources', 'policy_templates.json')
affected_files = input_api.change.AffectedFiles()
template_affected_file = next(iter(f \
for f in affected_files if f.AbsoluteLocalPath() == template_path))
if template_affected_file is not None:
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:
return [output_api.PresubmitError('Syntax error(s) in file:',
[filepath])]
finally:
sys.path = old_sys_path
return []
......@@ -207,14 +210,11 @@ def _CheckMissingPlaceholders(input_api, output_api, template_path):
def _CommonChecks(input_api, output_api):
results = []
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')
# policies in chrome/test/data/policy/policy_test_cases.json.
test_cases_path = input_api.os_path.join(
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()
results.extend(_CheckMissingPlaceholders(input_api, output_api,
......@@ -223,17 +223,15 @@ def _CommonChecks(input_api, output_api):
for f in affected_files)
tests_changed = any(f.AbsoluteLocalPath() == test_cases_path \
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:
policies = _GetPolicyTemplates(template_path)
except:
results.append(output_api.PresubmitError('Invalid Python/JSON syntax.'))
return results
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(_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