Пример #1
0
def load_workbench_library(lib_name, file_path, library=None, w_data=None) :
	"""
	lib_name - full library name, example 'logic.flipflops'
	"""
	if file_path is None :
		data = w_data
	else :
		with open(file_path, "rb") as f :
			data = serializer.unpickle_workbench_data(f)
	w = dfs.Workbench(
#		lib_dir=os.path.join(os.getcwd(), "library"),
		blockfactory=library,
		passive=True,
		do_create_block_factory=False)
	serializer.restore_workbench(data, w, library=library)
	return load_blocks_from_workbench(w, lib_name)
Пример #2
0
	def build_job(self, board_type, sheets, meta) :

		if board_type is None :
			self.__messages.put(("status", (("build", False, "board_type_not_set"), {})))
			return None

		board_info = build.get_board_types()[board_type]
		variant = board_info["build.variant"] if "build.variant" in board_info else "standard" 

		self.__messages.put(("status", (("build", True, "build_started"), {})))

		w_data = serializer.get_workbench_data(self)#TODO refac build invocation

		out_fobj = StringIO()
		try :
			w = Workbench(passive=True, do_create_block_factory=False,
				blockfactory=self.blockfactory)
			local_lib = core.BasicBlocksFactory(load_basic_blocks=False)
			local_lib.load_standalone_workbench_lib(None, "<local>",
				library=w.blockfactory,
				w_data=w_data)
			library = core.SuperLibrary([w.blockfactory, local_lib])
			serializer.restore_workbench(w_data, w,
				use_cached_proto=False,
				library=library)
			libs_used, = implement.implement_workbench(w, w.sheets, w.get_meta(),
				ccodegen, core.KNOWN_TYPES, library, out_fobj)
		except Exception as e:
			print(here(), traceback.format_exc())
			self.__messages.put(("status", (("build", False, str(e)), {})))
			return None

		if out_fobj.tell() < 1 :
			self.__messages.put(("status", (("build", False, "no_code_generated"), {})))
			return None

		source = out_fobj.getvalue()
		print(source)

		all_in_one_arduino_dir = self.config.get("Path", "all_in_one_arduino_dir")
		libc_dir, tools_dir, boards_txt, target_files_dir = build.get_avr_arduino_paths(
			all_in_one_arduino_dir=all_in_one_arduino_dir)

		source_dirs = set()
		for l in library.libs :
			if l.name in libs_used :
				for src_file in l.source_files :
					source_dirs.add(os.path.dirname(src_file))

		install_path = os.getcwd()#XXX replace os.getcwd() with path to dir with executable file
		blob_stream = StringIO()

#		term_stream = StringIO()
#		term_stream = sys.stdout
		term_stream = Workbench.TermStream(self.__messages)


		try :
			rc, = build.build_source(board_type, source,
				aux_src_dirs=(
					(os.path.join(target_files_dir, "cores", "arduino"), False),
					(os.path.join(target_files_dir, "variants", variant), False),
	#				(os.path.join(install_path, "library", "arduino"), False),
				) + tuple( (path, True) for path in source_dirs ),#TODO derive from libraries used
				aux_idirs=[ os.path.join(install_path, "target", "arduino", "include") ],
				boards_txt=boards_txt,
				libc_dir=libc_dir,
	#			board_db={},
				ignore_file=None,#"amkignore",
	#			ignore_lines=( "*.cpp", "*.hpp", "*" + os.path.sep + "main.cpp", ), #TODO remove this filter with adding cpp support to build.py
				ignore_lines=( "*" + os.path.sep + "main.cpp", ),
	#			prog_port=None,
	#			prog_driver="avrdude", # or "dfu-programmer"
	#			prog_adapter="arduino", #None for dfu-programmer
				optimization="-Os",
				verbose=False,
				skip_programming=True,#False,
	#			dry_run=False,
				blob_stream=blob_stream,
				term=term_stream)
		except Exception as e :
			self.__messages.put(("status", (("build", False, "compilation_failed"), {"term_stream":str(e)})))
			return None

		msg_info = {}
#		if term_stream != sys.stdout :
#			msg_info["term_stream"] = term_stream

		if rc :
			self.__blob = blob_stream.getvalue()
			self.__blob_time = time.time()
		else :
			self.__messages.put(("status", (("build", False, "compilation_failed"), msg_info)))
			return None
#			return (False, "build_failed")

		self.__messages.put(("status", (("build", True, ""), msg_info)))