Skip to content

Commit

Permalink
Moved scripts in the module and started work to run them via the main…
Browse files Browse the repository at this point in the history
… meson command.
  • Loading branch information
jpakkane committed Jan 15, 2016
1 parent d2a1407 commit 66c0140
Show file tree
Hide file tree
Showing 20 changed files with 156 additions and 68 deletions.
22 changes: 20 additions & 2 deletions meson.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,24 @@
#!/usr/bin/env python3

# Copyright 2016 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.

from meson import mesonmain
import sys
import sys, os

thisfile = __file__
if not os.path.isabs(thisfile):
thisfile = os.path.join(os.getcwd(), thisfile)

sys.exit(mesonmain.run(sys.argv[:]))
sys.exit(mesonmain.run(thisfile, sys.argv[1:]))
2 changes: 1 addition & 1 deletion meson/environment.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2012-2014 The Meson development team
# Copyright 2012-2016 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.
Expand Down
60 changes: 48 additions & 12 deletions meson/mesonmain.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python3

# Copyright 2012-2015 The Meson development team
# Copyright 2012-2016 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.
Expand All @@ -18,7 +18,7 @@
import datetime
import os.path
from . import environment, interpreter, mesonlib
from .import build
from . import build
import platform
from . import mlog, coredata

Expand Down Expand Up @@ -163,21 +163,58 @@ def generate(self):
dumpfile = os.path.join(env.get_scratch_dir(), 'build.dat')
pickle.dump(b, open(dumpfile, 'wb'))

def run(args):
def run_script_command(args):
cmdname = args[0]
cmdargs = args[1:]
if cmdname == 'test':
import meson.scripts.meson_test as abc
cmdfunc = abc.run
elif cmdname == 'benchmark':
import meson.scripts.meson_benchmark as abc
cmdfunc = abc.run
elif cmdname == 'commandrunner':
import meson.scripts.commandrunner as abc
cmdfunc = abc.run
elif cmdname == 'delsuffix':
import meson.scripts.delwithsuffix as abc
cmdfunc = abc.run
elif cmdname == 'dirchanger':
import meson.scripts.dirchanger as abc
cmdfunc = abc.run
elif cmdname == 'gtkdoc':
import meson.scripts.gtkdochelper as abc
cmdfunc = abc.run
elif cmdname == 'regencheck':
import meson.scripts.regen_checker as abc
cmdfunc = abc.run
elif cmdname == 'symbolextractor':
import meson.scripts.symbolextractor as abc
cmdfunc = abc.run
elif cmdname == 'vcstagger':
import meson.scripts.vcstagger as abc
cmdfunc = abc.run
else:
raise MesonException('Unknown internal command {}.'.format(cmdname))
return cmdfunc(cmdargs)

def run(mainfile, args):
if sys.version_info < (3, 3):
print('Meson works correctly only with python 3.3+.')
print('You have python %s.' % sys.version)
print('Please update your environment')
return 1
if args[-1] == 'secret-handshake':
args = args[:-1]
if args[0] == '--internal':
if args[1] != 'regenerate':
sys.exit(run_script_command(args[1:]))
args = args[2:]
handshake = True
else:
handshake = False
print(args)
args = mesonlib.expand_arguments(args)
if not args:
return 1
options = parser.parse_args(args[1:])
options = parser.parse_args(args)
if options.print_version:
print(coredata.version)
return 0
Expand All @@ -191,16 +228,15 @@ def run(args):
dir2 = args[1]
else:
dir2 = '.'
this_file = os.path.abspath(__file__)
while os.path.islink(this_file):
resolved = os.readlink(this_file)
while os.path.islink(mainfile):
resolved = os.readlink(mainfile)
if resolved[0] != '/':
this_file = os.path.join(os.path.dirname(this_file), resolved)
mainfile = os.path.join(os.path.dirname(mainfile), resolved)
else:
this_file = resolved
mainfile = resolved

