pw_build: Don't touch files unnecessarily

generate_python_package.py was touching __init__.py and py.typed files
to ensure they exist. This causes Ninja to unnecessarily re-run some
Python steps, which are quite slow. With this change, the files are only
touched if they do not exist.

Change-Id: Ide630e5e3714746b7fd2e8dcb44ba47db204f967
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/38160
Pigweed-Auto-Submit: Wyatt Hepler <hepler@google.com>
Commit-Queue: Auto-Submit <auto-submit@pigweed.google.com.iam.gserviceaccount.com>
Reviewed-by: Keir Mierle <keir@google.com>
diff --git a/pw_build/py/pw_build/generate_python_package.py b/pw_build/py/pw_build/generate_python_package.py
index 199cd45..81e6c48 100644
--- a/pw_build/py/pw_build/generate_python_package.py
+++ b/pw_build/py/pw_build/generate_python_package.py
@@ -105,7 +105,8 @@
     # Make sure there are __init__.py and py.typed files for each subpackage.
     for pkg in subpackages:
         for file in (pkg / name for name in ['__init__.py', 'py.typed']):
-            file.touch()
+            if not file.exists():
+                file.touch()
             files.append(file)
 
     pkg_data: Dict[str, Set[str]] = defaultdict(set)
diff --git a/pw_build/python.gni b/pw_build/python.gni
index 2b1ce22..fccf212 100644
--- a/pw_build/python.gni
+++ b/pw_build/python.gni
@@ -269,6 +269,8 @@
           args += [ "--module-as-package" ]
         }
 
+        inputs = [ "$_setup_dir/setup.json" ]
+
         public_deps = [
           ":$target_name._mirror_sources_to_out_dir",
           ":$target_name._protos",