Skip to content

Commit

Permalink
make_vscode improvements (#363)
Browse files Browse the repository at this point in the history
  • Loading branch information
Rostislav Khlebnikov authored and GitHub Enterprise committed Jan 21, 2025
1 parent a813fab commit 7f6eee8
Show file tree
Hide file tree
Showing 19 changed files with 633 additions and 106 deletions.
15 changes: 15 additions & 0 deletions BdeBuildSystem/BdeTestDriverUtils.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,17 @@ function(bbs_add_component_tests target)
get_filename_component(test_target_name ${test_src} NAME_WLE)
get_filename_component(test_target_name ${test_target_name} NAME_WLE)
add_executable(${test_target_name}.t EXCLUDE_FROM_ALL ${test_src})
set_target_properties(
${test_target_name}.t
PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/tests")
add_custom_command(TARGET ${test_target_name}.t
POST_BUILD
COMMAND
${CMAKE_COMMAND} -E create_hardlink
"$<TARGET_FILE:${test_target_name}.t>"
"$<TARGET_FILE_DIR:${test_target_name}.t>/${test_target_name}${CMAKE_EXECUTABLE_SUFFIX}"
)

# Explicitely adding flags here because we do not want those flags to be
# PUBLIC for standalone libraries.
Expand Down Expand Up @@ -268,6 +279,10 @@ function(bbs_add_component_tests target)
add_custom_target(${split_target_name}.t SOURCES ${td_output_dir}/${split_test})
else()
add_executable(${split_target_name}.t EXCLUDE_FROM_ALL ${td_output_dir}/${split_test})
set_target_properties(
${split_target_name}.t
PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/tests")

bbs_add_target_bde_flags(${split_target_name}.t PRIVATE)
bbs_add_target_thread_flags(${split_target_name}.t PRIVATE)
Expand Down
12 changes: 10 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.22)

project(bde-tools NONE)

# bbs-tools
# bbs-tools
install(DIRECTORY BdeBuildSystem
DESTINATION share/cmake
COMPONENT bbs-cmake-module)
Expand All @@ -15,6 +15,7 @@ install(PROGRAMS BdeBuildSystem/scripts/sim_cpp11_features.pl
# bbs shell wrappers
install(PROGRAMS bin/bbs_build
bin/bbs_build_env
bin/bbs_make_vscode
bin/get_dependers
DESTINATION libexec/bde-tools/bin
COMPONENT bde-tools)
Expand All @@ -27,11 +28,13 @@ install(FILES bin/bbs_build.py

# bde-tools
# keep pylibinit when removing old bde-tools install rules(!)
install(PROGRAMS bin/bde_build_env.py
install(PROGRAMS bin/bbs_make_vscode.py
bin/bde_build_env.py
bin/bde_runtest.py
bin/bde_input_limiter.pl
bin/cmake_build.py
bin/get_dependers.py
bin/bde_get_changed_components.sh
DESTINATION libexec/bde-tools/bin
COMPONENT bde-tools)

Expand All @@ -45,6 +48,11 @@ install(DIRECTORY bin/pylibinit
COMPONENT bde-tools
PATTERN "__pycache__" EXCLUDE)

# Install vscode templates
install(DIRECTORY share/templates/vscode
DESTINATION libexec/bde-tools/templates
COMPONENT bde-tools)

# Install rules for bde-gdb-printers
install(FILES contrib/gdb-printers/bde_printer.py
DESTINATION libexec/bde-gdb-printers
Expand Down
71 changes: 50 additions & 21 deletions bin/bbs_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,18 +69,20 @@ def get_msvc_env(version, bitness):
result = {}

bat_file = find_vcvars(version)
host_arch = platform.machine().lower() # typically amd64 or arm64
host_arch = platform.machine().lower() # typically amd64 or arm64
if "arm" in host_arch:
target_arch = "arm" if bitness == 32 else "arm64"
else:
target_arch = "x86" if bitness == 32 else "amd64"

arch_arg = host_arch if host_arch == target_arch else f"{host_arch}_{target_arch}"
arch_arg = (
host_arch if host_arch == target_arch else f"{host_arch}_{target_arch}"
)

process = subprocess.Popen(
[bat_file, arch_arg, "&&", "set"], stdout=subprocess.PIPE, shell=True
)
(out, err) = process.communicate()
(out, _) = process.communicate()

if sys.version_info > (3, 0):
out = out.decode("ascii", errors="ignore")
Expand Down Expand Up @@ -196,6 +198,7 @@ def __init__(self, args):
self.cpp11_verify_no_change = args.cpp11_verify_no_change
self.recover_sanitizer = args.recover_sanitizer
self.dump_cmake_flags = args.dump_cmake_flags
self.known_env = args.known_env

self.generator = args.generator
self.config = args.config
Expand Down Expand Up @@ -255,7 +258,11 @@ def generator(options):
@staticmethod
def generator_env(options):
host_platform = platform.system()
if options.generator != "msvc" and "Windows" == host_platform:
if (
options.generator != "msvc"
and "Windows" == host_platform
and not options.known_env
):
return get_msvc_env(
Platform.msvcVersionMap[options.compiler].version,
64 if options.ufid and "64" in options.ufid else 32,
Expand Down Expand Up @@ -298,26 +305,26 @@ def ctest_jobs_arg(options):

raise RuntimeError()


def wrapper():
description = """
bbs_build is a CMake/CTest wrapper that provides a simpler
interface for the CMake/CTest invocation.
"""
parser = argparse.ArgumentParser(prog="bbs_build",
description=description)
parser = argparse.ArgumentParser(prog="bbs_build", description=description)
parser.add_argument(
"cmd", nargs="+", choices=["configure", "build", "install"]
)

parser.add_argument(
"--build_dir",
help = '''
help="""
Path to the build directory. If not specified,
the build system generates the name using the
current platform, compiler, and ufid. The generated
build directory looks like this:
"./_build/unix-linux-x86_64-2.6.32-gcc-11.0.0-opt_64_cpp20"
'''
""",
)

parser.add_argument(
Expand All @@ -333,18 +340,18 @@ def wrapper():
"--verbose",
action="count",
default=0,
help ="Produce verbose output (including compiler " "command lines).",
help="Produce verbose output (including compiler " "command lines).",
)

parser.add_argument(
"--prefix",
default = "/opt/bb",
help = '''
default="/opt/bb",
help="""
The path prefix in which to look for
dependencies for this build. If "--refroot" is
specified, this prefix is relative to the
refroot (default="/opt/bb").
'''
""",
)

group = parser.add_argument_group(
Expand All @@ -353,10 +360,10 @@ def wrapper():
group.add_argument(
"-u",
"--ufid",
help = '''
help="""
Unified Flag IDentifier (e.g. "opt_dbg_64_cpp20"). See
bde-tools documentation.
'''
""",
)

group.add_argument("--toolchain", help="Path to the CMake toolchain file.")
Expand All @@ -374,7 +381,7 @@ def wrapper():
group.add_argument(
"--compiler",
help="Specify version of MSVC (Windows only). "
'Currently supported versions are: '
"Currently supported versions are: "
'"msvc-2022", "msvc-2019", and "msvc-2017". Latest '
"installed version will be default.",
)
Expand Down Expand Up @@ -415,6 +422,13 @@ def wrapper():
help="Dump CMake flags and exit.",
)

group.add_argument(
"--known-env",
action="store_true",
default=False,
help="(MSVC Only) Do not set the environment via vcvarsall.bat.",
)

genChoices = Platform.generator_choices()
if len(genChoices) > 1:
group.add_argument(
Expand All @@ -434,7 +448,7 @@ def wrapper():
target_group.add_argument(
"--targets",
type=lambda x: x.split(","),
help='''Comma-separated list of build system targets.
help="""Comma-separated list of build system targets.
The build system targets include the targets for
libraries and test drivers for
package groups ("bsl"/"bsl.t"), packages ("bslma"/"bslma.t"),
Expand All @@ -443,7 +457,7 @@ def wrapper():
cycle checks ("check_cycles"/"bsl.check_cycles") and cleanup
("clean"). Supplying a target of "help" will list all of the
available targets.
''',
""",
)

target_group.add_argument(
Expand Down Expand Up @@ -713,8 +727,19 @@ def configure(options):
if options.refroot:
flags.append("-DDISTRIBUTION_REFROOT:PATH=" + options.refroot)

generator_env = Platform.generator_env(options)

if options.dump_cmake_flags:
print(*flags, sep="\n")
cmakeFlags = {}
for arg in flags:
key, value = arg.split("=")

# Remove -D and the type
key = key.replace("-D", "").split(":")[0]

cmakeFlags[key] = value

print(json.dumps({"flags": cmakeFlags, "env": dict(generator_env)}))
return

configure_cmd = (
Expand All @@ -734,7 +759,7 @@ def configure(options):
subprocess.check_call(
configure_cmd,
cwd=options.build_dir,
env=Platform.generator_env(options),
env=generator_env,
)


Expand Down Expand Up @@ -817,8 +842,12 @@ def build(options):
# the dependers of the specified components. If '--test' was
# specified, build the test driver dependers. Otherwise, build the
# packages that the dependers belong to.
target_list = get_dependers(options.dependers_of, options.tests,
options.no_missing_target_warning)
target_list = get_dependers(
options.dependers_of,
options.tests,
options.no_missing_target_warning,
options.build_dir,
)

if target_list:
print("Dependers found: " + " ".join(target_list))
Expand Down
Loading

0 comments on commit 7f6eee8

Please sign in to comment.