Fixed issue with is_debug gn arg

Multiple is_debug arguements caused the script not to actually check the
is_debug arg from fuchsia.git. We now use JSON output to ensure we are
checking the is_debug arguement at the root.

Change-Id: I3e4b9ff1de26a05acf1ad352ca047378c1693fc2
Reviewed-on: https://fuchsia-review.googlesource.com/c/third_party/github.com/intel/media-driver/+/688847
Reviewed-by: John Bauman <jbauman@google.com>
diff --git a/fuchsia/upload.py b/fuchsia/upload.py
index 815edf1..a1a3c7f 100644
--- a/fuchsia/upload.py
+++ b/fuchsia/upload.py
@@ -102,10 +102,10 @@
                 self.symbol_input_names.append(entry["debug"])
 
     def GnArgs(self):
-        return [
-            ("is_debug", args.debug),
-            ("intel_media_driver_debug", args.debug),
-        ]
+        return {
+            "is_debug": args.debug,
+            "intel_media_driver_debug": args.debug,
+        }
 
 
 driver_list = [IntelDriver("intel/media-driver")]
@@ -152,17 +152,38 @@
 for driver in driver_list:
     gn_args = driver.GnArgs()
     gn_arg_mismatch = False
-    gn_output = subprocess.check_output(
+    gn_output_json = subprocess.check_output(
         [
             os.path.join(fuchsia_root, "prebuilt/third_party/gn/linux-x64/gn"),
-            "args", out_dir, "--short", "--list"
-        ]).decode("utf-8").strip()
+            "args",
+            out_dir,
+            "--short",
+            "--list",
+            "--json",
+        ]).decode("utf-8")
 
-    for arg_name, arg_val in gn_args:
-        expected_output = "%s = %s" % (arg_name, "true" if arg_val else "false")
-        if expected_output not in gn_output:
-            print("Missing \"%s\" from GN arguments" % expected_output)
-            gn_arg_mismatch = True
+    gn_output = json.loads(gn_output_json)
+    gn_arg_vars = set(gn_args.keys())
+
+    for gn_variable in gn_output:
+        var_name = gn_variable["name"]
+        if var_name in gn_args:
+            value = gn_variable["default"]["value"]
+            if "current" in gn_variable:
+                value = gn_variable["current"]["value"]
+            expected_val = "true" if gn_args[var_name] else "false"
+            if value != expected_val:
+                print(
+                    "GN argument \"{}\" should have a value of \"{}\" but has a value of \"{}\""
+                    .format(var_name, expected_val, value))
+                gn_arg_mismatch = True
+            gn_arg_vars.remove(var_name)
+
+    if gn_arg_vars:
+        print(
+            "Missing variable(s) \"{}\" from GN arguments".format(
+                ",".join(gn_arg_vars)))
+        gn_arg_mismatch = True
 
     if gn_arg_mismatch:
         if args.ignore_buildtype: