pw_presubmit: adds a preserve_args_gn arg to build.gn_gn

This helps projects that copy an args.gn to the output
directory before calling build.gn_gen.

Also, when there are no gn_arguments, the --args is
not passed to `gn gen`

Change-Id: I1cd07642abe82a41098c5314131c0923227ce4d4
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/98240
Reviewed-by: Rob Mohr <mohrr@google.com>
Commit-Queue: Zoltan Szatmary-Ban <szatmz@google.com>
diff --git a/pw_presubmit/py/pw_presubmit/build.py b/pw_presubmit/py/pw_presubmit/build.py
index 9da43e1..1c5dc75 100644
--- a/pw_presubmit/py/pw_presubmit/build.py
+++ b/pw_presubmit/py/pw_presubmit/build.py
@@ -104,14 +104,16 @@
            gn_check: bool = True,
            gn_fail_on_unused: bool = True,
            export_compile_commands: Union[bool, str] = True,
+           preserve_args_gn: bool = False,
            **gn_arguments) -> None:
     """Runs gn gen in the specified directory with optional GN args."""
     args_option = gn_args(**gn_arguments)
 
-    # Delete args.gn to ensure this is a clean build.
-    args_gn = gn_output_dir / 'args.gn'
-    if args_gn.is_file():
-        args_gn.unlink()
+    if not preserve_args_gn:
+        # Delete args.gn to ensure this is a clean build.
+        args_gn = gn_output_dir / 'args.gn'
+        if args_gn.is_file():
+            args_gn.unlink()
 
     export_commands_arg = ''
     if export_compile_commands:
@@ -126,7 +128,7 @@
          *(['--fail-on-unused-args'] if gn_fail_on_unused else []),
          *([export_commands_arg] if export_commands_arg else []),
          *args,
-         args_option,
+         *([args_option] if gn_arguments else []),
          cwd=gn_source_dir)
 
     if gn_check: