mirror of
				https://bitbucket.org/chromiumembedded/cef
				synced 2025-06-05 21:39:12 +02:00 
			
		
		
		
	automate-git: Windows: Patch VS toolchain scripts before runhooks
Split `gclient sync` into separate `gclient sync --nohooks` and `gclient runhooks` steps so that we can optionally apply patches from `runhooks.patch` in-between. This is necessary because the src/tools/clang/scripts/update.py script is run via a hook and has dependencies on the VS toolchain scripts which must be patched to properly consider the GYP_MSVS_VERSION environment variable.
This commit is contained in:
		@@ -26,9 +26,6 @@ patches = [
 | 
			
		||||
    # Move chrome target locales output to a chrome/ directory to avoid
 | 
			
		||||
    # conflicts with the CEF configuration.
 | 
			
		||||
    #
 | 
			
		||||
    # Support custom VS toolchain on Windows.
 | 
			
		||||
    # https://bugs.chromium.org/p/chromium/issues/detail?id=623342
 | 
			
		||||
    #
 | 
			
		||||
    # Write environment.* files with the correct SDK version on Windows.
 | 
			
		||||
    # https://bugs.chromium.org/p/chromium/issues/detail?id=634788
 | 
			
		||||
    #
 | 
			
		||||
@@ -36,6 +33,14 @@ patches = [
 | 
			
		||||
    # https://bitbucket.org/chromiumembedded/cef/issues/2432
 | 
			
		||||
    'name': 'gn_config',
 | 
			
		||||
  },
 | 
			
		||||
  {
 | 
			
		||||
    # Patches that must be applied after `gclient sync --nohooks` and before
 | 
			
		||||
    # `gclient runhooks`.
 | 
			
		||||
    #
 | 
			
		||||
    # Support custom VS toolchain on Windows.
 | 
			
		||||
    # https://bugs.chromium.org/p/chromium/issues/detail?id=623342
 | 
			
		||||
    'name': 'runhooks',
 | 
			
		||||
  },
 | 
			
		||||
  {
 | 
			
		||||
    # Support component builds (GN is_component_build=true).
 | 
			
		||||
    # https://bitbucket.org/chromiumembedded/cef/issues/1617
 | 
			
		||||
 
 | 
			
		||||
@@ -55,82 +55,6 @@ index 982fbe8d3f0d..e757be4688f1 100644
 | 
			
		||||
+         "You must set the visual_studio_runtime_dirs if you set the visual " +
 | 
			
		||||
+         "studio path")
 | 
			
		||||
 }
 | 
			
		||||
diff --git build/toolchain/win/setup_toolchain.py build/toolchain/win/setup_toolchain.py
 | 
			
		||||
index fa31688f36a2..69d74aa31c47 100644
 | 
			
		||||
--- build/toolchain/win/setup_toolchain.py
 | 
			
		||||
+++ build/toolchain/win/setup_toolchain.py
 | 
			
		||||
@@ -142,22 +142,25 @@ def _LoadToolchainEnv(cpu, sdk_dir, target_store):
 | 
			
		||||
       # variable.
 | 
			
		||||
       if 'VSINSTALLDIR' in os.environ:
 | 
			
		||||
         del os.environ['VSINSTALLDIR']
 | 
			
		||||
