utils.py 881 B

12345678910111213141516171819202122232425
  1. # Copyright 2022 The Chromium Authors. All rights reserved.
  2. # Use of this source code is governed by a BSD-style license that can be
  3. # found in the LICENSE file.
  4. import os
  5. import subprocess
  6. def depot_tools_version():
  7. depot_tools_root = os.path.dirname(os.path.abspath(__file__))
  8. try:
  9. commit_hash = subprocess.check_output(['git', 'rev-parse', 'HEAD'],
  10. cwd=depot_tools_root).decode(
  11. 'utf-8', 'ignore')
  12. return 'git-%s' % commit_hash
  13. except Exception:
  14. pass
  15. # git check failed, let's check last modification of frequently checked file
  16. try:
  17. mtime = os.path.getmtime(
  18. os.path.join(depot_tools_root, 'infra', 'config', 'recipes.cfg'))
  19. return 'recipes.cfg-%d' % (mtime)
  20. except Exception:
  21. return 'unknown'