[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1 | # Copyright (c) 2012 Google Inc. 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 | |
| 5 | import os |
| 6 | import re |
| 7 | import shutil |
| 8 | |
| 9 | prefixes = ["../third_party/WebKit/Source/WebCore/platform/graphics/chromium", |
| 10 | "../third_party/WebKit/Source/WebCore/platform/graphics/chromium/cc", |
| 11 | "../third_party/WebKit/Source/WebKit/chromium/tests"] |
| 12 | |
| 13 | def Copy(name): |
| 14 | src = name |
| 15 | dst = name |
| 16 | if name.startswith("test/"): |
| 17 | src = src[5:] |
| 18 | fullsrc = "" |
| 19 | for prefix in prefixes: |
| 20 | candidate = "%s/%s" % (prefix, src) |
| 21 | if os.path.exists(candidate): |
| 22 | fullsrc = candidate |
| 23 | break |
| 24 | assert fullsrc != "" |
| 25 | shutil.copyfile(fullsrc, dst) |
| 26 | print "copying from %s to %s" % (fullsrc, dst) |
| 27 | return dst |
| 28 | |
| 29 | def FixCopyrightHeaderText(text, year): |
| 30 | header_template = """// Copyright %s The Chromium Authors. All rights reserved. |
| 31 | // Use of this source code is governed by a BSD-style license that can be |
| 32 | // found in the LICENSE file. |
| 33 | """ |
| 34 | |
| 35 | while text[0].find(" */") == -1: |
| 36 | text = text[1:] |
| 37 | text = text[1:] |
| 38 | |
| 39 | return (header_template % year) + "".join(text) |
| 40 | |
| 41 | def FixCopyrightHeader(filepath): |
| 42 | with open(filepath, "r") as f: |
| 43 | text = f.readlines() |
| 44 | |
| 45 | if filepath.endswith("CCPageScaleAnimation.cpp"): |
| 46 | year = 2012 |
| 47 | else: |
| 48 | pattern = ".*Copyright \(C\) (20[01][0-9])" |
| 49 | m = re.match(pattern, text[0]) |
| 50 | if m == None: |
| 51 | m = re.match(pattern, text[1]) |
| 52 | assert m |
| 53 | year = m.group(1) |
| 54 | |
| 55 | fixed_text = FixCopyrightHeaderText(text, year) |
| 56 | with open(filepath, "w") as f: |
| 57 | f.write(fixed_text) |
| 58 | |
| 59 | def Readfile(gypfile): |
| 60 | with open(gypfile, "r") as cc_gyp: |
| 61 | obj = eval(cc_gyp.read()) |
| 62 | return obj |
| 63 | |
[email protected] | c0dd24c | 2012-08-30 23:25:27 | [diff] [blame] | 64 | def CopyFiles(files): |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 65 | for f in files: |
| 66 | dst = Copy(f) |
| 67 | FixCopyrightHeader(dst) |
| 68 | |
[email protected] | c0dd24c | 2012-08-30 23:25:27 | [diff] [blame] | 69 | def Main(): |
| 70 | CopyFiles(Readfile("cc.gyp")['variables']['cc_source_files']) |
| 71 | CopyFiles(Readfile("cc_tests.gyp")['variables']['cc_tests_source_files']) |
| 72 | CopyFiles(Readfile("cc_tests.gyp")['variables']['cc_tests_support_files']) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 73 | |
| 74 | if __name__ == '__main__': |
| 75 | import sys |
| 76 | os.chdir(os.path.dirname(__file__)) |
| 77 | sys.exit(Main()) |