From 105471512436b0c806ccd5254bc31345856dff4f Mon Sep 17 00:00:00 2001 From: Dean Lindqvist Todevski Date: Thu, 30 Jan 2025 23:26:37 +0100 Subject: [PATCH] feat: Add option to pass diff_args in write_source_files macro --- docs/write_source_files.md | 3 ++- lib/write_source_files.bzl | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/docs/write_source_files.md b/docs/write_source_files.md index 1ff20c8a6..7f12872b5 100644 --- a/docs/write_source_files.md +++ b/docs/write_source_files.md @@ -162,7 +162,7 @@ Name of the generated test target if requested, otherwise None.
 write_source_files(name, files, executable, additional_update_targets, suggested_update_target,
-                   diff_test, diff_test_failure_message, file_missing_failure_message,
+                   diff_test, diff_test_failure_message, diff_args, file_missing_failure_message,
                    check_that_out_file_exists, kwargs)
 
@@ -185,6 +185,7 @@ To disable the exists check and up-to-date tests set `diff_test` to `False`. | suggested_update_target | Label of the `write_source_files` or `write_source_file` target to suggest running when files are out of date. | `None` | | diff_test | Test that the source tree files and/or directories exist and are up to date. | `True` | | diff_test_failure_message | Text to print when the diff test fails, with templating options for relevant targets.

Substitutions are performed on the failure message, with the following substitutions being available:

`{{DEFAULT_MESSAGE}}`: Prints the default error message, listing the target(s) that may be run to update the file(s).

`{{TARGET}}`: The target to update the individual file that does not match in the diff test.

`{{SUGGESTED_UPDATE_TARGET}}`: The suggested_update_target if specified, or the target which will update all of the files which do not match. | `"{{DEFAULT_MESSAGE}}"` | +| diff_args | Arguments to pass to the `diff` command. (Ignored on Windows) | `[]` | | file_missing_failure_message | Text to print when the output file is missing. Subject to the same substitutions as diff_test_failure_message. | `"{{DEFAULT_MESSAGE}}"` | | check_that_out_file_exists | Test that each output file exists and print a helpful error message if it doesn't.

If `True`, destination files and directories must be in the same containing Bazel package as the target since the underlying mechanism for this check is limited to files in the same Bazel package. | `True` | | kwargs | Other common named parameters such as `tags` or `visibility` | none | diff --git a/lib/write_source_files.bzl b/lib/write_source_files.bzl index 936a7b90a..aa01c484c 100644 --- a/lib/write_source_files.bzl +++ b/lib/write_source_files.bzl @@ -114,6 +114,7 @@ def write_source_files( suggested_update_target = None, diff_test = True, diff_test_failure_message = "{{DEFAULT_MESSAGE}}", + diff_args = [], file_missing_failure_message = "{{DEFAULT_MESSAGE}}", check_that_out_file_exists = True, **kwargs): @@ -158,6 +159,8 @@ def write_source_files( `{{SUGGESTED_UPDATE_TARGET}}`: The suggested_update_target if specified, or the target which will update all of the files which do not match. + diff_args: Arguments to pass to the `diff` command. (Ignored on Windows) + file_missing_failure_message: Text to print when the output file is missing. Subject to the same substitutions as diff_test_failure_message. @@ -194,6 +197,7 @@ def write_source_files( suggested_update_target = this_suggested_update_target, diff_test = diff_test, diff_test_failure_message = diff_test_failure_message, + diff_args = diff_args, file_missing_failure_message = file_missing_failure_message, check_that_out_file_exists = check_that_out_file_exists, **kwargs