try:
app = MesonApp(dir1, dir2, this_file, handshake, options)
app = MesonApp(dir1, dir2, mainfile, handshake, options)
except Exception as e:
# Log directory does not exist, so just print
# to stdout.
Expand Down
2 changes: 1 addition & 1 deletion meson/modules/gnome.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2015 The Meson development team
# Copyright 2015-2016 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.
Expand Down
11 changes: 6 additions & 5 deletions meson/ninjabackend.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2012-2014 The Meson development team
# Copyright 2012-2016 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.
Expand Down Expand Up @@ -582,9 +582,8 @@ def generate_tests(self, outfile):
self.serialise_tests()
valgrind = environment.find_valgrind()
script_root = self.environment.get_script_dir()
test_script = os.path.join(script_root, 'meson_test.py')
test_data = os.path.join(self.environment.get_scratch_dir(), 'meson_test_setup.dat')
cmd = [sys.executable, test_script, test_data]
cmd = [sys.executable, self.environment.get_build_command(), '--internal', 'test', test_data]
elem = NinjaBuildElement('test', 'CUSTOM_COMMAND', ['all', 'PHONY'])
elem.add_item('COMMAND', cmd)
elem.add_item('DESC', 'Running all tests.')
Expand All @@ -604,7 +603,7 @@ def generate_tests(self, outfile):
# And then benchmarks.
benchmark_script = os.path.join(script_root, 'meson_benchmark.py')
benchmark_data = os.path.join(self.environment.get_scratch_dir(), 'meson_benchmark_setup.dat')
cmd = [sys.executable, benchmark_script, benchmark_data]
cmd = [sys.executable, self.environment.get_build_command(), '--internal', 'benchmark', benchmark_data]
elem = NinjaBuildElement('benchmark', 'CUSTOM_COMMAND', ['all', 'PHONY'])
elem.add_item('COMMAND', cmd)
elem.add_item('DESC', 'Running benchmark suite.')
Expand All @@ -628,9 +627,11 @@ def generate_rules(self, outfile):
outfile.write('rule REGENERATE_BUILD\n')
c = (quote_char + ninja_quote(sys.executable) + quote_char,
quote_char + ninja_quote(self.environment.get_build_command()) + quote_char,
'--internal',
'regenerate',
quote_char + ninja_quote(self.environment.get_source_dir()) + quote_char,
quote_char + ninja_quote(self.environment.get_build_dir()) + quote_char)
outfile.write(" command = %s %s %s %s --backend ninja secret-handshake\n" % c)
outfile.write(" command = %s %s %s %s %s %s --backend ninja\n" % c)
outfile.write(' description = Regenerating build files\n')
outfile.write(' generator = 1\n\n')
if len(self.build.pot) > 0:
Expand Down
12 changes: 8 additions & 4 deletions scripts/commandrunner.py → meson/scripts/commandrunner.py
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,18 @@ def run_command(source_dir, build_dir, subdir, command, arguments):
print('Could not execute command "%s".' % command)
sys.exit(1)

if __name__ == '__main__':
if len(sys.argv) < 5:
print(sys.argv[0], '<source dir> <build dir> <subdir> <command> [arguments]')
def run(args):
if len(sys.argv) < 4:
print('commandrunner.py <source dir> <build dir> <subdir> <command> [arguments]')
sys.exit(1)
src_dir = sys.argv[1]
build_dir = sys.argv[2]
subdir = sys.argv[3]
command = sys.argv[4]
arguments = sys.argv[5:]
pc = run_command(src_dir, build_dir, subdir, command, arguments)
pc.wait()
sys.exit(pc.returncode)
return pc.returncode

if __name__ == '__main__':
sys.exit(run(sys.argv[1:]))
33 changes: 19 additions & 14 deletions scripts/delwithsuffix.py → meson/scripts/delwithsuffix.py
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,22 @@

import os, sys

if len(sys.argv) != 3:
print('%s <root of subdir to process> <suffix to delete>' % sys.argv[0])
sys.exit(1)

topdir = sys.argv[1]
suffix = sys.argv[2]
if suffix[0] != '.':
suffix = '.' + suffix

for (root, dirs, files) in os.walk(topdir):
for f in files:
if f.endswith(suffix):
fullname = os.path.join(root, f)
os.unlink(fullname)
def run(args):
if len(sys.argv) != 2:
print('delwithsuffix.py <root of subdir to process> <suffix to delete>')
sys.exit(1)

topdir = sys.argv[1]
suffix = sys.argv[2]
if suffix[0] != '.':
suffix = '.' + suffix

for (root, _, files) in os.walk(topdir):
for f in files:
if f.endswith(suffix):
fullname = os.path.join(root, f)
os.unlink(fullname)
return 0

if __name__ == '__main__':
run(sys.argv[1:])
15 changes: 9 additions & 6 deletions scripts/depfixer.py → meson/scripts/depfixer.py
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -284,16 +284,19 @@ def remove_rpath_entry(self):
entry.write(self.bf)
return None

