| Index: tools/clang/refactor_message_loop/update_task_runner_headers.sh
|
| diff --git a/tools/clang/refactor_message_loop/update_task_runner_headers.sh b/tools/clang/refactor_message_loop/update_task_runner_headers.sh
|
| new file mode 100755
|
| index 0000000000000000000000000000000000000000..a7f4cb2fcbc8a1a59424af18046d8fc759369ad0
|
| --- /dev/null
|
| +++ b/tools/clang/refactor_message_loop/update_task_runner_headers.sh
|
| @@ -0,0 +1,108 @@
|
| +#!/bin/sh
|
| +# Copyright 2015 The Chromium Authors. All rights reserved.
|
| +# Use of this source code is governed by a BSD-style license that can be
|
| +# found in the LICENSE file.
|
| +#
|
| +# Fixes up includes in files which have been rewritten to use
|
| +# ThreadTaskRunnerHandle.
|
| +
|
| +set -e
|
| +
|
| +echo "Warning: This script throws away uncommitted changes!"
|
| +echo "Hit Ctrl-C now unless you know what you are doing."
|
| +read
|
| +
|
| +function modified_files {
|
| + git diff --numstat | awk "{print \$3;}"
|
| +}
|
| +
|
| +# Include TTRH instead of MLP.
|
| +#tools/git/mffr.py -f base/message_loop/message_loop_proxy[.]h \
|
| +# base/thread_task_runner_handle.h
|
| +
|
| +# Add an include to files which use TTRH/STTR but don't include or forward
|
| +# declare it.
|
| +function is_missing_include {
|
| + local fn=$1
|
| + local symbol=$2
|
| + local include=$3
|
| +
|
| + # If the .h for this .cc includes the header, don't add it again.
|
| + local header=${fn/.cc/.h}
|
| + if [ -f "$header" ]; then
|
| + if grep -q "$include" "$header"; then return 1; fi
|
| + fi
|
| +
|
| + grep -q "$symbol" "$fn" && \
|
| + ! grep -q "$include" "$fn" && \
|
| + ! grep -q "class $symbol;" "$fn"
|
| +}
|
| +
|
| +function add_missing_include {
|
| + local fn=$1
|
| + local include=$2
|
| + echo "Adding $include to $fn"
|
| + # Add the new header after the second #include "..." directive in the file.
|
| + awk "\$0 ~ /#include \"/ { n++ }
|
| + n == 2 && !done {
|
| + print \"#include \\\"$include\\\"\";
|
| + done = 1
|
| + }
|
| + { print }" "$fn" > "$fn.tmp"
|
| + mv "$fn.tmp" "$fn"
|
| +}
|
| +
|
| +# Fix forward declarations.
|
| +for f in $(modified_files); do
|
| + sed -i "s/class MessageLoopProxy;/class SingleThreadTaskRunner;/" "$f"
|
| +done
|
| +
|
| +# Remove base/message_loop/message_loop.h and message_loop_proxy.h includes.
|
| +for f in $(modified_files); do
|
| + sed -i "/#include \"base\/message_loop\/message_loop.h\"/d" "$f"
|
| + sed -i "/#include \"base\/message_loop\/message_loop_proxy.h\"/d" "$f"
|
| +done
|
| +
|
| +# Add fast paths for getting the task runner from a thread.
|
| +for f in $(modified_files); do
|
| + sed -i "s/message_loop()->task_runner()/task_runner()/" "$f"
|
| +done
|
| +
|
| +# Add missing includes to all the modified files. Process .h before .cc.
|
| +for f in $(modified_files | sort --reverse); do
|
| + if is_missing_include $f ThreadTaskRunnerHandle \
|
| + base/thread_task_runner_handle[.]h; then
|
| + add_missing_include $f base/thread_task_runner_handle.h
|
| + fi
|
| + if is_missing_include $f SingleThreadTaskRunner \
|
| + base/single_thread_task_runner[.]h; then
|
| + add_missing_include $f base/single_thread_task_runner.h
|
| + fi
|
| + if is_missing_include $f [^_]FROM_HERE \
|
| + base/location[.]h; then
|
| + add_missing_include $f base/location.h
|
| + fi
|
| + if is_missing_include $f Post.*Task\( \
|
| + base/single_thread_task_runner[.]h; then
|
| + add_missing_include $f base/single_thread_task_runner.h
|
| + fi
|
| +done
|
| +
|
| +# Hacks for specific files.
|
| +add_missing_include \
|
| + cc/resources/texture_mailbox_deleter_unittest.cc \
|
| + base/single_thread_task_runner.h
|
| +sed -i "s/origin_loop_(origin_loop)/origin_task_runner_(origin_task_runner)/" \
|
| + cc/debug/micro_benchmark_impl.cc
|
| +sed -i "s/base::ThreadTaskRunnerHandle::Get().get()/\
|
| +base::ThreadTaskRunnerHandle::Get()/" \
|
| + cc/debug/micro_benchmark_controller.cc
|
| +
|
| +# Fix header sorting.
|
| +tools/sort-headers.py -f $(modified_files) > /dev/null
|
| +
|
| +# Revert any modifications in files that don't match the given pattern.
|
| +pattern=$1
|
| +if [ -n "$pattern" ]; then
|
| + git checkout $(modified_files | grep -v "$pattern")
|
| +fi
|
|
|