Skip to content

Commit

Permalink
Added a mechanism to specify a common library path within the configu…
Browse files Browse the repository at this point in the history
…ration.

Prior to this change you could either put the 3rd party
library into the system 'libraries' directory for the arduino software
(typically at /usr/local/share/arduino/libraries) or copy/symlink it
into the [project]/lib directory.

With this change there is a third option for including 3rd party
libraries.  The build command now allows for another library
directory to be provided.  This library directory will be used just
like the prior two.

The option is "--common-library" and it can be used with the build
command or placed within the standard configuration files.
  • Loading branch information
Jason McHugh committed Feb 15, 2013
1 parent 77decf0 commit e55df22
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
9 changes: 9 additions & 0 deletions ino/commands/build.py
Expand Up @@ -43,6 +43,7 @@ def setup_arg_parser(self, parser):
super(Build, self).setup_arg_parser(parser)
self.e.add_board_model_arg(parser)
self.e.add_arduino_dist_arg(parser)
self.e.add_common_libs_arg(parser)
parser.add_argument('-v', '--verbose', default=False, action='store_true',
help='Verbose make output')

Expand All @@ -60,6 +61,11 @@ def discover(self):
['hardware', 'arduino', 'variants'],
human_name='Arduino variants directory')

if self.e.common_lib_dir:
print 'Using common library directory: ', self.e.common_lib_dir
else:
print 'No common library directory specified.'

toolset = [
('cc', 'avr-gcc'),
('cxx', 'avr-g++'),
Expand Down Expand Up @@ -169,6 +175,9 @@ def scan_dependencies(self):
self.e['deps'] = SpaceList()

lib_dirs = [self.e.arduino_core_dir] + list_subdirs(self.e.lib_dir) + list_subdirs(self.e.arduino_libraries_dir)
if self.e['common_lib_dir'] != None:
lib_dirs += list_subdirs(self.e['common_lib_dir'])

inc_flags = self.recursive_inc_lib_flags(lib_dirs)

# If lib A depends on lib B it have to appear before B in final
Expand Down
10 changes: 10 additions & 0 deletions ino/environment.py
Expand Up @@ -57,6 +57,7 @@ class Environment(dict):
src_dir = 'src'
lib_dir = 'lib'
hex_filename = 'firmware.hex'
common_lib_dir = None

arduino_dist_dir = None
arduino_dist_dir_guesses = [
Expand Down Expand Up @@ -211,6 +212,9 @@ def add_arduino_dist_arg(self, parser):
parser.add_argument('-d', '--arduino-dist', metavar='PATH',
help='Path to Arduino distribution, e.g. ~/Downloads/arduino-0022.\nTry to guess if not specified')

def add_common_libs_arg(self, parser):
parser.add_argument('-l', '--common-library', help='Path to common libraries')

def serial_port_patterns(self):
system = platform.system()
if system == 'Linux':
Expand Down Expand Up @@ -244,6 +248,12 @@ def process_args(self, args):
if arduino_dist:
self['arduino_dist_dir'] = arduino_dist

common_library_dir = getattr(args, 'common_library', None)
if common_library_dir:
if not os.path.exists(common_library_dir):
raise Abort( 'Common library path does not exist: %s' % common_library_dir );
self['common_lib_dir'] = common_library_dir

board_model = getattr(args, 'board_model', None)
if board_model:
all_models = self.board_models()
Expand Down

2 comments on commit e55df22

@doraess
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, Jason

I am checking your version and it recognizes the new option, but I am having the following errors:

  • issuing a wrong path or path to a file (not a directory) is detected and displays the message in the first case, a execution error in case of file path
  • issuing a good lib path seems to be ignored, as I always get "No common library directory specified."

I tried both the command line and the conf file, but the behavior is always the same.

Any clue of whats is wrong?

Thanks in advance.

@mchughj
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi there.

There are 2 things that I can think of:

1/ You have to specify a library directory that has the expected form used by the downstream tools. Specifically the library directory is a directory that contains within it 1 directory per library and then within those directories the actual library appears. The tools don't allow for any real variance in this. So for example I have:

$ ls -l ~/sketchbook/libraries/
total 16
drwxr-xr-x 3 mchughj mchughj 4096 Feb 9 22:09 manchester
drwxr-xr-x 3 mchughj mchughj 4096 Feb 9 22:27 RunningMedian
lrwxrwxrwx 1 mchughj mchughj 61 Feb 26 14:07 Ultrasonic -> /home/mchughj/projects/arduino/Ultrasonic-HC-SR04/Ultrasonic/
drwxrwxr-x 5 mchughj mchughj 4096 Feb 27 12:40 VirtualWire

$ ls -l ~/sketchbook/libraries/RunningMedian/
total 12
-rwxrwxr-x 1 mchughj mchughj 1582 Feb 10 00:04 README.md
-rwxrwxr-x 1 mchughj mchughj 3185 Feb 10 00:05 RunningMedian.cpp
-rwxrwxr-x 1 mchughj mchughj 3401 Feb 9 23:51 RunningMedian.h

Then I have to specify
ino build -l ~/sketchbook/libraries
and not ~/sketchbook/libraries/RunningMedian if I have #include "RunningMedian.h" in my sketch.

2/ The alternative is that you should do an 'ino clean' then an 'ino build -l [Your library directory].

Hope this helps.

Jason

Please sign in to comment.