summaryrefslogtreecommitdiffstats
path: root/components
diff options
context:
space:
mode:
authortnagel <tnagel@chromium.org>2015-04-24 11:44:41 -0700
committerCommit bot <commit-bot@chromium.org>2015-04-24 18:45:43 +0000
commit87a25e53185cfbd598a888cb35cd674b7d2394de (patch)
tree94d40a3e0b459480cd2545f5d19b90d84a101af5 /components
parent70d52bc9323a077b1ce28afa1d12f69c129e13bd (diff)
downloadchromium_src-87a25e53185cfbd598a888cb35cd674b7d2394de.zip
chromium_src-87a25e53185cfbd598a888cb35cd674b7d2394de.tar.gz
chromium_src-87a25e53185cfbd598a888cb35cd674b7d2394de.tar.bz2
Fix generate_policy_source.py to honour supported_on ranges.
BUG=451073 Review URL: https://codereview.chromium.org/929353002 Cr-Commit-Position: refs/heads/master@{#326848}
Diffstat (limited to 'components')
-rw-r--r--components/policy.gypi2
-rw-r--r--components/policy/BUILD.gn4
-rwxr-xr-xcomponents/policy/tools/generate_policy_source.py43
3 files changed, 40 insertions, 9 deletions
diff --git a/components/policy.gypi b/components/policy.gypi
index c2b99d8..06253e8 100644
--- a/components/policy.gypi
+++ b/components/policy.gypi
@@ -103,6 +103,7 @@
{
'inputs': [
'policy/resources/policy_templates.json',
+ '<(DEPTH)/chrome/VERSION',
'<(generate_policy_source_script_path)',
],
'outputs': [
@@ -123,6 +124,7 @@
'--cloud-policy-protobuf=<(cloud_policy_proto_path)',
'--cloud-policy-decoder=<(protobuf_decoder_path)',
'--app-restrictions-definition=<(app_restrictions_path)',
+ '<(DEPTH)/chrome/VERSION',
'<(OS)',
'<(chromeos)',
'policy/resources/policy_templates.json',
diff --git a/components/policy/BUILD.gn b/components/policy/BUILD.gn
index a708c2a..27e3007 100644
--- a/components/policy/BUILD.gn
+++ b/components/policy/BUILD.gn
@@ -64,6 +64,8 @@ if (enable_configuration_policy) {
action("cloud_policy_code_generate") {
script = "tools/generate_policy_source.py"
+ chrome_version_abspath = "//chrome/VERSION"
+ chrome_version_path = rebase_path(chrome_version_abspath, root_build_dir)
if (is_chromeos) {
chromeos_flag = "1"
@@ -72,6 +74,7 @@ if (enable_configuration_policy) {
}
inputs = [
+ chrome_version_abspath,
"resources/policy_templates.json",
]
outputs = [
@@ -100,6 +103,7 @@ if (enable_configuration_policy) {
rebase_path(protobuf_decoder_path, root_build_dir),
"--app-restrictions-definition=" +
rebase_path(app_restrictions_path, root_build_dir),
+ chrome_version_path,
target_os,
chromeos_flag,
rebase_path("resources/policy_templates.json", root_build_dir),
diff --git a/components/policy/tools/generate_policy_source.py b/components/policy/tools/generate_policy_source.py
index b3a723b..2a9e645 100755
--- a/components/policy/tools/generate_policy_source.py
+++ b/components/policy/tools/generate_policy_source.py
@@ -62,7 +62,7 @@ class PolicyDetails:
self.caption = PolicyDetails._RemovePlaceholders(item['caption'])
self.value = item['value']
- def __init__(self, policy, os, is_chromium_os):
+ def __init__(self, policy, chrome_major_version, os, is_chromium_os):
self.id = policy['id']
self.name = policy['name']
features = policy.get('features', {})
@@ -77,8 +77,18 @@ class PolicyDetails:
expected_platform = 'chrome_os' if is_chromium_os else os.lower()
self.platforms = []
- for platform, version in [ p.split(':') for p in policy['supported_on'] ]:
- if not version.endswith('-'):
+ for platform, version_range in [ p.split(':')
+ for p in policy['supported_on'] ]:
+ split_result = version_range.split('-')
+ if len(split_result) != 2:
+ raise RuntimeError('supported_on must have exactly one dash: "%s"' % p)
+ (version_min, version_max) = split_result
+ if version_min == '':
+ raise RuntimeError('supported_on must define a start version: "%s"' % p)
+
+ # Skip if the current Chromium version does not support the policy.
+ if (int(version_min) > chrome_major_version or
+ version_max != '' and int(version_max) < chrome_major_version):
continue
if platform.startswith('chrome.'):
@@ -127,6 +137,18 @@ class PolicyDetails:
return result
+def ParseVersionFile(version_path):
+ major_version = None
+ for line in open(version_path, 'r').readlines():
+ key, val = line.rstrip('\r\n').split('=', 1)
+ if key == 'MAJOR':
+ major_version = val
+ break
+ if major_version is None:
+ raise RuntimeError('VERSION file does not contain major version.')
+ return major_version
+
+
def main():
parser = OptionParser(usage=__doc__)
parser.add_option('--pch', '--policy-constants-header', dest='header_path',
@@ -155,17 +177,20 @@ def main():
(opts, args) = parser.parse_args()
- if len(args) != 3:
- print 'exactly platform, chromium_os flag and input file must be specified.'
+ if len(args) != 4:
+ print('Please specify path to src/chrome/VERSION, platform, '
+ 'chromium_os flag and input file as positional parameters.')
parser.print_help()
return 2
- os = args[0]
- is_chromium_os = args[1] == '1'
- template_file_name = args[2]
+ version_path = args[0]
+ os = args[1]
+ is_chromium_os = args[2] == '1'
+ template_file_name = args[3]
+ major_version = ParseVersionFile(version_path)
template_file_contents = _LoadJSONFile(template_file_name)
- policy_details = [ PolicyDetails(policy, os, is_chromium_os)
+ policy_details = [ PolicyDetails(policy, major_version, os, is_chromium_os)
for policy in _Flatten(template_file_contents) ]
sorted_policy_details = sorted(policy_details, key=lambda policy: policy.name)