Esempio n. 1
0
def supports_build_architecture(compiler, language, architecture):
	# "gcc -dumpmachine" yields the target triplet
	# use that to determine if we can build it.
	executor = Executor()

	commandline = "%s -dumpmachine" % (compiler.get_command())

	success, output = executor.execute(
		commandline=commandline, 
		log_output=False, 
		log_errors=True
	)
	if success:
		pieces = output.split("-")

		# may explicitly support the requested architecture
		if (architecture in pieces[0]):
			return True

		# or the supported architecture may be a subset of the requested
		# in the case of arm
		if "arm" in architecture and "arm" in pieces[0]:
			# see if the code will compile for this architecture
			return compiler.check_source_compiles("int main() { return 0; }",
							cflags=["-marm", "-march=%s" % architecture])

		if any(['i686' in pieces[0], 'i386' in pieces[0]]) and architecture == Architecture.x86:
			return compiler.check_source_compiles("int main() { return 0; }", cflags=['-m32'])

	return False
Esempio n. 2
0
	def post_load_driver_schema(self, driver_schema):
		commandline = "%s -dumpmachine" % (self.compiler.get_command())
		executor = Executor()
		result, output = executor.execute(commandline=commandline, log_output=False, log_errors=False, fail_on_error=False)

		if result and output:
			self.machine_triplet = output.strip()
Esempio n. 3
0
	def get_compiler_version(self):
		if self.version_string:
			return self.version_string

		# the best we can do is try to find the MSVC compiler version with this regex.
		version_pattern = re.compile("Compiler Version ((\d+)\..*) for")

		executor = Executor()
		result, output = executor.execute(
			commandline=self.get_command(),
			fail_on_error=False,
			log_output=False,
			log_errors=False
		)

		if result:
			match = re.search(version_pattern, output)
			if not match:
				raise Exception("Unable to find Compiler Version!")
			self.version_string = match.groups()[0]
		else:
			logging.warn(
				"\"%s\" not found. Make sure you're using a Visual Studio Command Prompt!" % self.get_command()
				)
			raise Exception("Compiler \"%s\" not found!" % self.get_command())
Esempio n. 4
0
def get_compiler_version(command):
	executor = Executor()
	commandline = "%s -v" % command
	result, output = executor.execute(commandline, fail_on_error=False, log_output=False, log_errors=False)
	if result and output:
		version_regex = re.compile(" version ((\d\.\d)(\.\d)?)")
		match = version_regex.search(output)
		if match:
			return match.groups(0)[0]

	return ""
Esempio n. 5
0
def get_current_xcode_root():
	executor = Executor()
	command = "xcode-select --print-path"
	result, output = executor.execute(
		commandline=command,
		fail_on_error=True,
		log_output=False,
		log_errors=False
	)	

	if not result:
		raise Exception("Error retrieving current Xcode path!")

	# e.g. /Applications/Xcode.app/Contents/Developer
	return output.strip()
Esempio n. 6
0
	def find_package(self, name, **kwargs):
		# TODO: check different package managers
		# assume debian for now (testing)

		debian = "dpkg -s %(package_name)s"

		package_managers = {
			"debian" : debian
		}

		package_manager = "debian"


		data = {
			"package_name": name
		}
		command = package_managers[package_manager] % data


		executor = Executor()

		result, output = executor.execute(commandline=command, fail_on_error=False, log_output=False, log_errors=False)
		return result
Esempio n. 7
0
def check_source_runs(compiler, source, **kwargs):
	cflags = kwargs.get("cflags", [])
	linkflags = kwargs.get("linkflags", [])

	executor = Executor()

	try:
		# generate a temporary output name
		output = (("./%024x" % uuid.uuid4().int)[:24])
		output = os.path.normpath(os.path.abspath(os.path.join(os.getcwd(), output)))

		# 1. See if this builds (compiles and links)
		result = compiler.check_source_compiles(source, cflags=cflags, linkflags=linkflags, output=output)
		if not result:
			logging.warn("check_source_runs: source failed to compile!")
			return False

		# 2. See if this actually executes
		result = executor.execute(
			commandline=output, 
			fail_on_error=False,
			log_output=False,
			log_errors=False
		)[0]

	finally:
		# 3. Remove the output file.
		if output:
			if os.path.exists(output):
				os.unlink(output)
			else:
				raise Exception("output not found: %s" % output)
		else:
			logging.info("no valid output")
			raise Exception("no valid output")

	return result
