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.
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
):
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
):
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()
34 generator
= [input_api
.python_executable
,
35 CHARACTER_COMPOSER_DATA_GENERATOR
,
39 CHARACTER_COMPOSER_DATA_HEADER
] + CHARACTER_COMPOSER_DATA_SOURCES
41 generate
= input_api
.subprocess
.Popen(generator
,
43 stdout
=input_api
.subprocess
.PIPE
)
44 errors
= generate
.communicate()[0].strip()
46 results
+= [output_api
.PresubmitPromptOrNotify(
47 'compose data generator failed.',
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
+ '".')]
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
)