|
|
|
@ -1,9 +1,10 @@
|
|
|
|
|
/* Copyright (c) 2016 - present Facebook, Inc.
|
|
|
|
|
* All rights reserved.
|
|
|
|
|
*
|
|
|
|
|
* This source code is licensed under the BSD style license found in the
|
|
|
|
|
* LICENSE file in the root directory of this source tree. An additional grant
|
|
|
|
|
* of patent rights can be found in the PATENTS file in the same directory.
|
|
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2016 - present Facebook, Inc.
|
|
|
|
|
* All rights reserved.
|
|
|
|
|
*
|
|
|
|
|
* This source code is licensed under the BSD style license found in the
|
|
|
|
|
* LICENSE file in the root directory of this source tree. An additional grant
|
|
|
|
|
* of patent rights can be found in the PATENTS file in the same directory.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/** Given a clang command, normalize it via `clang -###` if needed to get a clear view of what work
|
|
|
|
@ -19,8 +20,8 @@ type action_item =
|
|
|
|
|
|
|
|
|
|
/** Given a list of arguments for clang [args], return a list of new commands to run according to
|
|
|
|
|
the results of `clang -### [args]`. */
|
|
|
|
|
let normalize (args: array string) :list action_item => {
|
|
|
|
|
let cmd = ClangCommand.mk ClangQuotes.SingleQuotes args;
|
|
|
|
|
let normalize prog::prog args::args :list action_item => {
|
|
|
|
|
let cmd = ClangCommand.mk ClangQuotes.SingleQuotes prog::prog args::args;
|
|
|
|
|
let clang_hashhashhash =
|
|
|
|
|
Printf.sprintf
|
|
|
|
|
"%s 2>&1"
|
|
|
|
@ -38,13 +39,17 @@ let normalize (args: array string) :list action_item => {
|
|
|
|
|
let normalized_commands = ref [];
|
|
|
|
|
let one_line line =>
|
|
|
|
|
if (String.is_prefix prefix::" \"" line) {
|
|
|
|
|
let cmd =
|
|
|
|
|
/* massage line to remove edge-cases for splitting */
|
|
|
|
|
"\"" ^ line ^ " \"" |>
|
|
|
|
|
/* split by whitespace */
|
|
|
|
|
Str.split (Str.regexp_string "\" \"") |> Array.of_list |>
|
|
|
|
|
ClangCommand.mk ClangQuotes.EscapedDoubleQuotes;
|
|
|
|
|
Command cmd
|
|
|
|
|
Command (
|
|
|
|
|
switch (
|
|
|
|
|
/* massage line to remove edge-cases for splitting */
|
|
|
|
|
"\"" ^ line ^ " \"" |>
|
|
|
|
|
/* split by whitespace */
|
|
|
|
|
Str.split (Str.regexp_string "\" \"")
|
|
|
|
|
) {
|
|
|
|
|
| [prog, ...args] => ClangCommand.mk ClangQuotes.EscapedDoubleQuotes prog::prog args::args
|
|
|
|
|
| [] => failwith "ClangWrapper: argv cannot be empty"
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
} else if (
|
|
|
|
|
Str.string_match (Str.regexp "clang[^ :]*: warning: ") line 0
|
|
|
|
|
) {
|
|
|
|
@ -84,20 +89,20 @@ let exec_action_item =
|
|
|
|
|
| ClangWarning warning => Logging.stderr "%s@\n" warning
|
|
|
|
|
| Command clang_cmd => Capture.capture clang_cmd;
|
|
|
|
|
|
|
|
|
|
let exe args xx_suffix => {
|
|
|
|
|
/* make sure args.(0) points to clang in facebook-clang-plugins */
|
|
|
|
|
args.(0) = CFrontend_config.clang_bin xx_suffix;
|
|
|
|
|
let commands = normalize args;
|
|
|
|
|
let exe prog::prog args::args => {
|
|
|
|
|
let xx_suffix = String.is_suffix suffix::"++" prog ? "++" : "";
|
|
|
|
|
/* use clang in facebook-clang-plugins */
|
|
|
|
|
let clang_xx = CFrontend_config.clang_bin xx_suffix;
|
|
|
|
|
let commands = normalize prog::clang_xx args::args;
|
|
|
|
|
/* xcodebuild projects may require the object files to be generated by the Apple compiler, eg to
|
|
|
|
|
generate precompiled headers compatible with Apple's clang. */
|
|
|
|
|
let should_run_original_command =
|
|
|
|
|
let (prog, should_run_original_command) =
|
|
|
|
|
switch Config.fcp_apple_clang {
|
|
|
|
|
| Some bin =>
|
|
|
|
|
let bin_xx = bin ^ xx_suffix;
|
|
|
|
|
Logging.out "Will run Apple clang %s" bin_xx;
|
|
|
|
|
args.(0) = bin_xx;
|
|
|
|
|
true
|
|
|
|
|
| None => false
|
|
|
|
|
(bin_xx, true)
|
|
|
|
|
| None => (clang_xx, false)
|
|
|
|
|
};
|
|
|
|
|
IList.iter exec_action_item commands;
|
|
|
|
|
if (commands == [] || should_run_original_command) {
|
|
|
|
@ -112,8 +117,8 @@ let exe args xx_suffix => {
|
|
|
|
|
files. */
|
|
|
|
|
Logging.out
|
|
|
|
|
"WARNING: `clang -### <args>` returned an empty set of commands to run and no error. Will run the original command directly:@\n %s@\n"
|
|
|
|
|
(String.concat sep::" " @@ Array.to_list args)
|
|
|
|
|
(String.concat sep::" " @@ [prog, ...args])
|
|
|
|
|
};
|
|
|
|
|
Process.create_process_and_wait args
|
|
|
|
|
Process.create_process_and_wait prog::prog args::args
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|