Skip to content

Commit

Permalink
Add local debug options as a dependency, but only if the local_debug_…
Browse files Browse the repository at this point in the history
…options_enabled is specified at command line. Make xcode specify this config
  • Loading branch information
amberdixon committed Aug 10, 2020
1 parent 0f34ead commit e230690
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 4 deletions.
35 changes: 35 additions & 0 deletions rules/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,4 +1,39 @@

load("@bazel_skylib//rules:common_settings.bzl", "bool_flag")
load("@build_bazel_rules_swift//swift:swift.bzl", "swift_library")


exports_files(
glob(["*.bzl"]),
visibility = ["//docs:__pkg__"],
)

genrule(
name = "empty",
outs = ["empty.swift"],
cmd = "touch $(OUTS)",
)

# A dummy target that enables serialize-debugging-options but only in local development,
# so that swiftmodule paths will refer to paths on the local machine and LLDB will work.
swift_library(
name = "_LocalDebugOptions",
srcs = [":empty"],
copts = [
"-Xfrontend",
"-serialize-debugging-options",
],
module_name = "_LocalDebugOptions",
tags = ["no-remote"],
visibility = ["//visibility:public"],
)


bool_flag(name = "local_debug_options_enabled", build_setting_default = False)

config_setting(
name = "local_debug_options",
flag_values = {
":local_debug_options_enabled": "True",
}
)
9 changes: 8 additions & 1 deletion rules/app.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,16 @@ def ios_application(name, apple_library = apple_library, **kwargs):
application_kwargs["launch_storyboard"] = application_kwargs.pop("launch_storyboard", library.launch_screen_storyboard_name)
application_kwargs["families"] = application_kwargs.pop("families", ["iphone", "ipad"])

local_debug_options_for_swift = []
if library.has_swift_sources:
local_debug_options_for_swift += ["@build_bazel_rules_ios//rules:_LocalDebugOptions"]

rules_apple_ios_application(
name = name,
deps = library.deps,
deps = library.deps + select({
"@build_bazel_rules_ios//rules:local_debug_options": local_debug_options_for_swift,
"//conditions:default": [],
}),
infoplists = infoplists,
**application_kwargs
)
1 change: 1 addition & 0 deletions rules/library.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -608,4 +608,5 @@ def apple_library(name, library_tools = {}, export_private_headers = True, names
namespace = namespace,
linkopts = linkopts,
platforms = platforms,
has_swift_sources = (swift_sources and len(swift_sources) > 0),
)
9 changes: 8 additions & 1 deletion rules/test.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,15 @@ def ios_unit_test(name, apple_library = apple_library, **kwargs):

library = apple_library(name = name, namespace_is_module_name = False, platforms = {"ios": unit_test_kwargs.get("minimum_os_version")}, **kwargs)

local_debug_options_for_swift = []
if library.has_swift_sources and not unit_test_kwargs.get("test_host", None):
local_debug_options_for_swift += ["@build_bazel_rules_ios//rules:_LocalDebugOptions"]

rule(
name = name,
deps = library.lib_names,
deps = library.lib_names + select({
"@build_bazel_rules_ios//rules:local_debug_options": local_debug_options_for_swift,
"//conditions:default": [],
}),
**unit_test_kwargs
)
3 changes: 2 additions & 1 deletion tests/macos/xcodeproj/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ cd $(dirname $0)

xcodebuild -project Single-Application-Project-DirectTargetsOnly.xcodeproj -quiet
xcodebuild -project Single-Application-Project-AllTargets.xcodeproj -quiet
xcodebuild -project Test-Target-With-Test-Host-Project.xcodeproj -quiet
xcodebuild -project Test-Target-With-Test-Host-Project.xcodeproj -quiet
# TODO: use strings to test that absolute paths and debug-prefix-map are present in the LocalDebug.swiftmodule. Not sure if this is the right palce to do it. We could also grep out the build event text file maybe.
2 changes: 1 addition & 1 deletion tools/xcodeproj_shims/build-wrapper.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
set -euxo pipefail

$BAZEL_PATH build --experimental_execution_log_file=$BAZEL_BUILD_EXECUTION_LOG_FILENAME --build_event_text_file=$BAZEL_BUILD_EVENT_TEXT_FILENAME --build_event_publish_all_actions $1 2>&1 | $BAZEL_OUTPUT_PROCESSOR
$BAZEL_PATH build --experimental_execution_log_file=$BAZEL_BUILD_EXECUTION_LOG_FILENAME --build_event_text_file=$BAZEL_BUILD_EVENT_TEXT_FILENAME --build_event_publish_all_actions $1 --@build_bazel_rules_ios//rules:local_debug_options_enabled 2>&1 | $BAZEL_OUTPUT_PROCESSOR

0 comments on commit e230690

Please sign in to comment.