Add option to only install changed files.

pull/3590/head
Jussi Pakkanen 7 years ago
parent 6a21e19515
commit e60bf5d833
  1. 30
      mesonbuild/minstall.py

@ -30,6 +30,8 @@ def buildparser():
help='directory to cd into before running')
parser.add_argument('--no-rebuild', default=False, action='store_true',
help='Do not rebuild before installing.')
parser.add_argument('--only-changed', default=False, action='store_true',
help='Only overwrite files that are older than the copied file.')
return parser
class DirMaker:
@ -177,9 +179,17 @@ def check_for_stampfile(fname):
class Installer:
def __init__(self, lf):
def __init__(self, options, lf):
self.options = options
self.lf = lf
def should_preserve_existing_file(self, from_file, to_file):
if not self.options.only_changed:
return False
from_time = os.stat(from_file).st_mtime
to_time = os.stat(to_file).st_mtime
return from_time <= to_time
def do_copyfile(self, from_file, to_file):
if not os.path.isfile(from_file):
raise RuntimeError('Tried to install something that isn\'t a file:'
@ -191,11 +201,18 @@ class Installer:
if not os.path.isfile(to_file):
raise RuntimeError('Destination {!r} already exists and is not '
'a file'.format(to_file))
if self.should_preserve_existing_file(from_file, to_file):
append_to_log(self.lf, '# Preserving old file %s\n' % to_file)
print('Preserving existing file %s.' % to_file)
return False
os.unlink(to_file)
outdir = os.path.split(to_file)[0]
print('Installing %s to %s' % (from_file, outdir))
shutil.copyfile(from_file, to_file)
shutil.copystat(from_file, to_file)
selinux_updates.append(to_file)
append_to_log(self.lf, to_file)
return True
def do_copydir(self, data, src_dir, dst_dir, exclude, install_mode):
'''
@ -260,7 +277,8 @@ class Installer:
if not os.path.isdir(parent_dir):
os.mkdir(parent_dir)
shutil.copystat(os.path.dirname(abs_src), parent_dir)
shutil.copy2(abs_src, abs_dst, follow_symlinks=False)
# FIXME: what about symlinks?
self.do_copyfile(abs_src, abs_dst)
set_mode(abs_dst, install_mode, data.install_umask)
append_to_log(self.lf, abs_dst)
@ -306,7 +324,6 @@ class Installer:
mode = i[2]
outdir = os.path.dirname(outfilename)
d.dirmaker.makedirs(outdir, exist_ok=True)
print('Installing %s to %s' % (fullfilename, outdir))
self.do_copyfile(fullfilename, outfilename)
set_mode(outfilename, mode, d.install_umask)
@ -317,7 +334,6 @@ class Installer:
outdir = os.path.dirname(outfilename)
d.dirmaker.makedirs(outdir, exist_ok=True)
install_mode = m[2]
print('Installing %s to %s' % (full_source_filename, outdir))
if outfilename.endswith('.gz') and not full_source_filename.endswith('.gz'):
with open(outfilename, 'wb') as of:
with open(full_source_filename, 'rb') as sf:
@ -325,6 +341,7 @@ class Installer:
with gzip.GzipFile(fileobj=of, mode='wb', filename='', mtime=0) as gz:
gz.write(sf.read())
shutil.copystat(full_source_filename, outfilename)
print('Installing %s to %s' % (full_source_filename, outdir))
append_to_log(self.lf, outfilename)
else:
self.do_copyfile(full_source_filename, outfilename)
@ -337,7 +354,6 @@ class Installer:
outdir = get_destdir_path(d, t[1])
outfilename = os.path.join(outdir, fname)
install_mode = t[2]
print('Installing %s to %s' % (fname, outdir))
d.dirmaker.makedirs(outdir, exist_ok=True)
self.do_copyfile(fullfilename, outfilename)
set_mode(outfilename, install_mode, d.install_umask)
@ -376,7 +392,6 @@ class Installer:
should_strip = t[3]
install_rpath = t[4]
install_mode = t[5]
print('Installing %s to %s' % (fname, outname))
d.dirmaker.makedirs(outdir, exist_ok=True)
if not os.path.exists(fname):
raise RuntimeError('File {!r} could not be found'.format(fname))
@ -397,7 +412,6 @@ class Installer:
pdb_filename = os.path.splitext(fname)[0] + '.pdb'
if not should_strip and os.path.exists(pdb_filename):
pdb_outname = os.path.splitext(outname)[0] + '.pdb'
print('Installing pdb file %s to %s' % (pdb_filename, pdb_outname))
self.do_copyfile(pdb_filename, pdb_outname)
set_mode(pdb_outname, install_mode, d.install_umask)
elif os.path.isdir(fname):
@ -445,7 +459,7 @@ def run(args):
sys.exit(-1)
os.chdir(opts.wd)
with open(os.path.join(log_dir, 'install-log.txt'), 'w') as lf:
installer = Installer(lf)
installer = Installer(opts, lf)
append_to_log(lf, '# List of files installed by Meson')
append_to_log(lf, '# Does not contain files installed by custom scripts.')
installer.do_install(datafilename)

Loading…
Cancel
Save