diff options
Diffstat (limited to 'nixpkgs/pkgs/development/embedded/platformio')
6 files changed, 297 insertions, 0 deletions
diff --git a/nixpkgs/pkgs/development/embedded/platformio/chrootenv.nix b/nixpkgs/pkgs/development/embedded/platformio/chrootenv.nix new file mode 100644 index 000000000000..55adb0edaa75 --- /dev/null +++ b/nixpkgs/pkgs/development/embedded/platformio/chrootenv.nix @@ -0,0 +1,43 @@ +{ lib, buildFHSEnv, platformio-core }: + +let + pio-pkgs = pkgs: + let + inherit (platformio-core) python; + in + (with pkgs; [ + platformio-core + zlib + git + xdg-user-dirs + ncurses + ]) ++ (with python.pkgs; [ + python + setuptools + pip + bottle + ]); + +in +buildFHSEnv { + name = "platformio"; + + targetPkgs = pio-pkgs; + # disabled temporarily because fastdiff no longer support 32bit + # multiPkgs = pio-pkgs; + + meta = with lib; { + description = "An open source ecosystem for IoT development"; + homepage = "https://platformio.org"; + maintainers = with maintainers; [ mog ]; + license = licenses.asl20; + platforms = with platforms; linux; + }; + + extraInstallCommands = '' + ln -s $out/bin/platformio $out/bin/pio + ln -s ${platformio-core.udev}/lib $out/lib + ''; + + runScript = "platformio"; +} diff --git a/nixpkgs/pkgs/development/embedded/platformio/core.nix b/nixpkgs/pkgs/development/embedded/platformio/core.nix new file mode 100644 index 000000000000..82ccfa41c2f0 --- /dev/null +++ b/nixpkgs/pkgs/development/embedded/platformio/core.nix @@ -0,0 +1,190 @@ +{ lib +, python3Packages +, fetchFromGitHub +, fetchpatch +, git +, spdx-license-list-data +, substituteAll +}: + + +with python3Packages; buildPythonApplication rec { + pname = "platformio"; + version = "6.1.11"; + pyproject = true; + + # pypi tarballs don't contain tests - https://github.com/platformio/platformio-core/issues/1964 + src = fetchFromGitHub { + owner = "platformio"; + repo = "platformio-core"; + rev = "v${version}"; + hash = "sha256-NR4UyAt8q5sUGtz1Sy6E8Of7y9WrH9xpcAWzLBeDQmo="; + }; + + outputs = [ "out" "udev" ]; + + patches = [ + (substituteAll { + src = ./interpreter.patch; + interpreter = (python3Packages.python.withPackages (_: propagatedBuildInputs)).interpreter; + }) + (substituteAll { + src = ./use-local-spdx-license-list.patch; + spdx_license_list_data = spdx-license-list-data.json; + }) + ./missing-udev-rules-nixos.patch + (fetchpatch { + # restore PYTHONPATH when calling scons + # https://github.com/platformio/platformio-core/commit/097de2be98af533578671baa903a3ae825d90b94 + url = "https://github.com/platformio/platformio-core/commit/097de2be98af533578671baa903a3ae825d90b94.patch"; + hash = "sha256-yq+/QHCkhAkFND11MbKFiiWT3oF1cHhgWj5JkYjwuY0="; + revert = true; + }) + ]; + + nativeBuildInputs = [ + pythonRelaxDepsHook + setuptools + ]; + + pythonRelaxDeps = true; + + propagatedBuildInputs = [ + aiofiles + ajsonrpc + bottle + click + click-completion + colorama + git + lockfile + marshmallow + pyelftools + pyserial + requests + semantic-version + setuptools + spdx-license-list-data.json + starlette + tabulate + uvicorn + wsproto + zeroconf + + ]; + + preCheck = '' + export HOME=$(mktemp -d) + export PATH=$PATH:$out/bin + ''; + + nativeCheckInputs = [ + jsondiff + pytestCheckHook + ]; + + # Install udev rules into a separate output so all of platformio-core is not a dependency if + # you want to use the udev rules on NixOS but not install platformio in your system packages. + postInstall = '' + mkdir -p $udev/lib/udev/rules.d + cp platformio/assets/system/99-platformio-udev.rules $udev/lib/udev/rules.d/99-platformio-udev.rules + ''; + + disabledTestPaths = [ + "tests/commands/pkg/test_install.py" + "tests/commands/pkg/test_list.py" + "tests/commands/pkg/test_outdated.py" + "tests/commands/pkg/test_search.py" + "tests/commands/pkg/test_show.py" + "tests/commands/pkg/test_uninstall.py" + "tests/commands/pkg/test_update.py" + "tests/commands/test_boards.py" + "tests/commands/test_check.py" + "tests/commands/test_platform.py" + "tests/commands/test_run.py" + "tests/commands/test_test.py" + "tests/misc/test_maintenance.py" + # requires internet connection + "tests/misc/ino2cpp/test_ino2cpp.py" + ]; + + disabledTests = [ + # requires internet connection + "test_api_cache" + "test_ping_internet_ips" + ]; + + pytestFlagsArray = [ + "tests" + ] ++ (map (e: "--deselect tests/${e}") [ + "commands/pkg/test_exec.py::test_pkg_specified" + "commands/pkg/test_exec.py::test_unrecognized_options" + "commands/test_ci.py::test_ci_boards" + "commands/test_ci.py::test_ci_build_dir" + "commands/test_ci.py::test_ci_keep_build_dir" + "commands/test_ci.py::test_ci_lib_and_board" + "commands/test_ci.py::test_ci_project_conf" + "commands/test_init.py::test_init_custom_framework" + "commands/test_init.py::test_init_duplicated_boards" + "commands/test_init.py::test_init_enable_auto_uploading" + "commands/test_init.py::test_init_ide_atom" + "commands/test_init.py::test_init_ide_clion" + "commands/test_init.py::test_init_ide_eclipse" + "commands/test_init.py::test_init_ide_vscode" + "commands/test_init.py::test_init_incorrect_board" + "commands/test_init.py::test_init_special_board" + "commands/test_lib.py::test_global_install_archive" + "commands/test_lib.py::test_global_install_registry" + "commands/test_lib.py::test_global_install_repository" + "commands/test_lib.py::test_global_lib_list" + "commands/test_lib.py::test_global_lib_uninstall" + "commands/test_lib.py::test_global_lib_update" + "commands/test_lib.py::test_global_lib_update_check" + "commands/test_lib.py::test_install_duplicates" + "commands/test_lib.py::test_lib_show" + "commands/test_lib.py::test_lib_stats" + "commands/test_lib.py::test_saving_deps" + "commands/test_lib.py::test_search" + "commands/test_lib.py::test_update" + "commands/test_lib_complex.py::test_global_install_archive" + "commands/test_lib_complex.py::test_global_install_registry" + "commands/test_lib_complex.py::test_global_install_repository" + "commands/test_lib_complex.py::test_global_lib_list" + "commands/test_lib_complex.py::test_global_lib_uninstall" + "commands/test_lib_complex.py::test_global_lib_update" + "commands/test_lib_complex.py::test_global_lib_update_check" + "commands/test_lib_complex.py::test_install_duplicates" + "commands/test_lib_complex.py::test_lib_show" + "commands/test_lib_complex.py::test_lib_stats" + "commands/test_lib_complex.py::test_search" + "package/test_manager.py::test_download" + "package/test_manager.py::test_install_force" + "package/test_manager.py::test_install_from_registry" + "package/test_manager.py::test_install_lib_depndencies" + "package/test_manager.py::test_registry" + "package/test_manager.py::test_uninstall" + "package/test_manager.py::test_update_with_metadata" + "package/test_manager.py::test_update_without_metadata" + "test_builder.py::test_build_flags" + "test_builder.py::test_build_unflags" + "test_builder.py::test_debug_custom_build_flags" + "test_builder.py::test_debug_default_build_flags" + "test_misc.py::test_api_cache" + "test_misc.py::test_ping_internet_ips" + "test_misc.py::test_platformio_cli" + "test_pkgmanifest.py::test_packages" + ]); + + passthru = { + python = python3Packages.python; + }; + + meta = with lib; { + changelog = "https://github.com/platformio/platformio-core/releases/tag/v${version}"; + description = "An open source ecosystem for IoT development"; + downloadPage = "https://github.com/platformio/platformio-core"; + homepage = "https://platformio.org"; + license = licenses.asl20; + maintainers = with maintainers; [ mog makefu ]; + }; +} diff --git a/nixpkgs/pkgs/development/embedded/platformio/default.nix b/nixpkgs/pkgs/development/embedded/platformio/default.nix new file mode 100644 index 000000000000..956d7dee06cd --- /dev/null +++ b/nixpkgs/pkgs/development/embedded/platformio/default.nix @@ -0,0 +1,13 @@ +{ newScope, fetchFromGitHub, python3Packages }: + +let + callPackage = newScope self; + + self = { + platformio-core = python3Packages.callPackage ./core.nix { }; + + platformio-chrootenv = callPackage ./chrootenv.nix { }; + }; + +in +self diff --git a/nixpkgs/pkgs/development/embedded/platformio/interpreter.patch b/nixpkgs/pkgs/development/embedded/platformio/interpreter.patch new file mode 100644 index 000000000000..f7e212d57111 --- /dev/null +++ b/nixpkgs/pkgs/development/embedded/platformio/interpreter.patch @@ -0,0 +1,22 @@ +diff --git a/platformio/proc.py b/platformio/proc.py +index 707245a1..cae17a29 100644 +--- a/platformio/proc.py ++++ b/platformio/proc.py +@@ -165,7 +165,7 @@ def is_container(): + + + def get_pythonexe_path(): +- return os.environ.get("PYTHONEXEPATH", os.path.normpath(sys.executable)) ++ return "@interpreter@" + + + def copy_pythonpath_to_osenv(): +@@ -181,7 +181,7 @@ def copy_pythonpath_to_osenv(): + ) + if all(conditions): + _PYTHONPATH.append(p) +- os.environ["PYTHONPATH"] = os.pathsep.join(_PYTHONPATH) ++ os.environ["PYTHONPATH"] = os.pathsep.join(sys.path) + + + def where_is_program(program, envpath=None): diff --git a/nixpkgs/pkgs/development/embedded/platformio/missing-udev-rules-nixos.patch b/nixpkgs/pkgs/development/embedded/platformio/missing-udev-rules-nixos.patch new file mode 100644 index 000000000000..878470920577 --- /dev/null +++ b/nixpkgs/pkgs/development/embedded/platformio/missing-udev-rules-nixos.patch @@ -0,0 +1,12 @@ +diff --git a/platformio/exception.py b/platformio/exception.py +index 80ffb496..ea064f97 100644 +--- a/platformio/exception.py ++++ b/platformio/exception.py +@@ -49,6 +49,7 @@ class MissedUdevRules(InvalidUdevRules): + MESSAGE = ( + "Warning! Please install `99-platformio-udev.rules`. \nMore details: " + "https://docs.platformio.org/en/latest/core/installation/udev-rules.html" ++ "On NixOS set `services.udev.packages = with pkgs; [ platformio-core.udev ];`." + ) + + diff --git a/nixpkgs/pkgs/development/embedded/platformio/use-local-spdx-license-list.patch b/nixpkgs/pkgs/development/embedded/platformio/use-local-spdx-license-list.patch new file mode 100644 index 000000000000..ba9b55b788a1 --- /dev/null +++ b/nixpkgs/pkgs/development/embedded/platformio/use-local-spdx-license-list.patch @@ -0,0 +1,17 @@ +diff --git a/platformio/package/manifest/schema.py b/platformio/package/manifest/schema.py +index 95e08108..6c2cfaed 100644 +--- a/platformio/package/manifest/schema.py ++++ b/platformio/package/manifest/schema.py +@@ -276,9 +276,6 @@ class ManifestSchema(BaseSchema): + @staticmethod + @memoized(expire="1h") + def load_spdx_licenses(): +- version = "3.21" +- spdx_data_url = ( +- "https://raw.githubusercontent.com/spdx/license-list-data/" +- f"v{version}/json/licenses.json" +- ) +- return json.loads(fetch_remote_content(spdx_data_url)) ++ with open("@spdx_license_list_data@/json/licenses.json") as fd: ++ spdx = json.load(fd) ++ return spdx |