From a903b4dcc547e7c9c31504e3f226d2152d8122c2 Mon Sep 17 00:00:00 2001 From: Sergey Fedorov Date: Tue, 7 Jan 2025 06:16:00 +0800 Subject: [PATCH 10/16] Record patches in statefile Credits @RJVB --- src/port1.0/portpatch.tcl | 32 +++++++++++++++++++------------- src/port1.0/portutil.tcl | 12 ++++++++++-- 2 files changed, 29 insertions(+), 15 deletions(-) diff --git a/src/port1.0/portpatch.tcl b/src/port1.0/portpatch.tcl index 42dbbd227..3e61a230f 100644 --- a/src/port1.0/portpatch.tcl +++ b/src/port1.0/portpatch.tcl @@ -68,7 +68,7 @@ proc portpatch::build_getpatchtype {args} { } proc portpatch::patch_main {args} { - global UI_PREFIX + global UI_PREFIX target_state_fd # First make sure that patchfiles exists and isn't stubbed out. if {![exists patchfiles] || [option patchfiles] eq ""} { @@ -96,18 +96,24 @@ proc portpatch::patch_main {args} { catch {set xzcat "[findBinary xz $portutil::autoconf::xz_path] -dc"} foreach patch $patchlist { - ui_info "$UI_PREFIX [format [msgcat::mc "Applying %s"] [file tail $patch]]" - switch -- [file extension $patch] { - .Z - - .gz {command_exec patch "$gzcat \"$patch\" | (" ")"} - .bz2 {command_exec patch "$bzcat \"$patch\" | (" ")"} - .xz { - if {[info exists xzcat]} { - command_exec patch "$xzcat \"$patch\" | (" ")" - } else { - return -code error [msgcat::mc "xz binary not found; port needs to add 'depends_patch bin:xz:xz'"] - }} - default {command_exec patch "" "< '$patch'"} + set pfile [file tail $patch] + if {![check_statefile patch $pfile $target_state_fd]} { + ui_info "$UI_PREFIX [format [msgcat::mc "Applying %s"] [file tail $patch]]" + switch -- [file extension $patch] { + .Z - + .gz {command_exec patch "$gzcat \"$patch\" | (" ")"} + .bz2 {command_exec patch "$bzcat \"$patch\" | (" ")"} + .xz { + if {[info exists xzcat]} { + command_exec patch "$xzcat \"$patch\" | (" ")" + } else { + return -code error [msgcat::mc "xz binary not found; port needs to add 'depends_patch bin:xz:xz'"] + }} + default {command_exec patch "" "< '$patch'"} + } + write_statefile patch $pfile $target_state_fd + } else { + ui_info "$UI_PREFIX [format [msgcat::mc "Skipping already applied %s"] $pfile]" } } return 0 diff --git a/src/port1.0/portutil.tcl b/src/port1.0/portutil.tcl index fd3f002b8..bf11e794f 100644 --- a/src/port1.0/portutil.tcl +++ b/src/port1.0/portutil.tcl @@ -1889,7 +1889,11 @@ proc get_statefile_value {class fd result} { # check_statefile # Check completed/selected state of target/variant $id -proc check_statefile {class id fd} { +proc check_statefile {class id {fd {}}} { + global target_state_fd + if {$fd eq {} && [info exists target_state_fd]} { + set fd $target_state_fd + } seek $fd 0 while {[gets $fd line] >= 0} { if {$line eq "$class: $id"} { @@ -1901,7 +1905,11 @@ proc check_statefile {class id fd} { # write_statefile # Set target $id completed in the state file -proc write_statefile {class id fd} { +proc write_statefile {class id {fd {}}} { + global target_state_fd + if {$fd eq {} && [info exists target_state_fd]} { + set fd $target_state_fd + } if {[check_statefile $class $id $fd]} { return 0 }