build: Improve update ext srcs script for better CI

Add options (--debug --release --32 --64) to the
update_external_sources.bat script so that it can
be used to build external libraries for only the
desired platform/configuration combinations.

This helps the AppVeyor CI builds by building only
the platform/configuration combination needed for the
current job.
diff --git a/.appveyor.yml b/.appveyor.yml
index 65b00cb..087c5c6 100644
--- a/.appveyor.yml
+++ b/.appveyor.yml
@@ -8,7 +8,7 @@
 # build version format
 version: "{build}"
 
-# Probably not useful for free accounts, but ask anyway.
+# Free accounts have a max of 1, but ask anyway.
 max_jobs: 4
 
 os:
@@ -28,69 +28,27 @@
     - master
 
 before_build:
-# These steps are a replacement for
-# - update_external_sources.bat --all
-# Instead of using the above script to build glslang/spirv-tools
-# for all platform configs, build only the job's selected platform config.
-# Since the script doesn't support building a single platform config,
-# use parts of the script to build only the selected platform config.
-#
-# Also always build the x64 Release platform config in order to
-# get the shader compiler binary which is used to build the repo.
-#
-# For a 4 platform config setup:
-# All this results in 7 builds of glslang per commit, which isn't
-# as good as building 4 when building all 4 platform configs in
-# a single job, but is necessary when splitting the build into 4 jobs.
-# It is still better than 16 glslang builds.
-#
   - "SET PATH=C:\\Python35;C:\\Python35\\Scripts;%PATH%"
-  - setlocal EnableDelayedExpansion
-  # Set up some useful vars.
-  - set TOP_DIR="%APPVEYOR_BUILD_FOLDER%\"
-  - set EXT_DIR=%TOP_DIR%external
-  - set REVISION_DIR=%TOP_DIR%external_revisions
-  - set GLSLANG_DIR=%EXT_DIR%\glslang
-  - set /p GLSLANG_GITURL= < %REVISION_DIR%\glslang_giturl
-  - set /p GLSLANG_REVISION= < %REVISION_DIR%\glslang_revision
-  # Clone and checkout glslang.
-  - echo.
-  - echo Creating local glslang repository %GLSLANG_DIR%
-  - echo GLSLANG_GITURL=%GLSLANG_GITURL%
-  - echo GLSLANG_REVISION=%GLSLANG_REVISION%
-  - if not exist %GLSLANG_DIR% (mkdir %GLSLANG_DIR%)
-  - cd %GLSLANG_DIR%
-  # If this dir is not empty, then a build cache was restored. Update it by fetching any updates.
-  # If the dir is empty, clone the repo.
-  - dir /b /a | findstr .  > nul && (git fetch --all) || (git clone %GLSLANG_GITURL% . )
-  - git checkout %GLSLANG_REVISION%
-  - python.exe .\update_glslang_sources.py
-  # Build glslang.
-  - echo.
-  - echo Building %GLSLANG_DIR%
-  # We always need the x64 Release version of the shader compiler for building the repo.
-  - cd  %GLSLANG_DIR%
-  - if not exist build (mkdir build)
-  - cd build
-  - cmake -G "Visual Studio 12 2013 Win64" -DCMAKE_INSTALL_PREFIX=install ..
-  - msbuild INSTALL.vcxproj /p:Platform=x64 /p:Configuration=Release /verbosity:quiet
-  # Build the x64 debug version if selected.
-  - if %PLATFORM% == x64 (if %CONFIGURATION% == Debug (msbuild INSTALL.vcxproj /p:Platform=x64 /p:Configuration=Debug /verbosity:quiet))
-  # Build 32-bit platform configs if selected.
-  - cd %GLSLANG_DIR%
-  - if not exist build32 (mkdir build32)
-  - cd build32
-  - if %PLATFORM% == Win32 (cmake -G "Visual Studio 12 2013" -DCMAKE_INSTALL_PREFIX=install ..)
-  - if %PLATFORM% == Win32 (msbuild INSTALL.vcxproj /p:Platform=x86 /p:Configuration=%CONFIGURATION% /verbosity:quiet)
-  # Generate build files using CMake for the build step.
   - echo.
   - echo Starting build for %APPVEYOR_REPO_NAME%
-  - if %PLATFORM% == Win32 (set GENERATOR="Visual Studio 12 2013")
-  - if %PLATFORM% == x64 (set GENERATOR="Visual Studio 12 2013 Win64")
+  - echo Update external sources
+  - if %PLATFORM% == Win32 (if %CONFIGURATION% == Debug (update_external_sources.bat --32 --debug))
+  - if %PLATFORM% == Win32 (if %CONFIGURATION% == Release (update_external_sources.bat --32 --release))
+  - if %PLATFORM% == x64 (if %CONFIGURATION% == Debug (update_external_sources.bat --64 --debug))
+  - if %PLATFORM% == x64 (if %CONFIGURATION% == Release (update_external_sources.bat --64 --release))
+  # Determine the appropriate CMake generator for the current version of Visual Studio
+  - echo Determining VS version
+  - python .\scripts\determine_vs_version.py > vsversion.tmp
+  - set /p VS_VERSION=< vsversion.tmp
+  - echo Detected Visual Studio Version as %VS_VERSION%
+  - del /Q /F vsversion.tmp
+  - if %PLATFORM% == Win32 (set GENERATOR="Visual Studio %VS_VERSION%")
+  - if %PLATFORM% == x64 (set GENERATOR="Visual Studio %VS_VERSION% Win64")
+  # Generate build files using CMake for the build step.
+  - echo Generating CMake files for %GENERATOR%
   - cd %TOP_DIR%
   - mkdir build
   - cd build
