def findIncludes(instr, local=False): res = "" m = re.findall(r"^\s*#include\s+[\w+\".<>\-]+", instr, re.M) l = [z.split()[1].strip('<>"') for z in m] my = [] for z in l: path = os.path.join(misc.getArduinoLibsPath(), z.strip(".h")) if os.path.exists(path) or os.path.exists(path.lower()) or \ os.path.exists(path.upper()): my.append(os.path.join(misc.getArduinoLibsPath(), z.strip(".h"))) if config.user_library: for q in config.user_library.split(';'): fl = os.path.join(q.strip(), z) if os.path.exists(fl) or os.path.exists(fl.lower()) or \ os.path.exists(fl.upper()): my.append(q.strip()) fl = os.path.join(q.strip(), z.strip(".h")) if os.path.exists(fl) or os.path.exists(fl.lower()) or \ os.path.exists(fl.upper()): my.append(os.path.join(q.strip(), z.strip(".h"))) if local and (os.path.exists(z.strip(".h")) or \ os.path.exists(z.strip(".h").lower()) or \ os.path.exists(z.strip(".h").upper())): my.append(z.strip(".h")) if config.sketchFile: sketchPath = os.path.dirname(config.sketchFile) "is this really required" if local and os.path.exists(sketchPath): my.append(sketchPath) sp = os.path.join(sketchPath, z.strip(".h")) if local and os.path.exists(sp): my.append(sp) sp = os.path.abspath(os.path.join(sketchPath, "..")) if local and os.path.exists(sp): my.append(sp) sp = os.path.abspath(os.path.join(sketchPath, "..", z.strip(".h"))) if local and os.path.exists(sp): my.append(sp) for z in l: for r, d, f in os.walk(misc.getArduinoLibsPath()): if len(f)>0: for file in f: if file.strip(".h")+".cpp" == z.strip(".h")+".cpp": my.append(r) if len(my) == 0: for z in l: for r, d, f in os.walk(misc.getArduinoLibsPath()): if len(f)>0: my.extend([r for file in f if file == z]) for file in f: if file == z: break return list(set(my))
def generateCFlags(path, b): #cont = b.get_text(b.get_start_iter(), b.get_end_iter()) cont = b test = [] result = [] for i in findIncludes(cont): flag = os.path.join(misc.getArduinoLibsPath(), i) if flag not in set(test): test.append(flag) result.append("-I"+flag) lib = os.path.join(config.user_library, i) if lib not in set(test): test.append(lib) result.append("-I"+lib) for i in findIncludes(cont, True): if i not in set(test): test.append(i) result.append("-I"+i) return result
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))
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))