api: do not die when goma log directory doesn't exist
Previously when the goma logs directory did not exist, the whole build
ended unconditionally. But it seems to be too strict. This CL makes
such case non-critical by printing a warning instead of dying.
Also this CL checks more candidates of goma logs directory: previously
checking only GLOG_log_dir, but additionally TEST_TMPDIR, TMNPDIR and
TMP.
BUG=b:207806193
TEST=Ran `./run_tests api/controller/sysroot_unittest.py`
Change-Id: Icec547850d384cf932a2b63b8bae77975a7c9283
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/chromite/+/3343512
Reviewed-by: Fumitoshi Ukai <ukai@google.com>
Auto-Submit: Yoshiki Iguchi <yoshiki@chromium.org>
Reviewed-by: Mike Frysinger <vapier@chromium.org>
Reviewed-by: Alex Klein <saklein@chromium.org>
Tested-by: Yoshiki Iguchi <yoshiki@chromium.org>
Commit-Queue: Yoshiki Iguchi <yoshiki@chromium.org>
diff --git a/api/controller/sysroot.py b/api/controller/sysroot.py
index 765472a..2361071 100644
--- a/api/controller/sysroot.py
+++ b/api/controller/sysroot.py
@@ -28,6 +28,26 @@
_ACCEPTED_LICENSES = '@CHROMEOS'
+def _GetGomaLogDirectory():
+ """Get goma's log directory based on the env variables.
+
+ Returns:
+ a string of a directory name where goma's log may exist, or None if no
+ potential directories exist.
+ """
+ # TODO(crbug.com/1045001): Replace environment variable with query to
+ # goma object after goma refactoring allows this.
+ candidates = [
+ 'GLOG_log_dir', 'GOOGLE_LOG_DIR', 'TEST_TMPDIR', 'TMPDIR', 'TMP']
+ for candidate in candidates:
+ value = os.environ.get(candidate)
+ if value and os.path.isdir(value):
+ return value
+
+ # "/tmp" will always exist.
+ return '/tmp'
+
+
def ExampleGetResponse():
"""Give an example response to assemble upstream in caller artifacts."""
uabs = common_pb2.UploadedArtifactsByService
@@ -279,12 +299,7 @@
# Copy goma logs to specified directory if there is a goma_config and
# it contains a log_dir to store artifacts.
if input_proto.goma_config.log_dir.dir:
- # Get the goma log directory based on the GLOG_log_dir env variable.
- # TODO(crbug.com/1045001): Replace environment variable with query to
- # goma object after goma refactoring allows this.
- log_source_dir = os.getenv('GLOG_log_dir')
- if not log_source_dir:
- cros_build_lib.Die('GLOG_log_dir must be defined.')
+ log_source_dir = _GetGomaLogDirectory()
archiver = goma_lib.LogsArchiver(
log_source_dir,
dest_dir=input_proto.goma_config.log_dir.dir,