Skip to content

Commit

Permalink
Add option to tool to update patches. (#24)
Browse files Browse the repository at this point in the history
This only works when hunks are just slightly off.
  • Loading branch information
floitsch authored Sep 25, 2023
1 parent 8c01a91 commit 6e25810
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 22 deletions.
51 changes: 51 additions & 0 deletions tools/main.toit
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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:
Expand All @@ -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."
Expand All @@ -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."
Expand Down Expand Up @@ -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]
Expand All @@ -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]
Expand All @@ -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
Expand Down
8 changes: 4 additions & 4 deletions variants/esp32-eth-clk-out0-spiram/sdkconfig.defaults.patch
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -18,15 +18,15 @@
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
-# CONFIG_ESP32_WIFI_IRAM_OPT is not set
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
Expand Down
4 changes: 2 additions & 2 deletions variants/esp32-eth-clk-out0/sdkconfig.defaults.patch
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions variants/esp32-eth-clk-out17-spiram/sdkconfig.defaults.patch
Original file line number Diff line number Diff line change
@@ -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
Expand Down
18 changes: 13 additions & 5 deletions variants/esp32-eth-clk-out17/sdkconfig.defaults.patch
Original file line number Diff line number Diff line change
@@ -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
8 changes: 4 additions & 4 deletions variants/esp32-log-wifi/sdkconfig.defaults.patch
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions variants/esp32-no-ble/sdkconfig.defaults.patch
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions variants/esp32-qemu/sdkconfig.defaults.patch
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 6e25810

Please sign in to comment.