Skip to content

Commit

Permalink
fix(cxx_tools): replace sandboxed directory with bazel execroot (#4240)
Browse files Browse the repository at this point in the history
  • Loading branch information
shahms committed Dec 3, 2019
1 parent f762ae4 commit 4814f9f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,20 +67,6 @@ std::string JoinCommand(const std::vector<std::string>& command) {
return output;
}

std::string GetBuildDirectory() {
std::string build_dir;
{
char cwd[MAXPATHLEN];
build_dir = getcwd(cwd, MAXPATHLEN);
}
auto sandbox_start = build_dir.find("/bazel-sandbox/");
if (sandbox_start == std::string::npos) return build_dir;
auto sandbox_end =
build_dir.find("/", sandbox_start + strlen("/bazel-sandbox/"));

return build_dir.erase(sandbox_start, sandbox_end - sandbox_start);
}

std::string FormatCompilationCommand(const std::string& source_file,
const std::vector<std::string>& command) {
rapidjson::StringBuffer buffer;
Expand All @@ -89,7 +75,7 @@ std::string FormatCompilationCommand(const std::string& source_file,
writer.Key("file");
writer.String(source_file.c_str());
writer.Key("directory");
writer.String(GetBuildDirectory().c_str());
writer.String("@BAZEL_ROOT@");
writer.Key("command");
writer.String(JoinCommand(command).c_str());
writer.EndObject();
Expand Down
5 changes: 3 additions & 2 deletions tools/cpp/generate_compilation_database.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@ bazel build \
--noshow_loading_progress \
$(bazel query 'kind(cc_.*, //...) - attr(tags, manual, //...)') > /dev/null

pushd $(bazel info execution_root) > /dev/null
BAZEL_ROOT="$(bazel info execution_root)"
pushd "$BAZEL_ROOT" > /dev/null
echo "[" > compile_commands.json
COUNT=0
find . -name '*.compile_command.json' -print0 | while read -r -d '' fname; do
if ((COUNT++)); then
echo ',' >> compile_commands.json
fi
cat "$fname" >> compile_commands.json
sed -e "s|@BAZEL_ROOT@|$BAZEL_ROOT|g" < "$fname" >> compile_commands.json
done
echo "]" >> compile_commands.json
popd > /dev/null

0 comments on commit 4814f9f

Please sign in to comment.