App-ArduinoBuilder

 view release on metacpan or  search on metacpan

lib/App/ArduinoBuilder/Builder.pm  view on Meta::CPAN

  default_executor->wait();
  my $did_something;
  for my $t (@tasks) {
    my $o = $t->data();
    if ($o) {
      $this->_add_to_archive($o, $archive);
      $did_something = 1;
    }
  }
  return $did_something;
}

# Like in find_all_files_with_extensions, $source_dir can be a single directory (scalar)
# or an array-ref of directories.
# excluded_dirs must be an array-ref.
sub build_object_files {
  my ($this, $source_dir, $target_dir, $excluded_dirs, $force, $no_recurse) = @_;
  make_path($target_dir);
  my @sources = sort (find_all_files_with_extensions($source_dir, [@supported_source_extensions], $excluded_dirs, $no_recurse));
  my $obj_name = ObjectNameBuilder->new($target_dir);
  my @tasks;
  for my $s (@sources) {
    my $object_file = $obj_name->object_for($s);
    next unless $force || check_dep($s, $object_file);
    push @tasks, default_executor()->run(
      sub {
        # return unless $force || check_dep($s, $object_file);
        $this->build_file($s, $object_file);
        return 1;
      });
  }
  default_executor->wait();
  for my $t (@tasks) {
    my $o = $t->data();
    if ($o) {
      return 1;
    }
  }
  return 0;
}

sub link_executable {
  my ($this, $object_files, $archive) = @_;
  $this->_run_recipe_pattern('c.combine', with => {object_files => '"'.join('" "', @{$object_files}).'"', archive_file => $archive, archive_file_path => catfile($this->{config}->get('build.path'), $archive)});
  return;
}

sub compute_binary_size {
  my ($this) = @_;
  my $output;
  $this->_run_recipe_pattern('size', capture_output => \$output, is_size => 1);
  # TODO: There is a variant using the 'advanced_size' recipe that can be
  # implemented for more complex scenario and that we are not yet supporting.

  my $bin_size_re = $this->{config}->get('recipe.size.regex', default => undef);
  if ($bin_size_re) {
    my $bin_size = 0;
    while ($output =~ m/${bin_size_re}/mg) {
      $bin_size += $1;
    }
    my $max_bin_size = $this->{config}->get('upload.maximum_size', default => undef);
    if ($max_bin_size) {
      info '  Sketch uses %d bytes (%d%%) of program space. Maximum is %d bytes.', $bin_size, ($bin_size * 100 / $max_bin_size), $max_bin_size;
      fatal 'Sketch is too large' if $bin_size > $max_bin_size;
    } else {
      info '  Sketch uses %d bytes of program space.', $bin_size;
    }
  }

  my $data_size_re =$this->{config}->get('recipe.size.regex.data', default => undef);
  if ($data_size_re) {
    my $data_size = 0;
    while ($output =~ m/${data_size_re}/mg) {
      $data_size += $1;
    }
    my $max_data_size = $this->{config}->get('upload.maximum_data_size', default => undef);
    if ($max_data_size) {
      info '  Global variables use %d bytes (%d%%) of dynamic memory, leaving %d bytes for local variables. Maximum is %d bytes.', $data_size, ($data_size * 100 / $max_data_size), ($max_data_size - $data_size), $max_data_size;
      fatal 'Too much memory used' if $data_size > $max_data_size;
    } else {
      info '  Global variables use %d bytes of dynamic memory.', $data_size;
    }
  }

  return;
}

sub run_hook {
  my ($this, $hook_name) = @_;
  $this->_run_recipe_pattern("hooks.${hook_name}");
  return;
}

sub objcopy {
  my ($this) = @_;
  $this->_run_recipe_pattern('objcopy', is_objcopy => 1);
}

1;



( run in 0.861 second using v1.01-cache-2.11-cpan-b16cb0d3907 )