Use a separate DEPS file to drive LTO/release builds (#697)

Instead of using emscripten-version.txt, trigger LTO builds on changes to a
separate DEPS file, DEPS.tagged-release. This change copies that over the
existing DEPS file and reruns 'gclient sync' before building. This avoids the
problem of unrelated DEPS changes racing with release DEPS changes.
diff --git a/src/build.py b/src/build.py
index 7c37616..70d3a3e 100755
--- a/src/build.py
+++ b/src/build.py
@@ -48,7 +48,7 @@
 CMAKE_TOOLCHAIN_FILE = 'Wasi.cmake'
 
 EMSCRIPTEN_CONFIG_UPSTREAM = 'emscripten_config_upstream'
-EMSCRIPTEN_VERSION_FILE = 'emscripten-version.txt'
+RELEASE_DEPS_FILE = 'DEPS.tagged-release'
 
 # Avoid flakes: use cached repositories to avoid relying on external network.
 GIT_MIRROR_BASE = 'https://chromium.googlesource.com/'
@@ -281,7 +281,7 @@
         global g_should_use_lto
         if g_should_use_lto is None:
             g_should_use_lto = RevisionModifiesFile(
-                GetSrcDir(EMSCRIPTEN_VERSION_FILE))
+                GetSrcDir(RELEASE_DEPS_FILE))
         return g_should_use_lto
     return options.use_lto == 'true'
 
@@ -691,6 +691,14 @@
                 create_out_dir=True)
 
 
+def SyncReleaseDeps(name, src_dir, git_repo):
+    if not ShouldUseLTO():
+        print('ShouldUseLTO is false, skipping release DEPS')
+        return
+    shutil.copy2(GetSrcDir(RELEASE_DEPS_FILE), GetSrcDir('DEPS'))
+    proc.check_call(['gclient', 'sync'], cwd=GetSrcDir())
+
+
 def NoSync(*args):
     pass
 
@@ -725,7 +733,8 @@
         Source('java', '', '',  # The source and git args are ignored.
                custom_sync=SyncPrebuiltJava),
         Source('sysroot', '', '',  # The source and git args are ignored.
-               custom_sync=SyncLinuxSysroot)
+               custom_sync=SyncLinuxSysroot),
+        Source('deps', '', '', custom_sync=SyncReleaseDeps)
     ]
 
 
@@ -1160,13 +1169,6 @@
     proc.check_call(['npm', 'install', '--no-optional', native],
                     cwd=em_install_dir)
 
-    version_file = GetSrcDir(EMSCRIPTEN_VERSION_FILE)
-    if os.path.isfile(version_file):
-        with open(version_file) as f:
-            print('Copying emscripten version file (version %s)' %
-                  f.read().strip())
-        shutil.copy2(version_file, em_install_dir)
-
 
 def Emscripten():
     InstallEmscripten()