示例#1
0
def compileObjects(objects, flags, objout, output):
	status = True
	sout = ""
	b = board.Board()
	for i in objects:
		compline = [j for j in flags]
		compline.append("-mmcu="+b.getBoardMCU(b.getBoard()))
		compline.append("-DF_CPU="+b.getBoardFCPU(b.getBoard()))
		compline.extend(misc.getArduinoIncludes())
		if misc.getArduinoVersion() >= 100:
			try:
				compline.append("-DUSB_VID="+b.getBoardUSBVID(b.getBoard()))
				compline.append("-DUSB_PID="+b.getBoardUSBPID(b.getBoard()))
			except: pass
		if misc.getArduinoVersion() >= 100:
			compline.append("-DARDUINO=100")
		compline.append(os.path.join(misc.getArduinoPath(), i))
		compline.append("-o"+objout+"/"+i+".o")
		misc.printMessageLn(output, ' '.join(compline))
		misc.printLogMessageLn(' '.join(compline))
		try:
			(status, sout) = misc.runProg(compline)
			misc.printLogMessageLn(sout)
			misc.printMessageLn(output, sout)
		except:
			return (status, sout)
	return (True, "")
示例#2
0
def compileObjects(objects, flags, objout, output):
	status = True
	sout = ""
	b = board.Board()
	for i in objects:
		compline = [j for j in flags]
		compline.append("-mmcu="+b.getBoardMCU(b.getBoard()))
		compline.append("-DF_CPU="+b.getBoardFCPU(b.getBoard()))
		compline.extend(misc.getArduinoIncludes())
		if misc.getArduinoVersion() >= 100:
			try:
				compline.append("-DUSB_VID="+b.getBoardUSBVID(b.getBoard()))
				compline.append("-DUSB_PID="+b.getBoardUSBPID(b.getBoard()))
			except: pass
		if misc.getArduinoVersion() >= 100:
			compline.append("-DARDUINO=100")
		compline.append(os.path.join(misc.getArduinoPath(), i))
		compline.append("-o"+objout+"/"+i+".o")
		misc.printMessageLn(output, ' '.join(compline))
		misc.printLogMessageLn(' '.join(compline))
		try:
			(status, sout) = misc.runProg(compline)
			misc.printLogMessageLn(sout)
			misc.printMessageLn(output, sout)
		except:
			return (status, sout)
	return (True, "")