Esempio n. 8
0
 def check_source_compiles(self, source, **kwargs):
     executor = Executor()
     commandline = get_compile_commandline(self.get_command(), **kwargs)
     return executor.execute(
         commandline=commandline, fail_on_error=False, pipe_input=source, log_output=False, log_errors=False
     )[0]
Esempio n. 9
0
def cache_sdk_paths(target, platform_name):
	executor = Executor()
	command = "xcode-select --print-path"
	result, output = executor.execute(
		commandline=command,
		fail_on_error=True,
		log_output=False,
		log_errors=False
	)

	if result:

		target.library_search_paths = {}
		target.include_search_paths = {}
		target.framework_search_paths = {}

		target.xcode_developer_path = output.strip()
		#logging.info("xcode_path = %s" % target.xcode_developer_path)


		# check platform path exists
		platform_path = os.path.join(
			target.xcode_developer_path,
			"Platforms",
			("%s.platform" % platform_name)
		)
		#logging.info("platform_path: %s" % platform_path)
		platform_path_exists = os.path.isdir(platform_path)
		#logging.info("platform_path_exists: %s" % platform_path_exists)



		# check the compiler path in the Toolchain
		toolchain_path = os.path.join(
			target.xcode_developer_path,
			"Toolchains",
			"XcodeDefault.xctoolchain"
		)
		if not os.path.isdir(toolchain_path):
			raise Exception("Unable to find XcodeDefault.xctoolchain path!")

		compiler_sysroot = os.path.join(
			toolchain_path,
			"usr",
			"lib",
			"clang",
			target.compiler.get_version()
		)
		if not os.path.isdir(compiler_sysroot):
			raise Exception("Unable to find compiler sysroot path: \"%s\"" % compiler_sysroot)

		compiler_include = os.path.join(compiler_sysroot, "include")
		if not os.path.isdir(compiler_include):
			raise Exception("Unable to find compiler include path: \"%s\"" % compiler_include)

		target.compiler_includes = [
			compiler_include
		]

		# Gather SDK paths
		# Also search the SDK paths and organize them in a dict.
		sdks_path = os.path.join(
			platform_path,
			"Developer",
			"SDKs"
		)

		if not os.path.isdir(sdks_path):
			raise Exception("sdks_path: \"%s\", does not exist!" % sdks_path)

		# For each SDK we find...
		for sdk in os.listdir(sdks_path):
			canonical_name = sdk.strip(".sdk").lower()

			include_paths = target.include_search_paths[canonical_name] = []
			lib_paths = target.library_search_paths[canonical_name] = []
			framework_paths = target.framework_search_paths[canonical_name] = []

			sdk_root = os.path.join(sdks_path, sdk)
			if not os.path.isdir(sdk_root):
				raise Exception("Directory not found: \"%s\"" % sdk_root)
			logging.info("sdk_root: %s" % sdk_root)

			include_path = os.path.join(sdk_root, "usr", "include")
			if not os.path.isdir(include_path):
				raise Exception("Directory not found: \"%s\"" % include_path)
			#logging.info("include: %s" % include_path)
			include_paths.append(include_path)

			lib_path = os.path.join(sdk_root, "usr", "lib")
			if not os.path.isdir(lib_path):
				raise Exception("Directory not found: \"%s\"" % lib_path)
			#logging.info("lib: %s" % lib_path)
			lib_paths.append(lib_path)

			frameworks_path = os.path.join(
				sdk_root,
				"System",
				"Library",
				"Frameworks"
			)
			if not os.path.isdir(frameworks_path):
				raise Exception("Directory not found: \"%s\"" % frameworks_path)
			#logging.info("frameworks: %s" % frameworks_path)
			framework_paths.append(frameworks_path)