diff options
author | Jussi Pakkanen <jpakkane@gmail.com> | 2015-04-21 16:27:58 +0300 |
---|---|---|
committer | Jussi Pakkanen <jpakkane@gmail.com> | 2015-04-21 16:27:58 +0300 |
commit | bf9b5d7b726c9388e5204fb44969fd11730944c6 (patch) | |
tree | 9391fbac79ad1e5dfd9059c9a8bcfce5e00e6db5 | |
parent | a92fcb711b5b56ee6858d73dc90eda0e1e5d91a4 (diff) | |
download | meson-bf9b5d7b726c9388e5204fb44969fd11730944c6.zip meson-bf9b5d7b726c9388e5204fb44969fd11730944c6.tar.gz meson-bf9b5d7b726c9388e5204fb44969fd11730944c6.tar.bz2 |
The first step in a major refactoring starts by adding a new layer of abstraction.
-rw-r--r-- | build.py | 9 | ||||
-rw-r--r-- | compilers.py | 6 | ||||
-rw-r--r-- | interpreter.py | 15 | ||||
-rw-r--r-- | mesonlib.py | 30 | ||||
-rw-r--r-- | ninjabackend.py | 8 | ||||
-rw-r--r-- | test cases/common/81 file object/meson.build | 4 | ||||
-rw-r--r-- | test cases/common/81 file object/prog.c | 6 |
7 files changed, 72 insertions, 6 deletions
@@ -17,7 +17,7 @@ import environment import dependencies import mlog import copy, os - +from mesonlib import File known_basic_kwargs = {'install' : True, 'c_pch' : True, @@ -207,7 +207,7 @@ class BuildTarget(): # Holder unpacking. Ugly. if hasattr(s, 'held_object'): s = s.held_object - if isinstance(s, str): + if isinstance(s, str) or isinstance(s, File): # FIXME, accept only File objects if not s in added_sources: self.sources.append(s) added_sources[s] = True @@ -218,7 +218,10 @@ class BuildTarget(): def validate_sources(self): if len(self.sources) > 0: - first = os.path.split(self.sources[0])[1] + firstname = self.sources[0] + if isinstance(firstname, File): + firstname = firstname.fname + first = os.path.split(firstname)[1] (base, suffix) = os.path.splitext(first) if suffix == '.rs': if self.name != base: diff --git a/compilers.py b/compilers.py index 61a2372..59edb6e 100644 --- a/compilers.py +++ b/compilers.py @@ -28,14 +28,20 @@ clike_suffixes = c_suffixes + cpp_suffixes obj_suffixes = ['o', 'obj'] def is_header(fname): + if hasattr(fname, 'fname'): + fname = fname.fname suffix = fname.split('.')[-1] return suffix in header_suffixes def is_source(fname): + if hasattr(fname, 'fname'): + fname = fname.fname suffix = fname.split('.')[-1] return suffix in clike_suffixes def is_object(fname): + if hasattr(fname, 'fname'): + fname = fname.fname suffix = fname.split('.')[-1] return suffix in obj_suffixes diff --git a/interpreter.py b/interpreter.py index 75df340..647cc52 100644 --- a/interpreter.py +++ b/interpreter.py @@ -22,6 +22,8 @@ import optinterpreter import wrap import mesonlib import os, sys, platform, subprocess, shutil, uuid, re +from mesonlib import File + import importlib class InterpreterException(coredata.MesonException): @@ -777,6 +779,7 @@ class Interpreter(): 'vcs_tag' : self.func_vcs_tag, 'set_variable' : self.func_set_variable, 'import' : self.func_import, + 'file' : self.func_file, } def module_method_callback(self, invalues): @@ -877,6 +880,15 @@ class Interpreter(): self.environment.coredata.modules[modname] = module return ModuleHolder(modname, self.environment.coredata.modules[modname], self) + def func_file(self, node, args, kwargs): + if len(args) != 1: + raise InvalidCode('File takes one argument.') + fname = args[0] + if not isinstance(fname, str): + raise InvalidCode('Argument to import was not a string') + fobj = File.from_source_file(self.environment.source_dir, self.subdir, fname) + return fobj + def set_variable(self, varname, variable): if variable is None: raise InvalidCode('Can not assign None to variable.') @@ -1549,7 +1561,8 @@ class Interpreter(): isinstance(value, dependencies.Dependency) or\ isinstance(value, str) or\ isinstance(value, int) or \ - isinstance(value, list): + isinstance(value, list) or \ + isinstance(value, File): return True return False diff --git a/mesonlib.py b/mesonlib.py index af29421..f547379 100644 --- a/mesonlib.py +++ b/mesonlib.py @@ -1,4 +1,4 @@ -# Copyright 2012-2014 The Meson development team +# Copyright 2012-2015 The Meson development team # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -20,6 +20,34 @@ from glob import glob from coredata import MesonException +class File: + def __init__(self, is_built, subdir, fname): + self.is_built = is_built + self.subdir = subdir + self.fname = fname + + @staticmethod + def from_source_file(source_root, subdir, fname): + if not os.path.isfile(os.path.join(source_root, subdir, fname)): + raise MesonException('File %s does not exist.' % fname) + return File(False, subdir, fname) + + @staticmethod + def from_built_file(subdir, fname): + return File(True, subdir, fname) + + def rel_to_builddir(self, build_to_src): + if self.is_built: + return os.path.join(self.subdir, self.fname) + else: + return os.path.join(build_to_src, self.subdir, self.fname) + + def endswith(self, ending): + return self.fname.endswith(ending) + + def split(self, s): + return self.fname.split(s) + def is_osx(): return platform.system().lower() == 'darwin' diff --git a/ninjabackend.py b/ninjabackend.py index adfc59f..2c550fd 100644 --- a/ninjabackend.py +++ b/ninjabackend.py @@ -17,6 +17,7 @@ import environment, mesonlib import build import mlog import dependencies +from mesonlib import File from meson_install import InstallData from build import InvalidArguments from coredata import MesonException @@ -1107,10 +1108,15 @@ rule FORTRAN_DEP_HACK rel_src = os.path.join(self.get_target_private_dir(target), src) abs_src = os.path.join(self.environment.get_source_dir(), rel_src) else: - rel_src = os.path.join(self.build_to_src, target.get_source_subdir(), src) + if isinstance(src, File): # FIXME, accept only Files. + rel_src = src.rel_to_builddir(self.build_to_src) + else: + rel_src = os.path.join(self.build_to_src, target.get_source_subdir(), src) abs_src = os.path.join(self.environment.get_build_dir(), rel_src) if isinstance(src, RawFilename): src_filename = src.fname + elif isinstance(src, File): + src_filename = src.fname elif os.path.isabs(src): src_filename = os.path.basename(src) else: diff --git a/test cases/common/81 file object/meson.build b/test cases/common/81 file object/meson.build new file mode 100644 index 0000000..f993a16 --- /dev/null +++ b/test cases/common/81 file object/meson.build @@ -0,0 +1,4 @@ +project('file object', 'c') + +fileobj = file('prog.c') +test('fobj', executable('fobj', fileobj)) diff --git a/test cases/common/81 file object/prog.c b/test cases/common/81 file object/prog.c new file mode 100644 index 0000000..27ade3a --- /dev/null +++ b/test cases/common/81 file object/prog.c @@ -0,0 +1,6 @@ +#include<stdio.h> + +int main(int argc, char **argv) { + printf("Iz success.\n"); + return 0; +} |