예제 #1
0
파일: uploader.py 프로젝트: cefn/gnoduino
def upload(obj, serial, output, notify):
	p = prefs.preferences()
	pgm = programmer.Programmer()
	context = notify.get_context_id("main")
	notify.pop(context)
	notify.push(context, _("Flashing..."))
	b = board.Board()
	compline=[i for i in avr]
	protocol = b.getPGM(b.getBoard())
	# avrdude wants "stk500v1" to distinguish it from stk500v2
	if protocol == "stk500": protocol = "stk500v1"
	if protocol == "" or config.force_protocol is True:
		protocol =  pgm.getProtocol(pgm.getProgrammer())
		try:
			comm = pgm.getCommunication(pgm.getProgrammer())
			if comm == "serial":
				port = serial.getConfigSerialPort(notify, output)
				if port == -1:
					notify.pop(context)
					notify.push(context, _("Flashing error."))
					return
				serial.resetBoard()
				compline.append("-P" + port)
			else: compline.append("-P" + comm)
			try:
				compline.append("-b" + pgm.getSpeed(pgm.getProgrammer()))
			except: pass
		except: pass
	else:
		port = serial.getConfigSerialPort(notify, output)
		if port == -1:
			notify.pop(context)
			notify.push(context, _("Flashing error."))
			return
		compline.append("-P" + port)
		serial.resetBoard()
	compline.append("-c" + protocol)
	try:
		compline.append("-b" + b.getPGMSpeed(b.getBoard()))
	except: pass
	compline.append("-p" + b.getBoardMCU(b.getBoard()))
	compline.append("-Uflash:w:"+obj+".hex:i")
	try:
		if p.getBoolValue("upload.verbose"):
			sys.stderr.write(' '.join(compline)+"\n")
			misc.printMessageLn(output, ' '.join(compline))
		(run, sout) = misc.runProg(compline)
		misc.printMessageLn(output, sout, p.getBoolValue("upload.verbose"), 'false')
		if p.getBoolValue("upload.verbose"): sys.stderr.write(sout+"\n")
		if run == False: raise
	except:
		misc.printErrorLn(notify, output, _("Flashing Error"), _("Flash ERROR.\n"))
		return
	notify.pop(context)
	notify.push(context, _("Flashing complete."))
	misc.printMessageLn(output, \
		"Flash OK.");
예제 #2
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))
예제 #3
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
예제 #4
0
def burnBootloader(serial, output, notify, id):
	p = prefs.preferences()
	misc.clearConsole(output)
	context = notify.get_context_id("main")
	notify.pop(context)
	notify.push(context, _("Burning bootloader..."))
	b = board.Board()
	compline=[i for i in avr_bl]
	pgm = programmer.Programmer()
	if pgm.getCommunication(id) == 'serial':
        	port = serial.getConfigSerialPort(notify, output)
	        if port != -1:
        	        serial.resetBoard()
        	"""De-fuse and erase board"""

		port = serial.getConfigSerialPort(notify, output)
		if port == -1:
			notify.pop(context)
			notify.push(context, _("Flashing error."))
			return
		compline.append("-P" + port)
		if pgm.getSpeed(id) != 0:
			compline.append("-b" + pgm.getSpeed(id))
	elif pgm.getCommunication(id) == 'usb':
		compline.append("-Pusb")
	compline.append("-c" + pgm.getProtocol(id))
	compline.append("-p" + b.getBoardMCU(b.getBoard()))
	compline.append("-e")
	if pgm.getForce(id) == 'true':
		compline.append("-F")
	compline.append("-Ulock:w:" + b.getFuseUnlock(b.getBoard()) + ":m")
	if b.getBoardMCU(b.getBoard()) != 'atmega8':
		compline.append("-Uefuse:w:" + b.getFuseExtended(b.getBoard()) + ":m")
	compline.append("-Uhfuse:w:" + b.getFuseHigh(b.getBoard()) + ":m")
	compline.append("-Ulfuse:w:" + b.getFuseLow(b.getBoard()) + ":m")
	try:
		if p.getBoolValue("upload.verbose"):
			sys.stderr.write(' '.join(compline)+"\n")
			misc.printMessageLn(output, ' '.join(compline))
		(run, sout) = misc.runProg(compline)
		misc.printMessageLn(output, sout, p.getBoolValue("upload.verbose"), 'false')
		if p.getBoolValue("upload.verbose"): sys.stderr.write(sout+"\n")
		if run == False: raise
	except:
		misc.printErrorLn(notify, output, _("Burn Error"), _("Burn ERROR."))
		return
	"""Burn and fuse board"""
	compline=[i for i in avr_bl]
	compline.append("-c" + pgm.getProtocol(id))
	if pgm.getCommunication(id) == 'serial':
		port = serial.getConfigSerialPort(notify, output)
		if port == -1:
			notify.pop(context)
			notify.push(context, _("Flashing error."))
			return
		compline.append("-P" + port)
		if pgm.getSpeed(id) != 0:
			compline.append("-b" + pgm.getSpeed(id))
	elif pgm.getCommunication(id) == 'usb':
		compline.append("-Pusb")
	compline.append("-p" + b.getBoardMCU(b.getBoard()))
	compline.append("-e")
	if pgm.getForce(id) == 'true':
		compline.append("-F")
	compline.append("-Uflash:w:" + findBootLoader() + ":i")
	compline.append("-Ulock:w:" + b.getFuseLock(b.getBoard()) + ":m")
	try:
		if p.getBoolValue("upload.verbose"):
			sys.stderr.write(' '.join(compline)+"\n")
			misc.printMessageLn(output, ' '.join(compline))
		(run, sout) = misc.runProg(compline)
		misc.printMessageLn(output, sout, p.getBoolValue("upload.verbose"), 'false')
		if p.getBoolValue("upload.verbose"): sys.stderr.write(sout+"\n")
		if run == False: raise
	except:
		misc.printErrorLn(notify, output, _("Burn Error"), _("Burn ERROR."))
		return
	notify.pop(context)
	notify.push(context, _("Burn complete."))
	misc.printMessageLn(output, \
		"Burn OK.");
