Skip to content
This repository has been archived by the owner on Aug 27, 2021. It is now read-only.

Update for support Windows, Cygwin evironments #280

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions ino/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from ino.runner import main

if __name__ == '__main__':
main()
61 changes: 49 additions & 12 deletions ino/commands/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,24 @@ class Build(Command):
name = 'build'
help_line = "Build firmware from the current directory project"

default_make = 'make'
default_cc = 'avr-gcc'
default_cxx = 'avr-g++'
default_ar = 'avr-ar'
default_objcopy = 'avr-objcopy'
if platform.system() == 'Windows':
default_make= 'make.exe'
default_cc = 'avr-gcc.exe'
default_cxx = 'avr-g++.exe'
default_ar = 'avr-ar.exe'
default_objcopy = 'avr-objcopy.exe'
elif platform.system().startswith('CYGWIN'):
default_make= '/usr/bin/make'
default_cc = 'avr-gcc'
default_cxx = 'avr-g++'
default_ar = 'avr-ar'
default_objcopy = 'avr-objcopy'
else:
default_make= 'make'
default_cc = 'avr-gcc'
default_cxx = 'avr-g++'
default_ar = 'avr-ar'
default_objcopy = 'avr-objcopy'

default_cppflags = '-ffunction-sections -fdata-sections -g -Os -w'
default_cflags = ''
Expand Down Expand Up @@ -126,7 +139,8 @@ def discover(self, args):
human_name='Arduino core library')

if self.e.arduino_lib_version.major:
variants_place = os.path.join(board['_coredir'], 'variants')
variants_place = os.path.join( board['_coredir'], 'variants',
board['build']['variant'] )
self.e.find_dir('arduino_variants_dir', ['.'], [variants_place],
human_name='Arduino variants directory')

Expand All @@ -135,6 +149,14 @@ def discover(self, args):

toolset = [
('make', args.make),
]

for tool_key, tool_binary in toolset:
self.e.find_arduino_tool(
tool_key, ['hardware', 'tools', 'avr', 'utils','bin'],
items=[tool_binary], human_name=tool_binary)

