class Object

Constants

ARCH

Check for environment variables

BASE_DIR

Copyright (C) 2015 Franz Flasch <franz.flasch@gmx.at>

This file is part of REM - Rake for EMbedded Systems and Microcontrollers.

REM is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

REM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with REM. If not, see <www.gnu.org/licenses/>.

BUILD_DIR
DEPLOY_DIR
DL_DIR
DL_STATE_DIR
FILE_TASK
MACH
NON_FILE_TASK

Copyright (C) 2016 Franz Flasch <franz.flasch@gmx.at>

This file is part of REM - Rake for EMbedded Systems and Microcontrollers.

REM is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

REM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with REM. If not, see <www.gnu.org/licenses/>.

PROJECT_FOLDER
SIMPLECOV
STATE_DIR
VERBOSE
WORKDIR

Public Instance Methods

check_duplicates_exit_with_error(array, list_name) click to toggle source
# File scripts/misc/helper.rb, line 57
def check_duplicates_exit_with_error(array, list_name)
    # Now put warning if there are any duplicate recipes
    duplicates = get_duplicates_in_array(array)
    if duplicates.uniq.any?
        print_abort ("ERROR: Duplicates in #{list_name}, duplicates: #{duplicates.uniq}")
    end
end
create_compile_file_task(pkg_ref, package_list, tasks_common) click to toggle source
# File rem_core.rb, line 290
def create_compile_file_task(pkg_ref, package_list, tasks_common)

    pkg_compile_list = package_add_common_task_dep_list(package_list, tasks_common, FILE_TASK, pkg_ref.name)

    # Prepare include directories of the dependencies
    dep_inc_array = []
    pkg_ref.deps.each do |dep|
        dep_ref = pkg_get_ref_by_name(package_list, dep, pkg_ref.name)
        dep_inc_array.concat(dep_ref.inc_dirs_prepared)
    end

    pkg_ref.set_dependency_incdirs(dep_inc_array)
    pkg_ref.incdir_prepare()
    pkg_ref.compile_and_link_prepare()

    # Check for updated header or c files
    header_files = []
    pkg_ref.incdirs.each do |e|
        header_files.concat(find_files_with_ending("#{pkg_ref.get_pkg_work_dir}/#{e}", "h"))
    end
    pkg_compile_list.concat(header_files)

    c_files = pkg_ref.srcs.map { |element| "#{pkg_ref.get_pkg_work_dir}/#{element}" }
    pkg_compile_list.concat(c_files)

    desc "#{pkg_ref.get_package_state_file("compile")}"
    file "#{pkg_ref.get_package_state_file("compile")}" => pkg_compile_list do
        print_any_green "Compiling #{pkg_ref.name}..."
        pkg_ref.compile()
    end
end
create_download_file_task(pkg_ref, package_list, tasks_common) click to toggle source
# File rem_core.rb, line 212
def create_download_file_task(pkg_ref, package_list, tasks_common)

    # As this is the first task in the chain create work directories here:
    Rake::Task["package:create_workdir"].invoke()

    file "#{pkg_ref.pkg_dl_state_file}" do
        print_any_green "Downloading #{pkg_ref.name}..."
        pkg_ref.download()
    end
end
create_prepare_file_task(pkg_ref, package_list, tasks_common) click to toggle source
# File rem_core.rb, line 233
def create_prepare_file_task(pkg_ref, package_list, tasks_common)

    pkg_prepare_list = package_add_common_task_dep_list(package_list, tasks_common, FILE_TASK, pkg_ref.name)

    # Add source file dependencies and include folders
    # This is quite hacky, but the best solution so far:
    if pkg_ref.uri[0].uri_type == "local"
        pkg_ref.srcs.each do |e|
            found = 0
            pkg_ref.base_dir.each do |dir|
                if File.exist?("#{dir}/#{e}")
                    pkg_prepare_list.push("#{dir}/#{e}")
                    found = 1
                    break
                end
            end
            if found != 1
                print_abort("Could not find file #{e} in the following dirs #{pkg_ref.base_dir}")
            end
        end

        # At first find all *.h files:
        header_files = []
        pkg_ref.incdirs.each do |e|
            found = 0
            pkg_ref.base_dir.each do |dir|
                if File.exist?("#{dir}/#{e}")
                    header_files.concat(find_files_with_ending("#{dir}/#{e}", "h"))
                    found = 1
                    break
                end
            end
            if found != 1
                print_abort("Could not find path #{e} in the following dirs #{pkg_ref.base_dir}")
            end
        end
        pkg_prepare_list.concat(header_files)
    end

    file "#{pkg_ref.get_package_state_file("prepare")}" => pkg_prepare_list do
        print_any_green "Preparing #{pkg_ref.name}..."
        pkg_ref.prepare_package_state_dir()
        pkg_ref.prepare()
        print_debug "#{pkg_ref.name} prepare list: #{pkg_prepare_list}"
    end