예제 #5
0
def upload(obj, serial, output, notify, force_protocol):
	p = prefs.preferences()
	pgm = programmer.Programmer()
	context = notify.get_context_id("main")
	notify.pop(context)
	notify.push(context, _("Flashing..."))
	b = board.Board()
	compline=[i for i in avr]
	protocol = b.getPGM(b.getBoard())
	# avrdude wants "stk500v1" to distinguish it from stk500v2
	if protocol == "stk500": protocol = "stk500v1"
	# if we do not get any protocol back probably means board doesn't
	# enforce any particular programmer
	if protocol == "" or force_protocol is True:
		#try selected programmer (via menu)
		protocol =  pgm.getProtocol(pgm.getProgrammer())
		try:
			comm = pgm.getCommunication(pgm.getProgrammer())
			if comm:
				if comm == "serial":
					port = serial.getConfigSerialPort(notify, output)
					if port == -1:
						notify.pop(context)
						notify.push(context, _("Flashing error."))
						return
					serial.resetBoard()
					compline.append("-P" + port)
				else: compline.append("-P" + comm)
				try:
					compline.append("-b" + pgm.getSpeed(pgm.getProgrammer()))
				except: pass
		except: pass
	else:
		if protocol != "usbtiny":	#usbtiny works via spi, need to do some device parsing here
			port = serial.getConfigSerialPort(notify, output)
			if port == -1:
				notify.pop(context)
				notify.push(context, _("Flashing error."))
				return
			compline.append("-P" + port)
			serial.resetBoard(b.getPath(b.getBoard()))
	compline.append("-c" + protocol)
	try:
		compline.append("-b" + b.getPGMSpeed(b.getBoard()))
	except: pass
	compline.append("-p" + b.getBoardMCU(b.getBoard()))
	compline.append("-Uflash:w:"+obj+".hex:i")
	try:
		if p.getBoolValue("upload.verbose"):
			sys.stderr.write(' '.join(compline)+"\n")
			misc.printMessageLn(output, ' '.join(compline))
		(run, sout) = misc.runProg(compline)
		misc.printMessageLn(output, sout, p.getBoolValue("upload.verbose"), 'false')
		if p.getBoolValue("upload.verbose"): sys.stderr.write(sout+"\n")
		if run == False: raise
	except:
		misc.printErrorLn(notify, output, _("Flashing Error"), _("Flash ERROR.\n"))
		return
	notify.pop(context)
	notify.push(context, _("Flashing complete."))
	misc.printMessageLn(output, \
		"Flash OK.");
