env_setup: Split activate and bootstrap on Windows

This change creates a top level bootstrap and activate script on Windows
to mirror the Linux setup.

Change-Id: I6d06ea2112b68deceb0d6d2011c3c80699a7e77f
diff --git a/activate.bat b/activate.bat
new file mode 100644
index 0000000..1dbec98
--- /dev/null
+++ b/activate.bat
@@ -0,0 +1,23 @@
+@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.
+
+:: Activates a Pigweed development environment by setting the appropriate
+:: environment variables. bootstrap.bat must be run initially to install all
+:: required programs; after that, activate.bat can be used to enter the
+:: environment in a shell.
+
+set PW_SKIP_BOOTSTRAP=1
+call %~dp0\bootstrap.bat
+set PW_SKIP_BOOTSTRAP=
diff --git a/pw_env_setup/env_setup.bat b/bootstrap.bat
similarity index 75%
rename from pw_env_setup/env_setup.bat
rename to bootstrap.bat
index 7a81b72..aec00c5 100644
--- a/pw_env_setup/env_setup.bat
+++ b/bootstrap.bat
@@ -22,15 +22,14 @@
 :: will complain if they see that variable set.
 :: TODO(mohrr) find out a way to do this without PW_CHECKOUT_ROOT.
 if "%PW_CHECKOUT_ROOT%"=="" (
-  :: Calls a Powershell script that determines the correct PW_ROOT directory and
-  :: exports it as an environment variable.
-  for /F "usebackq tokens=1" %%i in (`powershell %%~dp0..\..\pw_env_setup\env_setup.ps1`) do set PW_ROOT=%%i
-) ELSE (
+  :: ~dp0 is the batchism for the directory in which a .bat file resides.
+  set PW_ROOT=%~dp0
+) else (
   set PW_ROOT=%PW_CHECKOUT_ROOT%
   set PW_CHECKOUT_ROOT=
 )
 
-:: Allow forcing a specifc Python version through the environment variable
+:: Allow forcing a specific Python version through the environment variable
 :: PW_BOOTSTRAP_PYTHON. Otherwise, use the system Python if one exists.
 if not "%PW_BOOTSTRAP_PYTHON%" == "" (
   set python="%PW_BOOTSTRAP_PYTHON%"
@@ -49,14 +48,23 @@
   )
 )
 
-call %python% %PW_ROOT%\pw_env_setup\py\pw_env_setup\windows_env_start.py
-
+set _pw_start_script=%PW_ROOT%\pw_env_setup\py\pw_env_setup\windows_env_start.py
 set shell_file="%PW_ROOT%\pw_env_setup\.env_setup.bat"
 
-if not exist %shell_file% (
+:: If PW_SKIP_BOOTSTRAP is set, only run the activation stage instead of the
+:: complete env_setup.
+if "%PW_SKIP_BOOTSTRAP%" == "" (
+  call %python% %_pw_start_script% --bootstrap
   call %python% %PW_ROOT%\pw_env_setup\py\pw_env_setup\env_setup.py^
     --pw-root %PW_ROOT%^
     --shell-file %shell_file%
+) else (
+  if exist %shell_file% (
+    call %python% %_pw_start_script%
+  ) else (
+    call %python% %_pw_start_script% --no-shell-file
+    goto finish
+  )
 )
 
 call %shell_file%
diff --git a/docs/setup.md b/docs/setup.md
index eb4b5fd..ad62f40 100644
--- a/docs/setup.md
+++ b/docs/setup.md
@@ -49,10 +49,10 @@
 **Windows**
 ```batch
 :: Run git commands from the shell you set up to use with Git during install.
-> git clone sso://pigweed.googlesource.com/pigweed/pigweed %HOMEPATH%\pigweed
 > cd %HOMEPATH%\pigweed
+> git clone sso://pigweed.googlesource.com/pigweed/pigweed
 > python pw_env_setup\py\pw_env_setup\cipd_setup\wrapper.py auth-login
-> pw_env_setup\env_setup.bat
+> bootstrap.bat
 ```
 
 ## Contributors
diff --git a/pw_cli/py/pw_cli/env.py b/pw_cli/py/pw_cli/env.py
index af6802d..b6cf5c0 100644
--- a/pw_cli/py/pw_cli/env.py
+++ b/pw_cli/py/pw_cli/env.py
@@ -31,6 +31,7 @@
                    type=envparse.strict_bool,
                    default=False)
     parser.add_var('PW_ROOT')
+    parser.add_var('PW_SKIP_BOOTSTRAP')
     parser.add_var('PW_SUBPROCESS', type=envparse.strict_bool, default=False)
     parser.add_var('PW_USE_COLOR', type=envparse.strict_bool, default=False)
 
diff --git a/pw_env_setup/env_setup.ps1 b/pw_env_setup/env_setup.ps1
deleted file mode 100644
index 9eb15c9..0000000
--- a/pw_env_setup/env_setup.ps1
+++ /dev/null
@@ -1,16 +0,0 @@
-# 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.
-
-# Prints the parent directory of the current script (i.e. the Pigweed root).
-Write-Output (Split-Path -path $PSScriptRoot)
diff --git a/pw_env_setup/py/pw_env_setup/colors.py b/pw_env_setup/py/pw_env_setup/colors.py
index 63cb834..22b06a9 100644
--- a/pw_env_setup/py/pw_env_setup/colors.py
+++ b/pw_env_setup/py/pw_env_setup/colors.py
@@ -29,6 +29,8 @@
 class Color:  # pylint: disable=too-few-public-methods
     """Helpers to surround text with ASCII color escapes"""
     bold = _make_color(1)
+    red = _make_color(31)
+    bold_red = _make_color(31, 1)
     green = _make_color(32)
     magenta = _make_color(35, 1)
 
diff --git a/pw_env_setup/py/pw_env_setup/windows_env_start.py b/pw_env_setup/py/pw_env_setup/windows_env_start.py
index dc81260..46ce452 100644
--- a/pw_env_setup/py/pw_env_setup/windows_env_start.py
+++ b/pw_env_setup/py/pw_env_setup/windows_env_start.py
@@ -22,6 +22,7 @@
 
 from __future__ import print_function
 
+import argparse
 import os
 import sys
 
@@ -37,17 +38,21 @@
 
 
 def main():
+    """Script entry point."""
     if os.name != 'nt':
         return 1
 
+    parser = argparse.ArgumentParser()
+    parser.add_argument('--bootstrap', action='store_true')
+    parser.add_argument('--no-shell-file', action='store_true')
+    args = parser.parse_args()
+
     enable_colors()
 
     print(Color.green('\n  WELCOME TO...'))
     print(Color.magenta(_PIGWEED_BANNER))
 
-    bootstrap = True
-
-    if bootstrap:
+    if args.bootstrap:
         print(
             Color.green('\n  BOOTSTRAP! Bootstrap may take a few minutes; '
                         'please be patient'))
@@ -57,8 +62,15 @@
     else:
         print(
             Color.green(
-                '\n  ACTIVATOR! This sets your console environment variables.')
-        )
+                '\n  ACTIVATOR! This sets your console environment variables.\n'
+            ))
+
+        if args.no_shell_file:
+            print(Color.bold_red('Error!\n'))
+            print(
+                Color.red('  Your Pigweed environment does not seem to be'
+                          ' configured.'))
+            print(Color.red('  Run bootstrap.bat to perform initial setup.'))
 
     return 0