-  - echo Generating CMake files for %GENERATOR%
   - cmake -G %GENERATOR% ..
   - echo Building platform=%PLATFORM% configuration=%CONFIGURATION%
 
diff --git a/update_external_sources.bat b/update_external_sources.bat
index e9d95e8..d4ac865 100644
--- a/update_external_sources.bat
+++ b/update_external_sources.bat
@@ -16,6 +16,10 @@
 set BASE_DIR="%BUILD_DIR%external"
 set REVISION_DIR="%BUILD_DIR%external_revisions"
 set GLSLANG_DIR=%BASE_DIR%\glslang
+set do_32=0
+set do_64=0
+set do_debug=0
+set do_release=0
 
 REM // ======== Parameter parsing ======== //
 
@@ -23,6 +27,10 @@
    set arg-do-glslang=0
    set arg-no-sync=0
    set arg-no-build=0
+   set arg-32=0
+   set arg-64=0
+   set arg-debug=0
+   set arg-release=0
 
    :parameterLoop
 
@@ -58,6 +66,34 @@
          goto:parameterLoop
       )
 
+      if "%1" == "--32" (
+         set arg-32=1
+         echo 32-bit build requested
+         shift
+         goto:parameterLoop
+      )
+
+      if "%1" == "--64" (
+         set arg-64=1
+         echo 64-bit build requested
+         shift
+         goto:parameterLoop
+      )
+
+      if "%1" == "--debug" (
+         set arg-debug=1
+         echo debug build requested
+         shift
+         goto:parameterLoop
+      )
+
+      if "%1" == "--release" (
+         set arg-release=1
+         echo release build requested
+         shift
+         goto:parameterLoop
+      )
+
       if "%1" == "--spirv-tools" (
          echo --spirv-tools argument has been deprecated and is no longer necessary
          shift
@@ -89,12 +125,22 @@
       echo     --all               enable all components
       echo     --no-sync           skip sync from git
       echo     --no-build          skip build
+      echo     --32                build for 32-bit
+      echo     --64                build for 64-bit
+      echo     --debug             build for debug
+      echo     --release           build for release
       echo.
       echo   If any component enables are provided, only those components are enabled.
       echo   If no component enables are provided, all components are enabled.
       echo.
       echo   Sync uses git to pull a specific revision.
       echo   Build configures CMake, builds Release and Debug.
+      echo.
+      echo   --32 without --64 builds only 32-bit, and vice-versa.
+      echo   --debug without --release builds only debug, and vice-versa.
+      echo   Specifying neither or both --32 and --64 builds both.
+      echo   Specifying neither or both --debug and --release builds both.
+      echo   So specifying none of these 4 options (default) builds all 4.
 
 
       goto:error
@@ -120,6 +166,32 @@
       )
    )
 
+   if %arg-32% equ 1 (
+       set do_32=1
+   )
+   if %arg-64% equ 1 (
+       set do_64=1
+   )
+   if %arg-32% equ 0 (
+      if %arg-64% equ 0 (
+          set do_32=1
+          set do_64=1
+      )
+   )
+
+   if %arg-debug% equ 1 (
+       set do_debug=1
+   )
+   if %arg-release% equ 1 (
+       set do_release=1
+   )
+   if %arg-debug% equ 0 (
+      if %arg-release% equ 0 (
+          set do_debug=1
+          set do_release=1
+      )
+   )
+
    REM this is a debugging aid that can be enabled while debugging command-line parsing
    if 0 equ 1 (
       set arg
@@ -254,61 +326,72 @@
        mkdir build
    )
 
-   echo Making 32-bit glslang
-   echo *************************
-
    set GLSLANG_BUILD_DIR=%GLSLANG_DIR%\build32
