cabal-buck2-0.6.0.0: buck2/prelude/ide_integrations/visual_studio/gen_user_macros.bxl
# Copyright (c) Meta Platforms, Inc. and affiliates.
#
# This source code is dual-licensed under either the MIT license found in the
# LICENSE-MIT file in the root directory of this source tree or the Apache
# License, Version 2.0 found in the LICENSE-APACHE file in the root directory
# of this source tree. You may select, at your option, one of the
# above-listed licenses.
load("constants.bxl", "ADDITIONAL_TARGETS", "BY_MODES", "DEBUG_ARGS", "DEBUG_CMD", "DEBUG_ENV", "DEBUG_PWD", "EXTRA_BUCK_OPTIONS", "IMMEDIATE_BUCK_OPTIONS")
load("utils.bxl", "get_vs_configuration", "h")
def gen_user_macros(target: bxl.ConfiguredTargetNode, vs_settings: dict, _cli_args, buck_root):
user_macros = []
user_macros.append(
h(
"PropertyGroup",
[
h("RepoRoot", buck_root, indent_level = 2),
h("ovrsource_root", buck_root, indent_level = 2), # Keep for backward compatibility
],
{
"Label": "UserMacros",
},
indent_level = 1,
)
)
for mode_file, settings in vs_settings[BY_MODES].items():
buck_targets_list = [target.label.raw_target()] + settings[ADDITIONAL_TARGETS]
user_macros.append(
h(
"PropertyGroup",
[
h("BuckModeFile", mode_file, indent_level = 2),
h("BuckTarget", " ".join([str(t) for t in buck_targets_list]), indent_level = 2),
h(EXTRA_BUCK_OPTIONS, " ".join(settings[EXTRA_BUCK_OPTIONS]), indent_level = 2),
h(IMMEDIATE_BUCK_OPTIONS, " ".join(settings[IMMEDIATE_BUCK_OPTIONS]), indent_level = 2),
h(DEBUG_CMD, settings[DEBUG_CMD], indent_level = 2),
h(DEBUG_ARGS, " ".join(settings[DEBUG_ARGS]), indent_level = 2),
h(DEBUG_PWD, settings[DEBUG_PWD], indent_level = 2),
h(DEBUG_ENV, ["{}={}".format(k, v) for (k, v) in settings[DEBUG_ENV].items()], indent_level = 2),
],
{
"Condition": "'$(Configuration)'=='{}'".format(get_vs_configuration(mode_file)),
"Label": "UserMacrosByModes",
},
indent_level = 1,
),
)
return user_macros