1#!/usr/bin/python2
2
3# Copyright 2018 The Chromium Authors. All rights reserved.
4# Use of this source code is governed by a BSD-style license that can be
5# found in the LICENSE file.
6"""Compile policy protobuf Python files.
7
8The policy protos are used by a bunch of policy_* and login_* autotests, as well
9as policy_testserver.py in the Chromium code base. policy_descriptor.proto is
10used by session_manager.py to store and retrieve policy from/to disk.
11"""
12
13import os
14import pipes
15from autotest_lib.client.bin import utils
16
17version = 2
18
19# cloud_policy.proto and chrome_extension_policy.proto are unreferenced here,
20# but used by policy_testserver.py in the Chromium code base, so don't remote
21# them!
22PROTO_PATHS = [
23        'usr/share/protofiles/chrome_device_policy.proto',
24        'usr/share/protofiles/policy_common_definitions.proto',
25        'usr/share/protofiles/device_management_backend.proto',
26        'usr/share/protofiles/cloud_policy.proto',
27        'usr/share/protofiles/chrome_extension_policy.proto',
28        'usr/include/chromeos/dbus/login_manager/policy_descriptor.proto',
29]
30
31def setup(top_dir):
32    sysroot = os.environ['SYSROOT']
33    dirs = set(os.path.dirname(p) for p in PROTO_PATHS)
34    include_args = ['--proto_path=' + os.path.join(sysroot, d) for d in dirs]
35    proto_paths = [os.path.join(sysroot, p) for p in PROTO_PATHS]
36    cmd = ['protoc', '--python_out=' + top_dir] + include_args + proto_paths
37    utils.run(' '.join(pipes.quote(arg) for arg in cmd))
38    return
39
40
41pwd = os.getcwd()
42utils.update_version(os.path.join(pwd, 'src'), False, version, setup, pwd)
43