Blame 0008-Fix-setting-c_args-and-friends-from-command-line.patch

Igor Gnatenko ef6081
From d2a770c87428655390a9dfb14afd120d67e00127 Mon Sep 17 00:00:00 2001
Igor Gnatenko ef6081
From: Xavier Claessens <xavier.claessens@collabora.com>
Igor Gnatenko ef6081
Date: Mon, 30 Apr 2018 13:53:40 -0400
Igor Gnatenko ef6081
Subject: [PATCH 08/16] Fix setting c_args and friends from command line
Igor Gnatenko ef6081
Igor Gnatenko ef6081
When passing more than one -Dc_args it should override the value
Igor Gnatenko ef6081
instead of appending. This is how all other options works.
Igor Gnatenko ef6081
Igor Gnatenko ef6081
Value should be split on spaces using shlex just like it does with
Igor Gnatenko ef6081
CFLAGS environment variable.
Igor Gnatenko ef6081
Igor Gnatenko ef6081
Fixes #3473.
Igor Gnatenko ef6081
---
Igor Gnatenko ef6081
 mesonbuild/interpreter.py                     | 27 +++++++++----------
Igor Gnatenko ef6081
 mesonbuild/mconf.py                           |  5 ++--
Igor Gnatenko ef6081
 .../common/181 initial c_args/meson.build     |  2 +-
Igor Gnatenko ef6081
 3 files changed, 16 insertions(+), 18 deletions(-)
