Upstream-Status: Backport

Backported from https://crrev.com/c/2277064

Signed-off-by: Maksim Sisov <msisov@igalia.com>
---
From 70c64f54eb173a233ecfabe1e7a621a652f9c2ca Mon Sep 17 00:00:00 2001
From: Tom Anderson <thomasanderson@chromium.org>
Date: Wed, 1 Jul 2020 20:37:59 +0000
Subject: [PATCH 2/2] Build with third-party xcbproto

R=nickdiego

Bug: 1066670
Change-Id: I08740b54d545160ed01ff2a96c06e6850bf993f9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2277064
Commit-Queue: Thomas Anderson <thomasanderson@chromium.org>
Reviewed-by: Nick Yamane <nickdiego@igalia.com>
Cr-Commit-Position: refs/heads/master@{#784549}
---
 ui/gfx/x/BUILD.gn      | 84 +++++++++++++++++-------------------------
 ui/gfx/x/gen_xproto.py |  8 +---
 2 files changed, 36 insertions(+), 56 deletions(-)

diff --git a/ui/gfx/x/BUILD.gn b/ui/gfx/x/BUILD.gn
index 5369e38efedd..1e99ce205d5e 100644
--- a/ui/gfx/x/BUILD.gn
+++ b/ui/gfx/x/BUILD.gn
@@ -3,23 +3,12 @@
 # found in the LICENSE file.
 
 import("//build/config/jumbo.gni")
-import("//build/config/sysroot.gni")
 import("//build/config/ui.gni")
 import("//ui/ozone/ozone.gni")
 
 assert(use_x11 || ozone_platform_x11)
 
-declare_args() {
-  xcbproto_path = ""
-}
-
-if (xcbproto_path == "") {
-  if (use_sysroot) {
-    xcbproto_path = "$sysroot/usr/share/xcb"
-  } else {
-    xcbproto_path = "/usr/share/xcb"
-  }
-}
+xcbproto_path = "//third_party/xcbproto/src"
 
 config("x11_private_config") {
   cflags = [
@@ -36,50 +25,45 @@ action_foreach("gen_xprotos") {
   visibility = [ ":xprotos" ]
   script = "gen_xproto.py"
   sources = [
-    "$xcbproto_path/bigreq.xml",
-    "$xcbproto_path/composite.xml",
-    "$xcbproto_path/damage.xml",
-    "$xcbproto_path/dpms.xml",
-    "$xcbproto_path/dri2.xml",
-    "$xcbproto_path/dri3.xml",
-    "$xcbproto_path/ge.xml",
-    "$xcbproto_path/glx.xml",
-    "$xcbproto_path/present.xml",
-    "$xcbproto_path/randr.xml",
-    "$xcbproto_path/record.xml",
-    "$xcbproto_path/render.xml",
-    "$xcbproto_path/res.xml",
-    "$xcbproto_path/screensaver.xml",
-    "$xcbproto_path/shape.xml",
-    "$xcbproto_path/shm.xml",
-    "$xcbproto_path/sync.xml",
-    "$xcbproto_path/xc_misc.xml",
-    "$xcbproto_path/xevie.xml",
-    "$xcbproto_path/xf86dri.xml",
-    "$xcbproto_path/xf86vidmode.xml",
-    "$xcbproto_path/xfixes.xml",
-    "$xcbproto_path/xinerama.xml",
-    "$xcbproto_path/xinput.xml",
-    "$xcbproto_path/xkb.xml",
-    "$xcbproto_path/xprint.xml",
-    "$xcbproto_path/xproto.xml",
-    "$xcbproto_path/xselinux.xml",
-    "$xcbproto_path/xtest.xml",
-    "$xcbproto_path/xv.xml",
-    "$xcbproto_path/xvmc.xml",
+    "$xcbproto_path/src/bigreq.xml",
+    "$xcbproto_path/src/composite.xml",
+    "$xcbproto_path/src/damage.xml",
+    "$xcbproto_path/src/dpms.xml",
+    "$xcbproto_path/src/dri2.xml",
+    "$xcbproto_path/src/dri3.xml",
+    "$xcbproto_path/src/ge.xml",
+    "$xcbproto_path/src/glx.xml",
+    "$xcbproto_path/src/present.xml",
+    "$xcbproto_path/src/randr.xml",
+    "$xcbproto_path/src/record.xml",
+    "$xcbproto_path/src/render.xml",
+    "$xcbproto_path/src/res.xml",
+    "$xcbproto_path/src/screensaver.xml",
+    "$xcbproto_path/src/shape.xml",
+    "$xcbproto_path/src/shm.xml",
+    "$xcbproto_path/src/sync.xml",
+    "$xcbproto_path/src/xc_misc.xml",
+    "$xcbproto_path/src/xevie.xml",
+    "$xcbproto_path/src/xf86dri.xml",
+    "$xcbproto_path/src/xf86vidmode.xml",
+    "$xcbproto_path/src/xfixes.xml",
+    "$xcbproto_path/src/xinerama.xml",
+    "$xcbproto_path/src/xinput.xml",
+    "$xcbproto_path/src/xkb.xml",
+    "$xcbproto_path/src/xprint.xml",
+    "$xcbproto_path/src/xproto.xml",
+    "$xcbproto_path/src/xselinux.xml",
+    "$xcbproto_path/src/xtest.xml",
+    "$xcbproto_path/src/xv.xml",
+    "$xcbproto_path/src/xvmc.xml",
   ]
   outputs = [
     "$target_gen_dir/{{source_name_part}}_undef.h",
     "$target_gen_dir/{{source_name_part}}.h",
     "$target_gen_dir/{{source_name_part}}.cc",
   ]
-  args = [ "{{source}}" ] + rebase_path(outputs, root_build_dir)
-  if (use_sysroot) {
-    args += [
-      "--sysroot",
-      rebase_path(sysroot, root_build_dir),
-    ]
-  }
+  args = rebase_path([ xcbproto_path ]) + [ "{{source}}" ] +
+         rebase_path(outputs, root_build_dir)
 }
 
 component("xprotos") {
diff --git a/ui/gfx/x/gen_xproto.py b/ui/gfx/x/gen_xproto.py
index 4a34901012d9..3d899ace848a 100644
--- a/ui/gfx/x/gen_xproto.py
+++ b/ui/gfx/x/gen_xproto.py
@@ -1003,18 +1003,14 @@ class GenXproto:
 
 def main():
     parser = argparse.ArgumentParser()
+    parser.add_argument('xcbproto_dir', type=str)
     parser.add_argument('xmlfile', type=argparse.FileType('r'))
     parser.add_argument('undeffile', type=argparse.FileType('w'))
     parser.add_argument('headerfile', type=argparse.FileType('w'))
     parser.add_argument('sourcefile', type=argparse.FileType('w'))
-    parser.add_argument('--sysroot')
     args = parser.parse_args()
 
-    if args.sysroot:
-        path = os.path.join(args.sysroot, 'usr', 'lib', 'python2.7',
-                            'dist-packages')
-        sys.path.insert(1, path)
-
+    sys.path.insert(1, args.xcbproto_dir)
     import xcbgen.xtypes
     import xcbgen.state
 
-- 
2.25.1

