Skip to content

Commit

Permalink
CROSSTOOLS wrapped_clang: handle spaces in paths
Browse files Browse the repository at this point in the history
When bazel calls wrapped_clang, it single-quotes all arguments. However
it passes flags with arguments quoted as a whole. That is, wrapped_clang
will be called with arguments like these:

  wrapped_clang '-isysroot /a/path/with spaces' '/a/file with spaces.m'

Before this commit, wrapped_clang was blindly splitting on space and
calling clang with invalid arguments. Now it only splits on the _first_
space, and only if the argument starts with '-'.

Closes bazelbuild#5147.

PiperOrigin-RevId: 200259496
  • Loading branch information
ob authored and ArielleA committed Jun 19, 2018
1 parent d21460b commit 072f5ad
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 12 deletions.
29 changes: 29 additions & 0 deletions src/test/shell/bazel/apple/bazel_apple_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -385,4 +385,33 @@ EOF
|| fail "should build apple_binary with dSYMs"
}

function test_apple_binary_spaces() {
rm -rf package
mkdir -p package
cat > package/BUILD <<EOF
apple_binary(
name = "main_binary",
deps = [":main_lib"],
platform_type = "ios",
minimum_os_version = "10.0",
)
objc_library(
name = "main_lib",
srcs = ["the main.m"],
)
EOF
cat > "package/the main.m" <<EOF
int main() {
return 0;
}
EOF

bazel build --verbose_failures //package:main_binary \
--apple_crosstool_transition \
--ios_multi_cpus=i386,x86_64 \
--xcode_version=$XCODE_VERSION \
--apple_generate_dsym=true \
|| fail "should build apple_binary with dSYMs"
}

run_suite "apple_tests"
13 changes: 1 addition & 12 deletions tools/osx/crosstool/wrapped_clang.cc
Original file line number Diff line number Diff line change
Expand Up @@ -118,17 +118,6 @@ void RunSubProcess(const std::vector<std::string> &args) {
}
}

// Splits txt using whitespace delimiter, pushing each substring into strs.
void SplitAndAdd(const std::string &txt, std::vector<std::string> &strs) {
for (std::istringstream stream(txt); !stream.eof();) {
std::string substring;
stream >> substring;
if (!substring.empty()) {
strs.push_back(substring);
}
}
}

// Finds and replaces all instances of oldsub with newsub, in-place on str.
void FindAndReplace(const std::string &oldsub, const std::string &newsub,
std::string *str) {
Expand Down Expand Up @@ -207,7 +196,7 @@ int main(int argc, char *argv[]) {
}
FindAndReplace("__BAZEL_XCODE_DEVELOPER_DIR__", developer_dir, &arg);
FindAndReplace("__BAZEL_XCODE_SDKROOT__", sdk_root, &arg);
SplitAndAdd(arg, processed_args);
processed_args.push_back(arg);
}

// Check to see if we should postprocess with dsymutil.
Expand Down

0 comments on commit 072f5ad

Please sign in to comment.