if __name__ == '__main__':
if len(sys.argv) < 2 or len(sys.argv) > 3:
def run(args):
if len(args) < 1 or len(args) > 2:
print('This application resets target rpath.')
print('Don\'t run this unless you know what you are doing.')
print('%s: <binary file> <prefix>' % sys.argv[0])
exit(1)
e = Elf(sys.argv[1])
if len(sys.argv) == 2:
e = Elf(args[0])
if len(args) == 1:
e.print_rpath()
else:
new_rpath = sys.argv[2]
new_rpath = args[1]
e.fix_rpath(new_rpath.encode('utf8'))
#e.fix_deps(prefix.encode())
return 0

if __name__ == '__main__':
run(sys.argv[1:])
12 changes: 8 additions & 4 deletions scripts/dirchanger.py → meson/scripts/dirchanger.py
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,12 @@

import os, subprocess, sys

dirname = sys.argv[1]
command = sys.argv[2:]
def run(args):
dirname = args[0]
command = args[1:]

os.chdir(dirname)
sys.exit(subprocess.call(command))
os.chdir(dirname)
return subprocess.call(command)

if __name__ == '__main__':
sys.exit(run(sys.argv[1:]))
10 changes: 7 additions & 3 deletions scripts/gtkdochelper.py → meson/scripts/gtkdochelper.py
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env python3
# Copyright 2015 The Meson development team
# Copyright 2015-2016 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.
Expand Down Expand Up @@ -87,8 +87,8 @@ def install_gtkdoc(build_root, doc_subdir, install_prefix, datadir, module):
shutil.rmtree(final_destination, ignore_errors=True)
shutil.copytree(source, final_destination)

if __name__ == '__main__':
options = parser.parse_args(sys.argv[1:])
def run(args):
options = parser.parse_args(args)
if len(options.htmlargs) > 0:
htmlargs = options.htmlargs.split('@@')
else:
Expand Down Expand Up @@ -116,3 +116,7 @@ def install_gtkdoc(build_root, doc_subdir, install_prefix, datadir, module):
installdir,
'share/gtk-doc/html',
options.modulename)
return 0

if __name__ == '__main__':
sys.exit(run(sys.argv[1:]))
File renamed without changes.
11 changes: 7 additions & 4 deletions scripts/meson_install.py → meson/scripts/meson_install.py
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -203,10 +203,13 @@ def install_targets(d):
print('Stderr:\n%s\n' % stde.decode())
sys.exit(1)

if __name__ == '__main__':
if len(sys.argv) != 2:
def run(args):
if len(args) != 1:
print('Installer script for Meson. Do not run on your own, mmm\'kay?')
print('%s [install info file]' % sys.argv[0])
datafilename = sys.argv[1]
print('meson_install.py [install info file]')
datafilename = args[0]
do_install(datafilename)
return 0

if __name__ == '__main__':
sys.exit(run(sys.argv[1:]))
2 changes: 1 addition & 1 deletion scripts/meson_test.py → meson/scripts/meson_test.py
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python3

# Copyright 2013-2015 The Meson development team
# Copyright 2013-2016 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.
Expand Down
9 changes: 6 additions & 3 deletions scripts/regen_checker.py → meson/scripts/regen_checker.py
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python3

# Copyright 2015 The Meson development team
# Copyright 2015-2016 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.
Expand Down Expand Up @@ -35,8 +35,11 @@ def regen(regeninfo):
'--backend=vs2010', 'secret-handshake']
subprocess.check_call(cmd)

if __name__ == '__main__':
regeninfo = pickle.load(open(os.path.join(sys.argv[1], 'regeninfo.dump'), 'rb'))
def run(args):
regeninfo = pickle.load(open(os.path.join(args[0], 'regeninfo.dump'), 'rb'))
if need_regen(regeninfo):
regen(regeninfo)
sys.exit(0)

if __name__ == '__main__':
run(sys.argv[1:])
12 changes: 8 additions & 4 deletions scripts/symbolextractor.py → meson/scripts/symbolextractor.py
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python3

# Copyright 2013-2015 The Meson development team
# Copyright 2013-2016 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.
Expand Down Expand Up @@ -92,11 +92,15 @@ def gen_symbols(libfilename, outfilename, cross_host):
else:
dummy_syms(outfilename)

if __name__ == '__main__':
options = parser.parse_args()
def run(args):
options = parser.parse_args(args)
if len(options.args) != 2:
print(sys.argv[0], '<shared library file> <output file>')
print('symbolextractor.py <shared library file> <output file>')
sys.exit(1)
libfile = options.args[0]
outfile = options.args[1]
gen_symbols(libfile, outfile, options.cross_host)
return 0

if __name__ == '__main__':
sys.exit(run(sys.argv[1:]))
Loading

0 comments on commit 66c0140

Please sign in to comment.