[clang][Tooling] Fix addTargetAndModeForProgramName to use correct flag names
authorKadir Cetinkaya <kadircet@google.com>
Sat, 1 Aug 2020 16:55:30 +0000 (18:55 +0200)
committerKadir Cetinkaya <kadircet@google.com>
Mon, 3 Aug 2020 09:46:58 +0000 (11:46 +0200)
commit87de54dbb6efa0fc5e304f94b350a39066bc2759
treeb99ea21d7859f42571651fd9ae26ed4c1cd16270
parent7e32797552c69155676e45ec7d39f948779daa92
[clang][Tooling] Fix addTargetAndModeForProgramName to use correct flag names

The logic was using incorrect flag versions. For example:
- `-target=` can't be a prefix, it must be `--target=`.
- `--driver-mode` can't appear on its own, value must be attached to it.

While fixing those, also changes the append logic to make use of new
`--target=X` format instead of the legacy `-target X` version.

In addition to that makes use of the OPTTable instead of hardcoded strings to
make sure helper also gets updated if clang's options are modified.

Differential Revision: https://reviews.llvm.org/D85076
clang/lib/Tooling/Tooling.cpp
clang/unittests/Tooling/ToolingTest.cpp