Snap for 9849129 from d97a3ff4f4681264074245bb00759580970ee793 to udc-release

Change-Id: I19ee2a1fe94742556c69578625d627fd48749c48
diff --git a/BUILD.bazel b/BUILD.bazel
index cd5af58..aa04800 100644
--- a/BUILD.bazel
+++ b/BUILD.bazel
@@ -20,6 +20,7 @@
     visibility = ["//visibility:public"],
     deps = [
         "//src:deps",
+        "@skia_user_config//:user_config",
     ],
 )
 
@@ -46,6 +47,7 @@
     ],
     deps = [
         "//src:deps",
+        "@skia_user_config//:user_config",
     ],
 )
 
diff --git a/PRESUBMIT.py b/PRESUBMIT.py
index a9c9603..e3f4fda 100644
--- a/PRESUBMIT.py
+++ b/PRESUBMIT.py
@@ -292,7 +292,7 @@
     excluded_paths = ["infra/", "bazel/rbe/", "bazel/external/", "bazel/common_config_settings/",
                       "modules/canvaskit/go/", "experimental/", "bazel/platform", "third_party/",
                       "tests/", "resources/", "bazel/deps_parser/", "bazel/exporter_tool/",
-                      "tools/gpu/gl/interface/", "bazel/utils/"]
+                      "tools/gpu/gl/interface/", "bazel/utils/", "include/config/"]
     is_excluded = any(affected_file_path.startswith(n) for n in excluded_paths)
     if is_bazel and not is_excluded:
       with open(affected_file_path, 'r') as file:
diff --git a/WORKSPACE.bazel b/WORKSPACE.bazel
index 67e1f86..8e38094 100644
--- a/WORKSPACE.bazel
+++ b/WORKSPACE.bazel
@@ -230,6 +230,12 @@
     firefox = True,
 )
 
+# Clients must specify their own version of skia_user_config to overwrite SkUserConfig.h
+local_repository(
+    name="skia_user_config",
+    path="include/config",
+)
+
 # Bazel will look for env variables ANDROID_HOME and ANDROID_NDK_HOME.
 # This is NOT hermetic as it requires the user to handle downloading the SDK  and accepting the
 # license independently.
diff --git a/bazel/cc_binary_with_flags.bzl b/bazel/cc_binary_with_flags.bzl
index 4c2d368..af20434 100644
--- a/bazel/cc_binary_with_flags.bzl
+++ b/bazel/cc_binary_with_flags.bzl
@@ -8,7 +8,7 @@
 
 """
 
-load("//bazel:copts.bzl", "DEFAULT_COPTS")
+load("@skia_user_config//:copts.bzl", "DEFAULT_COPTS")
 
 _bool_flags = [
     "//bazel/common_config_settings:use_harfbuzz",
diff --git a/bazel/cc_test_with_flags.bzl b/bazel/cc_test_with_flags.bzl
index f9741fb..93a22c3 100644
--- a/bazel/cc_test_with_flags.bzl
+++ b/bazel/cc_test_with_flags.bzl
@@ -12,7 +12,7 @@
 
 """
 
-load("//bazel:copts.bzl", "DEFAULT_COPTS")
+load("@skia_user_config//:copts.bzl", "DEFAULT_COPTS")
 load("//bazel:cc_binary_with_flags.bzl", "with_flags_transition")
 
 def _transition_rule_impl(ctx):
diff --git a/bazel/skia_rules.bzl b/bazel/skia_rules.bzl
index bc84ec0..ee44ac7 100644
--- a/bazel/skia_rules.bzl
+++ b/bazel/skia_rules.bzl
@@ -7,14 +7,14 @@
 in their WORKSPACE.bazel file.
 """
 
+load("@skia_user_config//:copts.bzl", "DEFAULT_COPTS", "DEFAULT_OBJC_COPTS")
+load("@skia_user_config//:linkopts.bzl", "DEFAULT_LINKOPTS")
 load("//bazel:cc_binary_with_flags.bzl", "cc_binary_with_flags")
-load("//bazel:copts.bzl", "DEFAULT_COPTS", "DEFAULT_OBJC_COPTS")
 load(
     "//bazel:generate_cpp_files_for_headers.bzl",
     _generate_cpp_files_for_header_list = "generate_cpp_files_for_header_list",
     _generate_cpp_files_for_headers = "generate_cpp_files_for_headers",
 )
-load("//bazel:linkopts.bzl", "DEFAULT_LINKOPTS")
 
 generate_cpp_files_for_headers = _generate_cpp_files_for_headers
 generate_cpp_files_for_header_list = _generate_cpp_files_for_header_list
@@ -73,10 +73,10 @@
     Args:
         name: the name of the underlying executable.
         copts: Flags which should be passed to the C++ compiler. By default, we use DEFAULT_COPTS
-            from //bazel/copts.bzl.
+            from @skia_user_config//:copts.bzl.
         linkopts: Global flags which should be passed to the C++ linker. By default, we use
-            DEFAULT_LINKOPTS from //bazel/linkopts.bzl. Other linker flags will be passed in
-            via deps (see deps_and_linkopts below).
+            DEFAULT_LINKOPTS from  @skia_user_config//:linkopts.bzl. Other linker flags will be
+            passed in via deps (see deps_and_linkopts below).
         **kwargs: All the normal arguments that cc_binary takes.
     """
     native.cc_binary(name = name, copts = copts, linkopts = linkopts, **kwargs)
