prepare_framework_version.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. # Copyright 2016 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 shutil
  6. import sys
  7. # Ensures that the current version matches the last-produced version, which is
  8. # stored in the version_file. If it does not, then the framework_root_dir is
  9. # obliterated.
  10. # Usage: python prepare_framework_version.py out/obj/version_file \
  11. # out/Framework.framework \
  12. # 'A'
  13. def PrepareFrameworkVersion(version_file, framework_root_dir, version):
  14. # Test what the current framework version is. Stop if it is up-to-date.
  15. try:
  16. with open(version_file, 'r') as f:
  17. current_version = f.read()
  18. if current_version == version:
  19. return
  20. except IOError:
  21. pass
  22. # The framework version has changed, so clobber the framework.
  23. if os.path.exists(framework_root_dir):
  24. shutil.rmtree(framework_root_dir)
  25. # Write out the new framework version file, making sure its containing
  26. # directory exists.
  27. dirname = os.path.dirname(version_file)
  28. if not os.path.isdir(dirname):
  29. os.makedirs(dirname, 0o700)
  30. with open(version_file, 'w+') as f:
  31. f.write(version)
  32. if __name__ == '__main__':
  33. PrepareFrameworkVersion(sys.argv[1], sys.argv[2], sys.argv[3])
  34. sys.exit(0)