1# Copyright 2016 The Chromium Authors 2# Use of this source code is governed by a BSD-style license that can be 3# found in the LICENSE file. 4 5import os 6import shutil 7import sys 8 9# Ensures that the current version matches the last-produced version, which is 10# stored in the version_file. If it does not, then the framework_root_dir is 11# obliterated. 12# Usage: python prepare_framework_version.py out/obj/version_file \ 13# out/Framework.framework \ 14# 'A' 15 16def PrepareFrameworkVersion(version_file, framework_root_dir, version): 17 # Test what the current framework version is. Stop if it is up-to-date. 18 try: 19 with open(version_file, 'r') as f: 20 current_version = f.read() 21 if current_version == version: 22 return 23 except IOError: 24 pass 25 26 # The framework version has changed, so clobber the framework. 27 if os.path.exists(framework_root_dir): 28 shutil.rmtree(framework_root_dir) 29 30 # Write out the new framework version file, making sure its containing 31 # directory exists. 32 dirname = os.path.dirname(version_file) 33 if not os.path.isdir(dirname): 34 os.makedirs(dirname, 0o700) 35 36 with open(version_file, 'w+') as f: 37 f.write(version) 38 39 40if __name__ == '__main__': 41 PrepareFrameworkVersion(sys.argv[1], sys.argv[2], sys.argv[3]) 42 sys.exit(0) 43