Revision: 10565 https://osdn.net/projects/ttssh2/scm/svn/commits/10565 Author: zmatsuo Date: 2023-02-03 00:21:39 +0900 (Fri, 03 Feb 2023) Log Message: ----------- svnrel.pl の出力ファイルの更新を不要なら行わないよう修正 - 出力ファイルがすでに存在して、更新後も同一の場合は上書きしないようにした - ただし日時に関する部分は比較対象外 - --overwriteオプション追加 Modified Paths: -------------- trunk/buildtools/svnrev/svnrev.cmake trunk/buildtools/svnrev/svnrev.pl -------------- next part -------------- Modified: trunk/buildtools/svnrev/svnrev.cmake =================================================================== --- trunk/buildtools/svnrev/svnrev.cmake 2023-02-02 15:21:29 UTC (rev 10564) +++ trunk/buildtools/svnrev/svnrev.cmake 2023-02-02 15:21:39 UTC (rev 10565) @@ -19,6 +19,11 @@ if((DEFINED GIT_EXECUTABLE) AND (DEFINED ${GIT_EXECUTABLE})) list(APPEND ARGS "--git" "${GIT_EXECUTABLE}") endif() +if((${SVNREV_PL} IS_NEWER_THAN ${SVNVERSION_H}) OR + (${SVNREV_PL} IS_NEWER_THAN ${BUILD_CONFIG})) + # 出力ファイルが古い(or存在しない)時は上書き指定 + list(APPEND ARGS "--overwrite") +endif() if(0) message("PERL=${PERL}") Modified: trunk/buildtools/svnrev/svnrev.pl =================================================================== --- trunk/buildtools/svnrev/svnrev.pl 2023-02-02 15:21:29 UTC (rev 10564) +++ trunk/buildtools/svnrev/svnrev.pl 2023-02-02 15:21:39 UTC (rev 10565) @@ -21,6 +21,7 @@ my $verbose = 0; my $script_name = $0; my $header = "This file was generated by buildtools/svnrev/svnrev.pl"; +my $overwrite = 0; my %svninfo = ( name => '', release => 0, @@ -91,6 +92,43 @@ print "BRANCH_NAME $info{'name'}\n"; } +sub read_whole_file { + my $fname = shift; + open(my $FD, '<', $fname) or die "error open $fname"; + + my $text; + while (<$FD>) { + if (/DATE/ || /TIME/) { + ; #pass + } else { + $text .= $_; + } + } + close $FD; + return $text; +} + +sub compare_file { + my ($f1, $f2) = @_; + if (! -f $f1) { + print "$f1 not exsit\n"; + return 1; + } + if (! -f $f2) { + print "$f2 not exsit\n"; + return 1; + } + my $t1 = read_whole_file($f1); + my $t2 = read_whole_file($f2); + if ($t1 eq $t2) { + # return same + print "$f1=$f2\n"; + return 0; + } + print "$f1 not equal $f2\n"; + return 1; +} + sub write_info_header { my ($out_header, %svninfo) = @_; my $revision = $svninfo{'Revision'}; @@ -151,27 +189,6 @@ close($FD); } -sub read_revision_from_header { - my ($out_header) = @_; - - # ヘッダーファイルがない場合 - if (! -f $out_header) { - return ''; - } - - open(FH, '<', $out_header) or die "error open $out_header"; - while (<FH>) { - if (/#define SVNVERSION (\d+)/) { - close FH; - return $1; - } - } - close FH; - - # パターンマッチしない場合 - return ''; -} - &search_svn(); &search_git(); &read_toolinfo(); @@ -183,7 +200,8 @@ 'header=s' => \$out_header, 'bat=s' => \$out_bat, 'cmake=s' => \$out_cmake, - 'verbose' => \$verbose + 'verbose' => \$verbose, + 'overwrite' => \$overwrite ); $git =~ s/"//g; @@ -198,6 +216,7 @@ print "header=\"$out_header\"\n"; print "bat=\"$out_bat\"\n"; print "cmake=\"$out_cmake\"\n"; + print "overwrite $overwrite\n"; } if (-d "$source_root/.svn" && $svn ne "") { @@ -273,31 +292,57 @@ &dump_info(%svninfo); } -# read revision from out header file -my $header_revision = &read_revision_from_header($out_header); -if ($verbose != 0) { - print "Revision of header is '$header_revision'\n"; -} +my $same; # output for source(C,C++) header -if (! -f $out_header || - $header_revision ne $svninfo{'Revision'}) { - if ($verbose != 0) { - print "write '$out_header'\n"; - } - write_info_header($out_header, %svninfo); +$same = 0; +my $out_header_tmp = $out_header . ".tmp"; +write_info_header($out_header_tmp, %svninfo); +if (!$overwrite && &compare_file($out_header, $out_header_tmp) == 0) { + # same + unlink $out_header_tmp; + $same = 1; +} else { + #diff + unlink $out_header; + rename $out_header_tmp, $out_header; } +if ($verbose != 0) { + printf("%s '$out_header'\n", $same == 1 ? "exists" : "update" ); +} # output for bat file +$same = 0; +my $out_bat_tmp = $out_bat . ".tmp"; +write_info_bat($out_bat_tmp, %svninfo); +if (!$overwrite && &compare_file($out_bat, $out_bat_tmp) == 0) { + # same + unlink $out_bat_tmp; + $same = 1; +} else { + #diff + unlink $out_bat; + rename $out_bat_tmp, $out_bat; +} if ($verbose != 0) { - print "write '$out_bat'\n"; + printf("%s '$out_bat'\n", $same == 1 ? "exists" : "update" ); } -write_info_bat($out_bat, %svninfo); # output for cmake if ($out_cmake ne "") { + my $out_cmake_tmp = $out_cmake . ".tmp"; + &write_info_cmake($out_cmake_tmp, %svninfo); + $same = 0; + if (!$overwrite && &compare_file($out_cmake, $out_cmake_tmp) == 0) { + # same + unlink $out_cmake_tmp; + $same = 1; + } else { + # diff + unlink $out_cmake; + rename $out_cmake_tmp, $out_cmake; + } if ($verbose != 0) { - print "write '$out_cmake'\n"; + printf("%s '$out_cmake'\n", $same == 1 ? "exists" : "update" ); } - write_info_cmake($out_cmake, %svninfo); }