Skip to content

Commit

Permalink
Move to using write_file from Bazel Skylib (#778)
Browse files Browse the repository at this point in the history
  • Loading branch information
luispadron authored Oct 17, 2023
1 parent 5490017 commit 70b497c
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 42 deletions.
20 changes: 0 additions & 20 deletions docs/library_doc.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,26 +24,6 @@ Extends a modulemap with a Swift submodule
| <a id="extend_modulemap-swift_header"></a>swift_header | - | String | optional | <code>""</code> |


<a id="write_file"></a>

## write_file

<pre>
write_file(<a href="#write_file-name">name</a>, <a href="#write_file-content">content</a>, <a href="#write_file-destination">destination</a>)
</pre>

Writes out a file verbatim

**ATTRIBUTES**


| Name | Description | Type | Mandatory | Default |
| :------------- | :------------- | :------------- | :------------- | :------------- |
| <a id="write_file-name"></a>name | A unique name for this target. | <a href="https://bazel.build/concepts/labels#target-names">Name</a> | required | |
| <a id="write_file-content"></a>content | - | String | required | |
| <a id="write_file-destination"></a>destination | - | <a href="https://bazel.build/concepts/labels">Label</a> | required | |


<a id="PrivateHeadersInfo"></a>

## PrivateHeadersInfo
Expand Down
24 changes: 5 additions & 19 deletions rules/library.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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("""
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions rules/plists.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 70b497c

Please sign in to comment.