blob: 7f83befee3ad34eaf2a106417d8508fee9cd9463 [file] [log] [blame]
#!/usr/bin/env python
# Copyright (C) 2019 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Script to wrap protoc execution.
This script exists to work-around the bad depfile generation by protoc when
generating descriptors."""
from __future__ import print_function
import argparse
import os
import sys
import subprocess
import tempfile
def main():
parser = argparse.ArgumentParser()
parser.add_argument('--descriptor_set_out', default=None)
parser.add_argument('--dependency_out', default=None)
parser.add_argument('protoc')
args, remaining = parser.parse_known_args()
if args.dependency_out and args.descriptor_set_out:
with tempfile.NamedTemporaryFile() as t:
custom = [
'--descriptor_set_out',
args.descriptor_set_out,
'--dependency_out',
t.name
]
subprocess.call([args.protoc] + custom + remaining)
dependency_data = t.read()
with open(args.dependency_out, 'w') as f:
f.write(args.descriptor_set_out + ":")
f.write(dependency_data)
else:
subprocess.call(sys.argv[1:])
if __name__ == '__main__':
sys.exit(main())