Example #1
0
def get_dllexports(dll):
	""" Get exports of DLL. """
	dll2def = os.path.join(env.bin_dir, 'dll2def.exe')
	if not os.path.isfile(dll2def):
		build_script = os.path.join(env.src_dir, 'dll2def', 'build.bat')
		try:
			subproc.check_call([ build_script ], stderr=subproc.VOID, stdout=subproc.VOID, stdin=subproc.VOID)
		except subproc.CalledProcessError:
			import traceback
			traceback.print_exc()
			fatal_message(
				'Failed to build dll2def',
				''.join((
					'There was an error while trying to build dll2def. To resolve this issue, you ',
					'may want to check the following files to make sure they are correct:\n\n',
					'  /repository/util/src/dll2def/build.bat\n'
					'  /repository/util/bin/msvcc.bat\n'
					'  /repository/util/bin/_buildenv.bat\n\n'
					'If you continue having issue, please report this error at this project\'s GitHub. ',
					'(https://github.com/Juntalis/dypywin32)'
				))
			)
	return split_lines_clean(subproc.check_output(
		[ dll2def, env.data_file(dll) ], stderr=subproc.VOID
	))
Example #2
0
def preprocess_sources(*srcs):
	""" Preprocess python.c, filter out the crap, clean it up, and
	    get the result as a string. """
	args = [ os.path.join(env.bin_dir, 'msvcpp.bat')] + \
		   [ '-I%s' % env.root_file('include') ] + \
		   [ env.data_file(s) for s in srcs ]
	print ' '.join(args)
	try:
		processed = subproc.check_output(args, stderr=subproc.VOID)
	except subproc.CalledProcessError:
		print 'Command Args:', args
		raise

	processed_parts = processed.split('void landmark();')
	if len(processed_parts) == 1:
		raise Exception('Could not find our landmark in pyport.h')

	filtered = '\n'.join(filter(
		lambda l: not l.startswith('#pragma') and len(l) > 0,
		split_lines_trim(processed_parts[1])
	))

	# Some formatting issues.
	filtered = re.sub(
		r"(?m)PythonDynLoad_(\w+)\s*\(([^)]+)\)\s*([^\s])",
		r"PythonDynLoad_\1(\2) \3",
		re.sub(
			r"(?m)\r?\n\)", ")",
			re.sub("(?m)([^;\r{])\r?\n", r"\1 ", filtered)
		)
	)

	# Compress structs, etc down to a single line.
	filtered = re.sub(
		r"(?sm)\{[\t ]*\r?\n(.+?)\r?\n\}",
		linearize_struct,
		re.sub(
			r"(?m)\{\s*\r?\n([^{}]+?)\}",
			linearize_struct,
			filtered
		)
	)

	# Filter out extra spaces.
	return condense_space(filtered)