@@ -109,7 +109,7 @@
     Args:
         name: the name of the underlying library.
         copts: Flags which should be passed to the C++ compiler. By default, we use DEFAULT_COPTS
-            from //bazel/copts.bzl.
+            from @skia_user_config//:copts.bzl.
         **kwargs: All the normal arguments that cc_library takes.
     """
     native.cc_library(name = name, copts = copts, **kwargs)
@@ -158,7 +158,7 @@
     Args:
         name: the name of the underlying target.
         copts: Flags which should be passed to the C++ compiler. By default, we use
-            DEFAULT_OBJC_COPTS from //bazel/copts.bzl.
+            DEFAULT_OBJC_COPTS from @skia_user_config//:copts.bzl.
         **kwargs: Normal arguments to objc_library
     """
 
diff --git a/include/BUILD.bazel b/include/BUILD.bazel
index e8cf679..c662501 100644
--- a/include/BUILD.bazel
+++ b/include/BUILD.bazel
@@ -9,7 +9,6 @@
     srcs = [
         "//include/android:public_hdrs",
         "//include/codec:public_hdrs",
-        "//include/config:public_hdrs",
         "//include/core:public_hdrs",
         "//include/docs:public_hdrs",
         "//include/effects:public_hdrs",
@@ -69,7 +68,6 @@
     # generated that is a copy of the header file just with a .cpp suffix so Bazel will try to
     # compile it. This allows us to run IWYU on these files.
     to_generate = [
-        "include/config/SkUserConfig.h",
         "include/core/SkAlphaType.h",
         "include/core/SkBlendMode.h",
         "include/core/SkBlurTypes.h",
diff --git a/include/config/BUILD.bazel b/include/config/BUILD.bazel
index ab9b9ac..d1ab50f 100644
--- a/include/config/BUILD.bazel
+++ b/include/config/BUILD.bazel
@@ -1,16 +1,18 @@
-load("//bazel:skia_rules.bzl", "exports_files_legacy", "skia_filegroup")
-
 licenses(["notice"])
 
-exports_files_legacy()
+# aka exports_files_legacy()
+exports_files(
+    ["SkUserConfig.h"],
+    visibility = ["//visibility:public"],
+)
 
-skia_filegroup(
-    name = "public_hdrs",
-    srcs = [
+cc_library(
+    name = "user_config",
+    hdrs = [
         "SkUserConfig.h",
     ],
-    visibility = [
-        "//include:__pkg__",
-        "//src:__pkg__",
+    defines = [
+        "SK_USE_BAZEL_CONFIG_HEADER",
     ],
+    visibility = ["//visibility:public"],
 )
diff --git a/include/config/OWNERS b/include/config/OWNERS
new file mode 100644
index 0000000..25b714b
--- /dev/null
+++ b/include/config/OWNERS
@@ -0,0 +1,2 @@
+bungeman@google.com
+kjlubick@google.com
\ No newline at end of file
diff --git a/include/config/WORKSPACE.bazel b/include/config/WORKSPACE.bazel
new file mode 100644
index 0000000..aa3d6b6
--- /dev/null
+++ b/include/config/WORKSPACE.bazel
@@ -0,0 +1,3 @@
+# This empty workspace file lets the SkUserConfig.h file be defined separately from Skia itself.
+# Clients can more easily set their own #defines, copts, and linkopts when building Skia using
+# Bazel.
diff --git a/bazel/copts.bzl b/include/config/copts.bzl
similarity index 100%
rename from bazel/copts.bzl
rename to include/config/copts.bzl
diff --git a/bazel/linkopts.bzl b/include/config/linkopts.bzl
similarity index 89%
rename from bazel/linkopts.bzl
rename to include/config/linkopts.bzl
index 439a86c..282b5bd 100644
--- a/bazel/linkopts.bzl
+++ b/include/config/linkopts.bzl
@@ -3,7 +3,7 @@
 
 This file contains flags for the C++ linker, referred to by Bazel as linkopts.
 
-For similar reasons as //bazel/copts.bzl, we define "global" flags we want to pass to the linker
+For similar reasons as ./copts.bzl, we define "global" flags we want to pass to the linker
 here. We do allow subpackages to conditionally set linkopts because that is likely to be more
 readable than trying to express with select statements whether a library should be linked against
 because the relevant Skia source file was compiled in.
diff --git a/include/private/base/SkLoadUserConfig.h b/include/private/base/SkLoadUserConfig.h
index 397d40b..b212ada 100644
--- a/include/private/base/SkLoadUserConfig.h
+++ b/include/private/base/SkLoadUserConfig.h
@@ -18,10 +18,15 @@
 
 // IWYU pragma: begin_exports
 
-// Note: SK_USER_CONFIG_HEADER will not work with Bazel builds, as that file will not
-// be specified for the Bazel sandbox.
-#if defined (SK_USER_CONFIG_HEADER)
+// Note: SK_USER_CONFIG_HEADER will not work with Bazel builds and some C++ compilers.
+#if defined(SK_USER_CONFIG_HEADER)
     #include SK_USER_CONFIG_HEADER
+#elif defined(SK_USE_BAZEL_CONFIG_HEADER)
+    // The Bazel config file is presumed to be in the root directory of its Bazel Workspace.
+    // This is achieved in Skia by having a nested WORKSPACE in include/config and a cc_library
+    // defined in that folder. As a result, we do not try to include SkUserConfig.h from the
+    // top of Skia because Bazel sandboxing will move it to a different location.
+    #include "SkUserConfig.h"
 #else
     #include "include/config/SkUserConfig.h"
 #endif
diff --git a/infra/bots/gen_tasks_logic/gen_tasks_logic.go b/infra/bots/gen_tasks_logic/gen_tasks_logic.go
index b097889..fe8aa97 100644
--- a/infra/bots/gen_tasks_logic/gen_tasks_logic.go
+++ b/infra/bots/gen_tasks_logic/gen_tasks_logic.go
@@ -546,6 +546,7 @@
 			"skia/WORKSPACE.bazel",
 			"skia/bazel",
 			"skia/go_repositories.bzl",
+			"skia/include/config", // There's a WORKSPACE.bazel in here
 			"skia/requirements.txt",
 			"skia/toolchain",
 			// Actually needed to build the task drivers
diff --git a/infra/bots/tasks.json b/infra/bots/tasks.json
index b7a417c..f03ceb4 100644
--- a/infra/bots/tasks.json
+++ b/infra/bots/tasks.json
@@ -94142,6 +94142,7 @@
         "skia/WORKSPACE.bazel",
         "skia/bazel",
         "skia/go_repositories.bzl",
+        "skia/include/config",
         "skia/requirements.txt",
         "skia/toolchain",
         "skia/infra/bots/BUILD.bazel",
diff --git a/modules/canvaskit/BUILD.bazel b/modules/canvaskit/BUILD.bazel
index a98fba6..066a599 100644
--- a/modules/canvaskit/BUILD.bazel
+++ b/modules/canvaskit/BUILD.bazel
@@ -1,6 +1,6 @@
 load("//bazel:macros.bzl", "bool_flag", "exports_files_legacy", "skia_filegroup", "wasm_cc_binary")
 load("//bazel:karma_test.bzl", "karma_test")
-load("//bazel:copts.bzl", "DEFAULT_COPTS")
+load("@skia_user_config//:copts.bzl", "DEFAULT_COPTS")
 
 licenses(["notice"])
 
diff --git a/src/BUILD.bazel b/src/BUILD.bazel
index 48ba4ee..8561857 100644
--- a/src/BUILD.bazel
+++ b/src/BUILD.bazel
@@ -150,7 +150,6 @@
 skia_cc_library(
     name = "base",
     srcs = [
-        "//include/config:public_hdrs",
         "//src/base:srcs",
     ] + select({
         "//bazel/common_config_settings:compile_generated_cpp_files_for_headers_true": [
@@ -165,6 +164,7 @@
     ],
     features = ["layering_check"],
     visibility = ["//src:__subpackages__"],
+    deps = ["@skia_user_config//:user_config"],
 )
 
 skia_cc_library(
diff --git a/src/opts/BUILD.bazel b/src/opts/BUILD.bazel
index ac5736f..dddf8f2 100644
--- a/src/opts/BUILD.bazel
+++ b/src/opts/BUILD.bazel
@@ -11,8 +11,8 @@
 (e.g. architecture options) and linked into the final library or binary.
 """
 
+load("@skia_user_config//:copts.bzl", "DEFAULT_COPTS")
 load("//:defines.bzl", "DEFAULT_DEFINES", "DEFAULT_LOCAL_DEFINES")
-load("//bazel:copts.bzl", "DEFAULT_COPTS")
 load("//bazel:skia_rules.bzl", "exports_files_legacy", "skia_cc_deps", "skia_cc_library", "skia_filegroup")
 load("//bazel:flags.bzl", "selects")
 
@@ -56,6 +56,7 @@
     copts = DEFAULT_COPTS + ["-march=armv8-a+crc"],
     local_defines = DEFAULT_DEFINES + DEFAULT_LOCAL_DEFINES,
     textual_hdrs = OPTS_HDRS,
+    deps = ["@skia_user_config//:user_config"],
 )
 
 skia_cc_library(
@@ -64,6 +65,7 @@
     copts = DEFAULT_COPTS + ["-mssse3"],
     local_defines = DEFAULT_DEFINES + DEFAULT_LOCAL_DEFINES,
     textual_hdrs = OPTS_HDRS,
+    deps = ["@skia_user_config//:user_config"],
 )
 
 skia_cc_library(
@@ -72,6 +74,7 @@
     copts = DEFAULT_COPTS + ["-msse4.2"],
     local_defines = DEFAULT_DEFINES + DEFAULT_LOCAL_DEFINES,
     textual_hdrs = OPTS_HDRS,
+    deps = ["@skia_user_config//:user_config"],
 )
 
 skia_cc_library(
@@ -80,6 +83,7 @@
     copts = DEFAULT_COPTS + ["-mavx"],
     local_defines = DEFAULT_DEFINES + DEFAULT_LOCAL_DEFINES,
     textual_hdrs = OPTS_HDRS,
+    deps = ["@skia_user_config//:user_config"],
 )
 
 skia_cc_library(
@@ -90,6 +94,7 @@
     textual_hdrs = OPTS_HDRS,
     deps = [
         "//modules/skcms",  # Needed to implement SkRasterPipeline_opts.h
+        "@skia_user_config//:user_config",
     ],
 )
 
@@ -99,6 +104,7 @@
     copts = DEFAULT_COPTS + ["-march=skylake-avx512"],
     local_defines = DEFAULT_DEFINES + DEFAULT_LOCAL_DEFINES,
     textual_hdrs = OPTS_HDRS,
+    deps = ["@skia_user_config//:user_config"],
 )
 
 skia_cc_deps(
diff --git a/tools/rewrite_includes.py b/tools/rewrite_includes.py
index 8c453f5..40594a8 100755
--- a/tools/rewrite_includes.py
+++ b/tools/rewrite_includes.py
@@ -86,7 +86,9 @@
       'tests/sksl/' in file_path or
       'third_party/skcms' in file_path or
       'modules/skcms' in file_path or
-      file_path.startswith('bazel/rbe')):
+      file_path.startswith('bazel/rbe') or
+      # We intentionally list SkUserConfig.h not from the root in this file.
+      file_path == 'include/private/base/SkLoadUserConfig.h'):
     continue
   if (file_path.endswith('.h') or
       file_path.endswith('.c') or
diff --git a/tools/sk_app/BUILD.bazel b/tools/sk_app/BUILD.bazel
index 784b98c..dd02cdb 100644
--- a/tools/sk_app/BUILD.bazel
+++ b/tools/sk_app/BUILD.bazel
@@ -1,5 +1,5 @@
 load("//bazel:skia_rules.bzl", "exports_files_legacy", "select_multi", "skia_cc_deps", "skia_cc_library", "skia_objc_library")
-load("//bazel:copts.bzl", "DEFAULT_OBJC_COPTS")
+load("@skia_user_config//:copts.bzl", "DEFAULT_OBJC_COPTS")
 
 licenses(["notice"])