Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 #!/bin/sh | |
|
dcheng
2015/05/26 20:35:44
How will you handle this for Windows? Generate the
| |
| 2 # Copyright 2015 The Chromium Authors. All rights reserved. | |
| 3 # Use of this source code is governed by a BSD-style license that can be | |
| 4 # found in the LICENSE file. | |
| 5 # | |
| 6 # Fixes up includes in files which have been rewritten to use | |
| 7 # ThreadTaskRunnerHandle. | |
| 8 | |
| 9 set -e | |
| 10 | |
| 11 echo "Warning: This script throws away uncommitted changes!" | |
| 12 echo "Hit Ctrl-C now unless you know what you are doing." | |
| 13 read | |
| 14 | |
| 15 function modified_files { | |
| 16 git diff --numstat | awk "{print \$3;}" | |
| 17 } | |
| 18 | |
| 19 # Include TTRH instead of MLP. | |
| 20 #tools/git/mffr.py -f base/message_loop/message_loop_proxy[.]h \ | |
| 21 # base/thread_task_runner_handle.h | |
| 22 | |
| 23 # Add an include to files which use TTRH/STTR but don't include or forward | |
| 24 # declare it. | |
| 25 function is_missing_include { | |
| 26 local fn=$1 | |
| 27 local symbol=$2 | |
| 28 local include=$3 | |
| 29 | |
| 30 # If the .h for this .cc includes the header, don't add it again. | |
| 31 local header=${fn/.cc/.h} | |
| 32 if [ -f "$header" ]; then | |
| 33 if grep -q "$include" "$header"; then return 1; fi | |
| 34 fi | |
| 35 | |
| 36 grep -q "$symbol" "$fn" && \ | |
| 37 ! grep -q "$include" "$fn" && \ | |
| 38 ! grep -q "class $symbol;" "$fn" | |
| 39 } | |
| 40 | |
| 41 function add_missing_include { | |
| 42 local fn=$1 | |
| 43 local include=$2 | |
| 44 echo "Adding $include to $fn" | |
| 45 # Add the new header after the second #include "..." directive in the file. | |
| 46 awk "\$0 ~ /#include \"/ { n++ } | |
| 47 n == 2 && !done { | |
| 48 print \"#include \\\"$include\\\"\"; | |
| 49 done = 1 | |
| 50 } | |
| 51 { print }" "$fn" > "$fn.tmp" | |
| 52 mv "$fn.tmp" "$fn" | |
| 53 } | |
| 54 | |
| 55 # Fix forward declarations. | |
| 56 for f in $(modified_files); do | |
| 57 sed -i "s/class MessageLoopProxy;/class SingleThreadTaskRunner;/" "$f" | |
| 58 done | |
| 59 | |
| 60 # Remove base/message_loop/message_loop.h and message_loop_proxy.h includes. | |
| 61 for f in $(modified_files); do | |
| 62 sed -i "/#include \"base\/message_loop\/message_loop.h\"/d" "$f" | |
| 63 sed -i "/#include \"base\/message_loop\/message_loop_proxy.h\"/d" "$f" | |
| 64 done | |
| 65 | |
| 66 # Add fast paths for getting the task runner from a thread. | |
| 67 for f in $(modified_files); do | |
| 68 sed -i "s/message_loop()->task_runner()/task_runner()/" "$f" | |
| 69 done | |
| 70 | |
| 71 # Add missing includes to all the modified files. Process .h before .cc. | |
| 72 for f in $(modified_files | sort --reverse); do | |
| 73 if is_missing_include $f ThreadTaskRunnerHandle \ | |
| 74 base/thread_task_runner_handle[.]h; then | |
| 75 add_missing_include $f base/thread_task_runner_handle.h | |
| 76 fi | |
| 77 if is_missing_include $f SingleThreadTaskRunner \ | |
| 78 base/single_thread_task_runner[.]h; then | |
| 79 add_missing_include $f base/single_thread_task_runner.h | |
| 80 fi | |
| 81 if is_missing_include $f [^_]FROM_HERE \ | |
| 82 base/location[.]h; then | |
| 83 add_missing_include $f base/location.h | |
| 84 fi | |
| 85 if is_missing_include $f Post.*Task\( \ | |
| 86 base/single_thread_task_runner[.]h; then | |
| 87 add_missing_include $f base/single_thread_task_runner.h | |
| 88 fi | |
| 89 done | |
| 90 | |
| 91 # Hacks for specific files. | |
| 92 add_missing_include \ | |
| 93 cc/resources/texture_mailbox_deleter_unittest.cc \ | |
| 94 base/single_thread_task_runner.h | |
| 95 sed -i "s/origin_loop_(origin_loop)/origin_task_runner_(origin_task_runner)/" \ | |
| 96 cc/debug/micro_benchmark_impl.cc | |
| 97 sed -i "s/base::ThreadTaskRunnerHandle::Get().get()/\ | |
| 98 base::ThreadTaskRunnerHandle::Get()/" \ | |
| 99 cc/debug/micro_benchmark_controller.cc | |
| 100 | |
| 101 # Fix header sorting. | |
| 102 tools/sort-headers.py -f $(modified_files) > /dev/null | |
| 103 | |
| 104 # Revert any modifications in files that don't match the given pattern. | |
| 105 pattern=$1 | |
| 106 if [ -n "$pattern" ]; then | |
| 107 git checkout $(modified_files | grep -v "$pattern") | |
| 108 fi | |
| OLD | NEW |