Can install entire subtrees with one command. Closes #14.

pull/18/head
Jussi Pakkanen 10 years ago
parent a500c6cfa8
commit 0c86f30d4b
  1. 4
      build.py
  2. 23
      interpreter.py
  3. 11
      meson_install.py
  4. 7
      ninjabackend.py
  5. 2
      test cases/common/66 install subdir/installed_files.txt
  6. 3
      test cases/common/66 install subdir/meson.build
  7. 1
      test cases/common/66 install subdir/subdir/meson.build
  8. 1
      test cases/common/66 install subdir/subdir/sub1/data1.dat
  9. 1
      test cases/common/66 install subdir/subdir/sub1/sub2/data2.dat

@ -77,6 +77,7 @@ class Build:
self.subprojects = {}
self.pkgconfig_gens = []
self.install_script = None
self.install_dirs = []
def has_language(self, language):
for i in self.compilers:
@ -120,6 +121,9 @@ class Build:
def get_configure_files(self):
return self.configure_files
def get_install_subdirs(self):
return self.install_dirs
def get_global_args(self, compiler):
return self.global_args.get(compiler.get_language(), [])

@ -326,6 +326,13 @@ class Data(InterpreterObject):
def get_custom_install_dir(self):
return self.custom_install_dir
class InstallDir(InterpreterObject):
def __init__(self, source_subdir, installable_subdir, install_dir):
InterpreterObject.__init__(self)
self.source_subdir = source_subdir
self.installable_subdir = installable_subdir
self.install_dir = install_dir
class Man(InterpreterObject):
def __init__(self, source_subdir, sources, kwargs):
@ -705,6 +712,7 @@ class Interpreter():
'install_man' : self.func_install_man,
'subdir' : self.func_subdir,
'install_data' : self.func_install_data,
'install_subdir' : self.func_install_subdir,
'configure_file' : self.func_configure_file,
'include_directories' : self.func_include_directories,
'add_global_arguments' : self.func_add_global_arguments,
@ -1218,6 +1226,21 @@ class Interpreter():
self.build.data.append(data)
return data
def func_install_subdir(self, node, args, kwargs):
if len(args ) != 1:
raise InvalidArguments('Install_subdir requires exactly one argument.')
for a in args:
if not isinstance(a, str):
raise InvalidArguments('Argument %s is not a string.' % str(a))
if not 'install_dir' in kwargs:
raise InvalidArguments('Missing keyword argument install_dir')
install_dir = kwargs['install_dir']
if not isinstance(install_dir, str):
raise InvalidArguments('Keyword argument install_dir not a string.')
idir = InstallDir(self.subdir, args[0], install_dir)
self.build.install_dirs.append(idir)
return idir
def func_configure_file(self, node, args, kwargs):
if len(args) > 0:
raise InterpreterException("configure_file takes only keyword arguments.")

@ -30,6 +30,7 @@ class InstallData():
self.po_package_name = ''
self.po = []
self.install_script = None
self.install_subdirs = []
def do_install(datafilename):
ifile = open(datafilename, 'rb')
@ -41,6 +42,7 @@ def do_install(datafilename):
else:
subdir = d.prefix
d.prefix = os.path.join(os.environ[destdir_var], subdir)
install_subdirs(d) # Must be first, because it needs to delete the old subtree.
install_targets(d)
install_headers(d)
install_man(d)
@ -48,6 +50,15 @@ def do_install(datafilename):
install_po(d)
run_install_script(d)
def install_subdirs(d):
for (src_dir, dst_dir) in d.install_subdirs:
# Python's copytree works in strange ways.
last_level = os.path.split(src_dir)[-1]
final_dst = os.path.join(dst_dir, last_level)
shutil.rmtree(final_dst, ignore_errors=True)
shutil.copytree(src_dir, final_dst, symlinks=True)
print('Installing subdir %s to %s.' % (src_dir, dst_dir))
def install_po(d):
packagename = d.po_package_name
for f in d.po:

@ -377,6 +377,7 @@ class NinjaBackend(backends.Backend):
self.generate_po_install(d, elem)
self.generate_pkgconfig_install(d)
self.generate_custom_install_script(d)
self.generate_subdir_install(d)
elem.write(outfile)
ofile = open(install_data_file, 'wb')
@ -466,6 +467,12 @@ class NinjaBackend(backends.Backend):
i = [srcabs, dstabs]
d.data.append(i)
def generate_subdir_install(self, d):
for sd in self.build.get_install_subdirs():
src_dir = os.path.join(self.environment.get_source_dir(), sd.source_subdir, sd.installable_subdir)
dst_dir = os.path.join(self.environment.get_prefix(), sd.install_dir)
d.install_subdirs.append([src_dir, dst_dir])
def generate_tests(self, outfile):
self.serialise_tests()
valgrind = environment.find_valgrind()

@ -0,0 +1,2 @@
share/sub1/data1.dat
share/sub1/sub2/data2.dat

@ -0,0 +1,3 @@
project('install a whole subdir', 'c')
subdir('subdir')

@ -0,0 +1 @@
install_subdir('sub1', install_dir : 'share')

@ -0,0 +1 @@
This is a data file in a deeper subdir.
Loading…
Cancel
Save