end
create_remfile_generate_file_task(pkg_ref, package_list, remfile, dep_chain) click to toggle source
# File rem_core.rb, line 191
def create_remfile_generate_file_task(pkg_ref, package_list, remfile, dep_chain)
    Rake::Task["package:create_workdir"].invoke()
    file remfile do
        dep_ref_array = []
        dep_chain.each do |dep|
            dep_ref = pkg_get_ref_by_name(package_list, dep, pkg_ref.name)
            dep_ref_array.concat(dep_ref.get_package_recipe_files)
            print_any_green("Writing #{dep_ref.name}")
        end
        yaml_store(remfile, "pkg", dep_ref_array)
    end
end
create_workdir() click to toggle source
# File rem_core.rb, line 69
def create_workdir
    FileUtils.mkdir_p(BUILD_DIR)
    FileUtils.mkdir_p(DL_DIR)
    FileUtils.mkdir_p(DL_STATE_DIR)
end
execute(cmd) click to toggle source
# File scripts/misc/helper.rb, line 65
def execute(cmd)
    Open3.popen2e(cmd) do |stdin, stdout_err, wait_thr|
        cmd_std_message = ""
        print_debug(cmd)
        stdout_err.each do |line|
            print_debug(line)
            cmd_std_message << line
        end
        exit_status = wait_thr.value
        unless exit_status.success?
            print_any_red("Error when calling #{cmd} - exit code: #{exit_status} - STDOUT/STDERR:")
            print_any_red(cmd_std_message)
            abort
        end
    end
end
filter_packages(pkg_list, current_arch_config, current_mach_config) click to toggle source
# File scripts/recipe_handling/recipes.rb, line 102
def filter_packages(pkg_list, current_arch_config, current_mach_config)
    tmp_pkg_list = []
    pkg_list.each_with_index do |cur_pkg, index|
        # Filter out packages which do not match arch or mach config
        arch_config = cur_pkg.get_arch()
        mach_config = cur_pkg.get_mach()

        if ( (arch_config == "generic") or 
             (arch_config == current_arch_config and mach_config == "generic")  or 
             (arch_config == current_arch_config and mach_config == current_mach_config)
            )
            tmp_pkg_list.push(cur_pkg)
        else
            print_debug "ARCH Config #{arch_config} or MACH Config #{mach_config} does not match - current arch config: #{current_arch_config} - current mach config: #{current_mach_config}, skipping recipe: #{cur_pkg.name}"
        end
    end

    pkg_list = tmp_pkg_list

    print_debug("Now having the following recipes:")
    pkg_list.each do | pkg |
        print_debug(pkg.name)
    end

    return tmp_pkg_list
end
find_files_with_ending(folder_list, ending) click to toggle source

Searches for files with ending in folderlist Returns files as array

# File scripts/misc/helper.rb, line 25
def find_files_with_ending(folder_list, ending)
    files = []
    folders = folder_list

    # check if folder_list is array or string
    unless folder_list.is_a?(Array)
        folders = folder_list.split(" ")
    end

    folders.each do |e|
        if File.exist?("#{e}")
            Find.find("#{e}") do |path|
                files << path if path =~ /.*\.#{ending}$/
            end
        else
            print_abort("Error: path #{e} does not exist!")
        end
    end
    return files
end
find_files_with_ending_str(folder_list, ending) click to toggle source

Searches for files with ending in folderlist Returns files as string

