diff options
author | Guillaume Rousse <guillomovitch@mandriva.org> | 2007-06-15 16:25:16 +0000 |
---|---|---|
committer | Guillaume Rousse <guillomovitch@mandriva.org> | 2007-06-15 16:25:16 +0000 |
commit | e6d7212898f42880b02ad99a98f570226fb06d20 (patch) | |
tree | 24209c398a10fa95dd51c97f9c3a39dba81984a2 | |
parent | d0e98725980532693aae79c7ca0792b1253a36ae (diff) | |
download | spec-helper-e6d7212898f42880b02ad99a98f570226fb06d20.tar spec-helper-e6d7212898f42880b02ad99a98f570226fb06d20.tar.gz spec-helper-e6d7212898f42880b02ad99a98f570226fb06d20.tar.bz2 spec-helper-e6d7212898f42880b02ad99a98f570226fb06d20.tar.xz spec-helper-e6d7212898f42880b02ad99a98f570226fb06d20.zip |
add fix-eol scriptlet
-rw-r--r-- | fix-eol | 47 | ||||
-rw-r--r-- | spec-helper.macros.in | 1 |
2 files changed, 48 insertions, 0 deletions
@@ -0,0 +1,47 @@ +#!/usr/bin/perl +# convert end of line patterns from DOS to UNIX + +use strict; +use File::Find; +use File::Temp; + +die "No build root defined" unless $ENV{RPM_BUILD_ROOT}; + +# normalize build root +my $buildroot = $ENV{RPM_BUILD_ROOT}; +$buildroot =~ s|/$||; + +my %exclude_files = ( + map { $buildroot . $_ => 1 } + split(' ', $ENV{EXCLUDE_FROM_EOL_CONVERSION}) +); + +find(\&convert, $buildroot); + +sub convert { + # reject symlinks + return unless -f $_; + # reject binary files + return unless -T $_; + # reject excluded files + return if $exclude_files{$File::Find::name}; + + # check if first line has less than 80 characters and ends with \r\n + open(my $in, '<', $_) or die "Unable to open file $_: $!"; + my $line = <$in>; + if (length($line) <= 80 && $line =~ s/\r\n$/\n/) { + # process all file + my $out = File::Temp->new(DIR => '.', UNLINK => 0); + print $out $line; + while ($line = <$in> && defined $line) { + $line =~ s/\r\n$/\n/; + print $out $line; + } + my $tmp = $out->filename; + $out = undef; + + rename($tmp, $_) or die "Unable to rename $tmp to $_: $!"; + } + + close($in); +} diff --git a/spec-helper.macros.in b/spec-helper.macros.in index 1cd529f..224718f 100644 --- a/spec-helper.macros.in +++ b/spec-helper.macros.in @@ -14,5 +14,6 @@ %{?!dont_translate_menu: [ -n "$DONT_TRANSLATE_MENU" ] || %_spec_helper_dir/translate_menu.pl} \ %{?!dont_fix_pamd: [ -n "$DONT_FIX_PAMD_CONFIGS" ] || %_spec_helper_dir/fixpamd} \ %{?!dont_remove_info_dir: [ -n "$DONT_REMOVE_INFO_DIR" ] || %_spec_helper_dir/remove_info_dir} \ + %{?!dont_fix_eol: [ -n "$DONT_FIX_EOL" ] || %_spec_helper_dir/fix-eol} \ %nil |