From 4884ac130816156095e69544257701fc620d4b36 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Sch=C3=BCtz?= Date: Tue, 17 May 2022 20:24:54 +0000 Subject: [PATCH 1/3] esptool: 3.3.1 -> 4.4 --- pkgs/tools/misc/esptool/default.nix | 30 +++---- .../misc/esptool/test-call-bin-directly.patch | 89 +++++++++++++++++++ 2 files changed, 100 insertions(+), 19 deletions(-) create mode 100644 pkgs/tools/misc/esptool/test-call-bin-directly.patch diff --git a/pkgs/tools/misc/esptool/default.nix b/pkgs/tools/misc/esptool/default.nix index e48e02694052..609c5d74c79e 100644 --- a/pkgs/tools/misc/esptool/default.nix +++ b/pkgs/tools/misc/esptool/default.nix @@ -1,20 +1,22 @@ -{ lib, fetchFromGitHub, python3, openssl }: +{ lib +, fetchFromGitHub +, python3 +}: python3.pkgs.buildPythonApplication rec { pname = "esptool"; - version = "3.3.1"; + version = "4.4"; src = fetchFromGitHub { owner = "espressif"; repo = "esptool"; rev = "v${version}"; - hash = "sha256-9WmiLji7Zoad5WIzgkpvkI9t96sfdkCtFh6zqVxF7qo="; + hash = "sha256-haLwf3loOvqdqQN/iuVBciQ6nCnuc9AqqOGKvDwLBHE="; }; - postPatch = '' - substituteInPlace test/test_imagegen.py \ - --replace "sys.executable, ESPTOOL_PY" "ESPTOOL_PY" - ''; + patches = [ + ./test-call-bin-directly.patch + ]; propagatedBuildInputs = with python3.pkgs; [ bitstring @@ -24,26 +26,16 @@ python3.pkgs.buildPythonApplication rec { reedsolo ]; - # wrapPythonPrograms will overwrite esptool.py with a bash script, - # but espefuse.py tries to import it. Since we don't add any binary paths, - # use patchPythonScript directly. - dontWrapPythonPrograms = true; - postFixup = '' - buildPythonPath "$out $pythonPath" - for f in $out/bin/*.py; do - echo "Patching $f" - patchPythonScript "$f" - done - ''; - checkInputs = with python3.pkgs; [ pyelftools + pytest ]; # tests mentioned in `.github/workflows/test_esptool.yml` checkPhase = '' runHook preCheck + export ESPSECURE_PY=$out/bin/espsecure.py export ESPTOOL_PY=$out/bin/esptool.py ${python3.interpreter} test/test_imagegen.py ${python3.interpreter} test/test_espsecure.py diff --git a/pkgs/tools/misc/esptool/test-call-bin-directly.patch b/pkgs/tools/misc/esptool/test-call-bin-directly.patch new file mode 100644 index 000000000000..b7d772780090 --- /dev/null +++ b/pkgs/tools/misc/esptool/test-call-bin-directly.patch @@ -0,0 +1,89 @@ +diff --git a/test/test_espsecure.py b/test/test_espsecure.py +index 25b0b87..627005c 100755 +--- a/test/test_espsecure.py ++++ b/test/test_espsecure.py +@@ -35,7 +35,7 @@ class EspSecureTestCase: + Returns output as a string if there is any, + raises an exception if espsecure.py fails + """ +- cmd = [sys.executable, ESPSECURE_PY] + args.split(" ") ++ cmd = [ESPSECURE_PY] + args.split(" ") + print("\nExecuting {}...".format(" ".join(cmd))) + + try: +diff --git a/test/test_esptool.py b/test/test_esptool.py +index 042a1ce..b294e26 100755 +--- a/test/test_esptool.py ++++ b/test/test_esptool.py +@@ -57,7 +57,10 @@ try: + ESPTOOL_PY = os.environ["ESPTOOL_PY"] + except KeyError: + ESPTOOL_PY = os.path.join(TEST_DIR, "..", "esptool/__init__.py") +-ESPSECURE_PY = os.path.join(TEST_DIR, "..", "espsecure/__init__.py") ++try: ++ ESPSECURE_PY = os.environ["ESPSECURE_PY"] ++except KeyError: ++ ESPSECURE_PY = os.path.join(TEST_DIR, "..", "espsecure/__init__.py") + ESPRFC2217SERVER_PY = os.path.join(TEST_DIR, "..", "esp_rfc2217_server.py") + + RETURN_CODE_FATAL_ERROR = 2 +@@ -74,7 +77,6 @@ class ESPRFC2217Server(object): + def __init__(self, rfc2217_port=None): + self.port = rfc2217_port or self.get_free_port() + self.cmd = [ +- sys.executable, + ESPRFC2217SERVER_PY, + "-p", + str(self.port), +@@ -130,7 +132,7 @@ class ESPRFC2217Server(object): + class EsptoolTestCase: + def run_espsecure(self, args): + +- cmd = [sys.executable, ESPSECURE_PY] + args.split(" ") ++ cmd = [ESPSECURE_PY] + args.split(" ") + print("\nExecuting {}...".format(" ".join(cmd))) + try: + output = subprocess.check_output( +@@ -155,7 +157,7 @@ class EsptoolTestCase: + Raises an exception if esptool.py fails. + """ + trace_args = ["--trace"] if arg_trace else [] +- cmd = [sys.executable, ESPTOOL_PY] + trace_args ++ cmd = [ESPTOOL_PY] + trace_args + if chip_name or arg_chip is not None and chip_name != "auto": + cmd += ["--chip", chip_name or arg_chip] + if rfc2217_port or arg_port is not None: +diff --git a/test/test_imagegen.py b/test/test_imagegen.py +index a1feec2..01bd59c 100755 +--- a/test/test_imagegen.py ++++ b/test/test_imagegen.py +@@ -108,7 +108,7 @@ class BaseTestCase: + Run esptool.py image_info on a binary file, + assert no red flags about contents. + """ +- cmd = [sys.executable, ESPTOOL_PY, "--chip", chip, "image_info", binpath] ++ cmd = [ESPTOOL_PY, "--chip", chip, "image_info", binpath] + try: + output = subprocess.check_output(cmd) + output = output.decode("utf-8") +@@ -123,7 +123,7 @@ class BaseTestCase: + + def run_elf2image(self, chip, elf_path, version=None, extra_args=[]): + """Run elf2image on elf_path""" +- cmd = [sys.executable, ESPTOOL_PY, "--chip", chip, "elf2image"] ++ cmd = [ESPTOOL_PY, "--chip", chip, "elf2image"] + if version is not None: + cmd += ["--version", str(version)] + cmd += [elf_path] + extra_args +diff --git a/test/test_merge_bin.py b/test/test_merge_bin.py +index 8230069..2df5f8c 100755 +--- a/test/test_merge_bin.py ++++ b/test/test_merge_bin.py +@@ -39,7 +39,6 @@ class TestMergeBin: + output_file.close() + + cmd = [ +- sys.executable, + ESPTOOL_PY, + "--chip", + chip, From df6b943ad047cdfac3d6a82a339d0572a0db2cd0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Sch=C3=BCtz?= Date: Sun, 27 Nov 2022 12:25:03 -0800 Subject: [PATCH 2/3] esptool_3: init at 3.3.2 --- pkgs/tools/misc/esptool/3.nix | 63 +++++++++++++++++++++++++++++++++ pkgs/top-level/all-packages.nix | 2 ++ 2 files changed, 65 insertions(+) create mode 100644 pkgs/tools/misc/esptool/3.nix diff --git a/pkgs/tools/misc/esptool/3.nix b/pkgs/tools/misc/esptool/3.nix new file mode 100644 index 000000000000..3ffa79b8c8bb --- /dev/null +++ b/pkgs/tools/misc/esptool/3.nix @@ -0,0 +1,63 @@ +{ lib, fetchFromGitHub, python3, openssl }: + +python3.pkgs.buildPythonApplication rec { + pname = "esptool"; + version = "3.3.2"; + + src = fetchFromGitHub { + owner = "espressif"; + repo = "esptool"; + rev = "v${version}"; + hash = "sha256-hpPL9KNPA+S57SJoKnQewBCOybDbKep0t5RKw9a9GjM="; + }; + + postPatch = '' + substituteInPlace test/test_imagegen.py \ + --replace "sys.executable, ESPTOOL_PY" "ESPTOOL_PY" + ''; + + propagatedBuildInputs = with python3.pkgs; [ + bitstring + cryptography + ecdsa + pyserial + reedsolo + ]; + + # wrapPythonPrograms will overwrite esptool.py with a bash script, + # but espefuse.py tries to import it. Since we don't add any binary paths, + # use patchPythonScript directly. + dontWrapPythonPrograms = true; + postFixup = '' + buildPythonPath "$out $pythonPath" + for f in $out/bin/*.py; do + echo "Patching $f" + patchPythonScript "$f" + done + ''; + + checkInputs = with python3.pkgs; [ + pyelftools + ]; + + # tests mentioned in `.github/workflows/test_esptool.yml` + checkPhase = '' + runHook preCheck + + export ESPTOOL_PY=$out/bin/esptool.py + ${python3.interpreter} test/test_imagegen.py + ${python3.interpreter} test/test_espsecure.py + ${python3.interpreter} test/test_merge_bin.py + ${python3.interpreter} test/test_modules.py + + runHook postCheck + ''; + + meta = with lib; { + description = "ESP8266 and ESP32 serial bootloader utility"; + homepage = "https://github.com/espressif/esptool"; + license = licenses.gpl2Plus; + maintainers = with maintainers; [ hexa ]; + platforms = platforms.linux; + }; +} diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 2ef429e339d9..d76d2362c8c4 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -3987,6 +3987,8 @@ with pkgs; esptool = callPackage ../tools/misc/esptool { }; + esptool_3 = callPackage ../tools/misc/esptool/3.nix { }; + esptool-ck = callPackage ../tools/misc/esptool-ck { }; ephemeralpg = callPackage ../development/tools/database/ephemeralpg {}; From 10492770b2e395d33099df87755821f212a73a2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Sch=C3=BCtz?= Date: Sun, 27 Nov 2022 12:27:41 -0800 Subject: [PATCH 3/3] esphome: use esptool_3 --- pkgs/tools/misc/esphome/default.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkgs/tools/misc/esphome/default.nix b/pkgs/tools/misc/esphome/default.nix index a214a210d78f..607db114d9fb 100644 --- a/pkgs/tools/misc/esphome/default.nix +++ b/pkgs/tools/misc/esphome/default.nix @@ -2,7 +2,7 @@ , python3 , fetchFromGitHub , platformio -, esptool +, esptool_3 , git }: @@ -66,7 +66,7 @@ with python.pkgs; buildPythonApplication rec { # platformio is used in esphomeyaml/platformio_api.py # esptool is used in esphomeyaml/__main__.py # git is used in esphomeyaml/writer.py - "--prefix PATH : ${lib.makeBinPath [ platformio esptool git ]}" + "--prefix PATH : ${lib.makeBinPath [ platformio esptool_3 git ]}" "--set ESPHOME_USE_SUBPROCESS ''" ];