From 6e258102a12834f6eec60328de3cb617a77fae39 Mon Sep 17 00:00:00 2001 From: Florian Loitsch Date: Mon, 25 Sep 2023 10:40:08 +0200 Subject: [PATCH] Add option to tool to update patches. (#24) This only works when hunks are just slightly off. --- tools/main.toit | 51 +++++++++++++++++++ .../sdkconfig.defaults.patch | 8 +-- .../sdkconfig.defaults.patch | 4 +- .../sdkconfig.defaults.patch | 4 +- .../sdkconfig.defaults.patch | 18 +++++-- .../esp32-log-wifi/sdkconfig.defaults.patch | 8 +-- .../esp32-no-ble/sdkconfig.defaults.patch | 6 +-- variants/esp32-qemu/sdkconfig.defaults.patch | 4 +- 8 files changed, 81 insertions(+), 22 deletions(-) diff --git a/tools/main.toit b/tools/main.toit index 5e0d193..1682c47 100644 --- a/tools/main.toit +++ b/tools/main.toit @@ -64,6 +64,9 @@ main args: --required, cli.Flag "ignore-errors" --short_help="Ignore errors when synthesizing variants.", + cli.Flag "update-patches" + --short_help="Update the patches in the variants." + --hidden, ] --rest=[ cli.Option "variant" @@ -124,6 +127,7 @@ variant_synthesize parsed/cli.Parsed --ui/cli.Ui: variants_root := parsed["variants-root"] variants := parsed["variant"] ignore_errors := parsed["ignore-errors"] + update_patches := parsed["update-patches"] variants.do: | variant/string | exception := catch: @@ -133,6 +137,7 @@ variant_synthesize parsed/cli.Parsed --ui/cli.Ui: --output="$output_root/$variant" --build_path="$build_root/$variant" --sdk_path=sdk_path + --update_patches=update_patches --ui=ui if exception: ui.print "Failed to synthesize variant '$variant': $exception." @@ -148,6 +153,7 @@ variant_synthesize --output/string --build_path/string --sdk_path/string + --update_patches/bool --ui/cli.Ui: if file.is_file output: ui.print "Output is a file." @@ -175,6 +181,34 @@ variant_synthesize --chip=chip --ui=ui + if update_patches: + if file.is_file "$variant_path/partitions.csv.patch": + original := "$toit_root/$(toit_partition_path_for_ --chip=chip)" + patched := "$output/partitions.csv" + update_patch_ + --from=original + --to=patched + --output="$variant_path/partitions.csv.patch" + --ui=ui + + if file.is_file "$variant_path/sdkconfig.defaults.patch": + original := "$toit_root/$(toit_sdk_config_defaults_path_for_ --chip=chip)" + patched := "$output/sdkconfig.defaults" + update_patch_ + --from=original + --to=patched + --output="$variant_path/sdkconfig.defaults.patch" + --ui=ui + + if file.is_file "$variant_path/main.patch": + original := "$toit_root/$(toit_main_path_for_ --chip=chip)" + patched := "$output/main" + update_patch_ + --from=original + --to=patched + --output="$variant_path/main.patch" + --ui=ui + apply_directory_patch_ --patch_path/string --directory/string --strip/int=1: patch := file.read_content patch_path args := ["patch", "-d", directory] @@ -185,6 +219,13 @@ apply_directory_patch_ --patch_path/string --directory/string --strip/int=1: writer.write patch writer.close +// Same as $pipe.from but doesn't throw if the exit code is non-zero. +pipe_from arguments/List: + pipe_ends := pipe.OpenPipe false --child_process_name=arguments[0] + stdout := pipe_ends.fd + pipes := pipe.fork true pipe.PIPE_INHERITED stdout pipe.PIPE_INHERITED arguments[0] arguments + return pipe_ends + apply_file_patch_ --patch_path/string --file_path/string: patch := file.read_content patch_path args := ["patch", file_path] @@ -193,6 +234,16 @@ apply_file_patch_ --patch_path/string --file_path/string: writer.write patch writer.close +update_patch_ --from/string --to/string --output/string --ui/cli.Ui: + ui.print "Updating $output." + file.delete output + args := ["diff", "-aur", from, to] + stream := pipe_from args + writer := Writer (file.Stream.for_write output) + while chunk := stream.read: + writer.write chunk + writer.close + ensure_main_ dir/string --toit_root/string --chip/string: if file.is_directory "$dir/main": return main_path := toit_main_path_for_ --chip=chip diff --git a/variants/esp32-eth-clk-out0-spiram/sdkconfig.defaults.patch b/variants/esp32-eth-clk-out0-spiram/sdkconfig.defaults.patch index 754d97b..28b35e3 100644 --- a/variants/esp32-eth-clk-out0-spiram/sdkconfig.defaults.patch +++ b/variants/esp32-eth-clk-out0-spiram/sdkconfig.defaults.patch @@ -1,5 +1,5 @@ ---- toolchains/esp32/sdkconfig.defaults 2023-09-07 17:14:30.952105304 +0200 -+++ toolchains/esp32-eth-clk-out0-spiram/sdkconfig.defaults 2023-09-07 17:20:30.187515185 +0200 +--- toit/toolchains/esp32/sdkconfig.defaults 2023-09-20 11:21:44.091952700 +0200 ++++ synn/esp32-eth-clk-out0-spiram/sdkconfig.defaults 2023-09-21 21:26:45.724049931 +0200 @@ -31,12 +31,17 @@ # CONFIG_SPI_SLAVE_ISR_IN_IRAM is not set CONFIG_UART_ISR_IN_IRAM=y @@ -18,7 +18,7 @@ CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ_240=y # CONFIG_ESP_INT_WDT is not set # CONFIG_ESP_TASK_WDT_EN is not set -@@ -45,7 +49,6 @@ +@@ -45,7 +50,6 @@ CONFIG_ESP32_WIFI_DYNAMIC_TX_BUFFER_NUM=16 # CONFIG_ESP32_WIFI_NVS_ENABLED is not set CONFIG_ESP32_WIFI_TASK_PINNED_TO_CORE_1=y @@ -26,7 +26,7 @@ CONFIG_FATFS_LFN_HEAP=y CONFIG_FREERTOS_THREAD_LOCAL_STORAGE_POINTERS=3 CONFIG_FREERTOS_IDLE_TASK_STACKSIZE=1024 -@@ -77,4 +80,5 @@ +@@ -77,4 +81,5 @@ CONFIG_SPI_FLASH_LOG_FAILED_WRITE=y CONFIG_SPI_FLASH_WARN_SETTING_ZERO_TO_ONE=y # CONFIG_WS_TRANSPORT is not set diff --git a/variants/esp32-eth-clk-out0/sdkconfig.defaults.patch b/variants/esp32-eth-clk-out0/sdkconfig.defaults.patch index 859b069..ad47873 100644 --- a/variants/esp32-eth-clk-out0/sdkconfig.defaults.patch +++ b/variants/esp32-eth-clk-out0/sdkconfig.defaults.patch @@ -1,5 +1,5 @@ ---- toolchains/esp32/sdkconfig.defaults 2023-09-07 15:57:43.119413430 +0200 -+++ toolchains/esp32-eth-clk-out0/sdkconfig.defaults 2023-09-11 17:21:39.069585368 +0200 +--- toit/toolchains/esp32/sdkconfig.defaults 2023-09-20 11:21:44.091952700 +0200 ++++ synn/esp32-eth-clk-out0/sdkconfig.defaults 2023-09-21 21:26:45.687383858 +0200 @@ -31,6 +31,8 @@ # CONFIG_SPI_SLAVE_ISR_IN_IRAM is not set CONFIG_UART_ISR_IN_IRAM=y diff --git a/variants/esp32-eth-clk-out17-spiram/sdkconfig.defaults.patch b/variants/esp32-eth-clk-out17-spiram/sdkconfig.defaults.patch index d666b34..99dfb4b 100644 --- a/variants/esp32-eth-clk-out17-spiram/sdkconfig.defaults.patch +++ b/variants/esp32-eth-clk-out17-spiram/sdkconfig.defaults.patch @@ -1,5 +1,5 @@ ---- toolchains/esp32/sdkconfig.defaults 2023-09-07 17:14:30.952105304 +0200 -+++ toolchains/esp32-eth-clk-out17-spiram/sdkconfig.defaults 2023-09-07 17:20:30.187515185 +0200 +--- toit/toolchains/esp32/sdkconfig.defaults 2023-09-20 11:21:44.091952700 +0200 ++++ synn/esp32-eth-clk-out17-spiram/sdkconfig.defaults 2023-09-21 21:26:45.557385967 +0200 @@ -31,12 +31,16 @@ # CONFIG_SPI_SLAVE_ISR_IN_IRAM is not set CONFIG_UART_ISR_IN_IRAM=y diff --git a/variants/esp32-eth-clk-out17/sdkconfig.defaults.patch b/variants/esp32-eth-clk-out17/sdkconfig.defaults.patch index d7af863..6b438d0 100644 --- a/variants/esp32-eth-clk-out17/sdkconfig.defaults.patch +++ b/variants/esp32-eth-clk-out17/sdkconfig.defaults.patch @@ -1,5 +1,13 @@ -41a42,45 -> # CONFIG_ETH_RMII_CLK_INPUT is not set -> CONFIG_ETH_RMII_CLK_OUTPUT=y -> # CONFIG_ETH_RMII_CLK_OUTPUT_GPIO0 is not set -> CONFIG_ETH_RMII_CLK_OUT_GPIO=17 +--- toit/toolchains/esp32/sdkconfig.defaults 2023-09-20 11:21:44.091952700 +0200 ++++ synn/esp32-eth-clk-out17/sdkconfig.defaults 2023-09-21 21:26:45.540719572 +0200 +@@ -39,6 +39,10 @@ + # CONFIG_ESP_PHY_CALIBRATION_AND_DATA_STORAGE is not set + CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ_240=y + # CONFIG_ESP_INT_WDT is not set ++# CONFIG_ETH_RMII_CLK_INPUT is not set ++CONFIG_ETH_RMII_CLK_OUTPUT=y ++# CONFIG_ETH_RMII_CLK_OUTPUT_GPIO0 is not set ++CONFIG_ETH_RMII_CLK_OUT_GPIO=17 + # CONFIG_ESP_TASK_WDT_EN is not set + # CONFIG_ESP_DEBUG_OCDAWARE is not set + CONFIG_ESP32_WIFI_DYNAMIC_RX_BUFFER_NUM=16 diff --git a/variants/esp32-log-wifi/sdkconfig.defaults.patch b/variants/esp32-log-wifi/sdkconfig.defaults.patch index d8aedee..93795b5 100644 --- a/variants/esp32-log-wifi/sdkconfig.defaults.patch +++ b/variants/esp32-log-wifi/sdkconfig.defaults.patch @@ -1,6 +1,6 @@ ---- toolchains/esp32/sdkconfig.defaults 2023-08-31 18:38:18.473937304 +0200 -+++ toolchains/esp32-log-wifi/sdkconfig.defaults 2023-09-05 13:20:04.990901463 +0200 -@@ -54,7 +54,7 @@ +--- toit/toolchains/esp32/sdkconfig.defaults 2023-09-20 11:21:44.091952700 +0200 ++++ synn/esp32-log-wifi/sdkconfig.defaults 2023-09-21 21:26:45.744049606 +0200 +@@ -53,7 +53,7 @@ CONFIG_FREERTOS_ISR_STACKSIZE=2096 CONFIG_FREERTOS_PLACE_FUNCTIONS_INTO_FLASH=y # CONFIG_FREERTOS_ENABLE_TASK_SNAPSHOT is not set @@ -9,7 +9,7 @@ # CONFIG_LOG_COLORS is not set CONFIG_LWIP_LOCAL_HOSTNAME="toit" # CONFIG_LWIP_DNS_SUPPORT_MDNS_QUERIES is not set -@@ -78,4 +78,5 @@ +@@ -77,4 +77,5 @@ CONFIG_SPI_FLASH_LOG_FAILED_WRITE=y CONFIG_SPI_FLASH_WARN_SETTING_ZERO_TO_ONE=y # CONFIG_WS_TRANSPORT is not set diff --git a/variants/esp32-no-ble/sdkconfig.defaults.patch b/variants/esp32-no-ble/sdkconfig.defaults.patch index 862d9df..f45a0bb 100644 --- a/variants/esp32-no-ble/sdkconfig.defaults.patch +++ b/variants/esp32-no-ble/sdkconfig.defaults.patch @@ -1,5 +1,5 @@ ---- toolchains/esp32/sdkconfig.defaults -+++ toolchains/esp32-no-ble/sdkconfig.defaults +--- toit/toolchains/esp32/sdkconfig.defaults 2023-09-20 11:21:44.091952700 +0200 ++++ synn/esp32-no-ble/sdkconfig.defaults 2023-09-21 21:26:45.760716002 +0200 @@ -9,23 +9,6 @@ CONFIG_PARTITION_TABLE_CUSTOM=y CONFIG_COMPILER_OPTIMIZATION_SIZE=y @@ -34,7 +34,7 @@ CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ_240=y # CONFIG_ESP_INT_WDT is not set # CONFIG_ESP_TASK_WDT_EN is not set -@@ -78,4 +64,3 @@ +@@ -77,4 +63,3 @@ CONFIG_SPI_FLASH_LOG_FAILED_WRITE=y CONFIG_SPI_FLASH_WARN_SETTING_ZERO_TO_ONE=y # CONFIG_WS_TRANSPORT is not set diff --git a/variants/esp32-qemu/sdkconfig.defaults.patch b/variants/esp32-qemu/sdkconfig.defaults.patch index 5596fe2..9624ecb 100644 --- a/variants/esp32-qemu/sdkconfig.defaults.patch +++ b/variants/esp32-qemu/sdkconfig.defaults.patch @@ -1,5 +1,5 @@ ---- toolchains/esp32/sdkconfig.defaults 2023-08-29 10:53:18.779468609 +0200 -+++ toolchains/esp32-qemu/sdkconfig.defaults 2023-08-29 10:54:22.488425944 +0200 +--- toit/toolchains/esp32/sdkconfig.defaults 2023-09-20 11:21:44.091952700 +0200 ++++ synn/esp32-qemu/sdkconfig.defaults 2023-09-21 21:26:45.594052040 +0200 @@ -33,6 +33,7 @@ # CONFIG_ESP_ERR_TO_NAME_LOOKUP is not set CONFIG_ETH_SPI_ETHERNET_DM9051=y