diff --git a/platformio/package/commands/install.py b/platformio/package/commands/install.py index 248a0b40..23589a5c 100644 --- a/platformio/package/commands/install.py +++ b/platformio/package/commands/install.py @@ -199,30 +199,49 @@ def _install_project_env_custom_tools(project_env, options): def _install_project_env_libraries(project_env, options): already_up_to_date = not options.get("force") config = ProjectConfig.get_instance() - lm = LibraryPackageManager( + env_lm = LibraryPackageManager( os.path.join(config.get("platformio", "libdeps_dir"), project_env) ) + private_lm = LibraryPackageManager( + os.path.join(config.get("platformio", "lib_dir")) + ) if options.get("silent"): - lm.set_log_level(logging.WARN) + env_lm.set_log_level(logging.WARN) + private_lm.set_log_level(logging.WARN) for library in config.get(f"env:{project_env}", "lib_deps"): spec = PackageSpec(library) # skip built-in dependencies if not spec.external and not spec.owner: continue - if not lm.get_package(spec): + if not env_lm.get_package(spec): already_up_to_date = False - lm.install( + env_lm.install( spec, skip_dependencies=options.get("skip_dependencies"), force=options.get("force"), ) # install dependencies from the priate libraries - plm = LibraryPackageManager(os.path.join(config.get("platformio", "lib_dir"))) - for pkg in plm.get_installed(): - lm.install_dependencies(pkg, print_header=False) + for pkg in private_lm.get_installed(): + _install_project_private_library_deps(pkg, private_lm, env_lm, options) return not already_up_to_date +def _install_project_private_library_deps(private_pkg, private_lm, env_lm, options): + for dependency in private_lm.get_pkg_dependencies(private_pkg) or []: + spec = private_lm.dependency_to_spec(dependency) + # skip built-in dependencies + if not spec.external and not spec.owner: + continue + pkg = private_lm.get_package(spec) + if not pkg and not env_lm.get_package(spec): + pkg = env_lm.install( + spec, + skip_dependencies=True, + force=options.get("force"), + ) + _install_project_private_library_deps(pkg, private_lm, env_lm, options) + + def _install_project_env_custom_libraries(project_env, options): already_up_to_date = not options.get("force") config = ProjectConfig.get_instance() diff --git a/platformio/package/manager/_install.py b/platformio/package/manager/_install.py index 24846be1..cd715e23 100644 --- a/platformio/package/manager/_install.py +++ b/platformio/package/manager/_install.py @@ -117,7 +117,7 @@ class PackageManagerInstallMixin(object): def install_dependencies(self, pkg, print_header=True): assert isinstance(pkg, PackageItem) - dependencies = dependencies = self.get_pkg_dependencies(pkg) + dependencies = self.get_pkg_dependencies(pkg) if not dependencies: return if print_header: diff --git a/tests/commands/pkg/test_install.py b/tests/commands/pkg/test_install.py index 3a2a1af8..d99e8f0d 100644 --- a/tests/commands/pkg/test_install.py +++ b/tests/commands/pkg/test_install.py @@ -219,22 +219,37 @@ platform = native """ ) with fs.cd(str(project_dir)): + config = ProjectConfig() + + # some deps were added by user manually + result = clirunner.invoke( + package_install_cmd, + [ + "-g", + "--storage-dir", + config.get("platformio", "lib_dir"), + "-l", + "paulstoffregen/OneWire@^2.3.5", + ], + ) + validate_cliresult(result) + + # ensure all deps are installed result = clirunner.invoke(package_install_cmd) validate_cliresult(result) - config = ProjectConfig() - installed_lib_pkgs = LibraryPackageManager( - os.path.join(config.get("platformio", "lib_dir")) + installed_private_pkgs = LibraryPackageManager( + config.get("platformio", "lib_dir") ).get_installed() - assert pkgs_to_specs(installed_lib_pkgs) == [ - PackageSpec("My Private Lib@1.0.0") + assert pkgs_to_specs(installed_private_pkgs) == [ + PackageSpec("OneWire@2.3.6"), + PackageSpec("My Private Lib@1.0.0"), ] - installed_libdeps_pkgs = LibraryPackageManager( + installed_env_pkgs = LibraryPackageManager( os.path.join(config.get("platformio", "libdeps_dir"), "private") ).get_installed() - assert pkgs_to_specs(installed_libdeps_pkgs) == [ + assert pkgs_to_specs(installed_env_pkgs) == [ PackageSpec("ArduinoJson@6.19.3"), PackageSpec("DallasTemperature@3.9.1"), - PackageSpec("OneWire@2.3.6"), ]