Skip to content

Commit

Permalink
buildifier
Browse files Browse the repository at this point in the history
  • Loading branch information
cerisier committed Sep 18, 2024
1 parent 589c964 commit ca0cd32
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 10 deletions.
8 changes: 4 additions & 4 deletions examples/runfiles/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ load("//swift:swift.bzl", "swift_binary")
swift_binary(
name = "binary",
srcs = ["main.swift"],
deps = [
"//swift/runfiles",
],
data = [
"data/sample.txt",
],
visibility = ["//visibility:public"],
)
deps = [
"//swift/runfiles",
],
)
3 changes: 3 additions & 0 deletions swift/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ bzl_library(
"//swift/internal:compiling",
"//swift/internal:feature_names",
"//swift/internal:linking",
"//swift/internal:runfiles",
"//swift/internal:toolchain_utils",
"//swift/internal:utils",
"@bazel_skylib//lib:paths",
Expand Down Expand Up @@ -189,6 +190,7 @@ bzl_library(
"//swift/internal:feature_names",
"//swift/internal:linking",
"//swift/internal:output_groups",
"//swift/internal:runfiles",
"//swift/internal:toolchain_utils",
"//swift/internal:utils",
"@bazel_skylib//lib:dicts",
Expand Down Expand Up @@ -252,6 +254,7 @@ bzl_library(
"//swift/internal:feature_names",
"//swift/internal:linking",
"//swift/internal:output_groups",
"//swift/internal:runfiles",
"//swift/internal:swift_symbol_graph_aspect",
"//swift/internal:toolchain_utils",
"//swift/internal:utils",
Expand Down
6 changes: 6 additions & 0 deletions swift/internal/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,12 @@ bzl_library(
],
)

bzl_library(
name = "runfiles",
srcs = ["runfiles.bzl"],
visibility = ["//swift:__subpackages__"],
)

bzl_library(
name = "swift_autoconfiguration",
srcs = ["swift_autoconfiguration.bzl"],
Expand Down
32 changes: 28 additions & 4 deletions swift/internal/runfiles.bzl
Original file line number Diff line number Diff line change
@@ -1,6 +1,30 @@
# Copyright 2024 The Bazel Authors. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Internal API to generate constants needed by the runfiles library"""

def include_runfiles_constants(label, actions, all_deps):
"""
TODO: Do this the right way.
"""TODO: Do this the right way.
Args:
label: The label of the target for which the Swift files are being generated.
actions: The actions object used to declare the files to be generated and the actions that generate them.
all_deps: The list of public dependencies of the target.
Returns:
A list containing the runfiles constant declared file if applicable;
otherwise an empty list.
"""
matches = [dep for dep in all_deps if dep.label == Label("@build_bazel_rules_swift//swift/runfiles:runfiles")]
if len(matches) > 0:
Expand All @@ -9,9 +33,9 @@ def include_runfiles_constants(label, actions, all_deps):
output = repo_name_file,
content = """
internal enum BazelRunfilesConstants {{
static let currentRepository = "{}"
static let currentRepository = "{}"
}}
""".format(label.workspace_name),
)
return [repo_name_file]
return []
return []
2 changes: 1 addition & 1 deletion swift/runfiles/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ swift_library(
],
module_name = "BazelRunfiles",
visibility = ["//visibility:public"],
)
)
1 change: 0 additions & 1 deletion swift/swift_test.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,6 @@ def _swift_test_impl(ctx):
all_supplemental_outputs = []

if srcs:

srcs = srcs + include_runfiles_constants(ctx.label, ctx.actions, ctx.attr.deps)

# If the `swift_test` target had sources, compile those first and then
Expand Down

0 comments on commit ca0cd32

Please sign in to comment.