1#!/usr/bin/env python 2# 3# Copyright (C) 2012 The Android Open Source Project 4# 5# Licensed under the Apache License, Version 2.0 (the "License"); 6# you may not use this file except in compliance with the License. 7# You may obtain a copy of the License at 8# 9# http://www.apache.org/licenses/LICENSE-2.0 10# 11# Unless required by applicable law or agreed to in writing, software 12# distributed under the License is distributed on an "AS IS" BASIS, 13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14# See the License for the specific language governing permissions and 15# limitations under the License. 16 17""" 18Prints to stdout the package names that have overlay changes between 19current_overlays.txt and previous_overlays.txt. 20 21Usage: diff_package_overlays.py <current_packages.txt> <current_overlays.txt> <previous_overlays.txt> 22current_packages.txt contains all package names separated by space in the current build. 23This script modfies current_packages.txt if necessary: if there is a package in 24previous_overlays.txt but absent from current_packages.txt, we copy that line 25from previous_overlays.txt over to current_packages.txt. Usually that means we 26just don't care that package in the current build (for example we are switching 27from a full build to a partial build with mm/mmm), and we should carry on the 28previous overlay config so current_overlays.txt always reflects the current 29status of the entire tree. 30 31Format of current_overlays.txt and previous_overlays.txt: 32 <package_name> <resource_overlay> [resource_overlay ...] 33 <package_name> <resource_overlay> [resource_overlay ...] 34 ... 35""" 36 37import sys 38 39def main(argv): 40 if len(argv) != 4: 41 print >> sys.stderr, __doc__ 42 sys.exit(1) 43 44 f = open(argv[1]) 45 all_packages = set(f.read().split()) 46 f.close() 47 48 def load_overlay_config(filename): 49 f = open(filename) 50 result = {} 51 for line in f: 52 line = line.strip() 53 if not line or line.startswith("#"): 54 continue 55 words = line.split() 56 result[words[0]] = " ".join(words[1:]) 57 f.close() 58 return result 59 60 current_overlays = load_overlay_config(argv[2]) 61 previous_overlays = load_overlay_config(argv[3]) 62 63 result = [] 64 carryon = [] 65 for p in current_overlays: 66 if p not in previous_overlays: 67 result.append(p) 68 elif current_overlays[p] != previous_overlays[p]: 69 result.append(p) 70 for p in previous_overlays: 71 if p not in current_overlays: 72 if p in all_packages: 73 # overlay changed 74 result.append(p) 75 else: 76 # we don't build p in the current build. 77 carryon.append(p) 78 79 # Add carryon to the current overlay config file. 80 if carryon: 81 f = open(argv[2], "a") 82 for p in carryon: 83 f.write(p + " " + previous_overlays[p] + "\n") 84 f.close() 85 86 # Print out the package names that have overlay change. 87 for r in result: 88 print r 89 90if __name__ == "__main__": 91 main(sys.argv) 92