-      other_path = os.path.normpath(os.path.join(
 | 
			
		||||
+      script_path = os.path.normpath(os.path.join(
 | 
			
		||||
                                         os.environ['GYP_MSVS_OVERRIDE_PATH'],
 | 
			
		||||
                                         'VC/Auxiliary/Build/vcvarsall.bat'))
 | 
			
		||||
-      if not os.path.exists(other_path):
 | 
			
		||||
-        raise Exception('%s is missing - make sure VC++ tools are installed.' %
 | 
			
		||||
-                        script_path)
 | 
			
		||||
-      script_path = other_path
 | 
			
		||||
-    cpu_arg = "amd64"
 | 
			
		||||
-    if (cpu != 'x64'):
 | 
			
		||||
-      # x64 is default target CPU thus any other CPU requires a target set
 | 
			
		||||
-      cpu_arg += '_' + cpu
 | 
			
		||||
-    args = [script_path, cpu_arg]
 | 
			
		||||
-    # Store target must come before any SDK version declaration
 | 
			
		||||
-    if (target_store):
 | 
			
		||||
-      args.append(['store'])
 | 
			
		||||
-    variables = _LoadEnvFromBat(args)
 | 
			
		||||
+    if os.path.exists(script_path):
 | 
			
		||||
+      cpu_arg = "amd64"
 | 
			
		||||
+      if (cpu != 'x64'):
 | 
			
		||||
+        # x64 is default target CPU thus any other CPU requires a target set
 | 
			
		||||
+        cpu_arg += '_' + cpu
 | 
			
		||||
+      args = [script_path, cpu_arg]
 | 
			
		||||
+      # Store target must come before any SDK version declaration
 | 
			
		||||
+      if (target_store):
 | 
			
		||||
+        args.append(['store'])
 | 
			
		||||
+      variables = _LoadEnvFromBat(args)
 | 
			
		||||
+    else:
 | 
			
		||||
+      variables = []
 | 
			
		||||
+      for k in sorted(os.environ.keys()):
 | 
			
		||||
+        variables.append('%s=%s' % (str(k), str(os.environ[k])))
 | 
			
		||||
+      variables = '\n'.join(variables)
 | 
			
		||||
+
 | 
			
		||||
   return _ExtractImportantEnvironment(variables)
 | 
			
		||||
 
 | 
			
		||||
 
 | 
			
		||||
diff --git build/vs_toolchain.py build/vs_toolchain.py
 | 
			
		||||
index 97600e73ba10..36773b159453 100755
 | 
			
		||||
--- build/vs_toolchain.py
 | 
			
		||||
+++ build/vs_toolchain.py
 | 
			
		||||
@@ -89,9 +89,16 @@ def SetEnvironmentAndGetRuntimeDllDirs():
 | 
			
		||||
     runtime_path = os.path.pathsep.join(vs_runtime_dll_dirs)
 | 
			
		||||
     os.environ['PATH'] = runtime_path + os.path.pathsep + os.environ['PATH']
 | 
			
		||||
   elif sys.platform == 'win32' and not depot_tools_win_toolchain:
 | 
			
		||||
+    has_override_path = True
 | 
			
		||||
     if not 'GYP_MSVS_OVERRIDE_PATH' in os.environ:
 | 
			
		||||
+      has_override_path = False
 | 
			
		||||
       os.environ['GYP_MSVS_OVERRIDE_PATH'] = DetectVisualStudioPath()
 | 
			
		||||
 
 | 
			
		||||
+    if has_override_path:
 | 
			
		||||
+      # Don't attempt to copy DLLs when using a custom toolchain.
 | 
			
		||||
+      # The DLLs should already be discoverable via the PATH env variable.
 | 
			
		||||
+      return None
 | 
			
		||||
+
 | 
			
		||||
     # When using an installed toolchain these files aren't needed in the output
 | 
			
		||||
     # directory in order to run binaries locally, but they are needed in order
 | 
			
		||||
     # to create isolates or the mini_installer. Copying them to the output
 | 
			
		||||
@@ -140,6 +147,10 @@ def _RegistryGetValue(key, value):
 | 
			
		||||
 def GetVisualStudioVersion():
 | 
			
		||||
   """Return best available version of Visual Studio.
 | 
			
		||||
   """
 | 
			
		||||
+  # Return the explicitly requested version, if any.
 | 
			
		||||
+  if 'GYP_MSVS_VERSION' in os.environ:
 | 
			
		||||
+    return os.environ['GYP_MSVS_VERSION']
 | 
			
		||||
+
 | 
			
		||||
   supported_versions = list(MSVS_VERSIONS.keys())
 | 
			
		||||
 
 | 
			
		||||
   # VS installed in depot_tools for Googlers
 | 
			
		||||
diff --git chrome/chrome_paks.gni chrome/chrome_paks.gni
 | 
			
		||||
index 5121fa721a06..b5ab128722f0 100644
 | 
			
		||||
--- chrome/chrome_paks.gni
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										76
									
								
								patch/patches/runhooks.patch
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										76
									
								
								patch/patches/runhooks.patch
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,76 @@
 | 
			
		||||
diff --git build/toolchain/win/setup_toolchain.py build/toolchain/win/setup_toolchain.py
 | 
			
		||||
index fa31688f36a2..69d74aa31c47 100644
 | 
			
		||||
--- build/toolchain/win/setup_toolchain.py
 | 
			
		||||
+++ build/toolchain/win/setup_toolchain.py
 | 
			
		||||
@@ -142,22 +142,25 @@ def _LoadToolchainEnv(cpu, sdk_dir, target_store):
 | 
			
		||||
       # variable.
 | 
			
		||||
       if 'VSINSTALLDIR' in os.environ:
 | 
			
		||||
         del os.environ['VSINSTALLDIR']
 | 
			
		||||
-      other_path = os.path.normpath(os.path.join(
 | 
			
		||||
+      script_path = os.path.normpath(os.path.join(
 | 
			
		||||
                                         os.environ['GYP_MSVS_OVERRIDE_PATH'],
 | 
			
		||||
                                         'VC/Auxiliary/Build/vcvarsall.bat'))
 | 
			
		||||
-      if not os.path.exists(other_path):
 | 
			
		||||
-        raise Exception('%s is missing - make sure VC++ tools are installed.' %
 | 
			
		||||
-                        script_path)
 | 
			
		||||
-      script_path = other_path
 | 
			
		||||
-    cpu_arg = "amd64"
 | 
			
		||||
-    if (cpu != 'x64'):
 | 
			
		||||
-      # x64 is default target CPU thus any other CPU requires a target set
 | 
			
		||||
-      cpu_arg += '_' + cpu
 | 
			
		||||
-    args = [script_path, cpu_arg]
 | 
			
		||||
-    # Store target must come before any SDK version declaration
 | 
			
		||||
-    if (target_store):
 | 
			
		||||
-      args.append(['store'])
 | 
			
		||||
-    variables = _LoadEnvFromBat(args)
 | 
			
		||||
+    if os.path.exists(script_path):
 | 
			
		||||
+      cpu_arg = "amd64"
 | 
			
		||||
+      if (cpu != 'x64'):
 | 
			
		||||
+        # x64 is default target CPU thus any other CPU requires a target set
 | 
			
		||||
+        cpu_arg += '_' + cpu
 | 
			
		||||
+      args = [script_path, cpu_arg]
 | 
			
		||||
+      # Store target must come before any SDK version declaration
 | 
			
		||||
+      if (target_store):
 | 
			
		||||
+        args.append(['store'])
 | 
			
		||||
+      variables = _LoadEnvFromBat(args)
 | 
			
		||||
+    else:
 | 
			
		||||
+      variables = []
 | 
			
		||||
+      for k in sorted(os.environ.keys()):
 | 
			
		||||
+        variables.append('%s=%s' % (str(k), str(os.environ[k])))
 | 
			
		||||
+      variables = '\n'.join(variables)
 | 
			
		||||
+
 | 
			
		||||
   return _ExtractImportantEnvironment(variables)
 | 
			
		||||
 
 | 
			
		||||
 
 | 
			
		||||
diff --git build/vs_toolchain.py build/vs_toolchain.py
 | 
			
		||||
index 97600e73ba10..36773b159453 100755
 | 
			
		||||
--- build/vs_toolchain.py
 | 
			
		||||
+++ build/vs_toolchain.py
 | 
			
		||||
@@ -89,9 +89,16 @@ def SetEnvironmentAndGetRuntimeDllDirs():
 | 
			
		||||
     runtime_path = os.path.pathsep.join(vs_runtime_dll_dirs)
 | 
			
		||||
     os.environ['PATH'] = runtime_path + os.path.pathsep + os.environ['PATH']
 | 
			
		||||
   elif sys.platform == 'win32' and not depot_tools_win_toolchain:
 | 
			
		||||
+    has_override_path = True
 | 
			
		||||
     if not 'GYP_MSVS_OVERRIDE_PATH' in os.environ:
 | 
			
		||||
+      has_override_path = False
 | 
			
		||||
       os.environ['GYP_MSVS_OVERRIDE_PATH'] = DetectVisualStudioPath()
 | 
			
		||||
 
 | 
			
		||||
+    if has_override_path:
 | 
			
		||||
+      # Don't attempt to copy DLLs when using a custom toolchain.
 | 
			
		||||
+      # The DLLs should already be discoverable via the PATH env variable.
 | 
			
		||||
+      return None
 | 
			
		||||
+
 | 
			
		||||
     # When using an installed toolchain these files aren't needed in the output
 | 
			
		||||
     # directory in order to run binaries locally, but they are needed in order
 | 
			
		||||
     # to create isolates or the mini_installer. Copying them to the output
 | 
			
		||||
@@ -140,6 +147,10 @@ def _RegistryGetValue(key, value):
 | 
			
		||||
 def GetVisualStudioVersion():
 | 
			
		||||
   """Return best available version of Visual Studio.
 | 
			
		||||
   """
 | 
			
		||||
+  # Return the explicitly requested version, if any.
 | 
			
		||||
+  if 'GYP_MSVS_VERSION' in os.environ:
 | 
			
		||||
+    return os.environ['GYP_MSVS_VERSION']
 | 
			
		||||
+
 | 
			
		||||
   supported_versions = list(MSVS_VERSIONS.keys())
 | 
			
		||||
 
 | 
			
		||||
   # VS installed in depot_tools for Googlers
 | 
			
		||||
		Reference in New Issue
	
	Block a user