Created a dist target. Closes #877.

pull/1669/head
Jussi Pakkanen 8 years ago
parent 1a87c967f1
commit 255be79e22
  1. 9
      mesonbuild/backend/ninjabackend.py
  2. 2
      mesonbuild/coredata.py
  3. 3
      mesonbuild/mesonmain.py
  4. 85
      mesonbuild/scripts/dist.py

@ -195,6 +195,7 @@ int dummy;
self.generate_tests(outfile)
outfile.write('# Install rules\n\n')
self.generate_install(outfile)
self.generate_dist(outfile)
if 'b_coverage' in self.environment.coredata.base_options and \
self.environment.coredata.base_options['b_coverage'].value:
outfile.write('# Coverage rules\n\n')
@ -2375,6 +2376,14 @@ rule FORTRAN_DEP_HACK
# affect behavior in any other way.
return sorted(cmds)
def generate_dist(self, outfile):
elem = NinjaBuildElement(self.all_outputs, 'dist', 'CUSTOM_COMMAND', 'PHONY')
elem.add_item('DESC', 'Creating source packages')
elem.add_item('COMMAND', [sys.executable, self.environment.get_build_command(), '--internal', 'dist',
self.environment.source_dir, self.environment.build_dir])
elem.add_item('pool', 'console')
elem.write(outfile)
# For things like scan-build and other helper tools we might have.
def generate_utils(self, outfile):
cmd = [sys.executable, self.environment.get_build_command(),

@ -347,4 +347,6 @@ forbidden_target_names = {'clean': None,
'build.ninja': None,
'scan-build': None,
'reconfigure': None,
'dist': None,
'distcheck': None,
}

@ -246,6 +246,9 @@ def run_script_command(args):
elif cmdname == 'uninstall':
import mesonbuild.scripts.uninstall as abc
cmdfunc = abc.run
elif cmdname == 'dist':
import mesonbuild.scripts.dist as abc
cmdfunc = abc.run
else:
raise MesonException('Unknown internal command {}.'.format(cmdname))
return cmdfunc(cmdargs)

@ -0,0 +1,85 @@
# Copyright 2017 The Meson development team
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import os
import shutil
import argparse
import subprocess
import pickle
import hashlib
import tarfile, zipfile
from glob import glob
def create_hash(fname):
hashname = fname + '.sha256sum'
m = hashlib.sha256()
m.update(open(fname, 'rb').read())
with open(hashname, 'w') as f:
f.write('%s %s\n' % (m.hexdigest(), os.path.split(fname)[-1]))
def create_zip(zipfilename, packaging_dir):
prefix = os.path.split(packaging_dir)[0]
removelen = len(prefix)+1
zf = zipfile.ZipFile(zipfilename, 'w', compression=zipfile.ZIP_DEFLATED,
allowZip64=True)
zf.write(packaging_dir, packaging_dir[removelen:])
for root, dirs, files in os.walk(packaging_dir):
for d in dirs:
dname = os.path.join(root, d)
zf.write(dname, dname[removelen:])
for f in files:
fname = os.path.join(root, f)
zf.write(fname, fname[removelen:])
zf.close()
def create_dist(dist_name, src_root, bld_root, dist_sub):
distdir = os.path.join(dist_sub, dist_name)
gitdir = os.path.join(src_root, '.git')
if os.path.exists(distdir):
shutil.rmtree(distdir)
os.makedirs(distdir)
dest_gitdir = os.path.join(distdir, '.git')
shutil.copytree(gitdir, dest_gitdir)
subprocess.check_call(['git', 'reset', '--hard'], cwd=distdir)
shutil.rmtree(dest_gitdir)
for f in glob(os.path.join(distdir, '.git*')):
os.unlink(f)
xzname = distdir + '.tar.xz'
zipname = distdir + '.zip'
tf = tarfile.open(xzname, 'w:xz')
tf.add(distdir, os.path.split(distdir)[1])
tf.close()
create_hash(xzname)
create_zip(zipname, distdir)
create_hash(zipname)
def run(args):
src_root = args[0]
bld_root = args[1]
priv_dir = os.path.join(bld_root, 'meson-private')
dist_sub = os.path.join(bld_root, 'meson-dist')
buildfile = os.path.join(priv_dir, 'build.dat')
build = pickle.load(open(buildfile, 'rb'))
dist_name = build.project_name + '-' + build.project_version
if not os.path.isdir(os.path.join(src_root, '.git')):
print('Dist currently only works with Git repos.')
return 1
create_dist(dist_name, src_root, bld_root, dist_sub)
return 0
Loading…
Cancel
Save