api: include src/config when compiling proto definitions.
We have protos in infra/proto that include protos from src/config
now, notable build_report.proto and test_platform/v2/request.proto.
Chromite compiles bindings separately from infra/proto/generate.sh
so we need to add src/config as an include path here as well to
avoid breaking things.
If a local checkout isn't found, then clone to a temporary directory
and use that instead.
BUG=none
TEST=manual
Change-Id: If7a2b8e0f6fbe0c3cd1e0f59fa0f9f91fb668a0c
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/chromite/+/2919931
Auto-Submit: Sean McAllister <smcallis@google.com>
Tested-by: Sean McAllister <smcallis@google.com>
Commit-Queue: Sean McAllister <smcallis@google.com>
Reviewed-by: Mike Frysinger <vapier@chromium.org>
diff --git a/api/compile_build_api_proto.py b/api/compile_build_api_proto.py
index e55558c..a9cf206 100644
--- a/api/compile_build_api_proto.py
+++ b/api/compile_build_api_proto.py
@@ -9,11 +9,13 @@
import enum
import os
+import tempfile
from chromite.lib import commandline
from chromite.lib import constants
from chromite.lib import cros_build_lib
from chromite.lib import cros_logging as logging
+from chromite.lib import git
from chromite.lib import osutils
@@ -142,25 +144,40 @@
# We have a match, add the file.
targets.append(os.path.join(dirpath, filename))
- cmd = [
- _get_protoc_command(protoc_version),
- '--python_out',
- output,
- '--proto_path',
- source,
- ]
- cmd.extend(targets)
+ chromeos_config_path = os.path.realpath(
+ os.path.join(constants.SOURCE_ROOT, 'src/config'))
- result = cros_build_lib.run(
- cmd,
- cwd=source,
- print_cmd=False,
- check=False,
- enter_chroot=protoc_version is ProtocVersion.SDK)
+ with tempfile.TemporaryDirectory() as tempdir:
+ if not os.path.exists(chromeos_config_path):
+ chromeos_config_path = os.path.join(tempdir, 'config')
- if result.returncode:
- raise GenerationError('Error compiling the proto. See the output for a '
- 'message.')
+ logging.info('Creating shallow clone of chromiumos/config')
+ git.Clone(chromeos_config_path,
+ '%s/chromiumos/config' % constants.EXTERNAL_GOB_URL,
+ depth=1
+ )
+
+ cmd = [
+ _get_protoc_command(protoc_version),
+ '-I',
+ os.path.join(chromeos_config_path, 'proto'),
+ '--python_out',
+ output,
+ '--proto_path',
+ source,
+ ]
+ cmd.extend(targets)
+
+ result = cros_build_lib.run(
+ cmd,
+ cwd=source,
+ print_cmd=False,
+ check=False,
+ enter_chroot=protoc_version is ProtocVersion.SDK)
+
+ if result.returncode:
+ raise GenerationError('Error compiling the proto. See the output for a '
+ 'message.')
def _InstallMissingInits(directory):