mirror of
https://github.com/platformio/platformio-core.git
synced 2025-07-30 10:07:14 +02:00
Save tool deps into the "platformio.ini" // Issue #3373
This commit is contained in:
@ -115,9 +115,7 @@ def install_project_env_dependencies(project_env, options=None):
|
||||
)
|
||||
# custom tools
|
||||
if options.get("tools"):
|
||||
installed_conds.append(
|
||||
_install_project_env_custom_tools(project_env, options)
|
||||
)
|
||||
installed_conds.append(_install_project_env_custom_tools(project_env, options))
|
||||
# custom ibraries
|
||||
if options.get("libraries"):
|
||||
installed_conds.append(
|
||||
@ -176,14 +174,25 @@ def _install_project_env_custom_tools(project_env, options):
|
||||
tm = ToolPackageManager()
|
||||
if not options.get("silent"):
|
||||
tm.set_log_level(logging.DEBUG)
|
||||
for spec in options.get("tools"):
|
||||
specs_to_save = []
|
||||
for tool in options.get("tools"):
|
||||
spec = PackageSpec(tool)
|
||||
if not tm.get_package(spec):
|
||||
already_up_to_date = False
|
||||
tm.install(
|
||||
pkg = tm.install(
|
||||
spec,
|
||||
skip_dependencies=options.get("skip_dependencies"),
|
||||
force=options.get("force"),
|
||||
)
|
||||
specs_to_save.append(_pkg_to_save_spec(pkg, spec))
|
||||
if not options.get("no_save") and specs_to_save:
|
||||
save_project_dependencies(
|
||||
os.getcwd(),
|
||||
specs_to_save,
|
||||
scope="platform_packages",
|
||||
action="add",
|
||||
environments=[project_env],
|
||||
)
|
||||
return not already_up_to_date
|
||||
|
||||
|
||||
|
@ -179,6 +179,7 @@ def test_custom_project_libraries(
|
||||
# do not expect any platforms/tools
|
||||
assert not os.path.exists(config.get("platformio", "platforms_dir"))
|
||||
assert not os.path.exists(config.get("platformio", "packages_dir"))
|
||||
|
||||
# check saved deps
|
||||
assert config.get("env:devkit", "lib_deps") == [
|
||||
"bblanchon/ArduinoJson@^6.19.2",
|
||||
@ -249,6 +250,26 @@ def test_custom_project_tools(
|
||||
# do not expect any platforms
|
||||
assert not os.path.exists(config.get("platformio", "platforms_dir"))
|
||||
|
||||
# check saved deps
|
||||
assert config.get("env:devkit", "platform_packages") == [
|
||||
"platformio/tool-openocd@^2.1100.211028",
|
||||
]
|
||||
|
||||
# install tool without saving to config
|
||||
result = clirunner.invoke(
|
||||
package_install_cmd,
|
||||
["-e", "devkit", "-t", "platformio/tool-esptoolpy@1.20310.0", "--no-save"],
|
||||
)
|
||||
validate_cliresult(result)
|
||||
config = ProjectConfig()
|
||||
assert pkgs_to_names(ToolPackageManager().get_installed()) == [
|
||||
"tool-esptoolpy",
|
||||
"tool-openocd",
|
||||
]
|
||||
assert config.get("env:devkit", "platform_packages") == [
|
||||
"platformio/tool-openocd@^2.1100.211028",
|
||||
]
|
||||
|
||||
# unknown tool
|
||||
result = clirunner.invoke(
|
||||
package_install_cmd, ["-t", "platformio/unknown_tool"]
|
||||
|
@ -22,20 +22,25 @@ board = uno
|
||||
framework = arduino
|
||||
lib_deps =
|
||||
SPI
|
||||
platform_packages =
|
||||
platformio/tool-jlink@^1.75001.0
|
||||
|
||||
[env:bare]
|
||||
|
||||
[env:release]
|
||||
platform = platformio/atmelavr
|
||||
platform = platformio/espressif32
|
||||
lib_deps =
|
||||
milesburton/DallasTemperature@^3.8
|
||||
|
||||
[env:debug]
|
||||
platform = platformio/atmelavr@^3.4.0
|
||||
platform = platformio/espressif32@^3.4.0
|
||||
lib_deps =
|
||||
${env.lib_deps}
|
||||
milesburton/DallasTemperature@^3.9.1
|
||||
bblanchon/ArduinoJson
|
||||
platform_packages =
|
||||
${env.platform_packages}
|
||||
platformio/framework-arduinoespressif32 @ https://github.com/espressif/arduino-esp32.git
|
||||
"""
|
||||
|
||||
|
||||
@ -124,3 +129,96 @@ def test_save_libraries(tmp_path):
|
||||
]
|
||||
assert config.get("env:bare", "lib_deps") == ["SPI"]
|
||||
assert config.get("env:release", "lib_deps") == ["SPI"]
|
||||
|
||||
|
||||
def test_save_tools(tmp_path):
|
||||
project_dir = tmp_path / "project"
|
||||
project_dir.mkdir()
|
||||
(project_dir / "platformio.ini").write_text(PROJECT_CONFIG_TPL)
|
||||
specs = [
|
||||
PackageSpec("platformio/framework-espidf@^2"),
|
||||
PackageSpec("platformio/tool-esptoolpy"),
|
||||
]
|
||||
|
||||
# add to the sepcified environment
|
||||
save_project_dependencies(
|
||||
str(project_dir),
|
||||
specs,
|
||||
scope="platform_packages",
|
||||
action="add",
|
||||
environments=["debug"],
|
||||
)
|
||||
config = ProjectConfig.get_instance(str(project_dir / "platformio.ini"))
|
||||
assert config.get("env:debug", "platform_packages") == [
|
||||
"platformio/tool-jlink@^1.75001.0",
|
||||
"platformio/framework-arduinoespressif32 @ https://github.com/espressif/arduino-esp32.git",
|
||||
"platformio/framework-espidf@^2",
|
||||
"platformio/tool-esptoolpy",
|
||||
]
|
||||
assert config.get("env:bare", "platform_packages") == [
|
||||
"platformio/tool-jlink@^1.75001.0"
|
||||
]
|
||||
assert config.get("env:release", "platform_packages") == [
|
||||
"platformio/tool-jlink@^1.75001.0"
|
||||
]
|
||||
|
||||
# add to the the all environments
|
||||
save_project_dependencies(
|
||||
str(project_dir), specs, scope="platform_packages", action="add"
|
||||
)
|
||||
config = ProjectConfig.get_instance(str(project_dir / "platformio.ini"))
|
||||
assert config.get("env:debug", "platform_packages") == [
|
||||
"platformio/tool-jlink@^1.75001.0",
|
||||
"platformio/framework-arduinoespressif32 @ https://github.com/espressif/arduino-esp32.git",
|
||||
"platformio/framework-espidf@^2",
|
||||
"platformio/tool-esptoolpy",
|
||||
]
|
||||
assert config.get("env:bare", "platform_packages") == [
|
||||
"platformio/framework-espidf@^2",
|
||||
"platformio/tool-esptoolpy",
|
||||
]
|
||||
assert config.get("env:release", "platform_packages") == [
|
||||
"platformio/framework-espidf@^2",
|
||||
"platformio/tool-esptoolpy",
|
||||
]
|
||||
|
||||
# remove deps from env
|
||||
save_project_dependencies(
|
||||
str(project_dir),
|
||||
[PackageSpec("platformio/framework-espidf")],
|
||||
scope="platform_packages",
|
||||
action="remove",
|
||||
environments=["release"],
|
||||
)
|
||||
config = ProjectConfig.get_instance(str(project_dir / "platformio.ini"))
|
||||
assert config.get("env:release", "platform_packages") == [
|
||||
"platformio/tool-esptoolpy",
|
||||
]
|
||||
# invalid requirements
|
||||
save_project_dependencies(
|
||||
str(project_dir),
|
||||
[PackageSpec("platformio/tool-esptoolpy@9.9.9")],
|
||||
scope="platform_packages",
|
||||
action="remove",
|
||||
environments=["release"],
|
||||
)
|
||||
config = ProjectConfig.get_instance(str(project_dir / "platformio.ini"))
|
||||
assert config.get("env:release", "platform_packages") == [
|
||||
"platformio/tool-jlink@^1.75001.0",
|
||||
]
|
||||
|
||||
# remove deps from all envs
|
||||
save_project_dependencies(
|
||||
str(project_dir), specs, scope="platform_packages", action="remove"
|
||||
)
|
||||
config = ProjectConfig.get_instance(str(project_dir / "platformio.ini"))
|
||||
assert config.get("env:debug", "platform_packages") == [
|
||||
"platformio/tool-jlink@^1.75001.0",
|
||||
"platformio/framework-arduinoespressif32 @ https://github.com/espressif/arduino-esp32.git",
|
||||
]
|
||||
assert config.get("env:bare", "platform_packages") == [
|
||||
"platformio/tool-jlink@^1.75001.0"
|
||||
]
|
||||
assert config.get("env:release", "platform_packages") == [
|
||||
"platformio/tool-jlink@^1.75001.0"
|
||||
]
|
||||
|
Reference in New Issue
Block a user