예제 #6
0
def burnBootloader(serial, output, notify, id):
    p = prefs.preferences()
    misc.clearConsole(output)
    context = notify.get_context_id("main")
    notify.pop(context)
    notify.push(context, _("Burning bootloader..."))
    b = board.Board()
    compline = [i for i in avr_bl]
    pgm = programmer.Programmer()
    if pgm.getCommunication(id) == 'serial':
        port = serial.getConfigSerialPort(notify, output)
        if port != -1:
            serial.resetBoard()
        """De-fuse and erase board"""

        port = serial.getConfigSerialPort(notify, output)
        if port == -1:
            notify.pop(context)
            notify.push(context, _("Flashing error."))
            return
        compline.append("-P" + port)
        if pgm.getSpeed(id) != 0:
            compline.append("-b" + pgm.getSpeed(id))
    elif pgm.getCommunication(id) == 'usb':
        compline.append("-Pusb")
    compline.append("-c" + pgm.getProtocol(id))
    compline.append("-p" + b.getBoardMCU(b.getBoard()))
    compline.append("-e")
    if pgm.getForce(id) == 'true':
        compline.append("-F")
    compline.append("-Ulock:w:" + b.getFuseUnlock(b.getBoard()) + ":m")
    if b.getBoardMCU(b.getBoard()) != 'atmega8':
        compline.append("-Uefuse:w:" + b.getFuseExtended(b.getBoard()) + ":m")
    compline.append("-Uhfuse:w:" + b.getFuseHigh(b.getBoard()) + ":m")
    compline.append("-Ulfuse:w:" + b.getFuseLow(b.getBoard()) + ":m")
    try:
        if p.getBoolValue("upload.verbose"):
            sys.stderr.write(' '.join(compline) + "\n")
            misc.printMessageLn(output, ' '.join(compline))
        (run, sout) = misc.runProg(compline)
        misc.printMessageLn(output, sout, p.getBoolValue("upload.verbose"),
                            'false')
        if p.getBoolValue("upload.verbose"): sys.stderr.write(sout + "\n")
        if run == False: raise
    except:
        misc.printErrorLn(notify, output, _("Burn Error"), _("Burn ERROR."))
        return
    """Burn and fuse board"""
    compline = [i for i in avr_bl]
    compline.append("-c" + pgm.getProtocol(id))
    if pgm.getCommunication(id) == 'serial':
        port = serial.getConfigSerialPort(notify, output)
        if port == -1:
            notify.pop(context)
            notify.push(context, _("Flashing error."))
            return
        compline.append("-P" + port)
        if pgm.getSpeed(id) != 0:
            compline.append("-b" + pgm.getSpeed(id))
    elif pgm.getCommunication(id) == 'usb':
        compline.append("-Pusb")
    compline.append("-p" + b.getBoardMCU(b.getBoard()))
    compline.append("-e")
    if pgm.getForce(id) == 'true':
        compline.append("-F")
    compline.append("-Uflash:w:" + findBootLoader() + ":i")
    compline.append("-Ulock:w:" + b.getFuseLock(b.getBoard()) + ":m")
    try:
        if p.getBoolValue("upload.verbose"):
            sys.stderr.write(' '.join(compline) + "\n")
            misc.printMessageLn(output, ' '.join(compline))
        (run, sout) = misc.runProg(compline)
        misc.printMessageLn(output, sout, p.getBoolValue("upload.verbose"),
                            'false')
        if p.getBoolValue("upload.verbose"): sys.stderr.write(sout + "\n")
        if run == False: raise
    except:
        misc.printErrorLn(notify, output, _("Burn Error"), _("Burn ERROR."))
        return
    notify.pop(context)
    notify.push(context, _("Burn complete."))
    misc.printMessageLn(output, \
     "Burn OK.")
예제 #7
0
def upload(obj, serial, output, notify, force_protocol):
    p = prefs.preferences()
    pgm = programmer.Programmer()
    context = notify.get_context_id("main")
    notify.pop(context)
    notify.push(context, _("Flashing..."))
    b = board.Board()
    compline = [i for i in avr]
    protocol = b.getPGM(b.getBoard())
    # avrdude wants "stk500v1" to distinguish it from stk500v2
    if protocol == "stk500": protocol = "stk500v1"
    # if we do not get any protocol back probably means board doesn't
    # enforce any particular programmer
    if protocol == "" or force_protocol is True:
        #try selected programmer (via menu)
        protocol = pgm.getProtocol(pgm.getProgrammer())
        try:
            comm = pgm.getCommunication(pgm.getProgrammer())
            if comm:
                if comm == "serial":
                    port = serial.getConfigSerialPort(notify, output)
                    if port == -1:
                        notify.pop(context)
                        notify.push(context, _("Flashing error."))
                        return
                    serial.resetBoard()
                    compline.append("-P" + port)
                else:
                    compline.append("-P" + comm)
                try:
                    compline.append("-b" + pgm.getSpeed(pgm.getProgrammer()))
                except:
                    pass
        except:
            pass
    else:
        if protocol != "usbtiny":  #usbtiny works via spi, need to do some device parsing here
            port = serial.getConfigSerialPort(notify, output)
            if port == -1:
                notify.pop(context)
                notify.push(context, _("Flashing error."))
                return
            compline.append("-P" + port)
            serial.resetBoard(b.getPath(b.getBoard()))
    compline.append("-c" + protocol)
    try:
        compline.append("-b" + b.getPGMSpeed(b.getBoard()))
    except:
        pass
    compline.append("-p" + b.getBoardMCU(b.getBoard()))
    compline.append("-Uflash:w:" + obj + ".hex:i")
    try:
        if p.getBoolValue("upload.verbose"):
            sys.stderr.write(' '.join(compline) + "\n")
            misc.printMessageLn(output, ' '.join(compline))
        (run, sout) = misc.runProg(compline)
        misc.printMessageLn(output, sout, p.getBoolValue("upload.verbose"),
                            'false')
        if p.getBoolValue("upload.verbose"): sys.stderr.write(sout + "\n")
        if run == False: raise
    except:
        misc.printErrorLn(notify, output, _("Flashing Error"),
                          _("Flash ERROR.\n"))
        return
    notify.pop(context)
    notify.push(context, _("Flashing complete."))
    misc.printMessageLn(output, \
     "Flash OK.")
예제 #8
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))
예제 #9
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