pw_env_setup: Add Windows py launcher

Some tools (nanopb) launch python using `py -3`. Pigweed doesn't
provide a full py launcher, so this is a stopgap change to add a
stub that should support scripts that launch python using the py
launcher.

Change-Id: Ibed1ae2ca79ef3c9698056c04110a1ab82d825c7
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/24022
Commit-Queue: Auto-Submit <auto-submit@pigweed.google.com.iam.gserviceaccount.com>
Reviewed-by: Anthony DiGirolamo <tonymd@google.com>
Pigweed-Auto-Submit: Armando Montanez <montanez.armando.l@gmail.com>
diff --git a/pw_env_setup/py/pw_env_setup/env_setup.py b/pw_env_setup/py/pw_env_setup/env_setup.py
index c03bd43..c5c23fb 100755
--- a/pw_env_setup/py/pw_env_setup/env_setup.py
+++ b/pw_env_setup/py/pw_env_setup/env_setup.py
@@ -267,6 +267,9 @@
         if not self._is_windows and self._enable_cargo:
             steps.append(("Rust cargo", self.cargo))
 
+        if self._is_windows:
+            steps.append(("Windows scripts", self.win_scripts))
+
         self._log(
             Color.bold('Downloading and installing packages into local '
                        'source directory:\n'))
@@ -432,6 +435,13 @@
         self._env.prepend('PATH', os.path.join(host_dir, 'host_tools'))
         return _Result(_Result.Status.DONE)
 
+    def win_scripts(self):
+        # These scripts act as a compatibility layer for windows.
+        env_setup_dir = os.path.join(self._pw_root, 'pw_env_setup')
+        self._env.prepend('PATH', os.path.join(env_setup_dir,
+                                               'windows_scripts'))
+        return _Result(_Result.Status.DONE)
+
     def cargo(self):
         install_dir = os.path.join(self._install_dir, 'cargo')
 
diff --git a/pw_env_setup/windows_scripts/py.bat b/pw_env_setup/windows_scripts/py.bat
new file mode 100644
index 0000000..27810f3
--- /dev/null
+++ b/pw_env_setup/windows_scripts/py.bat
@@ -0,0 +1,34 @@
+:<<"::WINDOWS_ONLY"
+@echo off
+:: Copyright 2020 The Pigweed Authors
+::
+:: Licensed under the Apache License, Version 2.0 (the "License"); you may not
+:: use this file except in compliance with the License. You may obtain a copy of
+:: the License at
+::
+::     https://www.apache.org/licenses/LICENSE-2.0
+::
+:: Unless required by applicable law or agreed to in writing, software
+:: distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+:: WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+:: License for the specific language governing permissions and limitations under
+:: the License.
+::WINDOWS_ONLY
+:; echo "ERROR: Attempting to run Windows .bat from a Unix/POSIX shell!"
+:; echo "Instead, run the following command."
+:; echo ""
+:; echo "    source ./bootstrap.sh"
+:; echo ""
+:<<"::WINDOWS_ONLY"
+
+if "%1"=="-3" (
+    for /f "tokens=1,* delims= " %%a in ("%*") do set ARGS=%%b
+) else (
+    echo ERROR: Pigweed's mini py launcher only supports python3.
+    exit /b 1
+)
+
+:: Ignore the `-3` flag, Pigweed's python is alwasy python3.
+call python %ARGS%
+
+::WINDOWS_ONLY