mirror of
https://chromium.googlesource.com/chromium/tools/depot_tools.git
synced 2026-01-11 18:51:29 +00:00
autoninja: cache negative result of gcloud account check
This is to remove 1~3 seconds from no-op build using autoninja. Bug: b/309720176 Change-Id: I2c15a43517d5a99eae794015c18c884a3f3fdef4 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/5092847 Commit-Queue: Takuto Ikuta <tikuta@chromium.org> Reviewed-by: Philipp Wollermann <philwo@chromium.org> Reviewed-by: Scott Lee <ddoman@chromium.org>
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -101,3 +101,6 @@ testing_support/google_appengine
|
||||
|
||||
# Ignore the file that logs Python 2 scripts run during presubmits.
|
||||
/python2_usage.txt
|
||||
|
||||
# Ignore the internal data used by autoninja.
|
||||
/.autoninja*
|
||||
19
autoninja.py
19
autoninja.py
@@ -19,10 +19,12 @@ import multiprocessing
|
||||
import os
|
||||
import platform
|
||||
import re
|
||||
import shelve
|
||||
import shlex
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
import time
|
||||
import warnings
|
||||
|
||||
import google.auth
|
||||
@@ -103,16 +105,29 @@ def _is_google_corp_machine_using_external_account():
|
||||
if not _is_google_corp_machine():
|
||||
return False
|
||||
|
||||
with shelve.open(os.path.join(SCRIPT_DIR, ".autoninja")) as db:
|
||||
last_false = db.get("last_false")
|
||||
now = time.time()
|
||||
if last_false is not None and now < last_false + 12 * 60 * 60:
|
||||
# Do not check account if it is checked in last 12 hours.
|
||||
return False
|
||||
|
||||
account = _adc_account()
|
||||
if account and not account.endswith("@google.com"):
|
||||
return True
|
||||
|
||||
account = _gcloud_auth_account()
|
||||
if not account:
|
||||
db["last_false"] = now
|
||||
return False
|
||||
|
||||
# Handle service account and google account as internal account.
|
||||
return not (account.endswith("@google.com")
|
||||
or account.endswith("gserviceaccount.com"))
|
||||
if not (account.endswith("@google.com")
|
||||
or account.endswith("gserviceaccount.com")):
|
||||
return True
|
||||
|
||||
db["last_false"] = now
|
||||
return False
|
||||
|
||||
|
||||
def _quote_for_cmd(arg):
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
# Use of this source code is governed by a BSD-style license that can be
|
||||
# found in the LICENSE file.
|
||||
|
||||
import glob
|
||||
import multiprocessing
|
||||
import os
|
||||
import os.path
|
||||
@@ -165,6 +166,11 @@ class AutoninjaTest(trial_dir.TestCase):
|
||||
adc_account,
|
||||
gcloud_auth_account,
|
||||
expected):
|
||||
for shelve_file in glob.glob(
|
||||
os.path.join(autoninja.SCRIPT_DIR, ".autoninja*")):
|
||||
# Clear cache.
|
||||
os.remove(shelve_file)
|
||||
|
||||
with mock.patch('autoninja._is_google_corp_machine',
|
||||
return_value=is_corp), mock.patch(
|
||||
'autoninja._adc_account',
|
||||
|
||||
Reference in New Issue
Block a user