[gtk-doc/scangobj-quotes-fix: 1/2] scangobj: keep quotes when splitting with shlex



commit bdd4b1b3d4287fa4bfa997c93342213d8220ce7b
Author: Marco Trevisan (TreviƱo) <mail 3v1n0 net>
Date:   Wed Sep 12 22:01:07 2018 +0200

    scangobj: keep quotes when splitting with shlex
    
    shlex.split doesn't keep double quotes when splitting, thus we need to redefine
    it so that double quotes are considered quotes by the lexer.
    
    Use it to parse ldflags and cflags.
    
    Added test-gobject-scangobj-quoted-cflags to verify the new behavior.
    
    Fixes GNOME/gtk-doc#57

 gtkdoc/scangobj.py                      | 11 +++++++++--
 tests/gobject/docs/meson.build          | 19 ++++++++++++++++++-
 tests/helpers/gtkdoc_scangobj_runner.py |  5 ++++-
 3 files changed, 31 insertions(+), 4 deletions(-)
---
diff --git a/gtkdoc/scangobj.py b/gtkdoc/scangobj.py
index 237863c..6cba988 100644
--- a/gtkdoc/scangobj.py
+++ b/gtkdoc/scangobj.py
@@ -1201,6 +1201,12 @@ def execute_command(options, description, command):
         return 1
     return 0
 
+def split_with_quote(string):
+    lex = shlex.shlex(string)
+    lex.quotes = '"'
+    lex.whitespace_split = True
+    lex.commenters = ''
+    return list(lex)
 
 def run(options):
     logging.info('options: %s', str(options.__dict__))
@@ -1278,14 +1284,15 @@ def run(options):
     logging.debug('Intermediate scanner files: %s, %s, %s', c_file, o_file, x_file)
 
     res = execute_command(options, 'Compiling',
-                          shlex.split(options.cc) + shlex.split(options.cflags) +
+                          shlex.split(options.cc) +
+                          split_with_quote(options.cflags) +
                           ["-c", "-o", o_file, c_file])
     if res:
         return res
 
     res = execute_command(options, 'Linking',
                           shlex.split(options.ld) + [o_file] +
-                          shlex.split(options.ldflags) + ['-o', x_file])
+                          split_with_quote(options.ldflags) + ['-o', x_file])
     if res:
         return res
 
diff --git a/tests/gobject/docs/meson.build b/tests/gobject/docs/meson.build
index 5a05e30..b7e4495 100644
--- a/tests/gobject/docs/meson.build
+++ b/tests/gobject/docs/meson.build
@@ -54,6 +54,23 @@ test(
   ],
 )
 
+test(
+  'test-gobject-scangobj-quoted-cflags',
+  python_prg,
+  workdir: gobject_test_output_dir,
+  is_parallel: false,
+  args: [
+    gtkdoc_scangobj_runner_script,
+    '--binary-dir=@0@'.format(builddir),
+    '--pkg-config=@0@'.format(pkgconfig_prg_path),
+    '--extra-pkg=@0@'.format('glib-2.0'),
+    '--extra-pkg=@0@'.format('gobject-2.0'),
+    '--extra-cflags=@0@'.format('-DG_LOG_DOMAIN="tester"'),
+    '--extra-lib=@0@'.format(gobject_test_lib.full_path()),
+    '--module=@0@'.format('tester'),
+  ],
+)
+
 test(
   'test-gobject-mkdb',
   python_prg,
@@ -123,4 +140,4 @@ test(
     '--input-dir=@0@'.format(gobject_test_docs_dir),
     '--output-dir=@0@'.format(gobject_test_output_dir),
   ],
-)
\ No newline at end of file
+)
diff --git a/tests/helpers/gtkdoc_scangobj_runner.py b/tests/helpers/gtkdoc_scangobj_runner.py
index b1005e6..45067ac 100644
--- a/tests/helpers/gtkdoc_scangobj_runner.py
+++ b/tests/helpers/gtkdoc_scangobj_runner.py
@@ -17,6 +17,8 @@ if __name__ == '__main__':
                         help='Path to the pkg-config executable to be used')
     parser.add_argument("--extra-pkg", type=str, default=[], action='append',
                         help='Extra package to be use while scanning')
+    parser.add_argument("--extra-cflags", type=str, default=[], action='append',
+                        help='Extra Cflags to be use while scanning')
     parser.add_argument("--extra-lib", type=str, default=[], action='append',
                         help='Extra library to be use while scanning')
 
@@ -33,6 +35,7 @@ if __name__ == '__main__':
     if process.returncode == 0:
         cflags += output.rstrip().decode('utf-8').split(' ')
 
+    cflags += options.extra_cflags
     arguments.append('--cflags={0}'.format(' '.join(cflags)))
 
     process = Popen([options.pkg_config,
@@ -51,4 +54,4 @@ if __name__ == '__main__':
 
     arguments.append('--ldflags={0}'.format(' '.join(libs)))
 
-    sys.exit(call(arguments))
\ No newline at end of file
+    sys.exit(call(arguments))


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]