diff --git a/migrate_cpp/migrate_cpp.py b/migrate_cpp/migrate_cpp.py index efc584668579..81d3ce72965b 100644 --- a/migrate_cpp/migrate_cpp.py +++ b/migrate_cpp/migrate_cpp.py @@ -79,7 +79,7 @@ class _Workflow(object): with open(self._data_file("clang_tidy.yaml")) as f: config = f.read() subprocess.run( - ["clang-tidy", "--fix", "--config", config] + self._cpp_files, + ["run-clang-tidy.py", "-fix", "-config", config], check=True, ) diff --git a/third_party/examples/woff2/carbon/include/woff2/decode.carbon b/third_party/examples/woff2/carbon/include/woff2/decode.carbon index 49f0fb0ac4f8..6d350dcd9b48 100644 --- a/third_party/examples/woff2/carbon/include/woff2/decode.carbon +++ b/third_party/examples/woff2/carbon/include/woff2/decode.carbon @@ -9,10 +9,11 @@ #ifndef WOFF2_WOFF2_DEC_H_ #define WOFF2_WOFF2_DEC_H_ -#include -#include #include +#include +#include + namespace woff2 { // Compute the size of the final uncompressed font, or 0 on error. diff --git a/third_party/examples/woff2/carbon/include/woff2/encode.carbon b/third_party/examples/woff2/carbon/include/woff2/encode.carbon index 10db7f42844d..93a45ae3132a 100644 --- a/third_party/examples/woff2/carbon/include/woff2/encode.carbon +++ b/third_party/examples/woff2/carbon/include/woff2/encode.carbon @@ -9,8 +9,8 @@ #ifndef WOFF2_WOFF2_ENC_H_ #define WOFF2_WOFF2_ENC_H_ -#include #include +#include #include namespace woff2 { diff --git a/third_party/examples/woff2/carbon/src/buffer.carbon b/third_party/examples/woff2/carbon/src/buffer.carbon index 54ba12bc79a9..a72e71fc5d25 100644 --- a/third_party/examples/woff2/carbon/src/buffer.carbon +++ b/third_party/examples/woff2/carbon/src/buffer.carbon @@ -26,6 +26,7 @@ typedef unsigned __int64 uint64_t; #define htons(x) _byteswap_ushort (x) #else #include + #include #endif diff --git a/third_party/examples/woff2/carbon/src/convert_woff2ttf_fuzzer.impl.carbon b/third_party/examples/woff2/carbon/src/convert_woff2ttf_fuzzer.impl.carbon index 696edf9f407a..c555dfb7235e 100644 --- a/third_party/examples/woff2/carbon/src/convert_woff2ttf_fuzzer.impl.carbon +++ b/third_party/examples/woff2/carbon/src/convert_woff2ttf_fuzzer.impl.carbon @@ -1,8 +1,8 @@ +#include + #include #include -#include - // Entry point for LibFuzzer. extern "C" fn LLVMFuzzerTestOneInput(data: const uint8_t*, size: size_t) -> int { var buf: std::string; diff --git a/third_party/examples/woff2/carbon/src/font.carbon b/third_party/examples/woff2/carbon/src/font.carbon index 7a1ade81c26b..ac7df3ac7c68 100644 --- a/third_party/examples/woff2/carbon/src/font.carbon +++ b/third_party/examples/woff2/carbon/src/font.carbon @@ -10,8 +10,8 @@ #ifndef WOFF2_FONT_H_ #define WOFF2_FONT_H_ -#include #include +#include #include #include diff --git a/third_party/examples/woff2/carbon/src/glyph.carbon b/third_party/examples/woff2/carbon/src/glyph.carbon index ec33d638ee90..89dc3cedfb67 100644 --- a/third_party/examples/woff2/carbon/src/glyph.carbon +++ b/third_party/examples/woff2/carbon/src/glyph.carbon @@ -10,8 +10,8 @@ #ifndef WOFF2_GLYPH_H_ #define WOFF2_GLYPH_H_ -#include #include +#include #include namespace woff2 { diff --git a/third_party/examples/woff2/carbon/src/glyph.impl.carbon b/third_party/examples/woff2/carbon/src/glyph.impl.carbon index 754a116cc858..e60f6a1b42ec 100644 --- a/third_party/examples/woff2/carbon/src/glyph.impl.carbon +++ b/third_party/examples/woff2/carbon/src/glyph.impl.carbon @@ -10,6 +10,7 @@ #include #include + #include "./buffer.h" #include "./store_bytes.h" diff --git a/third_party/examples/woff2/carbon/src/normalize.impl.carbon b/third_party/examples/woff2/carbon/src/normalize.impl.carbon index 2b573ba0c566..a1407462731f 100644 --- a/third_party/examples/woff2/carbon/src/normalize.impl.carbon +++ b/third_party/examples/woff2/carbon/src/normalize.impl.carbon @@ -12,9 +12,9 @@ #include #include "./buffer.h" -#include "./port.h" #include "./font.h" #include "./glyph.h" +#include "./port.h" #include "./round.h" #include "./store_bytes.h" #include "./table_tags.h" diff --git a/third_party/examples/woff2/carbon/src/variable_length.carbon b/third_party/examples/woff2/carbon/src/variable_length.carbon index 66f16d99b934..603347b8d2ab 100644 --- a/third_party/examples/woff2/carbon/src/variable_length.carbon +++ b/third_party/examples/woff2/carbon/src/variable_length.carbon @@ -11,6 +11,7 @@ #include #include + #include "./buffer.h" namespace woff2 { diff --git a/third_party/examples/woff2/carbon/src/woff2_common.carbon b/third_party/examples/woff2/carbon/src/woff2_common.carbon index af7f59ad48ef..d4798d1f17fa 100644 --- a/third_party/examples/woff2/carbon/src/woff2_common.carbon +++ b/third_party/examples/woff2/carbon/src/woff2_common.carbon @@ -9,9 +9,8 @@ #ifndef WOFF2_WOFF2_COMMON_H_ #define WOFF2_WOFF2_COMMON_H_ -#include #include - +#include #include namespace woff2 { diff --git a/third_party/examples/woff2/carbon/src/woff2_dec.impl.carbon b/third_party/examples/woff2/carbon/src/woff2_dec.impl.carbon index 07496bfc989f..a9ab3d09cf03 100644 --- a/third_party/examples/woff2/carbon/src/woff2_dec.impl.carbon +++ b/third_party/examples/woff2/carbon/src/woff2_dec.impl.carbon @@ -6,21 +6,20 @@ /* Library for converting WOFF2 format font files to their TTF versions. */ +#include #include -#include #include #include +#include #include #include -#include -#include -#include #include #include +#include #include +#include -#include #include "./buffer.h" #include "./port.h" #include "./round.h" diff --git a/third_party/examples/woff2/carbon/src/woff2_enc.impl.carbon b/third_party/examples/woff2/carbon/src/woff2_enc.impl.carbon index 29ab963375e7..ad63cdd80610 100644 --- a/third_party/examples/woff2/carbon/src/woff2_enc.impl.carbon +++ b/third_party/examples/woff2/carbon/src/woff2_enc.impl.carbon @@ -6,16 +6,16 @@ /* Library for converting TTF format font files to their WOFF2 versions. */ +#include #include -#include #include +#include #include #include #include #include -#include #include "./buffer.h" #include "./font.h" #include "./normalize.h" diff --git a/third_party/examples/woff2/migrate_cpp.sh b/third_party/examples/woff2/migrate_cpp.sh index 03f08dbf310b..cf700129d0f3 100755 --- a/third_party/examples/woff2/migrate_cpp.sh +++ b/third_party/examples/woff2/migrate_cpp.sh @@ -9,7 +9,7 @@ # cd to the carbon-lang root. cd "$(dirname "$0")/../../.." -EXAMPLE=third_party/examples/woff2 +EXAMPLE="${PWD}/third_party/examples/woff2" # Remove any previous conversion. Each time this is run, it should demonstrate # on a fresh copy of woff2. @@ -26,18 +26,36 @@ cp "${EXAMPLE}/BUILD.original" \ "${EXAMPLE}/carbon/BUILD" cp "${EXAMPLE}/WORKSPACE.original" \ "${EXAMPLE}/carbon/WORKSPACE" -cp "${EXAMPLE}/compile_flags.carbon.txt" \ - "${EXAMPLE}/carbon/compile_flags.txt" # Kludge for adding LLVM include paths into the compile flags. # TODO: Find better solution. +COMPILE_FLAGS=($(cat "${EXAMPLE}/compile_flags.carbon.txt" | sed 's/"/\\"/g')) for x in $( clang++ -Wp,-v -xc++ -stdlib=libc++ - -fsyntax-only < /dev/null 2>&1 | grep /llvm/); do - echo "-isystem" >> "${EXAMPLE}/carbon/compile_flags.txt" - echo "${x}" >> "${EXAMPLE}/carbon/compile_flags.txt" + COMPILE_FLAGS+=("-isystem") + COMPILE_FLAGS+=("${x}") done +# Construct a compilation database for use by run-clang-tidy.py. +COMPDB="${EXAMPLE}/carbon/compile_commands.json" +echo "[" > "${COMPDB}" +for f in $(find "${EXAMPLE}/carbon" -regex ".*\.\(cc\|h\)"); do + echo "{ \"file\": \"$(realpath --relative-to "${EXAMPLE}/carbon" ${f})\"," >> "${COMPDB}" + echo " \"directory\": \"${EXAMPLE}/carbon\"," >> "${COMPDB}" + echo " \"arguments\": [" >> "${COMPDB}" + echo " \"clang++\"," >> "${COMPDB}" + for index in ${!COMPILE_FLAGS[@]}; do + echo " \"${COMPILE_FLAGS[$index]}\"," >> "${COMPDB}" + done + echo " \"${f}\"" >> "${COMPDB}" + echo " ]" >> "${COMPDB}" + echo "}," >> "${COMPDB}" +done +# Remove the last comma, for JSON syntax correctness. +sed -i '$ s/,$//' "${COMPDB}" +echo "]" >> "${EXAMPLE}/carbon/compile_commands.json" + # Run the migration tool. bazel build -c opt //migrate_cpp # Not sure why, but execution of cpp_refactoring fails while saving refactorings @@ -48,4 +66,4 @@ pushd "${EXAMPLE}/carbon" popd # Don't save the compile flags. -rm "${EXAMPLE}/carbon/compile_flags.txt" +rm "${EXAMPLE}/carbon/compile_commands.json"