aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild
diff options
context:
space:
mode:
authorJussi Pakkanen <jpakkane@gmail.com>2017-04-02 00:15:22 +0300
committerGitHub <noreply@github.com>2017-04-02 00:15:22 +0300
commitc7f66c3a9e4f69e0bcde8819f15c9d8b972a2f75 (patch)
tree95785dfa61d2d01925f66498e16f4d4cadeb9760 /mesonbuild
parentd2548e6e839b2058aae7f242db35d6836ccbeef7 (diff)
parent8df671b6f3995ed3f31409677464fa2f8fd81af9 (diff)
downloadmeson-c7f66c3a9e4f69e0bcde8819f15c9d8b972a2f75.zip
meson-c7f66c3a9e4f69e0bcde8819f15c9d8b972a2f75.tar.gz
meson-c7f66c3a9e4f69e0bcde8819f15c9d8b972a2f75.tar.bz2
Merge pull request #1505 from centricular/dont-use-c++-for-assembly
Try harder to use the C compiler for compiling asm
Diffstat (limited to 'mesonbuild')
-rw-r--r--mesonbuild/build.py34
-rw-r--r--mesonbuild/compilers.py16
-rw-r--r--mesonbuild/coredata.py5
-rw-r--r--mesonbuild/interpreter.py6
-rw-r--r--mesonbuild/wrap/wrap.py2
5 files changed, 40 insertions, 23 deletions
diff --git a/mesonbuild/build.py b/mesonbuild/build.py
index 41e21e3..ce5638d 100644
--- a/mesonbuild/build.py
+++ b/mesonbuild/build.py
@@ -12,15 +12,17 @@
# See the License for the specific language governing permissions and
# limitations under the License.
+import copy, os, re
+from collections import OrderedDict
+
from . import environment
from . import dependencies
from . import mlog
-import copy, os, re
from .mesonlib import File, MesonException
from .mesonlib import flatten, stringlistify, classify_unity_sources
from .mesonlib import get_filenames_templates_dict, substitute_values
from .environment import for_windows, for_darwin
-from .compilers import is_object, clike_langs, lang_suffixes
+from .compilers import is_object, clike_langs, sort_clike, lang_suffixes
known_basic_kwargs = {'install': True,
'c_pch': True,
@@ -291,7 +293,7 @@ class BuildTarget(Target):
self.is_unity = environment.coredata.get_builtin_option('unity')
self.environment = environment
self.sources = []
- self.compilers = {}
+ self.compilers = OrderedDict()
self.objects = []
self.external_deps = []
self.include_dirs = []
@@ -391,13 +393,6 @@ class BuildTarget(Target):
raise InvalidArguments(msg)
@staticmethod
- def can_compile_sources(compiler, sources):
- for s in sources:
- if compiler.can_compile(s):
- return True
- return False
-
- @staticmethod
def can_compile_remove_sources(compiler, sources):
removed = False
for s in sources[:]:
@@ -442,13 +437,18 @@ class BuildTarget(Target):
if not s.endswith(lang_suffixes['vala']):
sources.append(s)
if sources:
- # Add compilers based on the above sources
- for lang, compiler in compilers.items():
- # We try to be conservative because sometimes people add files
- # in the list of sources that we can't determine the type based
- # just on the suffix.
- if self.can_compile_sources(compiler, sources):
- self.compilers[lang] = compiler
+ # For each source, try to add one compiler that can compile it.
+ # It's ok if no compilers can do so, because users are expected to
+ # be able to add arbitrary non-source files to the sources list.
+ for s in sources:
+ for lang, compiler in compilers.items():
+ if compiler.can_compile(s):
+ if lang not in self.compilers:
+ self.compilers[lang] = compiler
+ break
+ # Re-sort according to clike_langs
+ self.compilers = OrderedDict(sorted(self.compilers.items(),
+ key=lambda t: sort_clike(t[0])))
else:
# No source files, target consists of only object files of unknown
# origin. Just add the first clike compiler that we have and hope
diff --git a/mesonbuild/compilers.py b/mesonbuild/compilers.py
index f16a05f..5e7db24 100644
--- a/mesonbuild/compilers.py
+++ b/mesonbuild/compilers.py
@@ -57,6 +57,17 @@ clike_suffixes += ('h', 'll', 's')
# All these are only for C-like languages; see `clike_langs` above.
+def sort_clike(lang):
+ '''
+ Sorting function to sort the list of languages according to
+ reversed(compilers.clike_langs) and append the unknown langs in the end.
+ The purpose is to prefer C over C++ for files that can be compiled by
+ both such as assembly, C, etc. Also applies to ObjC, ObjC++, etc.
+ '''
+ if lang not in clike_langs:
+ return 1
+ return -clike_langs.index(lang)
+
def is_header(fname):
if hasattr(fname, 'fname'):
fname = fname.fname
@@ -514,6 +525,11 @@ class Compiler:
self.version = version
self.base_options = []
+ def __repr__(self):
+ repr_str = "<{0}: v{1} `{2}`>"
+ return repr_str.format(self.__class__.__name__, self.version,
+ ' '.join(self.exelist))
+
def can_compile(self, src):
if hasattr(src, 'fname'):
src = src.fname
diff --git a/mesonbuild/coredata.py b/mesonbuild/coredata.py
index 9562211..51eeaff 100644
--- a/mesonbuild/coredata.py
+++ b/mesonbuild/coredata.py
@@ -14,6 +14,7 @@
import pickle, os, uuid
from pathlib import PurePath
+from collections import OrderedDict
from .mesonlib import MesonException, commonpath
from .mesonlib import default_libdir, default_libexecdir, default_prefix
@@ -128,8 +129,8 @@ class CoreData:
else:
self.cross_file = None
self.wrap_mode = options.wrap_mode
- self.compilers = {}
- self.cross_compilers = {}
+ self.compilers = OrderedDict()
+ self.cross_compilers = OrderedDict()
self.deps = {}
self.modules = {}
# Only to print a warning if it changes between Meson invocations.
diff --git a/mesonbuild/interpreter.py b/mesonbuild/interpreter.py
index 7ee4bb9..0c6d980 100644
--- a/mesonbuild/interpreter.py
+++ b/mesonbuild/interpreter.py
@@ -1613,6 +1613,8 @@ class Interpreter(InterpreterBase):
@stringArgs
def func_project(self, node, args, kwargs):
+ if len(args) < 1:
+ raise InvalidArguments('Not enough arguments to project(). Needs at least the project name.')
default_options = kwargs.get('default_options', [])
if self.environment.first_invocation and (len(default_options) > 0 or
len(self.default_project_options) > 0):
@@ -1625,8 +1627,6 @@ class Interpreter(InterpreterBase):
)
oi.process(self.option_file)
self.build.environment.merge_options(oi.options)
- if len(args) < 2:
- raise InvalidArguments('Not enough arguments to project(). Needs at least the project name and one language')
self.active_projectname = args[0]
self.project_version = kwargs.get('version', 'undefined')
if self.build.project_version is None:
@@ -1755,7 +1755,7 @@ class Interpreter(InterpreterBase):
def add_languages(self, args, required):
success = True
need_cross_compiler = self.environment.is_cross_build() and self.environment.cross_info.need_cross_compiler()
- for lang in args:
+ for lang in sorted(args, key=compilers.sort_clike):
lang = lang.lower()
if lang in self.coredata.compilers:
comp = self.coredata.compilers[lang]
diff --git a/mesonbuild/wrap/wrap.py b/mesonbuild/wrap/wrap.py
index fcacc16..67e4700 100644
--- a/mesonbuild/wrap/wrap.py
+++ b/mesonbuild/wrap/wrap.py
@@ -39,7 +39,7 @@ def build_ssl_context():
return ctx
def quiet_git(cmd):
- pc = subprocess.Popen(['git'] + cmd, stdout=subprocess.PIPE)
+ pc = subprocess.Popen(['git'] + cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out, err = pc.communicate()
if pc.returncode != 0:
return False, err