From ca0cd32dbc1387f60022bc062ed192c0a39dbad1 Mon Sep 17 00:00:00 2001 From: Corentin Kerisit Date: Wed, 18 Sep 2024 13:16:13 +0200 Subject: [PATCH] buildifier --- examples/runfiles/BUILD | 8 ++++---- swift/BUILD | 3 +++ swift/internal/BUILD | 6 ++++++ swift/internal/runfiles.bzl | 32 ++++++++++++++++++++++++++++---- swift/runfiles/BUILD | 2 +- swift/swift_test.bzl | 1 - 6 files changed, 42 insertions(+), 10 deletions(-) diff --git a/examples/runfiles/BUILD b/examples/runfiles/BUILD index 8d0627973..33b0b93bf 100644 --- a/examples/runfiles/BUILD +++ b/examples/runfiles/BUILD @@ -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"], -) \ No newline at end of file + deps = [ + "//swift/runfiles", + ], +) diff --git a/swift/BUILD b/swift/BUILD index 79867c352..94bddfb9c 100644 --- a/swift/BUILD +++ b/swift/BUILD @@ -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", @@ -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", @@ -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", diff --git a/swift/internal/BUILD b/swift/internal/BUILD index 8a1c4bd75..9b6d1e793 100644 --- a/swift/internal/BUILD +++ b/swift/internal/BUILD @@ -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"], diff --git a/swift/internal/runfiles.bzl b/swift/internal/runfiles.bzl index ceba671ab..d3894fa84 100644 --- a/swift/internal/runfiles.bzl +++ b/swift/internal/runfiles.bzl @@ -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: @@ -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 [] \ No newline at end of file + return [] diff --git a/swift/runfiles/BUILD b/swift/runfiles/BUILD index c211d4cca..130d19200 100644 --- a/swift/runfiles/BUILD +++ b/swift/runfiles/BUILD @@ -7,4 +7,4 @@ swift_library( ], module_name = "BazelRunfiles", visibility = ["//visibility:public"], -) \ No newline at end of file +) diff --git a/swift/swift_test.bzl b/swift/swift_test.bzl index 15cb91efc..a040d6553 100644 --- a/swift/swift_test.bzl +++ b/swift/swift_test.bzl @@ -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