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

Add local debug options as a dependency, but only if local_debug_options_enabled #98

Merged
merged 4 commits into from
Aug 12, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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"],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: can we also tag as manual?

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"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we update some documentation / readme to reflect this important flag?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added comments in the BUILD.bazel where the _LocalDebugOptions target is defined. I will also reference this README: https://github.com/ios-bazel-users/ios-bazel-users/blob/master/DebuggableRemoteSwift.md

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding separate docs shouldn't be necessary, since the xcodeproj rule automatically enables the flag when necessary


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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

trailing newline

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: spelling of place

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

run the following to get test fixtures updated:

bazelisk query 'kind(xcodeproj, tests/ios/xcodeproj/...)' | xargs -n 1 bazelisk run
bazelisk query 'kind(xcodeproj, tests/macos/xcodeproj/...)' | xargs -n 1 bazelisk run
bazelisk query 'attr(executable, 1, kind(genrule, tests/macos/xcodeproj/...))' | xargs -n 1 bazelisk run
bazelisk query 'attr(executable, 1, kind(genrule, tests/ios/xcodeproj/...))' | xargs -n 1 bazelisk run
find . -type f \( -name 'WORKSPACE' -o -name '*.bzl' -o -name '*.bazel' \) | xargs buildifier -lint=fix