示例#3
0
def validateLib(library, tempobj, flags, output, notify):
	"""compile library also try to compile every cpp under libdir"""
	"""also try to compile utility dir if present"""
	paths = ["", misc.getArduinoLibsPath()]
	if config.user_library != None and config.user_library != -1:
		paths.extend(i.strip() for i in config.user_library.split(';'))
	dirs = ["", "utility"]
	b = board.Board()
	res = []
	fl = []
	for d in dirs:
		for q in paths:
			fl = os.path.join(q, library, d)
			"""test the path directly, in case include was specified to the library directory"""
			if fl not in set(queue) and not os.path.exists(fl):
				fl = os.path.join(q, d)
			if fl not in set(queue) and os.path.exists(fl):
				queue.append(fl)
				try:
					for i in glob.glob(os.path.join(fl, "*.c")):
						"""compile library c modules"""
						compline = [j for j in defc]
						compline.append("-mmcu="+b.getBoardMCU(b.getBoard()))
						compline.append("-DF_CPU="+b.getBoardFCPU(b.getBoard()))
						if misc.getArduinoVersion() >= 100:
							compline.append("-DARDUINO=100")
						compline.extend(misc.getArduinoIncludes())
						compline.append("-I" + os.path.join(misc.getArduinoLibsPath(), library, "utility"))
						compline.extend(preproc.generateCFlags(id, open(i).read()))
						compline.extend(flags)
						compline.append(i)
						compline.append("-o"+os.path.join(os.path.dirname(tempobj), \
							os.path.basename(i.replace(".c", ".o"))))
						misc.printLogMessageLn(' '.join(compline))
						(run, sout) = misc.runProg(compline)
						misc.printLogMessageLn(sout)
						if run == False:
							misc.printErrorLn(notify, output, _("Library Error"), sout)
							raise NameError('libs compile error')
						res.append(os.path.join(os.path.dirname(tempobj), \
							os.path.basename(i.replace(".c", ".o"))))
				except StandardError as e:
					print "Error: %s" % e
				try:
					for i in glob.glob(os.path.join(fl, "*.cpp")):
						"""compile library cpp modules"""
						compline = [j for j in defcpp]
						compline.append("-mmcu="+b.getBoardMCU(b.getBoard()))
						compline.append("-DF_CPU="+b.getBoardFCPU(b.getBoard()))
						if misc.getArduinoVersion() >= 100:
							compline.append("-DARDUINO=100")
						compline.extend(misc.getArduinoIncludes())
						compline.extend(preproc.generateCFlags(id, open(i).read()))
						compline.extend(flags)
						compline.append(i)
						compline.append("-I" + os.path.join(misc.getArduinoLibsPath(), library, "utility"))
						compline.append("-o"+os.path.join(os.path.dirname(tempobj), \
							os.path.basename(i.replace(".cpp", ".o"))))
						misc.printLogMessageLn(' '.join(compline))
						(run, sout) = misc.runProg(compline)
						misc.printLogMessageLn(sout)
						if run == False:
							misc.printErrorLn(notify, output, _("Library Error"), sout)
							raise NameError('libs compile error')
						res.append(os.path.join(os.path.dirname(tempobj), \
							os.path.basename(i.replace(".cpp", ".o"))))
				except StandardError as e:
					print "Error: %s" % e
	return list(set(res))