toolset = [
('cc', args.cc),
('cxx', args.cxx),
('ar', args.ar),
Expand All @@ -145,6 +167,7 @@ def discover(self, args):
self.e.find_arduino_tool(
tool_key, ['hardware', 'tools', 'avr', 'bin'],
items=[tool_binary], human_name=tool_binary)


def setup_flags(self, args):
board = self.e.board_model(args.board_model)
Expand All @@ -165,10 +188,12 @@ def setup_flags(self, args):
self.e['cppflags'].append('-DUSB_PID=%s' % board['build']['pid'])

if self.e.arduino_lib_version.major:
variant_dir = os.path.join(self.e.arduino_variants_dir,
board['build']['variant'])
variant_dir = self.e.arduino_variants_dir
self.e.cppflags.append('-I' + variant_dir)


self.e.cppflags.append('-I' + self.e.src_dir)
self.e.cppflags.append('-I' + self.e.lib_dir)

self.e['cflags'] = SpaceList(shlex.split(args.cflags))
self.e['cxxflags'] = SpaceList(shlex.split(args.cxxflags))

Expand Down Expand Up @@ -207,13 +232,22 @@ def render_template(self, source, target, **ctx):
contents = template.render(**ctx)
out_path = os.path.join(self.e.build_dir, target)
with open(out_path, 'wt') as f:
contents = contents.split('\\')
contents = '/'.join(contents)
f.write(contents)

return out_path

def make(self, makefile, **kwargs):

old_path = os.environ["PATH"]
os.environ['PATH'] = os.path.dirname(os.path.abspath(self.e.make)) + os.pathsep + old_path

makefile = self.render_template(makefile + '.jinja', makefile, **kwargs)
ret = subprocess.call([self.e.make, '-f', makefile, 'all'])
print "*** RUN %s ..." % (makefile)
ret = subprocess.call([self.e.make , '-f', makefile, 'all'])

os.environ['PATH'] = old_path
if ret != 0:
raise Abort("Make failed with code %s" % ret)

Expand All @@ -233,12 +267,15 @@ def _scan_dependencies(self, dir, lib_dirs, inc_flags):
# for this scan dependency file generated by make
# with regexes to find entries that start with
# libraries dirname
regexes = dict((lib, re.compile(r'\s' + lib + re.escape(os.path.sep))) for lib in lib_dirs)
regexes = dict((lib, re.compile(r'\s' + lib + re.escape('/'))) for lib in lib_dirs)
#regexes = dict((lib, re.compile(r'\s' + lib + re.escape(os.path.sep))) for lib in lib_dirs)
used_libs = set()
with open(output_filepath) as f:
for line in f:
for lib, regex in regexes.iteritems():
if regex.search(line) and lib != dir:
if regex.search(line) and lib != dir:
lib = os.path.abspath(lib)
lib = os.path.relpath(lib, os.getcwd())
used_libs.add(lib)

return used_libs
Expand Down
10 changes: 9 additions & 1 deletion ino/commands/clean.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import shutil

from ino.commands.base import Command
from ino.exc import Abort


class Clean(Command):
Expand All @@ -15,7 +16,14 @@ class Clean(Command):

name = 'clean'
help_line = "Remove intermediate compilation files completely"
error= 0

def run(self, args):
if os.path.isdir(self.e.output_dir):
shutil.rmtree(self.e.output_dir)
shutil.rmtree(self.e.output_dir,onerror=self.onerror)
if self.error > 0:
raise Abort('Can\'t remove the build directory - ' + self.e.output_dir)

def onerror(self, func, path, excinfo):
self.error += 1

42 changes: 28 additions & 14 deletions ino/commands/upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,40 +36,51 @@ def setup_arg_parser(self, parser):
self.e.add_arduino_dist_arg(parser)

def discover(self):
self.e.find_tool('stty', ['stty'])
if platform.system() == 'Linux':
self.e.find_tool('stty', ['stty'])
self.e.find_arduino_tool('avrdude', ['hardware', 'tools'])

conf_places = self.e.arduino_dist_places(['hardware', 'tools'])
conf_places.append('/etc/avrdude') # fallback to system-wide conf on Fedora
self.e.find_file('avrdude.conf', places=conf_places)

elif platform.system()== 'Windows':
self.e.find_arduino_tool('avrdude.exe', ['hardware', 'tools', 'avr', 'bin'])
self.e.find_arduino_file('avrdude.conf', ['hardware', 'tools', 'avr', 'etc'])

elif platform.system().startswith('CYGWIN'):
self.e.find_arduino_tool('avrdude', ['hardware', 'tools', 'avr', 'bin'])
self.e.find_arduino_file('avrdude.conf', ['hardware', 'tools', 'avr', 'etc'])

else:
self.e.find_tool('stty', ['stty'])
self.e.find_arduino_tool('avrdude', ['hardware', 'tools', 'avr', 'bin'])
self.e.find_arduino_file('avrdude.conf', ['hardware', 'tools', 'avr', 'etc'])

def run(self, args):
self.discover()
port = args.serial_port or self.e.guess_serial_port()
board = self.e.board_model(args.board_model)

port = self.e.guess_serial_port(args.serial_port)
board = self.e.board_model(args.board_model)
protocol = board['upload']['protocol']
if protocol == 'stk500':
# if v1 is not specifid explicitly avrdude will
# try v2 first and fail
protocol = 'stk500v1'

if not os.path.exists(port):
raise Abort("%s doesn't exist. Is Arduino connected?" % port)
if port is None:
raise Abort("%s doesn't exist. Is Arduino connected?" % args.serial_port)

# send a hangup signal when the last process closes the tty
file_switch = '-f' if platform.system() == 'Darwin' else '-F'
ret = subprocess.call([self.e['stty'], file_switch, port, 'hupcl'])
if ret:
raise Abort("stty failed")
if 'stty' in self.e:
# send a hangup signal when the last process closes the tty
file_switch = '-f' if platform.system() == 'Darwin' else '-F'
ret = subprocess.call([self.e['stty'], file_switch, port[0], 'hupcl'])
if ret:
raise Abort("stty failed")

# pulse on DTR
try:
s = Serial(port, 115200)
s = Serial(port[0], 115200)
except SerialException as e:
raise Abort(str(e))
s.setDTR(False)
Expand All @@ -92,7 +103,7 @@ def run(self, args):
before = self.e.list_serial_ports()
if port in before:
ser = Serial()
ser.port = port
ser.port = port[0]
ser.baudrate = 1200
ser.open()
ser.close()
Expand Down Expand Up @@ -125,12 +136,15 @@ def run(self, args):

port = new_port

print "Used %s for programming." % port[0]
print "Used %s protocol" % protocol

# call avrdude to upload .hex
subprocess.call([
self.e['avrdude'],
self.e['avrdude'] if 'avrdude' in self.e else self.e['avrdude.exe'],
'-C', self.e['avrdude.conf'],
'-p', board['build']['mcu'],
'-P', port,
'-P', port[0],
'-c', protocol,
'-b', board['upload']['speed'],
'-D',
Expand Down
Loading