Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / ui / base / ime / chromeos / PRESUBMIT.py
blobed44dfbee6414ebece1eb2813df5631ddcde2cb9
1 # Copyright 2015 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
5 """Presubmit script for ui/base/ime/chromeos
7 See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts
8 for more details about the presubmit API built into depot_tools.
9 """
11 import filecmp
12 import os
14 CHARACTER_COMPOSER_DATA_SOURCES=['character_composer_sequences.txt']
15 CHARACTER_COMPOSER_DATA_HEADER='character_composer_data.h'
16 CHARACTER_COMPOSER_DATA_GENERATOR='generate_character_composer_data.py'
18 def CheckCharacterComposerData(input_api, output_api):
19 results = []
20 whereami = input_api.PresubmitLocalPath()
21 files = map(lambda x: input_api.os_path.join(whereami, x),
22 (CHARACTER_COMPOSER_DATA_SOURCES +
23 [CHARACTER_COMPOSER_DATA_HEADER,
24 CHARACTER_COMPOSER_DATA_GENERATOR]))
26 if not input_api.AffectedFiles(
27 file_filter=lambda x: x.AbsoluteLocalPath() in files):
28 return results
30 # Generate a copy of the data header and compare it with the current file,
31 # to ensure that it is not hand-editied and stays in sync with the sources.
32 (tempfd, tempname) = input_api.tempfile.mkstemp()
33 os.close(tempfd)
34 generator = [input_api.python_executable,
35 CHARACTER_COMPOSER_DATA_GENERATOR,
36 '--output',
37 tempname,
38 '--guard',
39 CHARACTER_COMPOSER_DATA_HEADER] + CHARACTER_COMPOSER_DATA_SOURCES
40 print(generator)
41 generate = input_api.subprocess.Popen(generator,
42 cwd=whereami,
43 stdout=input_api.subprocess.PIPE)
44 errors = generate.communicate()[0].strip()
45 if errors:
46 results += [output_api.PresubmitPromptOrNotify(
47 'compose data generator failed.',
48 errors.splitlines())]
49 elif not filecmp.cmp(tempname, CHARACTER_COMPOSER_DATA_HEADER):
50 results += [output_api.PresubmitPromptOrNotify(
51 'Generated compose data does not match "' +
52 CHARACTER_COMPOSER_DATA_HEADER + '".')]
53 print(tempname)
54 else:
55 os.remove(tempname)
56 return results
58 def CheckChangeOnCommit(input_api, output_api):
59 return CheckCharacterComposerData(input_api, output_api)
61 def CheckChangeOnUpload(input_api, output_api):
62 return CheckCharacterComposerData(input_api, output_api)