示例#4
0
def compile(tw, sourcefile, id, output, notify):
	buf =  tw.get_buffer()
	cont = buf.get_text(buf.get_start_iter(), buf.get_end_iter())
	if cont is "": return -1
	context = notify.get_context_id("main")
	notify.pop(context)
	notify.push(context, _("Compiling..."))
	misc.printMessageLn(output, 'Compile start')
	misc.printLogMessageLn('Compile start')
	misc.clearConsole(output)
	tmpdir = id
	tempobj = tempfile.mktemp("", "Tempobj", id)
	global p
	global queue
	queue = []
	p = prefs.preferences()
	b = board.Board()
	#compile inter c objects
	try:
		"""preproces pde"""
		(pre_file, lines) = preproc.addHeaders(id, buf)
		"""compile C targets"""
		misc.printLogMessageLn('processing C targets')
		(run, sout) = compileObjects(cobj, defc, id, output)
		if run == False:
			misc.printErrorLn(notify, output, _("Compile Error"), stripOut(sout, pre_file))
			raise NameError("compile error")
		"""deprecated C targets (pre 1.0)"""
		if misc.getArduinoVersion() < 100:
			(run, sout) = compileObjects(cobj_deprecated, defc, id, output)
			if run == False:
				misc.printErrorLn(notify, output, _("Compile Error"), stripOut(sout, pre_file))
				raise NameError("compile error")
		"""compile C++ targets"""
		misc.printLogMessageLn('processing C++ targets')
		(run, sout) = compileObjects(cppobj, defcpp, id, output)
		if run == False:
			misc.printErrorLn(notify, output, _("Compile Error"), sout)
			raise NameError("compile error")
		"""compile C++ additional (1.0) targets"""
		if misc.getArduinoVersion() >= 100:
			misc.printLogMessageLn('processing C++ additional targets')
			(run, sout) = compileObjects(cppobj_additional, defcpp, id, output)
			if run == False:
				misc.printErrorLn(notify, output, _("Compile Error"), sout)
				raise NameError("compile error")
		"""generate archive objects"""
		misc.printLogMessageLn('generating ar objects')
		objects = cobj + cppobj
		if misc.getArduinoVersion() >= 100:
			objects += cppobj_additional
		else:
			objects += cobj_deprecated
		for i in objects:
			compline = [j for j in defar]
			compline.append(id+"/core.a")
			compline.append(id+"/"+i+".o")
			misc.printMessageLn(output, ' '.join(compline)+"\n")
			misc.printLogMessageLn(' '.join(compline))
			(run, sout) = misc.runProg(compline)
			misc.printLogMessageLn(sout)
			if run == False:
				misc.printErrorLn(notify, output, _("Compile Error"), stripOut(sout, pre_file))
				raise NameError("compile error")
			else:
				misc.printMessageLn(output, sout)
		"""precompile pde"""
		misc.printLogMessageLn('pde compile')
		misc.printLogMessageLn('-----------')
		compline=[j for j in defcpp]
		compline.append("-mmcu="+b.getBoardMCU(b.getBoard()))
		compline.append("-DF_CPU="+b.getBoardFCPU(b.getBoard()))
		if misc.getArduinoVersion() >= 100:
			compline.append("-DARDUINO=100")
		compline.extend(misc.getArduinoIncludes())
		flags = []
		flags = preproc.generateCFlags(id, cont)
		compline.extend(flags)
		compline.extend(["-I" + os.path.join(i, "utility") for i in preproc.generateLibs(id, buf)])
		compline.extend(misc.getArduinoIncludes())
		compline.append(pre_file)
		compline.append("-o"+pre_file+".o")
		compline.append("-I"+os.path.dirname(sourcefile))
		misc.printMessageLn(output, ' '.join(compline)+"\n")
		misc.printLogMessageLn(' '.join(compline))
		(run, sout) = misc.runProg(compline)
		misc.printLogMessageLn(sout)
		if run == False:
			misc.printErrorLn(notify, output, _("Compile Error"), stripOut(sout, pre_file))
			moveCursor(tw, int(getErrorLine(sout, lines)))
			raise NameError('compile-error')
		else:
			misc.printMessageLn(output, sout)

		"""compile all objects"""
		misc.printLogMessageLn('compile objects')
		misc.printLogMessageLn('---------------')
		compline = [i for i in link]
		compline.append("-mmcu="+b.getBoardMCU(b.getBoard()))
		compline.append("-o"+tempobj+".elf")
		compline.append(pre_file+".o")
		tmplibs = []
		for i in preproc.generateLibs(id, buf):
			tmplibs.extend(validateLib(os.path.basename(i), tempobj, flags, output, notify))
		compline.extend(list(set(tmplibs)))
		compline.extend(["-I" + i for i in preproc.generateLibs(id, buf)])
		compline.extend(["-I" + os.path.join(i, "utility") for i in preproc.generateLibs(id, buf)])
		if misc.getArduinoVersion() >= 100:
			compline.append("-DARDUINO=100")
		compline.extend(misc.getArduinoIncludes())
		compline.append(id+"/core.a")
		compline.append("-L"+id)
		compline.append("-lm")
		misc.printMessageLn(output, ' '.join(compline)+"\n")
		misc.printLogMessageLn(' '.join(compline))
		(run, sout) = misc.runProg(compline)
		misc.printLogMessageLn(sout)
		if run == False:
			misc.printErrorLn(notify, output, _("Linking error"), stripOut(sout, pre_file))
			raise NameError('linking-error')
		else:
			misc.printMessageLn(output, sout)
		compline=[i for i in eep]
		compline.append(tempobj+".elf")
		compline.append(tempobj+".eep")
		misc.printMessageLn(output, ' '.join(compline)+"\n")
		misc.printLogMessageLn(' '.join(compline))
		(run, sout) = misc.runProg(compline)
		misc.printLogMessageLn(sout)
		if run == False:
			misc.printErrorLn(notify, output, _("Object error"), stripOut(sout, pre_file))
			raise NameError('obj-copy')
		else:
			misc.printMessageLn(output, sout)
		compline=[i for i in hex]
		compline.append(tempobj+".elf")
		compline.append(tempobj+".hex")
		misc.printMessageLn(output, ' '.join(compline)+"\n")
		misc.printLogMessageLn(' '.join(compline))
		(run, sout) = misc.runProg(compline)
		misc.printMessageLn(output, sout)
		misc.printLogMessageLn(sout)
		if run == False:
			misc.printErrorLn(notify, output, _("Object error"), stripOut(sout, pre_file))
			raise NameError('obj-copy')
		else:
			misc.printMessageLn(output, sout)
		size = computeSize(tempobj+".hex")
		notify.pop(context)
		notify.push(context, _("Done compiling."))
		misc.printLogMessageLn("compile done.")

		misc.printMessageLn(output, \
			_("Binary sketch size: %s bytes (of a %s bytes maximum)\n") % (size, b.getBoardMemory(b.getBoard())), 'true')
	except StandardError as e:
		print "Error: %s" % e
		return -1
	except Exception as e:
		print "Error compiling. Op aborted!"
		print "Error: %s" % e
		return -1
	return tempobj
