Example #1
0
    def library_folders(self):
        # Arduino library format documentation:
        # https://arduino.github.io/arduino-cli/library-specification/#layout-of-folders-and-files
        # - If src folder exists,
        #   use that as the root include directory -Ilibraries/libname/src
        # - Else lib folder as root include -Ilibraries/libname
        #   (exclude source files in the examples folder in this case)

        if not self.library_names or not self.library_path:
            return []

        folder_patterns = ["*"]
        if self.library_names:
            folder_patterns = self.library_names

        library_folders = OrderedDict()
        for library_dir in self.library_path:
            found_library_names = file_operations.find_files(
                library_dir, folder_patterns, directories_only=True)
            _LOG.debug("Found Libraries %s: %s", library_dir,
                       found_library_names)
            for lib_name in found_library_names:
                lib_dir = os.path.join(library_dir, lib_name)
                src_dir = os.path.join(lib_dir, "src")
                if os.path.exists(src_dir) and os.path.isdir(src_dir):
                    library_folders[lib_name] = src_dir
                else:
                    library_folders[lib_name] = lib_dir

        return list(library_folders.values())
Example #2
0
 def project_files(self, pattern):
     sources = []
     for file_path in file_operations.find_files(self.project_path,
                                                 [pattern]):
         if not file_path.startswith(
                 "examples") and not file_path.startswith("libraries"):
             sources.append(file_path)
     return sources
Example #3
0
 def variant_files(self, pattern):
     sources = []
     if self.build_variant_path:
         for file_path in file_operations.find_files(
                 self.get_variant_path(), [pattern]):
             sources.append(os.path.join(self.get_variant_path(),
                                         file_path))
     return sources
Example #4
0
 def library_files(self, pattern):
     sources = []
     library_folders = self.library_folders()
     for lib_dir in library_folders:
         for file_path in file_operations.find_files(lib_dir, [pattern]):
             if not file_path.startswith("examples"):
                 sources.append((Path(lib_dir) / file_path).as_posix())
     return sources
Example #5
0
 def test_find_files(self, test_case, base_fileset, patterns,
                     expected_results):
     """Test find_files on source files and directories."""
     create_files(self.test_dir, base_fileset)
     result = file_operations.find_files(self.test_dir,
                                         patterns,
                                         directories_only=("directories"
                                                           in test_case))
     self.assertSequenceEqual(expected_results, result)
Example #6
0
 def library_files(self, pattern, only_library_name=None):
     sources = []
     library_folders = self.library_folders()
     if only_library_name:
         library_folders = [
             lf for lf in self.library_folders() if only_library_name in lf
         ]
     for lib_dir in library_folders:
         for file_path in file_operations.find_files(lib_dir, [pattern]):
             if not file_path.startswith("examples"):
                 sources.append((Path(lib_dir) / file_path).as_posix())
     return sources
Example #7
0
    def __init__(self,
                 arduino_path,
                 package_name,
                 build_path=None,
                 project_path=None,
                 project_source_path=None,
                 library_path=None,
                 library_names=None,
                 build_project_name=None,
                 compiler_path_override=False):
        self.arduino_path = arduino_path
        self.arduino_package_name = package_name
        self.selected_board = None
        self.build_path = build_path
        self.project_path = project_path
        self.project_source_path = project_source_path
        self.build_project_name = build_project_name
        self.compiler_path_override = compiler_path_override
        self.variant_includes = ""
        self.build_variant_path = False
        self.library_names = library_names
        self.library_path = library_path

        self.compiler_path_override_binaries = []
        if self.compiler_path_override:
            self.compiler_path_override_binaries = file_operations.find_files(
                self.compiler_path_override, "*")

        # Container dicts for boards.txt and platform.txt file data.
        self.board = OrderedDict()
        self.platform = OrderedDict()
        self.menu_options = OrderedDict({
            "global_options": {},
            "default_board_values": {},
            "selected": {}
        })
        self.tools_variables = {}

        # Set and check for valid hardware folder.
        self.hardware_path = os.path.join(self.arduino_path, "hardware")

        if not os.path.exists(self.hardware_path):
            raise FileNotFoundError(
                "Arduino package path '{}' does not exist.".format(
                    self.arduino_path))

        # Set and check for valid package name
        self.package_path = os.path.join(self.arduino_path, "hardware",
                                         package_name)
        # {build.arch} is the first folder name of the package (upcased)
        self.build_arch = os.path.split(package_name)[0].upper()

        if not os.path.exists(self.package_path):
            _LOG.error("Error: Arduino package name '%s' does not exist.",
                       package_name)
            _LOG.error("Did you mean:\n")
            # TODO(tonymd): On Windows concatenating "/" may not work
            possible_alternatives = [
                d.replace(self.hardware_path + os.sep, "", 1)
                for d in glob.glob(self.hardware_path + "/*/*")
            ]
            _LOG.error("\n".join(possible_alternatives))
            sys.exit(1)

        # Populate library paths.
        if not library_path:
            self.library_path = []
        # Append core libraries directory.
        core_lib_path = Path(self.package_path) / "libraries"
        if core_lib_path.is_dir():
            self.library_path.append(Path(self.package_path) / "libraries")
        if library_path:
            self.library_path = [
                os.path.realpath(os.path.expanduser(
                    os.path.expandvars(l_path))) for l_path in library_path
            ]

        # Grab all folder names in the cores directory. These are typically
        # sub-core source files.
        self.sub_core_folders = os.listdir(
            os.path.join(self.package_path, "cores"))

        self._find_tools_variables()

        self.boards_txt = os.path.join(self.package_path, "boards.txt")
        self.platform_txt = os.path.join(self.package_path, "platform.txt")
Example #8
0
 def core_files(self, pattern):
     sources = []
     for file_path in file_operations.find_files(self.get_core_path(),
                                                 [pattern]):
         sources.append(os.path.join(self.get_core_path(), file_path))
     return sources