-   cd %GLSLANG_BUILD_DIR%
+   if %do_32% equ 1 (
+      echo Making 32-bit glslang
+      echo *************************
+      cd %GLSLANG_BUILD_DIR%
 
-   echo Generating 32-bit Glslang CMake files for Visual Studio %VS_VERSION% -DCMAKE_INSTALL_PREFIX=install ..
-   cmake -G "Visual Studio %VS_VERSION%" -DCMAKE_INSTALL_PREFIX=install ..
+      echo Generating 32-bit Glslang CMake files for Visual Studio %VS_VERSION% -DCMAKE_INSTALL_PREFIX=install ..
+      cmake -G "Visual Studio %VS_VERSION%" -DCMAKE_INSTALL_PREFIX=install ..
 
-   echo Building 32-bit Glslang: MSBuild INSTALL.vcxproj /p:Platform=x86 /p:Configuration=Debug
-   msbuild INSTALL.vcxproj /p:Platform=x86 /p:Configuration=Debug /verbosity:quiet
+      if %do_debug% equ 1 (
+         echo Building 32-bit Glslang: MSBuild INSTALL.vcxproj /p:Platform=x86 /p:Configuration=Debug
+         msbuild INSTALL.vcxproj /p:Platform=x86 /p:Configuration=Debug /verbosity:quiet
 
-   REM Check for existence of one lib, even though we should check for all results
-   if not exist %GLSLANG_BUILD_DIR%\glslang\Debug\glslangd.lib (
-      echo.
-      echo glslang 32-bit Debug build failed!
-      set errorCode=1
-   )
-   echo Building Glslang: MSBuild INSTALL.vcxproj /p:Platform=x86 /p:Configuration=Release
-   msbuild INSTALL.vcxproj /p:Platform=x86 /p:Configuration=Release /verbosity:quiet
+         REM Check for existence of one lib, even though we should check for all results
+         if not exist %GLSLANG_BUILD_DIR%\glslang\Debug\glslangd.lib (
+            echo.
+            echo glslang 32-bit Debug build failed!
+            set errorCode=1
+         )
+      )
+      if %do_release% equ 1 (
+         echo Building Glslang: MSBuild INSTALL.vcxproj /p:Platform=x86 /p:Configuration=Release
+         msbuild INSTALL.vcxproj /p:Platform=x86 /p:Configuration=Release /verbosity:quiet
 
-   REM Check for existence of one lib, even though we should check for all results
-   if not exist %GLSLANG_BUILD_DIR%\glslang\Release\glslang.lib (
-      echo.
-      echo glslang 32-bit Release build failed!
-      set errorCode=1
+         REM Check for existence of one lib, even though we should check for all results
+         if not exist %GLSLANG_BUILD_DIR%\glslang\Release\glslang.lib (
+            echo.
+            echo glslang 32-bit Release build failed!
+            set errorCode=1
+         )
+      )
+      cd ..
    )
 
-   cd ..
-
-   echo Making 64-bit glslang
-   echo *************************
    set GLSLANG_BUILD_DIR=%GLSLANG_DIR%\build
-   cd %GLSLANG_BUILD_DIR%
+   if %do_64% equ 1 (
+      echo Making 64-bit glslang
+      echo *************************
+      cd %GLSLANG_BUILD_DIR%
 
-   echo Generating 64-bit Glslang CMake files for Visual Studio %VS_VERSION% -DCMAKE_INSTALL_PREFIX=install ..
-   cmake -G "Visual Studio %VS_VERSION% Win64" -DCMAKE_INSTALL_PREFIX=install ..
+      echo Generating 64-bit Glslang CMake files for Visual Studio %VS_VERSION% -DCMAKE_INSTALL_PREFIX=install ..
+      cmake -G "Visual Studio %VS_VERSION% Win64" -DCMAKE_INSTALL_PREFIX=install ..
 
-   echo Building 64-bit Glslang: MSBuild INSTALL.vcxproj /p:Platform=x64 /p:Configuration=Debug
-   msbuild INSTALL.vcxproj /p:Platform=x64 /p:Configuration=Debug /verbosity:quiet
+      if %do_debug% equ 1 (
+         echo Building 64-bit Glslang: MSBuild INSTALL.vcxproj /p:Platform=x64 /p:Configuration=Debug
+         msbuild INSTALL.vcxproj /p:Platform=x64 /p:Configuration=Debug /verbosity:quiet
 
-   REM Check for existence of one lib, even though we should check for all results
-   if not exist %GLSLANG_BUILD_DIR%\glslang\Debug\glslangd.lib (
-       echo.
-       echo glslang 64-bit Debug build failed!
-       set errorCode=1
+         REM Check for existence of one lib, even though we should check for all results
+         if not exist %GLSLANG_BUILD_DIR%\glslang\Debug\glslangd.lib (
+            echo.
+            echo glslang 64-bit Debug build failed!
+            set errorCode=1
+         )
+      )
+      if %do_release% equ 1 (
+         echo Building Glslang: MSBuild INSTALL.vcxproj /p:Platform=x64 /p:Configuration=Release
+         msbuild INSTALL.vcxproj /p:Platform=x64 /p:Configuration=Release /verbosity:quiet
+
+         REM Check for existence of one lib, even though we should check for all results
+         if not exist %GLSLANG_BUILD_DIR%\glslang\Release\glslang.lib (
+            echo.
+            echo glslang 64-bit Release build failed!
+            set errorCode=1
+         )
+      )
+      cd ..
    )
 
-   echo Building Glslang: MSBuild INSTALL.vcxproj /p:Platform=x64 /p:Configuration=Release
-   msbuild INSTALL.vcxproj /p:Platform=x64 /p:Configuration=Release /verbosity:quiet
-
-   REM Check for existence of one lib, even though we should check for all results
-   if not exist %GLSLANG_BUILD_DIR%\glslang\Release\glslang.lib (
-       echo.
-       echo glslang 64-bit Release build failed!
-       set errorCode=1
-   )
 goto:eof