示例#5
0
def validateLib(library, tempobj, flags, output, notify):
	"""compile library also try to compile every cpp under libdir"""
	"""also try to compile utility dir if present"""
	paths = ["", misc.getArduinoLibsPath(), misc.getLocalPath()]
	if config.user_library != None and config.user_library != -1:
		paths.extend(i.strip() for i in config.user_library.split(';'))
	if config.sketchFile:
		paths.append(os.path.dirname(config.sketchFile))
		paths.append(os.path.abspath(os.path.join(os.path.dirname(config.sketchFile), "..")))
	dirs = ["", "utility"]
	b = board.Board()
	res = []
	fl = []
	for d in dirs:
		for q in paths:
			fl = os.path.join(q, library, d)
			"""test the path directly, in case include was specified to the library directory"""
			if fl not in set(queue) and not os.path.exists(fl):
				fl = os.path.join(q, d)
			if fl not in set(queue) and os.path.exists(fl):
				queue.append(fl)
				try:
					for i in glob.glob(os.path.join(fl, "*.c")):
						"""compile library c modules"""
						compline = [j for j in defc]
						compline.append("-mmcu="+b.getBoardMCU(b.getBoard()))
						compline.append("-DF_CPU="+b.getBoardFCPU(b.getBoard()))
						if misc.getArduinoVersion() >= 100:
							compline.append("-DARDUINO=100")
						compline.extend(misc.getArduinoIncludes())
						compline.append("-I" + os.path.join(misc.getArduinoLibsPath(), library, "utility"))
						compline.extend(preproc.generateCFlags(id, open(i).read()))
						compline.extend(flags)
						compline.append(i)
						compline.append("-o"+os.path.join(os.path.dirname(tempobj), \
							os.path.basename(i.replace(".c", ".o"))))
						misc.printLogMessageLn(' '.join(compline))
						(run, sout) = misc.runProg(compline)
						misc.printLogMessageLn(sout)
						if run == False:
							misc.printErrorLn(notify, output, _("Library Error"), sout)
							raise NameError('libs compile error')
						res.append(os.path.join(os.path.dirname(tempobj), \
							os.path.basename(i.replace(".c", ".o"))))
				except StandardError as e:
					print "Error: %s" % e
				try:
					for i in glob.glob(os.path.join(fl, "*.cpp")):
						"""compile library cpp modules"""
						compline = [j for j in defcpp]
						compline.append("-mmcu="+b.getBoardMCU(b.getBoard()))
						compline.append("-DF_CPU="+b.getBoardFCPU(b.getBoard()))
						if misc.getArduinoVersion() >= 100:
							compline.append("-DARDUINO=100")
						compline.extend(misc.getArduinoIncludes())
						compline.extend(preproc.generateCFlags(id, open(i).read()))
						compline.extend(flags)
						compline.append(i)
						compline.append("-I" + os.path.join(misc.getArduinoLibsPath(), library, "utility"))
						compline.append("-o"+os.path.join(os.path.dirname(tempobj), \
							os.path.basename(i.replace(".cpp", ".o"))))
						misc.printLogMessageLn(' '.join(compline))
						(run, sout) = misc.runProg(compline)
						misc.printLogMessageLn(sout)
						if run == False:
							misc.printErrorLn(notify, output, _("Library Error"), sout)
							raise NameError('libs compile error')
						res.append(os.path.join(os.path.dirname(tempobj), \
							os.path.basename(i.replace(".cpp", ".o"))))
				except StandardError as e:
					print "Error: %s" % e
	return list(set(res))