Igor Gnatenko ef6081
Igor Gnatenko ef6081
diff --git a/mesonbuild/interpreter.py b/mesonbuild/interpreter.py
Igor Gnatenko ef6081
index fc97b62e..85634193 100644
Igor Gnatenko ef6081
--- a/mesonbuild/interpreter.py
Igor Gnatenko ef6081
+++ b/mesonbuild/interpreter.py
Igor Gnatenko ef6081
@@ -2274,24 +2274,21 @@ to directly access options of other subprojects.''')
Igor Gnatenko ef6081
             mlog.log('Native %s compiler: ' % comp.get_display_language(), mlog.bold(' '.join(comp.get_exelist())), version_string, sep='')
Igor Gnatenko ef6081
 
Igor Gnatenko ef6081
             # If <language>_args/_link_args settings are given on the
Igor Gnatenko ef6081
-            # command line, use them.
Igor Gnatenko ef6081
+            # command line, use them, otherwise take them from env.
Igor Gnatenko ef6081
+            (preproc_args, compile_args, link_args) = environment.get_args_from_envvars(comp)
Igor Gnatenko ef6081
             for optspec in self.build.environment.cmd_line_options.projectoptions:
Igor Gnatenko ef6081
                 (optname, optvalue) = optspec.split('=', maxsplit=1)
Igor Gnatenko ef6081
-                if optname.endswith('_link_args'):
Igor Gnatenko ef6081
-                    lang = optname[:-10]
Igor Gnatenko ef6081
-                    self.coredata.external_link_args.setdefault(lang, []).append(optvalue)
Igor Gnatenko ef6081
+                if optname == lang + '_link_args':
Igor Gnatenko ef6081
+                    link_args = shlex.split(optvalue)
Igor Gnatenko ef6081
                 elif optname.endswith('_args'):
Igor Gnatenko ef6081
-                    lang = optname[:-5]
Igor Gnatenko ef6081
-                    self.coredata.external_args.setdefault(lang, []).append(optvalue)
Igor Gnatenko ef6081
-            # Otherwise, look for definitions from environment
Igor Gnatenko ef6081
-            # variables such as CFLAGS.
Igor Gnatenko ef6081
-            (preproc_args, compile_args, link_args) = environment.get_args_from_envvars(comp)
Igor Gnatenko ef6081
-            if not comp.get_language() in self.coredata.external_preprocess_args:
Igor Gnatenko ef6081
-                self.coredata.external_preprocess_args[comp.get_language()] = preproc_args
Igor Gnatenko ef6081
-            if not comp.get_language() in self.coredata.external_args:
Igor Gnatenko ef6081
-                self.coredata.external_args[comp.get_language()] = compile_args
Igor Gnatenko ef6081
-            if not comp.get_language() in self.coredata.external_link_args:
Igor Gnatenko ef6081
-                self.coredata.external_link_args[comp.get_language()] = link_args
Igor Gnatenko ef6081
+                    compile_args = shlex.split(optvalue)
Igor Gnatenko ef6081
+            if lang not in self.coredata.external_preprocess_args:
Igor Gnatenko ef6081
+                self.coredata.external_preprocess_args[lang] = preproc_args
Igor Gnatenko ef6081
+            if lang not in self.coredata.external_args:
Igor Gnatenko ef6081
+                self.coredata.external_args[lang] = compile_args
Igor Gnatenko ef6081
+            if lang not in self.coredata.external_link_args:
Igor Gnatenko ef6081
+                self.coredata.external_link_args[lang] = link_args
Igor Gnatenko ef6081
+
Igor Gnatenko ef6081
             self.build.add_compiler(comp)
Igor Gnatenko ef6081
             if need_cross_compiler:
Igor Gnatenko ef6081
                 mlog.log('Cross %s compiler: ' % cross_comp.get_display_language(), mlog.bold(' '.join(cross_comp.get_exelist())), ' (%s %s)' % (cross_comp.id, cross_comp.version), sep='')
Igor Gnatenko ef6081
diff --git a/mesonbuild/mconf.py b/mesonbuild/mconf.py
Igor Gnatenko ef6081
index 9a113327..c22b98ff 100644
Igor Gnatenko ef6081
--- a/mesonbuild/mconf.py
Igor Gnatenko ef6081
+++ b/mesonbuild/mconf.py
Igor Gnatenko ef6081
@@ -15,6 +15,7 @@
Igor Gnatenko ef6081
 import os
Igor Gnatenko ef6081
 import sys
Igor Gnatenko ef6081
 import argparse
Igor Gnatenko ef6081
+import shlex
Igor Gnatenko ef6081
 from . import (coredata, mesonlib, build)
Igor Gnatenko ef6081
 
Igor Gnatenko ef6081
 def buildparser():
Igor Gnatenko ef6081
@@ -134,14 +135,14 @@ class Conf:
Igor Gnatenko ef6081
                     raise ConfException('Unknown language %s in linkargs.' % lang)
Igor Gnatenko ef6081
                 # TODO, currently split on spaces, make it so that user
Igor Gnatenko ef6081
                 # can pass in an array string.
Igor Gnatenko ef6081
-                newvalue = v.split()
Igor Gnatenko ef6081
+                newvalue = shlex.split(v)
Igor Gnatenko ef6081
                 self.coredata.external_link_args[lang] = newvalue
Igor Gnatenko ef6081
             elif k.endswith('_args'):
Igor Gnatenko ef6081
                 lang = k[:-5]
Igor Gnatenko ef6081
                 if lang not in self.coredata.external_args:
Igor Gnatenko ef6081
                     raise ConfException('Unknown language %s in compile args' % lang)
Igor Gnatenko ef6081
                 # TODO same fix as above
Igor Gnatenko ef6081
-                newvalue = v.split()
Igor Gnatenko ef6081
+                newvalue = shlex.split(v)
Igor Gnatenko ef6081
                 self.coredata.external_args[lang] = newvalue
Igor Gnatenko ef6081
             else:
Igor Gnatenko ef6081
                 raise ConfException('Unknown option %s.' % k)
Igor Gnatenko ef6081
diff --git a/test cases/common/181 initial c_args/meson.build b/test cases/common/181 initial c_args/meson.build
Igor Gnatenko ef6081
index 70a6e7a4..169d2bd5 100644
Igor Gnatenko ef6081
--- a/test cases/common/181 initial c_args/meson.build	
Igor Gnatenko ef6081
+++ b/test cases/common/181 initial c_args/meson.build	
Igor Gnatenko ef6081
@@ -1,7 +1,7 @@
Igor Gnatenko ef6081
 project('options', 'c')
Igor Gnatenko ef6081
 
Igor Gnatenko ef6081
 # Test passing c_args and c_link_args options from the command line.
Igor Gnatenko ef6081
-assert(get_option('c_args') == ['-march=native', '-funroll-loops'],
Igor Gnatenko ef6081
+assert(get_option('c_args') == ['-funroll-loops'],
Igor Gnatenko ef6081
        'Incorrect value for c_args option.')
Igor Gnatenko ef6081
 assert(get_option('c_link_args') == ['-random_linker_option'],
Igor Gnatenko ef6081
        'Incorrect value for c_link_args option.')
Igor Gnatenko ef6081
-- 
Igor Gnatenko ef6081
2.17.0
Igor Gnatenko ef6081