def test_read_setup_file(self): # trying to read a Setup file # (sample extracted from the PyGame project) setup = os.path.join(os.path.dirname(__file__), "Setup.sample") exts = read_setup_file(setup) names = [ext.name for ext in exts] names.sort() # here are the extensions read_setup_file should have created # out of the file wanted = [ "_arraysurfarray", "_camera", "_numericsndarray", "_numericsurfarray", "base", "bufferproxy", "cdrom", "color", "constants", "display", "draw", "event", "fastevent", "font", "gfxdraw", "image", "imageext", "joystick", "key", "mask", "mixer", "mixer_music", "mouse", "movie", "overlay", "pixelarray", "pypm", "rect", "rwobject", "scrap", "surface", "surflock", "time", "transform", ] self.assertEqual(names, wanted)
def test_read_setup_file(self): # trying to read a Setup file # (sample extracted from the PyGame project) setup = os.path.join(os.path.dirname(__file__), 'Setup.sample') exts = read_setup_file(setup) names = [ext.name for ext in exts] names.sort() # here are the extensions read_setup_file should have created # out of the file wanted = ['_arraysurfarray', '_camera', '_numericsndarray', '_numericsurfarray', 'base', 'bufferproxy', 'cdrom', 'color', 'constants', 'display', 'draw', 'event', 'fastevent', 'font', 'gfxdraw', 'image', 'imageext', 'joystick', 'key', 'mask', 'mixer', 'mixer_music', 'mouse', 'movie', 'overlay', 'pixelarray', 'pypm', 'rect', 'rwobject', 'scrap', 'surface', 'surflock', 'time', 'transform'] self.assertEqual(names, wanted)
config.main() print ('\nContinuing With "setup.py"') try: s_mtime = os.stat("Setup")[stat.ST_MTIME] sin_mtime = os.stat("Setup.in")[stat.ST_MTIME] if sin_mtime > s_mtime: print ('\n\nWARNING, "Setup.in" newer than "Setup",' 'you might need to modify "Setup".') except: pass # get compile info for all extensions try: extensions = read_setup_file('Setup') except: print ("""Error with the "Setup" file, perhaps make a clean copy from "Setup.in".""") raise #python 3.x: remove modules not yet ported if sys.version_info >= (3, 0, 0): python3_skip = ['_movie', '_numericsurfarray', '_numericsndarray', ] # if (sys.platform != 'linux2'): # python3_skip.append('scrap') tmp_extensions = extensions extensions = []
import config config.main() print('\nContinuing With "setup.py"') try: s_mtime = os.stat("Setup")[stat.ST_MTIME] sin_mtime = os.stat("Setup.in")[stat.ST_MTIME] if sin_mtime > s_mtime: print('\n\nWARNING, "Setup.in" newer than "Setup",' 'you might need to modify "Setup".') except: pass # get compile info for all extensions try: extensions = read_setup_file('Setup') except: print("""Error with the "Setup" file, perhaps make a clean copy from "Setup.in".""") raise #python 3.x: remove modules not yet ported if sys.version_info >= (3, 0, 0): python3_skip = [ '_numericsurfarray', '_numericsndarray', ] # if (sys.platform != 'linux2'): # python3_skip.append('scrap') tmp_extensions = extensions extensions = []
def main(dest_dir=None): # Top level directories. if dest_dir is None: dest_dir = prebuilt_dir if re.match(r'([A-Za-z]:){0,1}[^"<>:|?*]+$', dest_dir) is None: print "Invalid directory path name %s" % dest_dir return 1 dest_dir = os.path.abspath(dest_dir) if os.path.isdir(dest_dir): if not confirm("Directory %s already exists;\ncontinue" % dest_dir): return 1 mkdir(dest_dir) m = msys.Msys() src_dir = os.path.join(m.msys_root, 'local') prebuilt_template = os.path.abspath('prebuilt-template') dest_lib_dir = os.path.join(dest_dir, lib_subdir) # Read setup file. src_file = os.path.join(prebuilt_template, 'Setup_Win.in') file_copy(src_file, dest_dir) deps = read_setup_file(src_file) setup_in = open(src_file) match = re.compile('[A-Z_][A-Z0-9_]* *=(.*)').match header_dir_pat = re.compile(' -I([^ ]+)') lib_pat = re.compile(' -l([^ ]+)') macros = [] for line in setup_in: matches = match(line) if matches is not None: flags = matches.group(1) header_dirs = header_dir_pat.findall(flags) libs = lib_pat.findall(flags) macros.append((header_dirs, libs)) # Copy DLLs. src_bin_dir = os.path.join(src_dir, 'bin') have_dlls = set() for dep in deps: path_elements = dep.library_dirs[0].split('/') # / required by setup. dll_name = path_elements[-1] src_dll_path = os.path.join(src_bin_dir, dll_name) if os.path.exists(src_dll_path): if path_elements[0] == '.': path_elements = path_elements[2:] else: path_elements = path_elements[1:] dest_dll_dir = dest_dir for dir_name in path_elements[:-1]: dest_dll_dir = os.path.join(dest_dll_dir, dir_name) mkdir(dest_dll_dir) file_copy(os.path.join(src_bin_dir, dll_name), os.path.join(dest_dll_dir, dll_name)) have_dlls.add(dep.name[8:]) # Copy required import libraries only. copied_files = set() src_lib_dir = os.path.join(src_dir, 'lib') mkdir(dest_lib_dir) for ignore, libs in macros: use = False for lib in libs: if lib in have_dlls: use = True break if use and lib not in copied_files: copied_files.add(lib) lib_name = 'lib%s.dll.a' % lib src_lib_path = os.path.join(src_lib_dir, lib_name) if not os.path.exists(src_lib_path): print "Missing import library %s" % lib_name return 1 file_copy(src_lib_path, os.path.join(dest_lib_dir, lib_name)) # Copy required header directories only. copied_dirs = set() for header_dirs, libs in macros: use = False for lib in libs: if lib in have_dlls: use = True break if use: for header_dir in header_dirs: path_elements = header_dir.split('/') if path_elements[0] == '.': path_elements = path_elements[2:] else: path_elements = path_elements[1:] src_header_dir = os.path.join(src_dir, *path_elements) if not os.path.exists(src_header_dir): print "Missing include directory %s" % src_header_dir return 1 dest_header_dir = dest_dir for dir_name in path_elements: dest_header_dir = os.path.join(dest_header_dir, dir_name) mkdir(dest_header_dir) if not src_header_dir in copied_dirs: copy_dir(src_header_dir, dest_header_dir) copied_dirs.add(src_header_dir) # msvcr71.dll linking support. src_msvcr71_dir = os.path.join(src_dir, 'lib', 'msvcr71') dest_msvcr71_dir = os.path.join(dest_dir, 'lib', 'msvcr71') copy_dir(src_msvcr71_dir, dest_msvcr71_dir) # Def file bat. make_defs = open(os.path.join(dest_lib_dir, 'MakeDefs.bat'), 'w') try: make_defs.write('@echo off\n' 'rem Make .def files needed for .lib file creation.\n' 'rem Requires pexports.exe on the search path\n' 'rem (found in altbinutils-pe as SourceForge,\n' 'rem http://sourceforge.net/projects/mingwrep/).\n\n') for dep in deps: dll_name = os.path.split(dep.library_dirs[0])[1] lib = dep.name[8:] lib_name = 'lib%s.dll.a' % lib if os.path.exists(os.path.join(dest_lib_dir, lib_name)): start = '' else: start = 'rem ' make_defs.write('%spexports %s >%s.def\n' % (start, dll_name, lib)) finally: make_defs.close() # Lib import files bat. make_libs = open(os.path.join(dest_lib_dir, 'MakeLibs.bat'), 'w') try: make_libs.write('@echo off\n' 'rem Make .lib import libraries.\n' 'rem Requires Visual C++ Studio or Toolkit.\n' 'rem VCVARS32.BAT (VCVARS64.BAT (?) for 64 bit build)\n' 'rem must be run first to use LIB.EXE.\n\n') for dep in deps: dll_name = os.path.split(dep.library_dirs[0])[1] lib = dep.name[8:] lib_name = 'lib%s.dll.a' % lib if os.path.exists(os.path.join(dest_lib_dir, lib_name)): start = '' else: start = 'rem ' make_libs.write('%sLIB.EXE /NOLOGO /DEF:%s.def /MACHINE:IX86 /OUT:%s.lib\n' % (start, lib, lib)) finally: make_libs.close() # Top level make batch file for 32 bit build. file_copy(os.path.join(prebuilt_template, 'Make32.bat'), dest_lib_dir) return 0
config.main() print('\nContinuing With "setup.py"') try: s_mtime = os.stat("Setup")[stat.ST_MTIME] sin_mtime = os.stat("Setup.in")[stat.ST_MTIME] if sin_mtime > s_mtime: print('\n\nWARNING, "Setup.in" newer than "Setup",' 'you might need to modify "Setup".') except: pass # get compile info for all extensions try: extensions = read_setup_file("Setup") except: print( """Error with the "Setup" file, perhaps make a clean copy from "Setup.in".""" ) raise # decide whether or not to enable new buffer protocol support enable_newbuf = False if sys.version_info >= (2, 6, 0): try: sys.pypy_version_info except AttributeError: enable_newbuf = True