blob: 723c35e2bb8f245377b811323d933767884d4897 [file] [log] [blame]
Lalit Magantie87838f2019-06-25 18:31:49 +01001#!/usr/bin/env python
2# Copyright (C) 2019 The Android Open Source Project
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
Lalit Magantie87838f2019-06-25 18:31:49 +010015"""Script to wrap protoc execution.
16
17This script exists to work-around the bad depfile generation by protoc when
18generating descriptors."""
19
20from __future__ import print_function
21import argparse
22import os
23import sys
24import subprocess
25import tempfile
26
Matthew Clarkson9a5dfa52019-10-03 09:54:04 +010027from codecs import open
28
Primiano Tucci834fdc72019-10-04 11:33:44 +010029
Lalit Magantie87838f2019-06-25 18:31:49 +010030def main():
31 parser = argparse.ArgumentParser()
32 parser.add_argument('--descriptor_set_out', default=None)
33 parser.add_argument('--dependency_out', default=None)
34 parser.add_argument('protoc')
35 args, remaining = parser.parse_known_args()
36
37 if args.dependency_out and args.descriptor_set_out:
38 with tempfile.NamedTemporaryFile() as t:
39 custom = [
Primiano Tucci834fdc72019-10-04 11:33:44 +010040 '--descriptor_set_out', args.descriptor_set_out, '--dependency_out',
41 t.name
Lalit Magantie87838f2019-06-25 18:31:49 +010042 ]
Matthew Clarkson9a5dfa52019-10-03 09:54:04 +010043 subprocess.check_call([args.protoc] + custom + remaining)
Lalit Magantie87838f2019-06-25 18:31:49 +010044
Matthew Clarkson9a5dfa52019-10-03 09:54:04 +010045 dependency_data = t.read().decode('utf-8')
Lalit Magantie87838f2019-06-25 18:31:49 +010046
Primiano Tucci834fdc72019-10-04 11:33:44 +010047 with open(args.dependency_out, 'w', encoding='utf-8') as f:
Lalit Magantie87838f2019-06-25 18:31:49 +010048 f.write(args.descriptor_set_out + ":")
49 f.write(dependency_data)
50 else:
Matthew Clarkson9a5dfa52019-10-03 09:54:04 +010051 subprocess.check_call(sys.argv[1:])
Lalit Magantie87838f2019-06-25 18:31:49 +010052
Primiano Tucci834fdc72019-10-04 11:33:44 +010053
Lalit Magantie87838f2019-06-25 18:31:49 +010054if __name__ == '__main__':
55 sys.exit(main())