aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJussi Pakkanen <jpakkane@gmail.com>2013-01-14 01:13:55 +0200
committerJussi Pakkanen <jpakkane@gmail.com>2013-01-14 01:13:55 +0200
commit3eab3901587d935498259d61f5823d9a7484fb67 (patch)
treedb9161790650a1d97f8bf3478f8c7cc85504b9af
parent73f8a69d3942c1ce6ecb0fa19afca3a46341dee3 (diff)
downloadmeson-3eab3901587d935498259d61f5823d9a7484fb67.zip
meson-3eab3901587d935498259d61f5823d9a7484fb67.tar.gz
meson-3eab3901587d935498259d61f5823d9a7484fb67.tar.bz2
Can generate configure files.
-rw-r--r--build.py4
-rwxr-xr-xbuilder.py2
-rwxr-xr-xinterpreter.py39
-rwxr-xr-xshellgenerator.py42
-rw-r--r--test cases/16 configure file/builder.txt6
-rw-r--r--test cases/16 configure file/config.h.in3
6 files changed, 88 insertions, 8 deletions
diff --git a/build.py b/build.py
index 8fad6d4..67426c9 100644
--- a/build.py
+++ b/build.py
@@ -29,6 +29,7 @@ class Build:
self.man = []
self.data = []
self.static_linker = self.environment.detect_static_linker()
+ self.configure_files = []
def get_project(self):
return self.project
@@ -47,3 +48,6 @@ class Build:
def get_data(self):
return self.data
+
+ def get_configure_files(self):
+ return self.configure_files
diff --git a/builder.py b/builder.py
index b60de58..6ae567c 100755
--- a/builder.py
+++ b/builder.py
@@ -73,7 +73,7 @@ class BuilderApp():
b = build.Build(env)
intr = interpreter.Interpreter(code, b)
intr.run()
- g = shellgenerator.ShellGenerator(b)
+ g = shellgenerator.ShellGenerator(b, intr)
g.generate()
if __name__ == '__main__':
diff --git a/interpreter.py b/interpreter.py
index 3e1a066..c3d14b1 100755
--- a/interpreter.py
+++ b/interpreter.py
@@ -68,6 +68,25 @@ class Data(InterpreterObject):
def get_sources(self):
return self.sources
+class ConfigureFile(InterpreterObject):
+
+ def __init__(self, subdir, sourcename, targetname):
+ InterpreterObject.__init__(self)
+ self.subdir = subdir
+ self.sourcename = sourcename
+ self.targetname = targetname
+
+ def get_sources(self):
+ return self.sources
+
+ def get_subdir(self):
+ return self.subdir
+
+ def get_source_name(self):
+ return self.sourcename
+
+ def get_target_name(self):
+ return self.targetname
class Man(InterpreterObject):
@@ -86,7 +105,7 @@ class Man(InterpreterObject):
return self.sources
class BuildTarget(InterpreterObject):
-
+
def __init__(self, name, subdir, sources):
InterpreterObject.__init__(self)
self.name = name
@@ -216,8 +235,12 @@ class Interpreter():
'headers' : self.func_headers,
'man' : self.func_man,
'subdir' : self.func_subdir,
- 'data' : self.func_data
+ 'data' : self.func_data,
+ 'configure_file' : self.func_configure_file
}
+
+ def get_variables(self):
+ return self.variables
def sanity_check_ast(self):
if not isinstance(self.ast, nodes.CodeBlock):
@@ -248,6 +271,8 @@ class Interpreter():
return self.assignment(cur)
elif isinstance(cur, nodes.MethodCall):
return self.method_call(cur)
+ elif isinstance(cur, nodes.StringStatement):
+ return cur
else:
raise InvalidCode("Unknown statement in line %d." % cur.lineno())
@@ -350,6 +375,11 @@ class Interpreter():
data = Data(args[0], args[1:])
self.build.data.append(data)
return data
+
+ def func_configure_file(self, node, args):
+ self.validate_arguments(args, 2, [str, str])
+ c = ConfigureFile(self.subdir, args[0], args[1])
+ self.build.configure_files.append(c)
def build_target(self, node, args, targetclass):
for a in args:
@@ -376,7 +406,8 @@ class Interpreter():
def is_assignable(self, value):
if isinstance(value, InterpreterObject) or \
- isinstance(value, environment.PkgConfigDependency):
+ isinstance(value, environment.PkgConfigDependency) or\
+ isinstance(value, nodes.StringStatement):
return True
return False
@@ -406,7 +437,7 @@ class Interpreter():
elif isinstance(arg, nodes.MethodCall):
r = self.method_call(arg)
else:
- raise InvalidCode('Line %d: Irreducable argument.' % args.lineno())
+ raise InvalidCode('Line %d: Irreducible argument.' % args.lineno())
reduced.append(r)
assert(len(reduced) == len(args))
return reduced
diff --git a/shellgenerator.py b/shellgenerator.py
index 7052be0..5f59e4b 100755
--- a/shellgenerator.py
+++ b/shellgenerator.py
@@ -14,17 +14,42 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-import os, stat
-import interpreter
+import os, stat, re
+import interpreter, nodes
def shell_quote(cmdlist):
return ["'" + x + "'" for x in cmdlist]
+def do_conf_file(src, dst, variables):
+ data = open(src).readlines()
+ regex = re.compile('@(.*?)@')
+ result = []
+ for line in data:
+ match = re.search(regex, line)
+ while match:
+ varname = match.group(1)
+ print(varname)
+ if varname in variables:
+ var = variables[varname]
+ if isinstance(var, str):
+ pass
+ elif isinstance(var, nodes.StringStatement):
+ var = var.get_string()
+ else:
+ raise RuntimeError('Tried to replace a variable with something other than a string.')
+ else:
+ var = ''
+ line = line.replace('@' + varname + '@', var)
+ match = re.search(regex, line)
+ result.append(line)
+ open(dst, 'w').writelines(result)
+
class ShellGenerator():
- def __init__(self, build):
+ def __init__(self, build, interp):
self.build = build
self.environment = build.environment
+ self.interpreter = interp
self.build_filename = 'compile.sh'
self.test_filename = 'run_tests.sh'
self.install_filename = 'install.sh'
@@ -71,6 +96,7 @@ echo This is experimental and most likely will not work!
echo Run compile.sh before this or bad things will happen.
""" % self.build.get_project()
outfile = self.create_shfile(outfilename, message)
+ self.generate_configure_files()
self.generate_target_install(outfile)
self.generate_header_install(outfile)
self.generate_man_install(outfile)
@@ -85,6 +111,16 @@ echo Run compile.sh before this or bad things will happen.
cpcommand = ['cp', filename, outdir]
cpcommand = ' '.join(shell_quote(cpcommand)) + ' || exit\n'
outfile.write(cpcommand)
+
+ def generate_configure_files(self):
+ for cf in self.build.get_configure_files():
+ infile = os.path.join(self.environment.get_source_dir(),
+ cf.get_subdir(),
+ cf.get_source_name())
+ # FIXME, put in in the proper path.
+ outfile = os.path.join(self.environment.get_build_dir(),
+ cf.get_target_name())
+ do_conf_file(infile, outfile, self.interpreter.get_variables())
def generate_data_install(self, outfile):
prefix = self.environment.get_prefix()
diff --git a/test cases/16 configure file/builder.txt b/test cases/16 configure file/builder.txt
new file mode 100644
index 0000000..7fb3258
--- /dev/null
+++ b/test cases/16 configure file/builder.txt
@@ -0,0 +1,6 @@
+project('configure file test', 'c')
+
+var = 'mystring'
+other = 'string 2'
+second = ' bonus'
+configure_file('config.h.in', 'config.h')
diff --git a/test cases/16 configure file/config.h.in b/test cases/16 configure file/config.h.in
new file mode 100644
index 0000000..74736c0
--- /dev/null
+++ b/test cases/16 configure file/config.h.in
@@ -0,0 +1,3 @@
+#define MESSAGE "@var@"
+#define OTHER "@other@" "@second@" "@empty@"
+