Fix nocompile_driver.py when there are spaces in CFLAGS

To fix, retain the array-ness of the arguments rather
than concatenating strings.

Bug: 749393
Change-Id: Icceacf14e30117da1617134e4ef6a364f9808275
Reviewed-on: https://chromium-review.googlesource.com/587693
Reviewed-by: Wei-Yin Chen (陳威尹) <[email protected]>
Reviewed-by: Dirk Pranke <[email protected]>
Commit-Queue: Trent Apted <[email protected]>
Cr-Commit-Position: refs/heads/master@{#490147}
diff --git a/tools/nocompile_driver.py b/tools/nocompile_driver.py
index 598e4130..5418045 100755
--- a/tools/nocompile_driver.py
+++ b/tools/nocompile_driver.py
@@ -18,7 +18,6 @@
 import os
 import re
 import select
-import shlex
 import subprocess
 import sys
 import time
@@ -86,7 +85,9 @@
   """Make sure the arguments being passed in are sane."""
   assert parallelism >= 1
   assert type(sourcefile_path) is str
-  assert type(cflags) is str
+  assert type(cflags) is list
+  for flag in cflags:
+    assert(type(flag) is str)
   assert type(resultfile_path) is str
 
 
@@ -182,8 +183,7 @@
 
   Args:
     sourcefile_path: The path to the source file.
-    cflags: A string with all the CFLAGS to give to gcc. This string will be
-            split by shelex so be careful with escaping.
+    cflags: An array of strings with all the CFLAGS to give to gcc.
     config: A dictionary describing the test.  See ExtractTestConfigs
       for a description of the config format.
 
@@ -215,7 +215,7 @@
   cmdline = [os.path.join(os.path.dirname(os.path.realpath(__file__)),
                           '../third_party/llvm-build/Release+Asserts/bin',
                           'clang++')]
-  cmdline.extend(shlex.split(cflags))
+  cmdline.extend(cflags)
   name = config['name']
   expectations = config['expectations']
   if expectations is not None:
@@ -396,8 +396,8 @@
 
 
 def main():
-  if len(sys.argv) != 5:
-    print ('Usage: %s <parallelism> <sourcefile> <cflags> <resultfile>' %
+  if len(sys.argv) < 5 or sys.argv[4] != '--':
+    print ('Usage: %s <parallelism> <sourcefile> <resultfile> -- <cflags...>' %
            sys.argv[0])
     sys.exit(1)
 
@@ -408,8 +408,8 @@
 
   parallelism = int(sys.argv[1])
   sourcefile_path = sys.argv[2]
-  cflags = sys.argv[3]
-  resultfile_path = sys.argv[4]
+  resultfile_path = sys.argv[3]
+  cflags = sys.argv[5:]
 
   timings = {'started': time.time()}
 
@@ -433,9 +433,10 @@
   executing_tests = {}
   finished_tests = []
 
+  cflags.extend(['-MMD', '-MF', resultfile_path + '.d', '-MT', resultfile_path])
   test = StartTest(
       sourcefile_path,
-      cflags + ' -MMD -MF %s.d -MT %s' % (resultfile_path, resultfile_path),
+      cflags,
       { 'name': 'NCTEST_SANITY',
         'suite_name': suite_name,
         'expectations': None,