示例#6
0
def compile(tw, id, output, notify):
	buf =  tw.get_buffer()
	cont = buf.get_text(buf.get_start_iter(), buf.get_end_iter())
	if cont is "": return -1
	context = notify.get_context_id("main")
	notify.pop(context)
	notify.push(context, _("Compiling..."))
	misc.printMessageLn(output, 'Compile start')
	misc.printLogMessageLn('Compile start')
	misc.clearConsole(output)
	tmpdir = id
	tempobj = tempfile.mktemp("", "Tempobj", id)
	global p
	global queue
	queue = []
	p = prefs.preferences()
	b = board.Board()
	#compile inter c objects
	try:
		"""preproces pde"""
		(pre_file, lines) = preproc.addHeaders(id, buf)
		"""compile C targets"""
		misc.printLogMessageLn('processing C targets')
		(run, sout) = compileObjects(cobj, defc, id, output)
		if run == False:
			misc.printErrorLn(notify, output, _("Compile Error"), stripOut(sout, pre_file))
			raise NameError("compile error")
		"""deprecated C targets (pre 1.0)"""
		if misc.getArduinoVersion() < 100:
			(run, sout) = compileObjects(cobj_deprecated, defc, id, output)
			if run == False:
				misc.printErrorLn(notify, output, _("Compile Error"), stripOut(sout, pre_file))
				raise NameError("compile error")
		"""compile C++ targets"""
		misc.printLogMessageLn('processing C++ targets')
		(run, sout) = compileObjects(cppobj, defcpp, id, output)
		if run == False:
			misc.printErrorLn(notify, output, _("Compile Error"), sout)
			raise NameError("compile error")
		"""compile C++ additional (1.0) targets"""
		if misc.getArduinoVersion() >= 100:
			misc.printLogMessageLn('processing C++ additional targets')
			(run, sout) = compileObjects(cppobj_additional, defcpp, id, output)
			if run == False:
				misc.printErrorLn(notify, output, _("Compile Error"), sout)
				raise NameError("compile error")
		"""generate archive objects"""
		misc.printLogMessageLn('generating ar objects')
		objects = cobj + cppobj
		if misc.getArduinoVersion() >= 100:
			objects += cppobj_additional
		else:
			objects += cobj_deprecated
		for i in objects:
			compline = [j for j in defar]
			compline.append(id+"/core.a")
			compline.append(id+"/"+i+".o")
			misc.printMessageLn(output, ' '.join(compline)+"\n")
			misc.printLogMessageLn(' '.join(compline))
			(run, sout) = misc.runProg(compline)
			misc.printLogMessageLn(sout)
			if run == False:
				misc.printErrorLn(notify, output, _("Compile Error"), stripOut(sout, pre_file))
				raise NameError("compile error")
			else:
				misc.printMessageLn(output, sout)
		"""precompile pde"""
		misc.printLogMessageLn('pde compile')
		misc.printLogMessageLn('-----------')
		compline=[j for j in defcpp]
		compline.append("-mmcu="+b.getBoardMCU(b.getBoard()))
		compline.append("-DF_CPU="+b.getBoardFCPU(b.getBoard()))
		if misc.getArduinoVersion() >= 100:
			compline.append("-DARDUINO=100")
		compline.extend(misc.getArduinoIncludes())
		flags = []
		flags = preproc.generateCFlags(id, cont)
		compline.extend(flags)
		compline.extend(["-I" + os.path.join(i, "utility") for i in preproc.generateLibs(id, buf)])
		compline.extend(misc.getArduinoIncludes())
		compline.extend(["-I"+os.getcwd()])
		try:
			localDir = os.path.dirname(tw.get_data("file"))
			compline.extend(["-I"+localDir])
			compline.extend(["-I"+os.path.abspath(os.path.join(localDir, ".."))])
		except: pass
		compline.append(pre_file)
		compline.append("-o"+pre_file+".o")
		misc.printMessageLn(output, ' '.join(compline)+"\n")
		misc.printLogMessageLn(' '.join(compline))
		(run, sout) = misc.runProg(compline)
		misc.printLogMessageLn(sout)
		if run == False:
			misc.printErrorLn(notify, output, _("Compile Error"), stripOut(sout, pre_file))
			moveCursor(tw, int(getErrorLine(sout, lines)))
			raise NameError('compile-error')
		else:
			misc.printMessageLn(output, sout)

		"""compile all objects"""
		misc.printLogMessageLn('compile objects')
		misc.printLogMessageLn('---------------')
		compline = [i for i in link]
		compline.append("-mmcu="+b.getBoardMCU(b.getBoard()))
		compline.append("-o"+tempobj+".elf")
		compline.append(pre_file+".o")
		tmplibs = []
		for i in preproc.generateLibs(id, buf):
			tmplibs.extend(validateLib(os.path.basename(i), tempobj, flags, output, notify))
		compline.extend(list(set(tmplibs)))
		compline.extend(["-I" + i for i in preproc.generateLibs(id, buf)])
		compline.extend(["-I" + os.path.join(i, "utility") for i in preproc.generateLibs(id, buf)])
		if misc.getArduinoVersion() >= 100:
			compline.append("-DARDUINO=100")
		compline.extend(misc.getArduinoIncludes())
		compline.append(id+"/core.a")
		compline.append("-L"+id)
		compline.append("-lm")
		misc.printMessageLn(output, ' '.join(compline)+"\n")
		misc.printLogMessageLn(' '.join(compline))
		(run, sout) = misc.runProg(compline)
		misc.printLogMessageLn(sout)
		if run == False:
			misc.printErrorLn(notify, output, _("Linking error"), stripOut(sout, pre_file))
			raise NameError('linking-error')
		else:
			misc.printMessageLn(output, sout)
		compline=[i for i in eep]
		compline.append(tempobj+".elf")
		compline.append(tempobj+".eep")
		misc.printMessageLn(output, ' '.join(compline)+"\n")
		misc.printLogMessageLn(' '.join(compline))
		(run, sout) = misc.runProg(compline)
		misc.printLogMessageLn(sout)
		if run == False:
			misc.printErrorLn(notify, output, _("Object error"), stripOut(sout, pre_file))
			raise NameError('obj-copy')
		else:
			misc.printMessageLn(output, sout)
		compline=[i for i in hex]
		compline.append(tempobj+".elf")
		compline.append(tempobj+".hex")
		misc.printMessageLn(output, ' '.join(compline)+"\n")
		misc.printLogMessageLn(' '.join(compline))
		(run, sout) = misc.runProg(compline)
		misc.printMessageLn(output, sout)
		misc.printLogMessageLn(sout)
		if run == False:
			misc.printErrorLn(notify, output, _("Object error"), stripOut(sout, pre_file))
			raise NameError('obj-copy')
		else:
			misc.printMessageLn(output, sout)
		size = computeSize(tempobj+".hex")
		notify.pop(context)
		notify.push(context, _("Done compiling."))
		misc.printLogMessageLn("compile done.")

		misc.printMessageLn(output, \
			_("Binary sketch size: %s bytes (of a %s bytes maximum)\n") % (size, b.getBoardMemory(b.getBoard())), 'true')
	except StandardError as e:
		print "Error: %s" % e
		return -1
	except Exception as e:
		print "Error compiling. Op aborted!"
		print "Error: %s" % e
		return -1
	return tempobj