Repository: flutter
Issue: Duplicate targets in engine build files
Labels: engine,P2,team-engine,triaged-engine

I noticed that when I specifically request an ARM build on my M1 mac it generates over 1000 extra targets to build which causes ninja to report an extra 3000 build steps. Investigating, I found that there are many duplicate targets in the `compile_commands.json` file when you specify `--mac-cpu arm64` compared to the default that builds for an Intel CPU but even the Intel build has a number of duplicate targets. For example:

```
% grep '"file"' out/host_debug_unopt/compile_commands.json | sort | uniq -d | wc
     513    1026   37467
% grep '"file"' out/host_debug_unopt_arm64/compile_commands.json | sort | uniq -d | wc
    1671    3342  118651
```

[intel.dups.txt](https://github.com/flutter/flutter/files/10015391/intel.dups.txt)
[m1.dups.txt](https://github.com/flutter/flutter/files/10015395/m1.dups.txt)

Here is a sample command that is dup'd in the M1 build. It looks like it is built once into `obj/flutter/fml` and a second time into `clang_x64/obj/flutter/fml`...

```
[
  {
    "file": "../../flutter/fml/ascii_trie.cc",
    "directory": "/Users/<username>/Development/engine/src/out/host_debug_unopt_arm64",
    "command": "/Users/<username>/Development/flutter_goma/gomacc  ../../buildtools/mac-x64/clang/bin/clang++ -MD -MF  obj/flutter/fml/fml.ascii_trie.o.d  -DUSE_OPENSSL=1 -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D_FORTIFY_SOURCE=2 -D_LIBCPP_DISABLE_AVAILABILITY=1 -D_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS -D_LIBCPP_ENABLE_THREAD_SAFETY_ANNOTATIONS -D_DEBUG -DU_USING_ICU_NAMESPACE=0 -DU_ENABLE_DYLOAD=0 -DUSE_CHROMIUM_ICU=1 -DU_ENABLE_TRACING=1 -DU_ENABLE_RESOURCE_TRACING=0 -DU_STATIC_IMPLEMENTATION -DICU_UTIL_DATA_IMPL=ICU_UTIL_DATA_FILE -DFLUTTER_RUNTIME_MODE_DEBUG=1 -DFLUTTER_RUNTIME_MODE_PROFILE=2 -DFLUTTER_RUNTIME_MODE_RELEASE=3 -DFLUTTER_RUNTIME_MODE_JIT_RELEASE=4 \"-DDART_LEGACY_API=[[deprecated]]\" -DFLUTTER_RUNTIME_MODE=1 -DFLUTTER_JIT_RUNTIME=1  -I../.. -Igen -I../../third_party/libcxx/include -I../../third_party/libcxxabi/include -I../../build/secondary/third_party/libcxx/config -I../../third_party/icu/source/common -I../../third_party/icu/source/i18n -I../../third_party/dart/runtime -I../../third_party/dart/runtime/include -I../../third_party/abseil-cpp -isysroot /Users/<username>/Development/engine/src/out/host_debug_unopt_arm64/gen/SDKs/MacOSX12.3.sdk -mmacosx-version-min=10.14.0  -fno-strict-aliasing -fstack-protector-all -arch arm64 -fcolor-diagnostics -Wall -Wextra -Wendif-labels -Werror -Wno-missing-field-initializers -Wno-unused-parameter -Wno-unused-but-set-parameter -Wno-unused-but-set-variable -Wno-implicit-int-float-conversion -Wno-c99-designator -Wno-deprecated-copy -Wno-psabi -Wno-unqualified-std-cast-call -Wno-non-c-typedef-for-linkage -Wno-range-loop-construct -Wunguarded-availability -Wno-deprecated-declarations -fvisibility=hidden -stdlib=libc++ -Wstring-conversion -Wnewline-eof -O0 -g2  -fvisibility-inlines-hidden -std=c++17 -fno-rtti -nostdinc++ -nostdinc++ -fvisibility=hidden -fno-exceptions -Wno-unknown-warning-option -Wno-deprecated-builtins  -c ../../flutter/fml/ascii_trie.cc -o  obj/flutter/fml/fml.ascii_trie.o"
  },
  {
    "file": "../../flutter/fml/ascii_trie.cc",
    "directory": "/Users/<username>/Development/engine/src/out/host_debug_unopt_arm64",
    "command": "/Users/<username>/Development/flutter_goma/gomacc  ../../buildtools/mac-x64/clang/bin/clang++ -MD -MF  clang_x64/obj/flutter/fml/fml.ascii_trie.o.d  -DUSE_OPENSSL=1 -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D_FORTIFY_SOURCE=2 -D_LIBCPP_DISABLE_AVAILABILITY=1 -D_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS -D_LIBCPP_ENABLE_THREAD_SAFETY_ANNOTATIONS -D_DEBUG -DU_USING_ICU_NAMESPACE=0 -DU_ENABLE_DYLOAD=0 -DUSE_CHROMIUM_ICU=1 -DU_ENABLE_TRACING=1 -DU_ENABLE_RESOURCE_TRACING=0 -DU_STATIC_IMPLEMENTATION -DICU_UTIL_DATA_IMPL=ICU_UTIL_DATA_FILE -DFLUTTER_RUNTIME_MODE_DEBUG=1 -DFLUTTER_RUNTIME_MODE_PROFILE=2 -DFLUTTER_RUNTIME_MODE_RELEASE=3 -DFLUTTER_RUNTIME_MODE_JIT_RELEASE=4 \"-DDART_LEGACY_API=[[deprecated]]\" -DFLUTTER_RUNTIME_MODE=1 -DFLUTTER_JIT_RUNTIME=1  -I../.. -Iclang_x64/gen -I../../third_party/libcxx/include -I../../third_party/libcxxabi/include -I../../build/secondary/third_party/libcxx/config -I../../third_party/icu/source/common -I../../third_party/icu/source/i18n -I../../third_party/dart/runtime -I../../third_party/dart/runtime/include -I../../third_party/abseil-cpp -isysroot /Users/<username>/Development/engine/src/out/host_debug_unopt_arm64/gen/SDKs/MacOSX12.3.sdk -mmacosx-version-min=10.14.0  -fno-strict-aliasing -fstack-protector-all -arch x86_64 -fcolor-diagnostics -Wall -Wextra -Wendif-labels -Werror -Wno-missing-field-initializers -Wno-unused-parameter -Wno-unused-but-set-parameter -Wno-unused-but-set-variable -Wno-implicit-int-float-conversion -Wno-c99-designator -Wno-deprecated-copy -Wno-psabi -Wno-unqualified-std-cast-call -Wno-non-c-typedef-for-linkage -Wno-range-loop-construct -Wunguarded-availability -Wno-deprecated-declarations -fvisibility=hidden -stdlib=libc++ -Wstring-conversion -Wnewline-eof -O0 -g2  -fvisibility-inlines-hidden -std=c++17 -fno-rtti -nostdinc++ -nostdinc++ -fvisibility=hidden -fno-exceptions -Wno-unknown-warning-option -Wno-deprecated-builtins  -c ../../flutter/fml/ascii_trie.cc -o  clang_x64/obj/flutter/fml/fml.ascii_trie.o"
  },
]
```