Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cc_wrapper: make built artifacts more reproducible but specifying -ffile-prefix-map #445

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion toolchain/cc_toolchain_config.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,12 @@ def cc_toolchain_config(
unfiltered_compile_flags = [
# Do not resolve our symlinked resource prefixes to real paths.
"-no-canonical-prefixes",
# Reproducibility
# Reproducibility.
"-Wno-builtin-macro-redefined",
"-D__DATE__=\"redacted\"",
"-D__TIMESTAMP__=\"redacted\"",
"-D__TIME__=\"redacted\"",
"-ffile-prefix-map=${{pwd}}=__bazel_toolchain_llvm_repo__",
]

is_xcompile = not (exec_os == target_os and exec_arch == target_arch)
Expand Down
5 changes: 5 additions & 0 deletions toolchain/cc_wrapper.sh.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,14 @@ set -euo pipefail

if [[ -f %{toolchain_path_prefix}bin/clang ]]; then
execroot_path=""
execroot_abs_path="${PWD}/"
elif [[ ${BASH_SOURCE[0]} == "/"* ]]; then
# Some consumers of `CcToolchainConfigInfo` (e.g. `cmake` from rules_foreign_cc)
# change CWD and call $CC (this script) with its absolute path.
# For cases like this, we'll try to find `clang` through an absolute path.
# This script is at _execroot_/external/_repo_name_/bin/cc_wrapper.sh
execroot_path="${BASH_SOURCE[0]%/*/*/*/*}/"
execroot_abs_path="$(cd "${execroot_path}" && pwd -P)/"
else
echo >&2 "ERROR: could not find clang; PWD=\"${PWD}\"; PATH=\"${PATH}\"."
exit 5
Expand All @@ -53,6 +55,9 @@ function sanitize_option() {
# shellcheck disable=SC2206
parts=(${opt/=/ }) # Split flag name and value into array.
printf "%s" "${parts[0]}=${execroot_path}${parts[1]}"
elif [[ ${opt} == *"\${{pwd}}"* ]]; then
# Replace the literal string '${{pwd}}' with the execroot.
printf "%s" "${opt//\$\{\{pwd\}\}/${execroot_abs_path%/}}"
else
printf "%s" "${opt}"
fi
Expand Down
3 changes: 3 additions & 0 deletions toolchain/osx_cc_wrapper.sh.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ function sanitize_option() {
# shellcheck disable=SC2206
parts=(${opt/=/ }) # Split flag name and value into array.
printf "%s" "${parts[0]}=${execroot_path}${parts[1]}"
elif [[ ${opt} == *"\${{pwd}}"* ]]; then
# Replace the literal string '${{pwd}}' with the execroot.
printf "%s" "${opt//\$\{\{pwd\}\}/${execroot_abs_path%/}}"
else
printf "%s" "${opt}"
fi
Expand Down
Loading