# File scripts/misc/helper.rb, line 48
def find_files_with_ending_str(folder_list, ending)
    list = find_files_with_ending(folder_list, ending)
    return list.join(" ")
end
get_dirname_from_uri(uri) click to toggle source

Cuts the filename from the given uri

# File scripts/misc/helper.rb, line 107
def get_dirname_from_uri(uri)
    return File.dirname(uri)
end
get_duplicates_in_array(array) click to toggle source
# File scripts/misc/helper.rb, line 53
def get_duplicates_in_array(array)
    return array.select{|element| array.count(element) > 1 }
end
get_extension_from_uri(uri) click to toggle source

Returns the file extension from the given uri

# File scripts/misc/helper.rb, line 117
def get_extension_from_uri(uri)
    tmp = File.extname(uri)
    # return the "."
    tmp.slice!(0)
    return tmp
end
get_filename_from_uri(uri) click to toggle source

Cuts the directory from the given uri

# File scripts/misc/helper.rb, line 112
def get_filename_from_uri(uri)
    return File.basename(uri)
end
get_filename_without_extension_from_uri(uri) click to toggle source

Cuts the directory and the extension from the given uri

# File scripts/misc/helper.rb, line 96
def get_filename_without_extension_from_uri(uri)
    #return File.basename(uri, extension)
    return File.basename(uri, File.extname(uri))
end
get_recipes(project_folders, recipe_file_ending) click to toggle source

Copyright (C) 2015 Franz Flasch <franz.flasch@gmx.at>

This file is part of REM - Rake for EMbedded Systems and Microcontrollers.

REM is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

REM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with REM. If not, see <www.gnu.org/licenses/>.

# File scripts/recipe_handling/recipes.rb, line 21
def get_recipes(project_folders, recipe_file_ending)
    project_folders = project_folders.split(",")
    files = []
    files = find_files_with_ending(project_folders, recipe_file_ending)

    if files.empty?
        return nil
    end

    print_debug("Found the following recipes:")
    print_debug(files)
    print_debug("")

    return files
end
get_rem_path() click to toggle source

Copyright (C) 2016 Franz Flasch <franz.flasch@gmx.at>

This file is part of REM - Rake for EMbedded Systems and Microcontrollers.

REM is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

REM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with REM. If not, see <www.gnu.org/licenses/>.

# File rem_path.rb, line 21
def get_rem_path()
        File.expand_path(File.dirname(__FILE__))
end
get_uri_without_extension(uri) click to toggle source

Cuts the extension from the given uri

# File scripts/misc/helper.rb, line 102
def get_uri_without_extension(uri)
    return File.join(File.dirname(uri), File.basename(uri, '.*'))
end
global_config() click to toggle source
# File scripts/global_config/global_config.rb, line 234
def global_config
    return $global_config
