The first step in a major refactoring starts by adding a new layer of abstraction.

pull/102/head
Jussi Pakkanen 10 years ago
parent a92fcb711b
commit bf9b5d7b72
  1. 9
      build.py
  2. 6
      compilers.py
  3. 15
      interpreter.py
  4. 30
      mesonlib.py
  5. 8
      ninjabackend.py
  6. 4
      test cases/common/81 file object/meson.build
  7. 6
      test cases/common/81 file object/prog.c

@ -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:

@ -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

@ -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

@ -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'

@ -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:

@ -0,0 +1,4 @@
project('file object', 'c')
fileobj = file('prog.c')
test('fobj', executable('fobj', fileobj))

@ -0,0 +1,6 @@
#include<stdio.h>
int main(int argc, char **argv) {
printf("Iz success.\n");
return 0;
}
Loading…
Cancel
Save