diff options
author | Jussi Pakkanen <jpakkane@gmail.com> | 2013-01-01 21:00:22 +0200 |
---|---|---|
committer | Jussi Pakkanen <jpakkane@gmail.com> | 2013-01-01 21:00:22 +0200 |
commit | 016b9093d72d6c9cb3e7057d1143d0603abe525e (patch) | |
tree | 4731da160413bac94ef9400e30859d6a4f63b5d7 | |
parent | 6502708b08ad6653f2cc457e758894f67c46a638 (diff) | |
download | meson-016b9093d72d6c9cb3e7057d1143d0603abe525e.zip meson-016b9093d72d6c9cb3e7057d1143d0603abe525e.tar.gz meson-016b9093d72d6c9cb3e7057d1143d0603abe525e.tar.bz2 |
Moved compiler detection inside Environment.
-rwxr-xr-x | builder.py | 2 | ||||
-rwxr-xr-x | environment.py | 37 | ||||
-rwxr-xr-x | interpreter.py | 10 | ||||
-rwxr-xr-x | shellgenerator.py | 2 |
4 files changed, 19 insertions, 32 deletions
@@ -67,7 +67,7 @@ class Builder(): raise interpreter.InvalidCode('Builder file is empty.') assert(isinstance(code, str)) env = environment.Environment(self.source_dir, self.build_dir) - intr = interpreter.Interpreter(code, env.get_scratch_dir()) + intr = interpreter.Interpreter(code, env) g = shellgenerator.ShellGenerator(intr, env) g.generate() diff --git a/environment.py b/environment.py index 227b5f0..097ba1f 100755 --- a/environment.py +++ b/environment.py @@ -20,16 +20,6 @@ class EnvironmentException(Exception): def __init(self, *args, **kwargs): Exception.__init__(self, *args, **kwargs) -def detect_c_compiler(execmd): - exelist = execmd.split() - p = subprocess.Popen(exelist + ['--version'], stdout=subprocess.PIPE) - out = p.communicate()[0] - out = out.decode() - if (out.startswith('cc ') or out.startswith('gcc')) and \ - 'Free Software Foundation' in out: - return GnuCCompiler(exelist) - raise EnvironmentException('Unknown compiler "' + execmd + '"') - class CCompiler(): def __init__(self, exelist): if type(exelist) == type(''): @@ -91,19 +81,6 @@ class GnuCCompiler(CCompiler): def shell_quote(cmdlist): return ["'" + x + "'" for x in cmdlist] -def test_cmd_line_building(): - src_file = 'file.c' - dst_file = 'file.o' - gnuc = detect_c_compiler('/usr/bin/cc') - cmds = gnuc.get_exelist() - cmds += gnuc.get_std_warn_flags() - cmds += gnuc.get_compile_only_flags() - cmds.append(src_file) - cmds += gnuc.get_output_flags() - cmds.append(dst_file) - cmd_line = ' '.join(shell_quote(cmds)) - print(cmd_line) - class Environment(): def __init__(self, source_dir, build_dir): self.source_dir = source_dir @@ -121,16 +98,26 @@ class Environment(): self.static_lib_prefix = 'lib' self.object_suffix = 'o' - def get_c_compiler(self): + def get_c_compiler_exelist(self): evar = 'CC' if evar in os.environ: return os.environ[evar].split() return self.default_c + def detect_c_compiler(self): + exelist = self.get_c_compiler_exelist() + p = subprocess.Popen(exelist + ['--version'], stdout=subprocess.PIPE) + out = p.communicate()[0] + out = out.decode() + if (out.startswith('cc ') or out.startswith('gcc')) and \ + 'Free Software Foundation' in out: + return GnuCCompiler(exelist) + raise EnvironmentException('Unknown compiler "' + execmd + '"') + def get_scratch_dir(self): return self.scratch_dir - def get_cxx_compiler(self): + def get_cxx_compiler_exelist(self): evar = 'CXX' if evar in os.environ: return os.environ[evar].split() diff --git a/interpreter.py b/interpreter.py index 7b86683..0425f2e 100755 --- a/interpreter.py +++ b/interpreter.py @@ -66,14 +66,14 @@ class Executable(BuildTarget): class Interpreter(): - def __init__(self, code, scratch_dir): + def __init__(self, code, environment): self.ast = parser.build_ast(code) self.sanity_check_ast() self.project = None self.compilers = [] self.targets = {} self.variables = {} - self.scratch_dir = scratch_dir + self.environment = environment def get_project(self): return self.project @@ -141,8 +141,8 @@ class Interpreter(): raise InvalidCode('Function language() can only be called once (line %d).' % node.lineno()) for lang in args: if lang.lower() == 'c': - comp = environment.detect_c_compiler('gcc') - comp.sanity_check(self.scratch_dir) + comp = self.environment.detect_c_compiler() + comp.sanity_check(self.environment.get_scratch_dir()) self.compilers.append(comp) else: raise InvalidCode('Tried to use unknown language "%s".' % lang) @@ -238,5 +238,5 @@ if __name__ == '__main__': dep = find_dep('gtk+-3.0') prog.add_dep(dep) """ - i = Interpreter(code, '.') + i = Interpreter(code, environment.Environment('.', 'work area')) i.run() diff --git a/shellgenerator.py b/shellgenerator.py index 4e66522..49267f3 100755 --- a/shellgenerator.py +++ b/shellgenerator.py @@ -98,6 +98,6 @@ if __name__ == '__main__': import interpreter, environment os.chdir(os.path.split(__file__)[0]) envir = environment.Environment('.', 'work area') - intpr = interpreter.Interpreter(code, envir.get_scratch_dir()) + intpr = interpreter.Interpreter(code, envir) g = ShellGenerator(intpr, envir) g.generate() |