end
merge_recipes_append(recipe_list, append_recipe_list) click to toggle source
# File scripts/recipe_handling/recipes.rb, line 59
def merge_recipes_append(recipe_list, append_recipe_list)
    append_recipe_list.each do |append_pkg|
        tmp_pkg = pkg_get_ref_by_name(recipe_list, append_pkg.name)

        if tmp_pkg == nil
            print_any_yellow("Could not find matching base recipe for append recipe " + append_pkg.name)
        else
            print_any_yellow("Appending #{tmp_pkg.name}")

            # Iterate through instance_var_to_reset and reset all instance variables listed in this array
            vars_to_reset = append_pkg.instance_variable_get(:@instance_var_to_reset)
            if nil!=vars_to_reset
                vars_to_reset.each do |var|
                    print_any_cyan("Reset all in #{var}")
                    if tmp_pkg.instance_variable_get("@#{var}").nil?
                        print_abort("sw_package variable #{var} does not exist!")
                    else
                        print_any_cyan("Clearing #{var}, which was #{tmp_pkg.instance_variable_get("@#{var}")}")
                        tmp_pkg.instance_variable_get("@#{var}").clear
                    end
                end
                print_any_cyan("Clearing instance_var_to_reset which was #{append_pkg.instance_variable_get(:@instance_var_to_reset)}")
                append_pkg.instance_variable_get(:@instance_var_to_reset).clear
            end


            # OK now simply load the new append package into the base package
            tmp_pkg.load_package(append_pkg.get_package_recipe_files[0])

            # Add the remappend path
            tmp_pkg.add_recipe_path(append_pkg.get_package_recipe_files[0])

            # Also add the new base_dir
            tmp_pkg.add_base_dir(append_pkg.get_package_recipe_files[0])

            tmp_pkg.instance_variables.each do |var|
                print_any_cyan("#{var} is now #{tmp_pkg.instance_variable_get("#{var}")}")
            end
        end
    end
    print_any_yellow("Merging append recipes done.")
end
package_add_common_task_dep_list(package_list, task_list, file_task, pkg_name) click to toggle source

Generates a list of dependencies input has to be composed like this package_list - list of package references task_list - [ pkg.deps_array, “compile”, pkg.get_name_splitted, “prepare”] # Every second entry is the dependency array, Every second+1 entry is the “which” entry file_task - specifies if the output dependencies shall be file tasks or non file tasks

# File scripts/dependency_functions/dependency_tasks.rb, line 52
def package_add_common_task_dep_list(package_list, task_list, file_task, pkg_name)
    dep_str_array = []
    # At first get the number of tasks
    task_count = ((task_list.length/2)-1)
    (0..task_count).step(1) do |i|
        # Every second entry is the dependency list
        deps_array = task_list[(i*2)]
        which = task_list[(i*2)+1]
        if(file_task == 1)
            dep_str_array.concat(package_add_file_task_dep(package_list, deps_array, which, pkg_name))
        else
            dep_str_array.concat(package_add_non_file_task_dep(package_list, deps_array, which, pkg_name))
        end
    end
    return dep_str_array
end
package_add_file_task_dep(package_list, dependency_list, which, pkg_name) click to toggle source
# File scripts/dependency_functions/dependency_tasks.rb, line 33
def package_add_file_task_dep(package_list, dependency_list, which, pkg_name)
    dep_str_array = []
    dependency_list.each do |dep|
        dep_ref = pkg_get_ref_by_name(package_list, dep, pkg_name)
        case which
            when "download"
                    dep_str_array.push("#{dep_ref.pkg_dl_state_file}")
            else
                    dep_str_array.push("#{dep_ref.get_package_state_file("#{which}")}")
        end
    end
    return dep_str_array
end
package_add_non_file_task_dep(package_list, dependency_list, which, pkg_name) click to toggle source
# File scripts/dependency_functions/dependency_tasks.rb, line 24
def package_add_non_file_task_dep(package_list, dependency_list, which, pkg_name)
    dep_str_array = []
    dependency_list.each do |dep|
        dep_ref = pkg_get_ref_by_name(package_list, dep, pkg_name)
        dep_str_array.push("package:#{dep_ref.name}:#{which}")
    end
    return dep_str_array
end
package_get_dependency_list(package_list, pkg, dep_list) click to toggle source
# File scripts/dependency_functions/dependency_tasks.rb, line 69
def package_get_dependency_list(package_list, pkg, dep_list)
    if(pkg.deps.any?)
        dep_list.concat(pkg.deps)
    end
    pkg.deps.each do |dep|
        dep_ref = pkg_get_ref_by_name(package_list, dep, pkg.name)
        package_get_dependency_list(package_list, dep_ref, dep_list)
    end
end
parse_string(str_input_array, what) click to toggle source

Copyright (C) 2016 Franz Flasch <franz.flasch@gmx.at>

This file is part of REM - Rake for EMbedded Systems and Microcontrollers.

REM is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

REM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with REM. If not, see <www.gnu.org/licenses/>.

# File scripts/misc/helper_string_parse.rb, line 21
def parse_string(str_input_array, what)
    found = 0
    ret_str = ""
    tmp_str_arr = str_input_array
    tmp_str = tmp_str_arr.split(";")

    tmp_str.each do |e|
        if(e[/#{what}(.*)/])
            e.slice! "#{what}"
            ret_str = e
            found = 1
        end
    end

    if(found == 1)
        return ret_str
    else
        return "undefined"
    end
end
pkg_get_ref_by_name(pkg_list, name, needed_by_info=nil) click to toggle source
# File scripts/recipe_handling/recipes.rb, line 129
def pkg_get_ref_by_name(pkg_list, name, needed_by_info=nil)

    # find via index:
    #result = ref_list.index{ |item| item.name == name }
    #return ref_list[result]

    # find directly:
    result = pkg_list.find{ |item| item.name == name }

    if result == nil
        if needed_by_info != nil
            return print_abort("ERROR: No recipe found for package #{name}!" + " Needed by: " + needed_by_info)
        else
            return nil
        end
    else
        return result
    end
end
prepare_recipes(recipes) click to toggle source
# File scripts/recipe_handling/recipes.rb, line 37
def prepare_recipes(recipes)
    recipe_filenames = []
    pkgs = []

    print_debug "Searching for recipes..."

    # Remove directory from all recipes - this is needed to check for duplicates
    recipes.each {|e| recipe_filenames.push(get_filename_from_uri(e))}

    check_duplicates_exit_with_error(recipe_filenames, "recipes")

    recipes.each do |r|

        print_debug "parsing recipe #{r}:"

        # Parse and include submakefiles
        cur_pkg = SoftwarePackage.new(r)
        pkgs.push(cur_pkg)
    end
    return pkgs
end
print_abort(text) click to toggle source
print_any(text) click to toggle source
print_any_cyan(text) click to toggle source
print_any_green(text) click to toggle source
print_any_red(text) click to toggle source
print_any_yellow(text) click to toggle source
print_debug(text) click to toggle source

Copyright (C) 2016 Franz Flasch <franz.flasch@gmx.at>

This file is part of REM - Rake for EMbedded Systems and Microcontrollers.

REM is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

REM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with REM. If not, see <www.gnu.org/licenses/>.

set_input_env(var) click to toggle source
# File scripts/global_config/config_helper/check_env.rb, line 23
def set_input_env(var)
    if ENV[var].nil? || ENV[var].empty?
        abort ("#{var} not set!")
    end
    return ENV[var]
end
set_input_env_default(var, default_val) click to toggle source
# File scripts/global_config/config_helper/check_env.rb, line 31
def set_input_env_default(var, default_val)
    if ENV[var].nil? || ENV[var].empty?
        puts ("#{var} not set, using #{default_val}")
        return default_val
    else
        return ENV[var]
    end
end
set_workdir(input_keyword, default_val) click to toggle source
# File scripts/global_config/config_helper/check_env.rb, line 40
def set_workdir(input_keyword, default_val)
    tmp_path = set_input_env_default(input_keyword, default_val)

    if (Pathname.new tmp_path).absolute?
        return "#{tmp_path}"
    else
        return "#{Rake.original_dir}/#{tmp_path}"
    end
end
string_strip(val) click to toggle source

Removes leading and trailing spaces as well as removing superflous spaces between strings

# File scripts/misc/helper.rb, line 84
def string_strip(val)
    return "#{val.gsub(/\s+/, " ").strip} "
end
string_strip_to_array(val) click to toggle source

Does the same as string_strip plus converts it to an array

# File scripts/misc/helper.rb, line 89
def string_strip_to_array(val)
    tmp = string_strip(val)
    tmp = tmp.split(" ")
    return tmp
end
sw_package() click to toggle source
# File scripts/package.rb, line 27
def sw_package; return $global_sw_package; end
sw_package_set(pkg) click to toggle source
# File scripts/package.rb, line 28
def sw_package_set(pkg); $global_sw_package = pkg; end
yaml_parse(file, append) click to toggle source
# File scripts/remfile_functions/remfile_gen.rb, line 31
def yaml_parse(file, append)
    data = YAML::load_file(file)

    recipes = []

    data['pkg'].each do |pkg|
        if append == true
            if pkg.include? ".remappend"
                (recipes||= []).push(pkg)
            end
        else
            if !pkg.include? ".remappend"
                (recipes||= []).push(pkg)
            end
        end
    end

    if recipes.empty? 
        return nil
    else
        return recipes
    end
end
yaml_store(file, fieldname, data) click to toggle source
# File scripts/remfile_functions/remfile_gen.rb, line 24
def yaml_store(file, fieldname, data)
    store = YAML::Store.new(file)
    store.transaction do
        store[fieldname] = data
    end
end