0
0
mirror of https://github.com/mongodb/mongo.git synced 2024-11-21 12:39:08 +01:00

SERVER-97283 fix ninja compiledb (#29306)

GitOrigin-RevId: c571ee716edb731ab2c0dbb7ab83d4ba56dd82fa
This commit is contained in:
Daniel Moody 2024-11-19 11:35:47 -05:00 committed by MongoDB Bot
parent 2b556d1d0a
commit 6982155e42
6 changed files with 65 additions and 19 deletions

2
.gitignore vendored
View File

@ -280,7 +280,7 @@ buildifier
.bazelrc.gitinfo
.bazelrc.workstation
.bazelrc.xcode
.bazel_info_for_ninja.txt
*.bazel_info_for_ninja.txt
.ninja_last_command_line_targets.txt
bazel/coverity/analysis/BUILD.bazel
.bazel_include_info.json

View File

@ -744,6 +744,31 @@ add_option(
help="Name a toolchain root for use with toolchain selection Variables files in etc/scons",
)
if mongo_toolchain_execroot:
bin_dir = os.path.join(mongo_toolchain_execroot, "external/mongo_toolchain/v4/bin")
gcc_path = os.path.dirname(
os.path.realpath(os.path.join(bin_dir, os.readlink(os.path.join(bin_dir, "g++"))))
)
clang_path = os.path.dirname(
os.path.realpath(os.path.join(bin_dir, os.readlink(os.path.join(bin_dir, "clang++"))))
)
else:
gcc_path = ""
clang_path = ""
add_option(
"bazel-toolchain-clang",
default=clang_path,
help="used in Variables files to help find the real bazel toolchain location.",
)
add_option(
"bazel-toolchain-gcc",
default=gcc_path,
help="used in Variables files to help find the real bazel toolchain location.",
)
add_option(
"msvc-debugging-format",
choices=["codeview", "pdb"],
@ -6615,9 +6640,8 @@ elif env.GetOption("build-mongot"):
# __NINJA_NO is ninja callback to scons signal, in that case we care about
# scons only targets not thin targets.
if env.get("__NINJA_NO") != "1":
env.Tool("integrate_bazel")
else:
env.Tool("integrate_bazel")
if env.get("__NINJA_NO") == "1":
env.LoadBazelBuilders()
def noop(*args, **kwargs):

View File

@ -57,16 +57,22 @@ if not ARGUMENTS.get('CC') and not ARGUMENTS.get("CXX") and platform.machine() !
READELF = os.path.join(local_toolchain_bindir, 'readelf')
GDB = os.path.join(local_toolchain_bindir, 'gdb')
bazel_toolchain_bin = SCons.Script.Main.GetOption('bazel-toolchain-clang')
if bazel_toolchain_bin:
cxx_realpath = os.path.join(bazel_toolchain_bin, "clang++")
else:
cxx_realpath = CXX
try:
AR = subprocess.check_output([CXX, '-print-prog-name=ar']).decode('utf-8').strip()
AS = subprocess.check_output([CXX, '-print-prog-name=as']).decode('utf-8').strip()
OBJCOPY = subprocess.check_output([CXX, '-print-prog-name=objcopy']).decode('utf-8').strip()
LLVM_SYMBOLIZER = subprocess.check_output([CXX, '-print-prog-name=llvm-symbolizer']).decode('utf-8').strip()
AR = subprocess.check_output([cxx_realpath, '-print-prog-name=ar']).decode('utf-8').strip()
AS = subprocess.check_output([cxx_realpath, '-print-prog-name=as']).decode('utf-8').strip()
OBJCOPY = subprocess.check_output([cxx_realpath, '-print-prog-name=objcopy']).decode('utf-8').strip()
LLVM_SYMBOLIZER = subprocess.check_output([cxx_realpath, '-print-prog-name=llvm-symbolizer']).decode('utf-8').strip()
except subprocess.CalledProcessError as e:
print("Failed while invoking toolchain binary " + CXX + ": " + str(e.output))
print("Failed while invoking toolchain binary " + cxx_realpath + ": " + str(e.output))
SCons.Script.Exit(-1)
except OSError as e:
print("Failed to invoke toolchain binary " + CXX + ": " + str(e))
print("Failed to invoke toolchain binary " + cxx_realpath + ": " + str(e))
SCons.Script.Exit(-1)
DWARF_VERSION=4

View File

@ -56,15 +56,21 @@ if not ARGUMENTS.get('CC') and not ARGUMENTS.get("CXX"):
READELF = os.path.join(local_toolchain_bindir, 'readelf')
GDB = os.path.join(local_toolchain_bindir, 'gdb')
bazel_toolchain_bin = SCons.Script.Main.GetOption('bazel-toolchain-gcc')
if bazel_toolchain_bin:
cxx_realpath = os.path.join(bazel_toolchain_bin, "g++")
else:
cxx_realpath = CXX
try:
AR = subprocess.check_output([CXX, '-print-prog-name=ar']).decode('utf-8').strip()
AS = subprocess.check_output([CXX, '-print-prog-name=as']).decode('utf-8').strip()
OBJCOPY = subprocess.check_output([CXX, '-print-prog-name=objcopy']).decode('utf-8').strip()
AR = subprocess.check_output([cxx_realpath, '-print-prog-name=ar']).decode('utf-8').strip()
AS = subprocess.check_output([cxx_realpath, '-print-prog-name=as']).decode('utf-8').strip()
OBJCOPY = subprocess.check_output([cxx_realpath, '-print-prog-name=objcopy']).decode('utf-8').strip()
except subprocess.CalledProcessError as e:
print('Failed while invoking toolchain binary ' + CXX + ': ' + str(e.output))
print('Failed while invoking toolchain binary ' + cxx_realpath + ': ' + str(e.output))
SCons.Script.Exit(-1)
except OSError as e:
print('Failed to invoke toolchain binary ' + CXX + ': ' + str(e))
print('Failed to invoke toolchain binary ' + cxx_realpath + ': ' + str(e))
SCons.Script.Exit(-1)
DWARF_VERSION=5

View File

@ -47,7 +47,8 @@ except OSError as exc:
# the specific ninja file
ninja_build_info = dict()
try:
bazel_info_file = ".bazel_info_for_ninja.txt"
ninja_prefix = args.ninja_file.split(".")[0]
bazel_info_file = f".{ninja_prefix}.bazel_info_for_ninja.txt"
with open(bazel_info_file) as f:
ninja_build_info = json.load(f)
except OSError as exc:

View File

@ -441,6 +441,9 @@ def bazel_build_thread_func(env, log_dir: str, verbose: bool, ninja_generate: bo
os.remove(file)
extra_args += ["--build_tag_filters=scons_link_lists"]
if SCons.Script.BUILD_TARGETS == ["compiledb"]:
bazel_cmd = Globals.bazel_base_build_command + extra_args + ["//:compiledb"]
else:
bazel_cmd = Globals.bazel_base_build_command + extra_args + ["//src/..."]
if ninja_generate:
@ -599,7 +602,7 @@ def generate_bazel_info_for_ninja(env: SCons.Environment.Environment) -> None:
"CXX": env.get("CXX", ""),
"USE_NATIVE_TOOLCHAIN": os.environ.get("USE_NATIVE_TOOLCHAIN"),
}
with open(".bazel_info_for_ninja.txt", "w") as f:
with open(f".{env.subst('$NINJA_PREFIX')}.bazel_info_for_ninja.txt", "w") as f:
json.dump(ninja_bazel_build_json, f)
# we also store the outputs in the env (the passed env is intended to be
@ -616,6 +619,9 @@ def generate_bazel_info_for_ninja(env: SCons.Environment.Environment) -> None:
ninja_bazel_outs += [bazel_t["bazel_output"]]
ninja_bazel_ins += env.NinjaGetInputs(env.File(scons_t))
if platform.system() == "Linux" and not os.environ.get("USE_NATIVE_TOOLCHAIN"):
ninja_bazel_outs += [env.get("CC"), env.get("CXX")]
# This is to be used directly by ninja later during generation of the ninja file
env["NINJA_BAZEL_OUTPUTS"] = ninja_bazel_outs
env["NINJA_BAZEL_INPUTS"] = ninja_bazel_ins
@ -1260,6 +1266,9 @@ def generate(env: SCons.Environment.Environment) -> None:
"\\", "/"
)
if env.get("__NINJA_NO") == "1":
return
# ThinTarget builder is a special bazel target and should not be prefixed with Bazel in the builder
# name to exclude it from the other BazelBuilder's. This builder excludes any normal builder
# mechanisms like scanners or emitters and functions as a pass through for targets which exist