Debian Codegraph @

pypy/tool/release/package.py

raw symbols SCIP
1 #!/usr/bin/env python3
2 from __future__ import print_function
3 """ packages PyPy, provided that it's already built.
4 It uses 'pypy/goal/pypy%d.%d-c' and parts of the rest of the working
5 copy. Usage:
6
7 package.py [--options] --archive-name=pypy-VER-PLATFORM
8
9 The output is found in the directory from --builddir,
10 by default /tmp/usession-YOURNAME/build/.
11
12 For a list of all options, see 'package.py --help'.
13 """
14
15 import shutil
16 import sys
17 import os
18 #Add toplevel repository dir to sys.path
19 basedir = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
20 sys.path.insert(0,basedir)
21 import py
22 import fnmatch
23 import subprocess
24 import platform
25 import warnings
26 from pypy.tool.release.smartstrip import smartstrip
27 from pypy.tool.release.make_portable import make_portable
28
29
30 def get_arch():
31 if sys.platform in ('win32', 'darwin'):
32 return sys.platform
33 else:
34 return platform.uname()[-1]
35
36 ARCH = get_arch()
37
38
39 USE_ZIPFILE_MODULE = ARCH == 'win32'
40
41 STDLIB_VER = "3"
42 POSIX_EXE = 'pypy3.11'
43
44
45 from lib_pypy.pypy_tools.build_cffi_imports import (create_cffi_import_libraries,
46 MissingDependenciesError, cffi_build_scripts)
47
48 def ignore_patterns(*patterns):
49 """Function that can be used as copytree() ignore parameter.
50
51 Patterns is a sequence of glob-style patterns
52 that are used to exclude files"""
53 def _ignore_patterns(path, names):
54 ignored_names = []
55 for pattern in patterns:
56 ignored_names.extend(fnmatch.filter(names, pattern))
57 return set(ignored_names)
58 return _ignore_patterns
59
60 def copytree(src, dst, ignore=None):
61 """Recursively copy a directory tree using shtuil.copy2().
62
63 If exception(s) occur, an Error is raised with a list of reasons.
64
65 The optional ignore argument is a callable. If given, it
66 is called with the `src` parameter, which is the directory
67 being visited by copytree(), and `names` which is the list of
68 `src` contents, as returned by os.listdir():
69
70 callable(src, names) -> ignored_names
71
72 Since copytree() is called recursively, the callable will be
73 called once for each directory that is copied. It returns a
74 list of names relative to the `src` directory that should
75 not be copied.
76
77 XXX Derived from shutil.copytree, but allow dst dir to exist
78
79 """
80 names = os.listdir(src)
81 if ignore is not None:
82 ignored_names = ignore(src, names)
83 else:
84 ignored_names = set()
85
86 if not os.path.isdir(dst):
87 os.makedirs(dst)
88 errors = []
89 for name in names:
90 if name in ignored_names:
91 continue
92 srcname = os.path.join(src, name)
93 dstname = os.path.join(dst, name)
94 try:
95 if os.path.isdir(srcname):
96 copytree(srcname, dstname, ignore)
97 else:
98 # Will raise a SpecialFileError for unsupported file types
99 shutil.copy2(srcname, dstname)
100 # catch the Error from the recursive copytree so that we can
101 # continue with other files
102 except Error as err:
103 errors.extend(err.args[0])
104 except EnvironmentError as why:
105 errors.append((srcname, dstname, str(why)))
106 try:
107 shutil.copystat(src, dst)
108 except OSError as why:
109 if WindowsError is not None and isinstance(why, WindowsError):
110 # Copying file access times may fail on Windows
111 pass
112 else:
113 errors.append((src, dst, str(why)))
114 if errors:
115 raise Error(errors)
116
117
118
119 class PyPyCNotFound(Exception):
120 pass
121
122 def fix_permissions(dirname):
123 if ARCH != 'win32':
124 os.system("chmod -R a+rX %s" % dirname)
125 os.system("chmod -R g-w %s" % dirname)
126
127
128 def get_python_ver(pypy_c, quiet=False):
129 kwds = {'universal_newlines': True}
130 if quiet:
131 kwds['stderr'] = subprocess.NULL
132 ver = subprocess.check_output([str(pypy_c), '-c',
133 'import sysconfig as s; print(s.get_python_version())'], **kwds)
134 return ver.strip()
135
136 def get_platlibdir(pypy_c, quiet=False):
137 kwds = {'universal_newlines': True}
138 if quiet:
139 kwds['stderr'] = subprocess.NULL
140 ver = subprocess.check_output([str(pypy_c), '-c',
141 'import sysconfig as s; print(s.get_config_var("platlibdir"))'], **kwds)
142 return ver.strip()
143
144 def get_tcl_patch_level(pypy_c, quiet=False):
145 kwds = {'universal_newlines': True}
146 if quiet:
147 kwds['stderr'] = subprocess.NULL
148 ver = subprocess.check_output([str(pypy_c), '-c',
149 'import _tkinter; print(_tkinter.TCL_PATCH_LEVEL)'], **kwds)
150 return ver.strip()
151
152 def get_tk_patch_level(pypy_c, quiet=False):
153 kwds = {'universal_newlines': True}
154 if quiet:
155 kwds['stderr'] = subprocess.NULL
156 ver = subprocess.check_output([str(pypy_c), '-c',
157 'import _tkinter; print(_tkinter.TK_PATCH_LEVEL)'], **kwds)
158 return ver.strip()
159
160 def generate_sysconfigdata(pypy_c, stdlib):
161 """Create a _sysconfigdata_*.py file that is platform specific and can be
162 parsed by non-python tools. Used in cross-platform package building and
163 when calling sysconfig.get_config_var
164 """
165 if ARCH == 'win32':
166 return
167 # run ./config.guess to add the HOST_GNU_TYPE (copied from CPython,
168 # apparently useful for the crossenv package)
169 config_guess = os.path.join(os.path.dirname(os.path.abspath(__file__)),
170 'config.guess')
171 try:
172 host_gnu_type = subprocess.check_output([config_guess]).strip()
173 except Exception:
174 host_gnu_type = "unkown"
175
176 # this creates a _sysconfigdata_*.py file in some directory, the name
177 # of the directory is written into pybuilddir.txt
178 subprocess.check_call([str(pypy_c), '-m' 'sysconfig',
179 '--generate-posix-vars',
180 # Use PyPy-specific extension to get HOST_GNU_TYPE
181 'HOST_GNU_TYPE', host_gnu_type])
182 with open('pybuilddir.txt') as fid:
183 dirname = fid.read().strip()
184 assert os.path.exists(dirname)
185 sysconfigdata_names = os.listdir(dirname)
186 # what happens if there is more than one file?
187 assert len(sysconfigdata_names) == 1
188 shutil.copy(os.path.join(dirname, sysconfigdata_names[0]), stdlib)
189 shutil.rmtree(dirname)
190
191
192 def create_package(basedir, options, _fake=False):
193 retval = 0
194 name = options.name
195 if not name:
196 name = 'pypy-nightly'
197 assert '/' not in name
198 rename_pypy_c = options.pypy_c
199 override_pypy_c = options.override_pypy_c
200
201 basedir = py.path.local(basedir)
202 if not override_pypy_c:
203 basename = POSIX_EXE + '-c'
204 if ARCH == 'win32':
205 basename += '.exe'
206 pypy_c = basedir.join('pypy', 'goal', basename)
207 else:
208 pypy_c = py.path.local(override_pypy_c)
209 if not _fake and not pypy_c.check():
210 raise PyPyCNotFound(
211 'Expected but did not find %s.'
212 ' Please compile pypy first, using translate.py,'
213 ' or check that you gave the correct path'
214 ' with --override_pypy_c' % pypy_c)
215 builddir = py.path.local(options.builddir)
216 pypydir = builddir.ensure(name, dir=True)
217 if _fake:
218 python_ver = '3.11'
219 else:
220 python_ver = get_python_ver(pypy_c)
221 IMPLEMENTATION = 'pypy{}'.format(python_ver)
222 if ARCH == 'win32':
223 target = pypydir.join('Lib')
224 elif _fake:
225 target = pypydir.join('lib', IMPLEMENTATION)
226 else:
227 target = pypydir.join(get_platlibdir(pypy_c), IMPLEMENTATION)
228 os.makedirs(str(target))
229 if not _fake:
230 # issue 5015: portable builds cannot use the static data
231 # See that issue for a post-installation solution
232 # generate_sysconfigdata(pypy_c, str(target))
233 subprocess.check_call([str(pypy_c), "-c", "import _testmultiphase_build"])
234 subprocess.check_call([str(pypy_c), "-c", "import _ctypes_test_build"])
235 subprocess.check_call([str(pypy_c), "-c", "import _testcapi"])
236 if ARCH == 'win32':
237 os.environ['PATH'] = str(basedir.join('externals').join('bin')) + ';' + \
238 os.environ.get('PATH', '')
239 if not options.no_cffi:
240 failures = create_cffi_import_libraries(
241 str(pypy_c), options, str(basedir),
242 embed_dependencies=options.embed_dependencies,
243 rebuild=options.rebuild_extensions,
244 )
245
246 for key, module in failures:
247 print("""!!!!!!!!!!\nBuilding {0} bindings failed.
248 You can either install development headers package,
249 add the --without-{0} option to skip packaging this
250 binary CFFI extension, or say --without-cffi.""".format(key),
251 file=sys.stderr)
252 if len(failures) > 0:
253 return 1, None
254
255 if ARCH == 'win32' and not rename_pypy_c.lower().endswith('.exe'):
256 rename_pypy_c += '.exe'
257 binaries = [(pypy_c, rename_pypy_c, None)]
258
259 if (ARCH != 'win32' and # handled below
260 not _fake and os.path.getsize(str(pypy_c)) < 500000):
261 # This 'pypy_c' is very small, so it means it relies on a so/dll
262 # If it would be bigger, it wouldn't. That's a hack.
263 if ARCH.startswith('darwin'):
264 ext = 'dylib'
265 else:
266 ext = 'so'
267 libpypy_name = 'lib' + POSIX_EXE + '-c.' + ext
268 libpypy_c = pypy_c.new(basename=libpypy_name)
269 if not libpypy_c.check():
270 raise PyPyCNotFound('Expected pypy to be mostly in %r, but did '
271 'not find it' % (str(libpypy_c),))
272 binaries.append((libpypy_c, libpypy_name, None))
273 #
274
275 includedir = basedir.join('include')
276 copytree(str(includedir), str(pypydir.join('include')))
277 pypydir.ensure('include', dir=True)
278
279 if ARCH == 'win32':
280 src, tgt, _ = binaries[0]
281 pypyw = src.new(purebasename=src.purebasename + 'w')
282 if pypyw.exists():
283 tgt = py.path.local(tgt)
284 binaries.append((pypyw, tgt.new(purebasename=tgt.purebasename + 'w').basename, None))
285 print("Picking %s" % str(pypyw))
286 binaries.append((pypyw, 'pythonw.exe', None))
287 print('Picking {} as pythonw.exe'.format(pypyw))
288 binaries.append((pypyw, 'pypyw.exe', None))
289 print('Picking {} as pypyw.exe'.format(pypyw))
290 binaries.append((src, 'python.exe', None))
291 print('Picking {} as python.exe'.format(src))
292 binaries.append((src, 'pypy.exe', None))
293 print('Picking {} as pypy.exe'.format(src))
294 binaries.append((src, 'pypy{}.exe'.format(python_ver), None))
295 print('Picking {} as pypy{}.exe'.format(src, python_ver))
296 binaries.append((src, 'python{}.exe'.format(python_ver), None))
297 print('Picking {} as python{}.exe'.format(src, python_ver))
298 binaries.append((src, 'pypy{}.exe'.format(python_ver[0]), None))
299 print('Picking {} as pypy{}.exe'.format(src, python_ver[0]))
300 binaries.append((src, 'python{}.exe'.format(python_ver[0]), None))
301 print('Picking {} as python{}.exe'.format(src, python_ver[0]))
302 # Can't rename a DLL
303 win_extras = [('lib' + POSIX_EXE + '-c.dll', None)]
304 if options.copy_dlls:
305 win_extras +=[
306 ('sqlite3.dll', target),
307 # Needs fixing for openssl3
308 ('libssl-1_1.dll', target),
309 ('libcrypto-1_1.dll', target),
310 ('libffi-8.dll', None),
311 ]
312 if not options.no__tkinter:
313 tkinter_dir = target.join('_tkinter')
314 win_extras += [
315 ('tcl86t.dll', tkinter_dir),
316 ('tk86t.dll', tkinter_dir),
317 ]
318 # for testing, copy the dlls to the `base_dir` as well
319 tkinter_dir = basedir.join('lib_pypy', '_tkinter')
320 win_extras += [
321 ('tcl86t.dll', tkinter_dir),
322 ('tk86t.dll', tkinter_dir),
323 ]
324 for extra, target_dir in win_extras:
325 p = pypy_c.dirpath().join(extra)
326 if not p.check():
327 p = py.path.local.sysfind(extra)
328 if not p:
329 print("%s not found, expect trouble if this "
330 "is a shared build" % (extra,))
331 continue
332 print("Picking %s" % p)
333 binaries.append((p, p.basename, target_dir))
334 libsdir = basedir.join('libs')
335 if libsdir.exists():
336 print('Picking %s (and contents)' % libsdir)
337 copytree(str(libsdir), str(pypydir.join('libs')))
338 else:
339 if not _fake:
340 raise RuntimeError('"libs" dir with import library not found.')
341 # XXX users will complain that they cannot compile capi (cpyext)
342 # modules for windows, also embedding pypy (i.e. in cffi)
343 # will fail.
344 # Has the lib moved, was translation not 'shared', or are
345 # there no exported functions in the dll so no import
346 # library was created?
347 if getattr(options, 'copy_dlls', True) and not options.no__tkinter:
348 try:
349 p = pypy_c.dirpath().join('tcl86t.dll')
350 if not p.check():
351 p = py.path.local.sysfind('tcl86t.dll')
352 if p is None:
353 raise WindowsError("tcl86t.dll not found")
354 tktcldir = p.dirpath().join('..').join('lib')
355 copytree(str(tktcldir), str(pypydir.join('tcl')))
356 except WindowsError:
357 print("Packaging Tk runtime failed. tk86t.dll and tcl86t.dll "
358 "found in %s, expecting to find runtime in %s directory "
359 "next to the dlls, as per build "
360 "instructions." %(p, tktcldir), file=sys.stderr)
361 import traceback;traceback.print_exc()
362 raise MissingDependenciesError('Tk runtime')
363
364 print('* Binaries:', [source.relto(str(basedir))
365 for source, dst, target_dir in binaries])
366
367 copytree(str(basedir.join('lib-python').join(STDLIB_VER)),
368 str(target),
369 ignore=ignore_patterns('.svn', 'py', '*.pyc', '*~','__pycache__'))
370 # Careful: to copy lib_pypy, copying just the hg-tracked files
371 # would not be enough: there are also build artifacts like cffi-generated
372 # dynamic libs
373 copytree(str(basedir.join('lib_pypy')), str(target),
374 ignore=ignore_patterns('.svn', 'py', '*.pyc', '*~',
375 '*_cffi.c', '*.o', '*.pyd-*', '*.obj',
376 '*.lib', '*.exp', '*.manifest', '__pycache__'))
377 for file in ['README.rst',]:
378 shutil.copy(str(basedir.join(file)), str(pypydir))
379 for file in ['__init__.py',]:
380 os.unlink(str(target / file))
381 # Use original LICENCE file
382 base_file = str(basedir.join('LICENSE'))
383 with open(base_file) as fid:
384 license = fid.read()
385 with open(str(pypydir.join('LICENSE')), 'w') as LICENSE:
386 LICENSE.write(license)
387 #
388 spdir = target.ensure('site-packages', dir=True)
389 shutil.copy(str(basedir.join('lib-python/3/site-packages/README.txt')),
390 str(spdir))
391 #
392 if ARCH == 'win32':
393 bindir = pypydir
394 else:
395 bindir = pypydir.join('bin')
396 bindir.ensure(dir=True)
397 for source, dst, target_dir in binaries:
398 if target_dir:
399 archive = target_dir.join(dst)
400 else:
401 archive = bindir.join(dst)
402 if not _fake:
403 shutil.copy(str(source), str(archive))
404 else:
405 open(str(archive), 'wb').close()
406 os.chmod(str(archive), 0o755)
407 if not _fake and not ARCH == 'win32':
408 # create a link to pypy, python
409 old_dir = os.getcwd()
410 os.chdir(str(bindir))
411 try:
412 os.symlink(POSIX_EXE, 'pypy')
413 # os.symlink(POSIX_EXE, 'pypy{}'.format(python_ver))
414 os.symlink(POSIX_EXE, 'pypy{}'.format(python_ver[0]))
415 os.symlink(POSIX_EXE, 'python')
416 os.symlink(POSIX_EXE, 'python{}'.format(python_ver))
417 os.symlink(POSIX_EXE, 'python{}'.format(python_ver[0]))
418 finally:
419 os.chdir(old_dir)
420 fix_permissions(pypydir)
421
422 old_dir = os.getcwd()
423 try:
424 os.chdir(str(builddir))
425 if not _fake:
426 for source, dst, target_dir in binaries:
427 if target_dir:
428 archive = target_dir.join(dst)
429 else:
430 archive = bindir.join(dst)
431 smartstrip(archive, keep_debug=options.keep_debug)
432
433 # make the package portable by adding rpath=$ORIGIN/..lib,
434 # bundling dependencies
435 if options.make_portable:
436 os.chdir(str(name))
437 if not os.path.exists('lib'):
438 os.mkdir('lib')
439 tk_patch = get_tk_patch_level(pypy_c)
440 tcl_patch = get_tcl_patch_level(pypy_c)
441 deps = make_portable(copytree, python_ver, tk_patch, tcl_patch)
442 with open("lib/PYPY_PORTABLE_DEPS.txt", "wt") as fid:
443 for k in deps.keys():
444 fid.write("%s\n" % k)
445 if not options.no__tkinter:
446 fid.write("tk8.6\n")
447 fid.write("tcl8.6\n")
448 os.chdir(str(builddir))
449 if USE_ZIPFILE_MODULE:
450 import zipfile
451 archive = str(builddir.join(name + '.zip'))
452 zf = zipfile.ZipFile(archive, 'w',
453 compression=zipfile.ZIP_DEFLATED)
454 for (dirpath, dirnames, filenames) in os.walk(name):
455 for fnname in filenames:
456 filename = os.path.join(dirpath, fnname)
457 zf.write(filename)
458 zf.close()
459 else:
460 archive = str(builddir.join(name + '.tar.bz2'))
461 if ARCH == 'darwin':
462 print("Warning: tar on current platform does not suport "
463 "overriding the uid and gid for its contents. The tarball "
464 "will contain your uid and gid. If you are building the "
465 "actual release for the PyPy website, you may want to be "
466 "using another platform...", file=sys.stderr)
467 e = os.system('tar --numeric-owner -cjf ' + archive + " " + name)
468 elif sys.platform.startswith('freebsd'):
469 e = os.system('tar --uname=root --gname=wheel -cjf ' + archive + " " + name)
470 elif sys.platform == 'cygwin':
471 e = os.system('tar --owner=Administrator --group=Administrators --numeric-owner -cjf ' + archive + " " + name)
472 else:
473 e = os.system('tar --owner=root --group=root --numeric-owner -cjf ' + archive + " " + name)
474 if e:
475 raise OSError('"tar" returned exit status %r' % e)
476 finally:
477 os.chdir(old_dir)
478 if options.targetdir:
479 tdir = os.path.normpath(options.targetdir)
480 adir = os.path.dirname(archive)
481 if tdir != adir:
482 print("Copying %s to %s" % (archive, options.targetdir))
483 shutil.copy(archive, options.targetdir)
484 print("Ready in %s" % (builddir,))
485 return retval, builddir # for tests
486
487 def package(*args, **kwds):
488 import argparse
489
490 class NegateAction(argparse.Action):
491 def __init__(self, option_strings, dest, nargs=0, **kwargs):
492 super(NegateAction, self).__init__(option_strings, dest, nargs,
493 **kwargs)
494
495 def __call__(self, parser, ns, values, option):
496 setattr(ns, self.dest, option[2:4] != 'no')
497
498 if ARCH == 'win32':
499 pypy_exe = POSIX_EXE + '.exe'
500 else:
501 pypy_exe = POSIX_EXE
502 keep_debug_default = True
503 no__tkinter_default = False
504 embed_dependencies_default = (ARCH in ('darwin', 'aarch64', 'x86_64', 'i686'))
505 rebuild_extensions_default = (ARCH in ('darwin', 'aarch64', 'x86_64', 'i686'))
506 make_portable_default = (ARCH in ('darwin',))
507 copy_dlls_default = True
508 if "PYPY_PACKAGE_NOKEEPDEBUG" in os.environ:
509 keep_debug_default = False
510 if "PYPY_PACKAGE_WITHOUTTK" in os.environ:
511 no__tkinter_default = True
512 if "PYPY_EMBED_DEPENDENCIES" in os.environ:
513 embed_dependencies_default = True
514 elif "PYPY_NO_EMBED_DEPENDENCIES" in os.environ:
515 embed_dependencies_default = False
516 if "PYPY_REBUILD_EXTENSIONS" in os.environ:
517 rebuild_extensions_default = True
518 elif "PYPY_NO_REBUILD_EXTENSIONS" in os.environ:
519 rebuild_extensions_default = False
520 if "PYPY_MAKE_PORTABLE" in os.environ:
521 make_portable_default = True
522 if "PYPY_NO_MAKE_PORTABLE" in os.environ:
523 make_portable_default = False
524 if "PYPY_PACKAGE_NO_DLLS" in os.environ:
525 copy_dlls_default = False
526 parser = argparse.ArgumentParser()
527 args = list(args)
528 if args:
529 args[0] = str(args[0])
530 for key, module in cffi_build_scripts:
531 if module is not None and key != '_tkinter':
532 parser.add_argument('--without-' + key,
533 dest='no_' + key,
534 action='store_true',
535 help='do not build and package the %r cffi module' % (key,))
536
537 parser.add_argument('--without-_tkinter',
538 dest='no__tkinter',
539 default=no__tkinter_default,
540 action='store_true',
541 help='do not build and package the _tkinter cffi module')
542 parser.add_argument('--without-cffi', dest='no_cffi', action='store_true',
543 help='skip building *all* the cffi modules listed above')
544 parser.add_argument('--keep-debug', '--no-keep-debug', dest='keep_debug',
545 action=NegateAction,
546 default=keep_debug_default,
547 help='do not keep debug symbols')
548 parser.add_argument('--rename_pypy_c', dest='pypy_c', type=str, default=pypy_exe,
549 help='target executable name, defaults to "%s"' % pypy_exe)
550 parser.add_argument('--archive-name', dest='name', type=str, default='',
551 help='pypy-VER-PLATFORM')
552 parser.add_argument('--builddir', type=str, default='',
553 help='tmp dir for packaging')
554 parser.add_argument('--targetdir', type=str, default='',
555 help='destination dir for archive')
556 parser.add_argument('--override_pypy_c', type=str, default='',
557 help='use as pypy3 exe, default is %s' % POSIX_EXE)
558 parser.add_argument('--embedded-dependencies', '--no-embedded-dependencies',
559 dest='embed_dependencies',
560 action=NegateAction,
561 default=embed_dependencies_default,
562 help='whether to embed dependencies in CFFI modules. '
563 'Defaults to {} on this platform. Uses environment '
564 'PYPY_EMBED_DEPENDENCIES and PYPY_NO_EMBED_DEPENDENCIES'
565 .format(embed_dependencies_default)
566 )
567 parser.add_argument('--rebuild-extensions', '--no-rebuild-extensions',
568 dest='rebuild_extensions',
569 action=NegateAction,
570 default=rebuild_extensions_default,
571 help='whether to force rebuilding CFFI modules '
572 'Defaults to {} on this platform. Uses environment '
573 'PYPY_REBUILD_EXTENSIONS and PYPY_NO_REBUILD_EXTENSIONS'
574 .format(rebuild_extensions_default)
575 )
576 parser.add_argument('--make-portable', '--no-make-portable',
577 dest='make_portable',
578 action=NegateAction,
579 default=make_portable_default,
580 help='make the package portable by shipping '
581 'dependent shared objects and mangling RPATH. '
582 'Defaults to {} on this platform. Uses environment '
583 'PYPY_MAKE_PORTABLE and PYPY_NO_MAKE_PORTABLE'
584 .format(make_portable_default)
585 )
586 if ARCH == 'win32':
587 parser.add_argument('--copy-dlls', '--no-copy-dlls', dest='copy_dlls',
588 action=NegateAction,
589 default=copy_dlls_default,
590 help='copy support dlls into the package.'
591 'Defaults to True. '
592 'Uses environment PYPY_PACKAGE_NO_DLLS to override the default.'
593 )
594 options = parser.parse_args(args)
595
596 if not options.builddir:
597 # The import actually creates the udir directory
598 from rpython.tool.udir import udir
599 options.builddir = udir.ensure("build", dir=True)
600 else:
601 # if a user provides a path it must be converted to a local file system path
602 # otherwise ensure in create_package will fail
603 options.builddir = py.path.local(options.builddir)
604 assert '/' not in options.pypy_c
605 return create_package(basedir, options, **kwds)
606
607
608 if __name__ == '__main__':
609 import sys
610 if ARCH == 'win32':
611 # Try to avoid opeing a dialog box if one of the
612 # subprocesses causes a system error
613 import ctypes
614 winapi = ctypes.windll.kernel32
615 SetErrorMode = winapi.SetErrorMode
616 SetErrorMode.argtypes=[ctypes.c_int]
617
618 SEM_FAILCRITICALERRORS = 1
619 SEM_NOGPFAULTERRORBOX = 2
620 SEM_NOOPENFILEERRORBOX = 0x8000
621 flags = SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX | SEM_NOOPENFILEERRORBOX
622 #Since there is no GetErrorMode, do a double Set
623 old_mode = SetErrorMode(flags)
624 SetErrorMode(old_mode | flags)
625
626 retval, _ = package(*sys.argv[1:])
627 sys.exit(retval)