Make it possible to run a custom script during install.

pull/15/head
Jussi Pakkanen 11 years ago
parent 5e648a9fb9
commit 6759e404d9
  1. 1
      build.py
  2. 13
      interpreter.py
  3. 20
      meson_install.py
  4. 9
      ninjabackend.py
  5. 2
      test cases/common/60 install script/installed_files.txt
  6. 4
      test cases/common/60 install script/meson.build
  7. 5
      test cases/common/60 install script/myinstall.sh
  8. 6
      test cases/common/60 install script/prog.c

@ -43,6 +43,7 @@ class Build:
self.pot = []
self.subprojects = {}
self.pkgconfig_gens = []
self.install_script = None
def has_language(self, language):
for i in self.compilers:

@ -565,8 +565,21 @@ class MesonMain(InterpreterObject):
'is_unity' : self.is_unity_method,
'current_source_dir' : self.current_source_dir_method,
'current_build_dir' : self.current_build_dir_method,
'set_install_script' : self.set_install_script_method,
})
def set_install_script_method(self, args, kwargs):
if len(args) != 1:
raise InterpreterException('Set_install_script takes exactly one argument.')
scriptbase = args[0]
if not isinstance(scriptbase, str):
raise InterpreterException('Set_install_script argument is not a string.')
scriptfile = os.path.join(self.interpreter.environment.source_dir,
self.interpreter.subdir, scriptbase)
if not os.path.isfile(scriptfile):
raise InterpreterException('Can not find install script %s.' % scriptbase)
self.build.install_script = scriptfile
def current_source_dir_method(self, args, kwargs):
src = self.interpreter.environment.source_dir
sub = self.interpreter.subdir

@ -18,7 +18,9 @@ import sys, pickle, os, shutil, subprocess, gzip, platform
from glob import glob
class InstallData():
def __init__(self, prefix, depfixer, dep_prefix):
def __init__(self, source_dir, build_dir, prefix, depfixer, dep_prefix):
self.source_dir = source_dir
self.build_dir= build_dir
self.prefix = prefix
self.targets = []
self.depfixer = depfixer
@ -28,6 +30,7 @@ class InstallData():
self.data = []
self.po_package_name = ''
self.po = []
self.install_script = None
def do_install(datafilename):
ifile = open(datafilename, 'rb')
@ -44,6 +47,7 @@ def do_install(datafilename):
install_man(d)
install_data(d)
install_po(d)
run_install_script(d)
def install_po(d):
packagename = d.po_package_name
@ -94,6 +98,19 @@ def install_headers(d):
shutil.copyfile(fullfilename, outfilename)
shutil.copystat(fullfilename, outfilename)
def run_install_script(d):
if d.install_script is None:
return
env = {'MESON_SOURCE_ROOT' : d.source_dir,
'MESON_BUILD_ROOT' : d.build_dir,
'MESON_INSTALL_PREFIX' : d.prefix
}
script = d.install_script
print('Running custom install script %s' % script)
child_env = os.environ.copy()
child_env.update(env)
subprocess.check_call(script, env=child_env)
def is_elf_platform():
platname = platform.system().lower()
if platname == 'darwin' or platname == 'windows':
@ -123,7 +140,6 @@ def check_for_stampfile(fname):
sys.exit(1)
if len(files) == 1:
return files[0]
return fname
def install_targets(d):

@ -218,7 +218,9 @@ class NinjaBackend(backends.Backend):
install_script = os.path.join(script_root, 'meson_install.py')
install_data_file = os.path.join(self.environment.get_scratch_dir(), 'install.dat')
depfixer = os.path.join(script_root, 'depfixer.py')
d = InstallData(self.environment.get_prefix(), depfixer, './') # Fixme
d = InstallData(self.environment.get_source_dir(),
self.environment.get_build_dir(),
self.environment.get_prefix(), depfixer, './') # Fixme
elem = NinjaBuildElement('install', 'CUSTOM_COMMAND', '')
elem.add_dep('all')
elem.add_item('DESC', 'Installing files.')
@ -229,6 +231,7 @@ class NinjaBackend(backends.Backend):
self.generate_data_install(d)
self.generate_po_install(d, elem)
self.generate_pkgconfig_install(d)
self.generate_custom_install_script(d)
elem.write(outfile)
ofile = open(install_data_file, 'wb')
@ -273,6 +276,10 @@ class NinjaBackend(backends.Backend):
i = [srcabs, dstabs]
d.man.append(i)
def generate_custom_install_script(self, d):
d.install_script = self.build.install_script
def generate_header_install(self, d):
incroot = self.environment.get_includedir()
headers = self.build.get_headers()

@ -0,0 +1,4 @@
project('custom install script', 'c')
meson.set_install_script('myinstall.sh')
executable('prog', 'prog.c', install : true)

@ -0,0 +1,5 @@
#!/bin/sh
mkdir "${DESTDIR}/${MESON_INSTALL_PREFIX}/diiba"
mkdir "${DESTDIR}/${MESON_INSTALL_PREFIX}/diiba/daaba"
touch "${DESTDIR}/${MESON_INSTALL_PREFIX}/diiba/daaba/file.dat"

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