From 70b497c3af7e299426d76d9b75900a361adc0f29 Mon Sep 17 00:00:00 2001 From: Luis Padron Date: Tue, 17 Oct 2023 10:05:56 -0400 Subject: [PATCH] Move to using `write_file` from Bazel Skylib (#778) --- docs/library_doc.md | 20 -------------------- rules/library.bzl | 24 +++++------------------- rules/plists.bzl | 6 +++--- 3 files changed, 8 insertions(+), 42 deletions(-) diff --git a/docs/library_doc.md b/docs/library_doc.md index 31ab9cfdf..504129253 100755 --- a/docs/library_doc.md +++ b/docs/library_doc.md @@ -24,26 +24,6 @@ Extends a modulemap with a Swift submodule | swift_header | - | String | optional | "" | - - -## write_file - -
-write_file(name, content, destination)
-
- -Writes out a file verbatim - -**ATTRIBUTES** - - -| Name | Description | Type | Mandatory | Default | -| :------------- | :------------- | :------------- | :------------- | :------------- | -| name | A unique name for this target. | Name | required | | -| content | - | String | required | | -| destination | - | Label | required | | - - ## PrivateHeadersInfo diff --git a/rules/library.bzl b/rules/library.bzl index 86bac105c..8301aa668 100644 --- a/rules/library.bzl +++ b/rules/library.bzl @@ -3,6 +3,7 @@ load("@bazel_skylib//lib:paths.bzl", "paths") load("@bazel_skylib//lib:sets.bzl", "sets") load("@bazel_skylib//lib:selects.bzl", "selects") +load("@bazel_skylib//rules:write_file.bzl", "write_file") load("@build_bazel_rules_apple//apple:apple.bzl", "apple_dynamic_framework_import", "apple_static_framework_import") load("@build_bazel_rules_apple//apple/internal/resource_rules:apple_intent_library.bzl", "apple_intent_library") load("@build_bazel_rules_swift//swift:swift.bzl", "swift_library") @@ -45,21 +46,6 @@ _private_headers = rule( }, ) -def _write_file_impl(ctx): - ctx.actions.write( - output = ctx.outputs.destination, - content = ctx.attr.content, - ) - -write_file = rule( - implementation = _write_file_impl, - attrs = { - "content": attr.string(mandatory = True), - "destination": attr.output(mandatory = True), - }, - doc = "Writes out a file verbatim", -) - def _extend_modulemap_impl(ctx): args = ctx.actions.args() args.add(""" @@ -120,8 +106,8 @@ module {module_name} {{ write_file( name = basename + "~", - destination = destination, - content = content, + out = destination, + content = content.split("\n"), tags = _MANUAL, ) return destination @@ -170,8 +156,8 @@ FOUNDATION_EXPORT const unsigned char {module_name}VersionString[]; write_file( name = basename + "~", - destination = destination, - content = content, + out = destination, + content = content.split("\n"), tags = _MANUAL, ) return destination diff --git a/rules/plists.bzl b/rules/plists.bzl index e3532b09e..d62717373 100644 --- a/rules/plists.bzl +++ b/rules/plists.bzl @@ -4,8 +4,8 @@ Defines macros for working with plist files. load("@bazel_skylib//lib:types.bzl", "types") load("@bazel_skylib//lib:sets.bzl", "sets") +load("@bazel_skylib//rules:write_file.bzl", "write_file") load("@build_bazel_rules_ios//rules:substitute_build_settings.bzl", "substitute_build_settings") -load("//rules:library.bzl", "write_file") load("//rules/library:xcconfig.bzl", "build_setting_name", "merge_xcconfigs") def process_infoplists(name, infoplists, infoplists_by_build_setting, xcconfig, xcconfig_by_build_setting): @@ -109,8 +109,8 @@ def write_info_plists_if_needed(name, plists): plist_name = "{name}.infoplist.{idx}".format(name = name, idx = idx) write_file( name = plist_name, - destination = plist_name + ".plist", - content = struct(**plist).to_json(), + out = plist_name + ".plist", + content = [struct(**plist).to_json()], ) written_plists.append(plist_name) else: