OLD | NEW |
(Empty) | |
| 1 #!/bin/sh |
| 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 # Fix header sorting. |
| 92 tools/sort-headers.py -f $(modified_files) > /dev/null |
| 93 |
| 94 # Revert any modifications in files that don't match the given pattern. |
| 95 pattern=$1 |
| 96 if [ -n "$pattern" ]; then |
| 97 git checkout $(modified_files | grep -v "$pattern") |
| 98 fi |
OLD | NEW |