xref: /aosp_15_r20/external/bazel-skylib/docs/write_file_doc.md (revision bcb5dc7965af6ee42bf2f21341a2ec00233a8c8a)
1*bcb5dc79SHONG Yifan<!-- Generated with Stardoc: http://skydoc.bazel.build -->
2*bcb5dc79SHONG Yifan
3*bcb5dc79SHONG YifanA rule that writes a UTF-8 encoded text file from user-specified contents.
4*bcb5dc79SHONG Yifan
5*bcb5dc79SHONG Yifannative.genrule() is sometimes used to create a text file. The 'write_file' and
6*bcb5dc79SHONG Yifanmacro does this with a simpler interface than genrule.
7*bcb5dc79SHONG Yifan
8*bcb5dc79SHONG YifanThe rules generated by the macro do not use Bash or any other shell to write the
9*bcb5dc79SHONG Yifanfile. Instead they use Starlark's built-in file writing action
10*bcb5dc79SHONG Yifan(ctx.actions.write).
11*bcb5dc79SHONG Yifan
12*bcb5dc79SHONG Yifan<a id="write_file"></a>
13*bcb5dc79SHONG Yifan
14*bcb5dc79SHONG Yifan## write_file
15*bcb5dc79SHONG Yifan
16*bcb5dc79SHONG Yifan<pre>
17*bcb5dc79SHONG Yifanwrite_file(<a href="#write_file-name">name</a>, <a href="#write_file-out">out</a>, <a href="#write_file-content">content</a>, <a href="#write_file-is_executable">is_executable</a>, <a href="#write_file-newline">newline</a>, <a href="#write_file-kwargs">kwargs</a>)
18*bcb5dc79SHONG Yifan</pre>
19*bcb5dc79SHONG Yifan
20*bcb5dc79SHONG YifanCreates a UTF-8 encoded text file.
21*bcb5dc79SHONG Yifan
22*bcb5dc79SHONG Yifan**PARAMETERS**
23*bcb5dc79SHONG Yifan
24*bcb5dc79SHONG Yifan
25*bcb5dc79SHONG Yifan| Name  | Description | Default Value |
26*bcb5dc79SHONG Yifan| :------------- | :------------- | :------------- |
27*bcb5dc79SHONG Yifan| <a id="write_file-name"></a>name |  Name of the rule.   |  none |
28*bcb5dc79SHONG Yifan| <a id="write_file-out"></a>out |  Path of the output file, relative to this package.   |  none |
29*bcb5dc79SHONG Yifan| <a id="write_file-content"></a>content |  A list of strings. Lines of text, the contents of the file. Newlines are added automatically after every line except the last one.   |  `[]` |
30*bcb5dc79SHONG Yifan| <a id="write_file-is_executable"></a>is_executable |  A boolean. Whether to make the output file executable. When True, the rule's output can be executed using `bazel run` and can be in the srcs of binary and test rules that require executable sources.   |  `False` |
31*bcb5dc79SHONG Yifan| <a id="write_file-newline"></a>newline |  one of ["auto", "unix", "windows"]: line endings to use. "auto" for platform-determined, "unix" for LF, and "windows" for CRLF.   |  `"auto"` |
32*bcb5dc79SHONG Yifan| <a id="write_file-kwargs"></a>kwargs |  further keyword arguments, e.g. `visibility`   |  none |
33*bcb5dc79SHONG Yifan
34*bcb5dc79SHONG Yifan
35