Example #1
0
File: dfs.py Project: vdorr/bloced
	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)))
Example #2
0
def main() :
	started = time.time()

	files = get_files("./examples")
#	print here(), files

	main_lib = core.create_block_factory(scan_dir=os.path.join(os.getcwd(), "library"))

#	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()

	failed = []
	succeeded = []

	for fname in files :

		print here(), "loading:", fname

		local_lib = core.BasicBlocksFactory(load_basic_blocks=False)

		try :
			local_lib.load_standalone_workbench_lib(fname, "<local>")
		except Exception :
			print(here())
			traceback.print_exc()
			failed.append((fname, "loading_as_library"))
			continue

		library = core.SuperLibrary([main_lib, local_lib])

		w = dfs.Workbench(passive=True)

		try :
			with open(fname, "rb") as f :
				serializer.unpickle_workbench(f, w, use_cached_proto=False, library=library)
		except Exception :
			print(here())
			traceback.print_exc()
			failed.append((fname, "loading_worbench"))
			continue

		sheets = w.sheets
		global_meta = w.get_meta()

		out_fobj = StringIO()

		try :
			libs_used, = implement.implement_workbench(w, sheets, global_meta,
				ccodegen, core.KNOWN_TYPES, library, out_fobj)#sys.stdout)
		except Exception :
			print(here())
			traceback.print_exc()
			failed.append((fname, "implementing"))
			continue

		if out_fobj.tell() < 1 :
			print(here())
			failed.append((fname, "no_code_generated"))
			continue

		source = out_fobj.getvalue()

		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()
		blob_stream = StringIO()
		term_stream = StringIO()

		board_type = w.get_board()

		try :
			board_info = build.get_board_types()[board_type]
			variant = board_info["build.variant"] if "build.variant" in board_info else "standard" 
		except Exception :
			print(here())
			traceback.print_exc()
			failed.append((fname, "get_target_info"))
			continue


		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 :
			print(here())
			failed.append((fname, "build_failed"))
			continue



		succeeded.append((fname, ))

	finished = time.time()


	assert(len(failed) + len(succeeded) == len(files))

	print("")
	print("done in {:.3}s, {} of {} failed".format(finished - started, len(failed), len(files)))
	print("")
	print("failed files:")
	pprint(failed)
Example #3
0
        sheets = w.sheets
        global_meta = w.get_meta()
    else:
        blockfactory = create_block_factory(
            scan_dir=os.path.join(os.getcwd(), "library"))
        try:
            with open(fname, "rb") as f:
                model = unpickle_dfs_model(f, lib=blockfactory)
        except:
            print("error loading sheet file")
            exit(666)
        sheets = {"tsk": model}
        global_meta = {}

    out_fobj = StringIO()
    implement_workbench(sheets, global_meta, ccodegen, KNOWN_TYPES,
                        blockfactory, out_fobj)

    source = out_fobj.getvalue()
    print source

    blob_stream = StringIO()
    rc, = build.build_source(
        w.get_board(),
        source,
        aux_src_dirs=[
            ("/usr/share/arduino/hardware/arduino/cores/arduino", False),
            (os.path.join(os.getcwd(), "library", "arduino"), False)
        ],  #TODO derive from libraries used
        boards_txt=build.BOARDS_TXT,
        #		board_db={},
        ignore_file=None,  #"amkignore",
Example #4
0
		sheets = w.sheets
		global_meta = w.get_meta()
	else :
		blockfactory = create_block_factory(
				scan_dir=os.path.join(os.getcwd(), "library"))
		try :
			with open(fname, "rb") as f :
				model = unpickle_dfs_model(f, lib=blockfactory)
		except :
			print("error loading sheet file")
			exit(666)
		sheets = { "tsk" : model }
		global_meta = {}

	out_fobj = StringIO()
	implement_workbench(sheets, global_meta,
		ccodegen, KNOWN_TYPES, blockfactory, out_fobj)

	source = out_fobj.getvalue()
	print source

	blob_stream = StringIO()
	rc, = build.build_source(w.get_board(), source,
		aux_src_dirs=[
			("/usr/share/arduino/hardware/arduino/cores/arduino", False),
			(os.path.join(os.getcwd(), "library", "arduino"), False)
		],#TODO derive from libraries used
		boards_txt=build.BOARDS_TXT,
#		board_db={},
		ignore_file=None,#"amkignore",
		ignore_lines=[ "*.cpp", "*.hpp" ], #TODO remove this filter with adding cpp support to build.py
#		prog_port=None,