From 74a0c34178d61919d940ce28bf515dfee4f50c0c61887a82974f12e23d17d4ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrian=20Schr=C3=B6ter?= Date: Thu, 1 Dec 2011 14:11:20 +0000 Subject: [PATCH 1/9] update OBS-URL: https://build.opensuse.org/package/show/openSUSE:Tools/obs-service-format_spec_file?expand=0&rev=25 --- format_spec_file | 9 ++++++++- format_spec_file.service | 7 +++++-- obs-service-format_spec_file.changes | 5 +++++ obs-service-format_spec_file.spec | 4 ++-- 4 files changed, 20 insertions(+), 5 deletions(-) diff --git a/format_spec_file b/format_spec_file index e6da271..1554799 100644 --- a/format_spec_file +++ b/format_spec_file @@ -9,6 +9,10 @@ while test $# -gt 0; do MYOUTDIR="$2" shift ;; + *-specfile) + MYSPECFILES="$MYSPECFILES $2" + shift + ;; *) echo Unknown parameter $1. echo 'Usage: this service is not excepting parameters' @@ -19,7 +23,10 @@ while test $# -gt 0; do done RETURN=0 -for i in *.spec; do +if [ -z "$MYSPECFILES" ]; then + MYSPECFILES=`echo *.spec` +fi +for i in $MYSPECFILES; do if [ "$i" == '*.spec' ]; then echo "WARNING: no spec file found" exit 0 diff --git a/format_spec_file.service b/format_spec_file.service index 8b502ac..e6607d9 100644 --- a/format_spec_file.service +++ b/format_spec_file.service @@ -1,5 +1,8 @@ - - Validate sources + + Format the spec files The default SUSE source validator which catches common pitfalls before build. + + Just run on specified spec file instead all available + diff --git a/obs-service-format_spec_file.changes b/obs-service-format_spec_file.changes index a94cf35..9b95e02 100644 --- a/obs-service-format_spec_file.changes +++ b/obs-service-format_spec_file.changes @@ -1,3 +1,8 @@ +------------------------------------------------------------------- +Thu Dec 1 14:10:52 UTC 2011 - adrian@suse.de + +- allow to specify a defined spec file (version 0.2) + ------------------------------------------------------------------- Wed Sep 7 13:34:45 CEST 2011 - dmueller@suse.de diff --git a/obs-service-format_spec_file.spec b/obs-service-format_spec_file.spec index 5a26eea..8616a34 100644 --- a/obs-service-format_spec_file.spec +++ b/obs-service-format_spec_file.spec @@ -21,8 +21,8 @@ Name: obs-service-format_spec_file License: GPL v2 or later Group: Development/Tools/Building Summary: An OBS source service: reformats a spec file to SUSE standard. -Version: 0.1 -Release: 9 +Version: 0.2 +Release: 11 Source: format_spec_file Source1: format_spec_file.service Source2: prepare_spec From 0b56edb01710763778d6fa6c213c7c9f1c140a238541ba55d55feafe16dd765c Mon Sep 17 00:00:00 2001 From: Stephan Kulow Date: Tue, 6 Dec 2011 08:55:21 +0000 Subject: [PATCH 2/9] - update from https://github.com/openSUSE/obs-service-format_spec_file OBS-URL: https://build.opensuse.org/package/show/openSUSE:Tools/obs-service-format_spec_file?expand=0&rev=26 --- ...pec_file:obs-service-format_spec_file.spec | 59 +++ obs-service-format_spec_file.changes | 5 + obs-service-format_spec_file.spec | 9 +- prepare_spec | 380 +++++++++++++----- 4 files changed, 338 insertions(+), 115 deletions(-) create mode 100644 _service:format_spec_file:obs-service-format_spec_file.spec diff --git a/_service:format_spec_file:obs-service-format_spec_file.spec b/_service:format_spec_file:obs-service-format_spec_file.spec new file mode 100644 index 0000000..7613a14 --- /dev/null +++ b/_service:format_spec_file:obs-service-format_spec_file.spec @@ -0,0 +1,59 @@ +# +# spec file for package obs-service-format_spec_file +# +# Copyright (c) 2011 SUSE LINUX Products GmbH, Nuernberg, Germany. +# +# All modifications and additions to the file contributed by third parties +# remain the property of their copyright owners, unless otherwise agreed +# upon. The license for this file, and modifications and additions to the +# file, is the same license as for the pristine package itself (unless the +# license for the pristine package is not an Open Source License, in which +# case the license is the MIT License). An "Open Source License" is a +# license that conforms to the Open Source Definition (Version 1.9) +# published by the Open Source Initiative. + +# Please submit bugfixes or comments via http://bugs.opensuse.org/ +# + + + +Name: obs-service-format_spec_file +Summary: An OBS source service: reformats a spec file to SUSE standard. +License: GPL-2.0+ +Group: Development/Tools/Building +Version: 0.3 +Release: 0 +Source: format_spec_file +Source1: format_spec_file.service +Source2: prepare_spec +Requires: osc-source_validator +BuildRoot: %{_tmppath}/%{name}-%{version}-build +BuildArch: noarch + +%description +This is a source service for openSUSE Build Service. + +This source service is formating the spec file to SUSE standard. The rational +behind is to make it easier to review spec files from unknown packagers. + +This should be used in "trylocal" mode, so that osc is adapting the existing +spec file instead of creating a new one. + +%prep + +%setup -q -D -T 0 -n . + +%build + +%install +mkdir -p $RPM_BUILD_ROOT/usr/lib/obs/service/format_spec_file.files +install -m 0755 %{SOURCE0} $RPM_BUILD_ROOT/usr/lib/obs/service +install -m 0644 %{SOURCE1} $RPM_BUILD_ROOT/usr/lib/obs/service +install -m 0755 %{SOURCE2} $RPM_BUILD_ROOT/usr/lib/obs/service/format_spec_file.files + +%files +%defattr(-,root,root) +%dir /usr/lib/obs +/usr/lib/obs/service + +%changelog diff --git a/obs-service-format_spec_file.changes b/obs-service-format_spec_file.changes index 9b95e02..1aa0934 100644 --- a/obs-service-format_spec_file.changes +++ b/obs-service-format_spec_file.changes @@ -1,3 +1,8 @@ +------------------------------------------------------------------- +Tue Dec 6 08:50:41 UTC 2011 - coolo@suse.com + +- update from https://github.com/openSUSE/obs-service-format_spec_file + ------------------------------------------------------------------- Thu Dec 1 14:10:52 UTC 2011 - adrian@suse.de diff --git a/obs-service-format_spec_file.spec b/obs-service-format_spec_file.spec index 8616a34..4463c72 100644 --- a/obs-service-format_spec_file.spec +++ b/obs-service-format_spec_file.spec @@ -16,13 +16,12 @@ # - Name: obs-service-format_spec_file -License: GPL v2 or later -Group: Development/Tools/Building Summary: An OBS source service: reformats a spec file to SUSE standard. -Version: 0.2 -Release: 11 +License: GPL-2.0+ +Group: Development/Tools/Building +Version: 0.3 +Release: 0 Source: format_spec_file Source1: format_spec_file.service Source2: prepare_spec diff --git a/prepare_spec b/prepare_spec index 5c6517b..43615d0 100644 --- a/prepare_spec +++ b/prepare_spec @@ -15,21 +15,20 @@ use strict; my @oldspec = (); my @newspec = (); my $base_package = ""; -my $neededforbuild = ""; my $icecreamforbuild = ""; -my $norootforbuild = 0; my @copyrights = (); my $needsrootforbuild = 0; my $needsbinariesforbuild = 0; my $nodebuginfo = 0; -my %multiline_macros = (); +my $vim_modeline; my $nosrc_result = 0; my $current_section = "header"; my $had_debug_package = 0; my %pkg_version = (); -my %pkg_release = (); -my %please_replace = (); -my %replace_hash = (); +my $main_license; +my %seen_licenses = (); +my $main_group; +my %seen_groups = (); my $build_root = $ENV{'BUILD_ROOT'}; my $disabled_packs; my $ifhandler; @@ -51,6 +50,8 @@ my @global_tags_list = 'ExcludeArch', 'ExclusiveArch', 'Freshens', + 'Group', + 'Name', 'NoPatch', 'NoSource', 'Obsoletes', @@ -62,6 +63,7 @@ my @global_tags_list = 'Requires', 'Source\d*', 'Suggests', + 'Summary', 'Supplements', 'Url', ); @@ -93,10 +95,19 @@ sub capitalize_case($) return $tag; } +sub compare_arrays { + my ($first, $second) = @_; + return 0 unless @$first == @$second; + for (my $i = 0; $i < @$first; $i++) { + return 0 if $first->[$i] ne $second->[$i]; + } + return 1; +} + sub maybe_add_empty_line() { push @oldspec, "XXXBLANKLINE" - if ($current_section ne "description" && $oldspec[-1] !~ /^\s*$/); + if ($current_section ne "description" && $oldspec[-1] !~ /^\s*$/ && $oldspec[-1] !~ /^[#%]/); } sub change_section($) @@ -109,6 +120,149 @@ sub change_section($) warn "section changed to $current_section\n" if $debug; } +sub replace_single_spdx($) +{ + my ($l) = @_; + + my %replace = ( + "lgplv2.1only" =>"LGPL-2.1", + "lgplv2.1orlater" => "LGPL-2.1+", + "lgplv2.1+" => "LGPL-2.1+", + "lgplv2.1" => "LGPL-2.1", + "lgplv2.0+" => "LGPL-2.0+", + "lgplv2.0" => "LGPL-2.0", + "lgplv2+" => "LGPL-2.1+", + + 'lgplv3' => "LGPL-3.0", + 'lgplv3+' => "LGPL-3.0+", + 'gnulgplv2.1orlater' => "LGPL-2.1+", + 'gnulgplv2.1' => "LGPL-2.1", + 'lgplv2.0orlater' => 'LGPL-2.0+', + 'lgplv2orlater' => 'LGPL-2.0+', + + "lgplv3only" => "LGPL-3.0", + "lgplv3orlater" => "LGPL-3.0+", + + "gpl" => "GPL-1.0", + "gpl+" => "GPL-1.0+", + "gplv2only" => "GPL-2.0", + "gplv2" => "GPL-2.0", + "gpl2" => "GPL-2.0", + "gplv2orlater" => "GPL-2.0+", + "gplv2.0orlater" => "GPL-2.0+", + "gplv2+" => "GPL-2.0+", + "gpl-2+" => "GPL-2.0+", + "gplv3only" => "GPL-3.0", + "gplv3orlater" => "GPL-3.0+", + "gplv3+" => "GPL-3.0+", + "gplv3" => "GPL-3.0", + "gpl-3+" => "GPL-3.0+", + "gnugplversion3" => "GPL-3.0", + + "fdl1.1" => "GFDL-1.1", + "gfdlv1.1" => "GFDL-1.1", + 'gnufreedocumentationlicense,version1.1(fdl1.1)' => "GFDL-1.1", + 'gnufreedocumentationlicense,version1.1(gfdl1.1)' => "GFDL-1.1", + "fdl1.2" => "GFDL-1.2", + "gfdl1.2" => "GFDL-1.2", + "gfdlv1.2" => "GFDL-1.2", + 'gnufreedocumentationlicense,version1.2(fdl1.2)' => "GFDL-1.2", + 'gnufreedocumentationlicense,version1.2(gfdl1.2)' => "GFDL-1.2", + "fdl1.3" => "GFDL-1.3", + + "bsd-2c" => "BSD-2-Clause", + "bsd3-clause" => "BSD-3-Clause", + "bsd3c" => "BSD-3-Clause", + "bsd3c(orsimilar)" => "BSD-3-Clause", + "bsd3-clause(orsimilar)" => "BSD-3-Clause", + + "bsd4c" => "BSD-4-Clause", + "bsd4c(orsimilar)" => "BSD-4-Clause", + + "x11/mit" => "MIT", + "X11mit" => "MIT", + "mitlicense(orsimilar)" => "MIT", + + "asl2.0" => "Apache-2.0", + 'apachelicense2.0' => "Apache-2.0", + 'apachelicense' => "Apache-2.0", + 'theapachesoftwarelicense' => "Apache-2.0", + "apachesoftwarelicense.." => "Apache-2.0", + 'apachesoftware license..' => "Apache-2.0", + 'aslv..' => "Apache-2.0", + 'aslv2' => "Apache-2.0", + + "artistic" => "Artistic-1.0", + "artistic2.0" => "Artistic-2.0", + + "thephplicense,version3.01" => "PHP-3.01", + "phplicense" => "PHP-3.01", + "mplv1.0" => "MPL-1.0", + "mplv1.1" => "MPL-1.1", + + "ibmpubliclicense.." => "IPL-1.0", + "ibmpl" => "IPL-1.0", + + "eclipsepubliclicense" => "EPL-1.0", + + "openldap2.8" => "OLDAP-2.8", + + "zliblicense" => "Zlib" + + ); + + my $tl = lc $l; + $tl =~ s, ,,g; + if (defined $replace{$tl}) { + $l = $replace{$tl}; + } else { + my @m = grep(lc($_) eq lc($l), values(%replace)); + if (@m) { + $l = $m[0]; + } else { + print STDERR "unknown license '$l'\n"; + } + } + return $l; +} + +sub replace_spdx_or($) +{ + my ($license) = @_; + + # special case as or later is common in our spec files + $license =~ s, or later, orlater,g; + + my @licenses = (); + for (split(/\s+or\s+/, $license)) { + push @licenses, replace_single_spdx($_); + } + + return join(' or ', sort(@licenses)); +} + +sub replace_spdx_and($) +{ + my ($license) = @_; + + my @licenses = (); + for (split(/\s*and\s*/, $license)) { + push @licenses, replace_spdx_or($_); + } + return join(' and ', sort(@licenses)); +} + +sub replace_spdx($) +{ + my ($license) = @_; + + my @licenses = (); + for (split(/\s*;\s*/, $license)) { + push @licenses, replace_spdx_and($_); + } + return join(' ; ', sort(@licenses)); +} + sub set_current_pkg { my ( $arg ) = @_; print "DEBUG: set_current_pkg receiving $arg\n" if $debug; @@ -148,15 +302,23 @@ sub read_and_parse_old_spec { while (@readspec) { $_ = shift @readspec; + if ( /^\s*$/ && $current_section ne "description") { + # stop preamble parsing on two blank lines + if ($print_comments eq "false" && $oldspec[0] && $oldspec[-1] eq "XXXBLANKLINE") { + $print_comments = "true"; + push @oldspec, "XXXDOUBLELINE"; + next; + } push @oldspec, "XXXBLANKLINE"; next; } - - if ( /^#\s*norootforbuild\s*$/ ) { - $norootforbuild = 1; - next; + + if ( /^# vim:/ ) { + $vim_modeline = $_; + next; } + if ( /^#\s*needsrootforbuild\s*$/ ) { $needsrootforbuild = 1; next; @@ -165,6 +327,10 @@ sub read_and_parse_old_spec { $needsbinariesforbuild = 1; next; } + if ( /^#\s*norootforbuild/ ) { + next; + } + if ( /^#\s*nodebuginfo\s*$/ ) { $nodebuginfo = 1; next; @@ -175,6 +341,7 @@ sub read_and_parse_old_spec { next; } if ( /^#\s*Copyright\s*/ ) { + my $lastlineblank = 0; for (;;) { # check if line is ONLY a standard copyright line, if so, ignore. @@ -182,22 +349,11 @@ sub read_and_parse_old_spec { $c =~ s{\s*(\d+|copyrights?|\(c\)|suse|linux|products|gmbh|nuremberg|n..?rnberg|germany|\W+)\s*}{}gi; push(@copyrights, $_) if length $c > 5; last if length $readspec[0] < 10 || $readspec[0] =~ m{modifications and additions}i || $readspec[0] !~ /^[\#\s]/ - || grep { $readspec[0] =~ /^#\s*$_/ } ("norootforbuild","needsrootforbuild","needsbinariesforbuild","nodebuginfo","icecream","neededforbuild","usedforbuild","Commandline","MD5SUM","!BuildIgnore"); + || grep { $readspec[0] =~ /^#\s*$_/ } ("needsrootforbuild","needsbinariesforbuild","nodebuginfo","icecream","usedforbuild","Commandline","MD5SUM","!BuildIgnore"); $_ = shift @readspec; } next; } - if ( /^#\s*neededforbuild/ ) { - $neededforbuild = $_; - $neededforbuild =~ s/^#\s*neededforbuild\s*//; - my (%aa) = (); - foreach my $x (split(' ',$neededforbuild)){ - $aa{$x}=1; - } - $neededforbuild = join(' ',sort keys (%aa)); - - next; - } # evil epoch removal next if ( /^Epoch:/ ); $_ =~ s/%{?epoch}?[:-]//g; @@ -213,7 +369,9 @@ sub read_and_parse_old_spec { # ignore line if it looks like a "usedforbuild" line, i.e. # if it contains too many base packages next if (grep {$aa{$_}} qw{gcc rpm glibc bash}) > 2; - push @oldspec, "BuildRequires: ".join(' ',sort keys(%aa)); + for my $br (sort keys(%aa)) { + push @oldspec, "BuildRequires: $br"; + } next; } next if ( /^#\s*usedforbuild/ ); @@ -229,6 +387,7 @@ sub read_and_parse_old_spec { push @oldspec, $_; next; } + if ( /^#/ && $current_section ne "description") { warn "$_ $current_section\n" if $debug; if ( $print_comments eq "true" || $readspec[0] =~ /^%define/ || $readspec[0] =~ /^%if/) { @@ -236,6 +395,7 @@ sub read_and_parse_old_spec { } next; } + if ( /^%debug_package/ ) { # remove, we add this ourselves next; @@ -245,9 +405,7 @@ sub read_and_parse_old_spec { if ( /^%define\s*vendor\s/ || /^%define\s*distribution\s/ ) { next; } - if ( /^%define\s+(\w[\w\d]+).*\\$/ ) { - $multiline_macros{$1} = 1; - } + if ( /^\s*%if/ || /^\s*%\{/ || /^\s*%define/ || /^\s*%el/ || /^\s*%endif/ ) { change_section("header") if ($current_section eq "description"); push @oldspec, $_; @@ -330,13 +488,7 @@ sub read_and_parse_old_spec { } if ( /^%description\b/i ) { change_section("description"); - $_ =~ s/^(%\w+)/lc($1)/e; push @oldspec, $_; - ($current_package, $current_lang) = set_current_pkg ( $_ ); - my $target = $current_package; - $target .= "_$current_lang" if $current_lang; - $target .= "_disabled" if $ifhandler->{"disabled"}; - push @oldspec, "XXXDESCRIPTION $target"; next; } if ( /^%install\b/i ) { @@ -363,64 +515,56 @@ sub read_and_parse_old_spec { } push @oldspec, "$_"; - # multiline macros need an extra newline with old RPMs - if (/^%(\w[\w\d]+).*[^\\]$/) { - push @oldspec, "" if (defined($multiline_macros{$1})); - } next; } + if ($current_section eq "header") { my $c_pack = $current_package; $c_pack .= "_disabled" if $ifhandler->{"disabled"}; - if ( /^Summary\b\s*:\s*(.*)/i ) { - $replace_hash{"XXXSUMMARY $c_pack"} = sprintf("%-16s%s","Summary:", $1); - push @oldspec, "XXXSUMMARY $c_pack"; - next; - } - if ( /^Group\b\s*:\s*(.*)/i ) { - $replace_hash{"XXXGROUP $c_pack"} = sprintf("%-16s%s", "Group:", $1); - push @oldspec, "XXXGROUP $c_pack"; - next; - } + if ( /^Vendor:/ || /^Distribution:/ || /^Packager:/ ) { next; } - if ( /^Name\s*:\s*(.*)/i ) { - my $orig_name = $1; - my $changed_name = $orig_name; - $changed_name =~ s/\Q$_\E/$definelist->{$_}/ for (sort { length($b) <=> length($a) } keys (%{$definelist})); - if ($changed_name eq $base_package) { - push @oldspec, sprintf("\n%-16s%s","Name:", $orig_name); - } else { - push @oldspec, sprintf("\n%-16s%s","Name:", $base_package); - } - $definelist->{"%name"} = $base_package if $ifhandler->{"disabled"} == 0; - $definelist->{"%{name}"} = $base_package if $ifhandler->{"disabled"} == 0; - warn ("line is $_, orig_name is $orig_name, base_package is $base_package\n") if $ifhandler->{"disabled"} == 0 && $debug; - next; + # remove default value of Autoreqprov + if ( /^Autoreqprov\s*:\s*(.*)/i ) { + next if ( lc($1) eq "on" || lc($1) eq "yes"); } + # reset Release + if ( /^Release\s*:\s*(.*)/i ) { + # will be after Version + next; + } + if ( /^Summary\s*:\s*(.*)\s*$/i ) { + push @oldspec, sprintf("%-16s%s", "Summary:", $1); + push @oldspec, "XXXPOSTSUMMARY $current_package"; + next; + } + + # remove license and print out after license later + if ( /^License\s*:\s*(.*)\s*$/i || /^Copyright\s*:\s*(.*)\s*$/i ) { + my $license = replace_spdx($1); + $main_license = $license if (!$main_license); + $seen_licenses{$current_package} = $license; + next; + } + + # remove groups and print out after summary later + if ( /^Group\s*:\s*(.*)\s*$/i ) { + my $group = $1; + $main_group = $group if (!$main_group); + $seen_groups{$current_package} = $group; + next; + } + if ( /^BuildArchitectures\s*:/i ) { $_ =~ s/^[^:]+:/BuildArch:/; } - if ( /^Release\s*:\s*(.*)/i ) { - $pkg_release{$c_pack} = $_; - $replace_hash{"XXXRELEASE $c_pack"} = sprintf("%-16s%s","Release:", $1); - next; - } + if ( /^BuildRoot\s*:/i ) { push @oldspec, "BuildRoot: %{_tmppath}/%{name}-%{version}-build"; next; } - if ( /^Copyright\s*:\s*(.*)/i || /^License\s*:\s*(.*)/i ) { - $replace_hash{"XXXLICENSE $c_pack"} = sprintf("%-16s%s","License:", $1); - push @oldspec, "XXXLICENSE $c_pack"; - next; - } - if ( /^Url\s*:\s*(.*)/i ) { - $replace_hash{"XXXURL $c_pack"} = sprintf("%-16s%s","Url:", $1); - push @oldspec, "XXXURL $c_pack"; - next; - } + if ( m/$global_tags_re\s*(.*)/oi ) { my ($tag, $value) = ($1, $2); $nosrc_result = 1 if ($tag =~ /(?:nosource|nopatch)/i); @@ -431,24 +575,17 @@ sub read_and_parse_old_spec { warn "found Version, section = $current_section\n" if $debug; $version{$c_pack} = $_; $version{$c_pack} =~ s/^Version:\s*(.*)\s*/$1/; - $replace_hash{"XXXVERSION $c_pack"} = sprintf("%-16s%s","Version:",$version{$c_pack}); - push @oldspec, $replace_hash{"XXXVERSION $c_pack"}; - push @oldspec, "XXXRELEASE $c_pack"; + push @oldspec, sprintf("%-16s%s","Version:",$version{$c_pack}); + push @oldspec, sprintf("%-16s%s","Release:", "0"); next; } } - if ( $current_section eq "description" ) { - my $target = $current_package; - $target .= "_$current_lang" if $current_lang; - $target .= "_disabled" if $ifhandler->{"disabled"}; - $replace_hash{"XXXDESCRIPTION $target"} .= "\n" if ( $replace_hash{"XXXDESCRIPTION $target"} ); - $replace_hash{"XXXDESCRIPTION $target"} .= $_; + if ( $current_section ne "changelog" ) { + push @oldspec, $_; next; } - if ( $current_section ne "description" && $current_section ne "changelog" ) { - push @oldspec, $_; - } } + } if ($ARGV[0] eq '--debug') { @@ -518,16 +655,40 @@ if ( ! stat ((glob("$specdir/$base_package*.spec"))[0] || "") ) { read_and_parse_old_spec ( $specfile, $base_package ); -for (@oldspec) { - next unless /^XXX/; - $please_replace{$_} = 1; +my $linesmoved = 1; +while ($linesmoved) { + $linesmoved = 0; + my @firstlines = (); + my @buildrequires = (); + while ($oldspec[0]) { + my $l = shift @oldspec; + if ($l =~ m/^BuildRequires:/ ) { + push(@buildrequires, $l); + } else { + # if there are already buildrequires, we need to sort and exit + if (@buildrequires > 0) { + my @sortedbrs = sort(@buildrequires); + $linesmoved = !compare_arrays(\@buildrequires, \@sortedbrs); + @oldspec = (@firstlines, sort(@buildrequires), $l, @oldspec); + @firstlines = (); + @buildrequires = (); + last; + } else { + push(@firstlines, $l); + } + } + } + @oldspec = (@firstlines, @oldspec); } + my $thisyear = localtime->year() + 1900; unshift @copyrights, "# Copyright (c) $thisyear SUSE LINUX Products GmbH, Nuernberg, Germany."; my $copy_list = join("\n", @copyrights); + +print $vim_modeline . "\n" if (defined $vim_modeline); print < Date: Wed, 7 Dec 2011 08:27:18 +0000 Subject: [PATCH 3/9] - another update from git to replace way more licenses (0.4) OBS-URL: https://build.opensuse.org/package/show/openSUSE:Tools/obs-service-format_spec_file?expand=0&rev=27 --- ...pec_file:obs-service-format_spec_file.spec | 9 +- format_spec_file.service | 2 +- licenses_changes.txt | 366 ++++++++++++ obs-service-format_spec_file.changes | 5 + obs-service-format_spec_file.spec | 9 +- patch_license | 564 ++++++++++++++++++ prepare_spec | 175 ++---- 7 files changed, 1009 insertions(+), 121 deletions(-) create mode 100644 licenses_changes.txt create mode 100644 patch_license diff --git a/_service:format_spec_file:obs-service-format_spec_file.spec b/_service:format_spec_file:obs-service-format_spec_file.spec index 7613a14..c61d7c8 100644 --- a/_service:format_spec_file:obs-service-format_spec_file.spec +++ b/_service:format_spec_file:obs-service-format_spec_file.spec @@ -18,14 +18,16 @@ Name: obs-service-format_spec_file -Summary: An OBS source service: reformats a spec file to SUSE standard. +Summary: An OBS source service: reformats a spec file to SUSE standard License: GPL-2.0+ Group: Development/Tools/Building -Version: 0.3 +Version: 0.4 Release: 0 Source: format_spec_file Source1: format_spec_file.service Source2: prepare_spec +Source3: patch_license +Source4: licenses_changes.txt Requires: osc-source_validator BuildRoot: %{_tmppath}/%{name}-%{version}-build BuildArch: noarch @@ -49,7 +51,8 @@ spec file instead of creating a new one. mkdir -p $RPM_BUILD_ROOT/usr/lib/obs/service/format_spec_file.files install -m 0755 %{SOURCE0} $RPM_BUILD_ROOT/usr/lib/obs/service install -m 0644 %{SOURCE1} $RPM_BUILD_ROOT/usr/lib/obs/service -install -m 0755 %{SOURCE2} $RPM_BUILD_ROOT/usr/lib/obs/service/format_spec_file.files +install -m 0755 %{SOURCE2} %{SOURCE3} $RPM_BUILD_ROOT/usr/lib/obs/service/format_spec_file.files +install -m 0644 %{SOURCE4} $RPM_BUILD_ROOT/usr/lib/obs/service/format_spec_file.files %files %defattr(-,root,root) diff --git a/format_spec_file.service b/format_spec_file.service index e6607d9..4379d57 100644 --- a/format_spec_file.service +++ b/format_spec_file.service @@ -1,6 +1,6 @@ Format the spec files - The default SUSE source validator which catches common pitfalls before build. + Formatting the spec files Just run on specified spec file instead all available diff --git a/licenses_changes.txt b/licenses_changes.txt new file mode 100644 index 0000000..7aeebb7 --- /dev/null +++ b/licenses_changes.txt @@ -0,0 +1,366 @@ +AAL AAL +AFL-2.1 Academic Free License 2.1 +AGPL-3.0 Affero GPL +AFL-2.1 AFL 2.1 +AFL-1.2 AFL-1.2 +AFL-2.0 AFL-2.0 +AFL-2.1 AFL-2.1 +AFL-3.0 AFL-3.0 +AGPL-3.0 AGPL-3.0 +AGPL-3.0 AGPLv3 +SUSE-AGPL-3.0+ AGPLv3+ +ANTLR-PD ANTLR-PD +Apache-1.1 Apache 1.1 (Indiana University) +Apache-2.0 Apache 2.0 +Apache-2.0 Apache License +Apache-2.0 Apache License 2.0 +Apache-2.0 Apache License, Version 2.0 +Apache-2.0 Apache Software License .. +Apache-2.0 Apache Software License +Apache-2.0 Apache v2.0 +Apache-1.0 Apache-1.0 +Apache-1.1 Apache-1.1 +Apache-2.0 Apache-2.0 +APL-1.0 APL-1.0 +APL-1.0 APL-1.0 (spdx.org/licenses) +APSL-1.0 APSL-1.0 +APSL-1.1 APSL-1.1 +APSL-1.2 APSL-1.2 +APSL-2.0 APSL-2.0 +Artistic-1.0 Artistic +Artistic-1.0 Artistic 1.0 +Artistic-2.0 Artistic 2.0 +Artistic-1.0 Artistic license +Artistic-1.0 Artistic License +Artistic-1.0 Artistic License .. +Artistic-1.0 Artistic-1.0 +SUSE-Artistic-1.0+ Artistic-1.0+ +Artistic-2.0 Artistic-2.0 +Apache-1.1 ASL 1.1 +Apache-2.0 ASL 2.0 +Apache-2.0 ASL2 +Apache-2.0 ASLv.. +Apache-2.0 ASLv2 +Apache-2.0 ASLv2.0 +SUSE-Apache-2.0+ ASLv2.0+ +BSD-3-Clause BSD (3-Clause) +BSD-2-Clause BSD 2 clause +BSD-2-Clause BSD 2 Clause +BSD-2-Clause BSD 2-clause +BSD-2-Clause BSD 2-Clause +BSD-3-Clause BSD 3-Clause +BSD-3-Clause BSD 3-clause (or similar) +BSD-2-Clause BSD-2-Clause +BSD-2-Clause BSD-2c +BSD-3-Clause BSD-3 +BSD-3-Clause BSD-3-Clause +BSD-3-Clause BSD-3-clause (or similar) +BSD-4-Clause BSD-4-Clause +BSD-2-Clause BSD2c +BSD-3-Clause BSD3 +BSD-3-Clause BSD3c +BSD-3-Clause BSD3c (or similar) +BSD-3-Clause BSD3c(or similar) +BSD-4-Clause BSD4c +BSD-4-Clause BSD4c(or similar) +BSL-1.0 BSL-1.0 +CATOSL-1.1 CATOSL-1.1 +CC-BY-SA-3.0 CC BY-SA 3.0 +CC-BY-SA-2.5 CC by-sa V2.5 +CC-BY-SA-3.0 CC BY-SA V3.0 +CC-BY-1.0 CC-BY-1.0 +CC-BY-2.0 CC-BY-2.0 +CC-BY-2.5 CC-BY-2.5 +CC-BY-3.0 CC-BY-3.0 +CC-BY-NC-1.0 CC-BY-NC-1.0 +CC-BY-NC-2.0 CC-BY-NC-2.0 +CC-BY-NC-2.5 CC-BY-NC-2.5 +CC-BY-NC-3.0 CC-BY-NC-3.0 +CC-BY-NC-ND-1.0 CC-BY-NC-ND-1.0 +CC-BY-NC-ND-2.0 CC-BY-NC-ND-2.0 +CC-BY-NC-ND-2.5 CC-BY-NC-ND-2.5 +CC-BY-NC-ND-3.0 CC-BY-NC-ND-3.0 +CC-BY-NC-SA-1.0 CC-BY-NC-SA-1.0 +CC-BY-NC-SA-2.0 CC-BY-NC-SA-2.0 +CC-BY-NC-SA-2.5 CC-BY-NC-SA-2.5 +CC-BY-NC-SA-3.0 CC-BY-NC-SA-3.0 +CC-BY-ND-1.0 CC-BY-ND-1.0 +CC-BY-ND-2.0 CC-BY-ND-2.0 +CC-BY-ND-2.5 CC-BY-ND-2.5 +CC-BY-ND-3.0 CC-BY-ND-3.0 +CC-BY-SA-1.0 CC-BY-SA-1.0 +CC-BY-SA-2.0 CC-BY-SA-2.0 +CC-BY-SA-2.5 CC-BY-SA-2.5 +CC-BY-SA-3.0 CC-BY-SA-3.0 +CC0-1.0 CC0-1.0 +CDDL-1.0 CDDL +CDDL-1.0 CDDL 1.0 +CDDL-1.0 CDDL-1.0 +CDDL-1.0 or LGPL-2.1 CDDLv1.0 | LGPLv2.1 +CECILL-1.0 CECILL-1.0 +CECILL-1.1English CECILL-1.1English +CECILL-2.0 CECILL-2.0 +CECILL-B CECILL-B +CECILL-C CECILL-C +ClArtistic ClArtistic +CPL-1.0 Common Public License - v 1.0 +CPL-1.0 Common Public License v1.0 +CPL-1.0 Common Public License v1.0 (CPL) +CPL-1.0 Common Public License Version 1.0 +CPL-1.0 Common Public License Version 1.0 (CPL1.0) +CPAL-1.0 CPAL-1.0 +CPL-1.0 CPL (Common Public License) v1 +CPL-1.0 CPL 1.0 +CPL-1.0 CPL 1.0 ... +CPL-1.0 CPL-1.0 +CUA-OPL-1.0 CUA-OPL-1.0 +ECL-1.0 ECL-1.0 +ECL-2.0 ECL-2.0 +EPL-1.0 Eclipse Public License +EPL-1.0 Eclipse-1.0 +EPL-1.0 Eclipse Public License 1.0 +eCos-2.0 eCos-2.0 +EFL-1.0 EFL-1.0 +EFL-2.0 EFL-2.0 +Entessa Entessa +EPL-1.0 EPL +EPL-1.0 EPL 1.0 +EPL-1.0 EPL 1.0 ... +EPL-1.0 EPL v1.0 +EPL-1.0 EPL-1 +EPL-1.0 EPL-1.0 +ErlPL-1.1 Erlang Public License +ErlPL-1.1 ErlPL-1.1 +EUDatagrid EUDatagrid +EUPL-1.0 EUPL-1.0 +EUPL-1.1 EUPL-1.1 +MIT Expat +MIT Expat License +Fair Fair +SUSE-GFDL-1.1 FDL v1.1 or later +SUSE-GFDL-1.2+ FDL-1.2+ +SUSE-GFDL-1.3+ FDL-1.3+ +SUSE-GFDL-1.2+ FDLv1.2+ +Frameworx-1.0 Frameworx-1.0 +SUSE-Freeware Freeware +SUSE-Freeware Freeware license +GFDL-1.1 GFDL 1.1 +GFDL-1.2 GFDL 1.2 +GFDL-1.1 GFDL v1.1 +GFDL-1.2 GFDL v1.2 +GFDL-1.1 GFDL-1.1 +GFDL-1.2 GFDL-1.2 +GFDL-1.3 GFDL-1.3 +GFDL-1.1 GFDLv1.1 +GFDL-1.2 GFDLv1.2 +SUSE-GFDL-1.2+ GFDLv1.2+ +GPL-2.0 GLPv2 +GFDL-1.1 GNU Free Documentation License, Version 1.1 (GFDL 1.1) +GFDL-1.2 GNU Free Documentation License, Version 1.2 (GFDL 1.2) +GFDL-1.3 GNU Free Documentation License, Version 1.3 (GFDL 1.3) +GPL-2.0 GNU General Public License (GPL) v2 +GPL-2.0 GNU General Public License version 2 (GPL v2) +GPL-2.0+ GNU General Public License version 2 or later +GPL-2.0+ GNU General Public License version 2 or later (GPL v2 or later) +GPL-2.0+ GNU General Public License version 2 or later (GPLv2 or later) +GPL-3.0 GNU General Public License version 3 (GPLv3) +GPL-2.0 GNU GPL v2 +GPL-3.0+ GNU GPL v3 or later +GPL-3.0 GNU GPL version 3 +LGPL-3.0 GNU Lesser General Public License (LGPL), Version 3 +LGPL-2.1 GNU Lesser General Public License version 2.1 (LGPL v2.1) +LGPL-3.0 GNU Lesser General Public License version 3 (LGPL v3) +LGPL-2.1+ GNU LGPL v2.1 or later +LGPL-2.1 GNU LGPLv2.1 +GPL-2.0 GPL 2.0 +GPL-3.0 GPL 3 +GPL-2.0 GPL v2 +GPL-2.0 GPL v2 only +GPL-2.0+ GPL v2 or later +GPL-2.0+ GPL v2 or later +GPL-2.0 GPL v2.0 +GPL-2.0+ GPL v2.0 or later +GPL-2.0+ GPL v2+ +GPL-3.0 GPL v3 +GPL-3.0 GPL v3 only +GPL-3.0+ GPL v3 or later +GPL-1.0 GPL-1.0 +GPL-1.0+ GPL-1.0+ +GPL-2.0 GPL-2 +GPL-2.0 GPL-2.0 +GPL-2.0; GPL-2.0+ GPL-2.0 GPL-2.0+ +GPL-2.0+ GPL-2.0 or later +GPL-2.0-with-autoconf-exception GPL-2.0-with-autoconf-exception +GPL-2.0-with-bison-exception GPL-2.0-with-bison-exception +GPL-2.0-with-classpath-exception GPL-2.0-with-classpath-exception +GPL-2.0-with-font-exception GPL-2.0-with-font-exception +GPL-2.0-with-GCC-exception GPL-2.0-with-GCC-exception +GPL-2.0; GPL-2.0+ GPL-2.0, GPL-2.0+ +GPL-2.0+ GPL-2.0+ +Apache-2.0; GPL-2.0+ GPL-2.0+, Apache-2.0 +GPL-2.0+; LGPL-2.0+ GPL-2.0+,LGPL-2.0+ +GPL-2.0 GPL-2.Ã0 +GPL-2.0+ GPL-2+ +GPL-3.0 GPL-3 +GPL-3.0 GPL-3.0 +GPL-3.0-with-autoconf-exception GPL-3.0-with-autoconf-exception +GPL-3.0-with-GCC-exception GPL-3.0-with-GCC-exception +GPL-3.0; GPL-2.0+ GPL-3.0, GPL-2.0+ +GPL-3.0+ GPL-3.0+ +GPL-3.0+ GPL-3+ +GPL-1.0+ GPL+ +GPL-2.0 GPL2 +GPL-2.0+ GPL2+ +GPL-3.0 GPL3 +GPL-1.0+ GPLv1+ +GPL-2.0 GPLv2 +GPL-2.0 or GPL-3.0 GPLv2 || GPLv3 +GPL-2.0+ GPLv2 or later +GPL-2.0+ GPLv2+ +GPL-3.0 GPLv3 +GPL-3.0+ GPLv3+ +gSOAP-1.3b gSOAP-1.3b +HPND HPND +IPL-1.0 IBM PL +IPL-1.0 IBM Public License +IPL-1.0 IBM Public License .. +IPA IPA +IPL-1.0 IPL-1.0 +ISC ISC +ISC ISC License +LGPL-2.1 LGPL 2.1 +LGPL-2.0 LGPL v2 +LGPL-2.0+ LGPL v2 or later +LGPL-2.0 LGPL v2.0 only +LGPL-2.0+ LGPL v2.0 or later +LGPL-2.1 LGPL v2.1 +LGPL-2.1 LGPL v2.1 only +LGPL-2.1+ LGPL v2.1 or later +LGPL-2.1+ LGPL v2.1+ +LGPL-2.1+ LGPL v2+ +LGPL-2.1+ LGPL V2+ +LGPL-3.0+ LGPL v3 or later +LGPL-2.0 LGPL-2.0 +LGPL-2.1+ LGPL-2.0.1 or later +LGPL-2.0+ LGPL-2.0+ +LGPL-2.1 LGPL-2.1 +LGPL-2.1+ LGPL-2.1+ +LGPL-3.0 LGPL-3.0 +LGPL-3.0+ LGPL-3.0+ +LGPL-2.1 LGPL2.1 +LGPL-2.0 LGPLv2 +LGPL-2.0 LGPLv2.0 +LGPL-2.0+ LGPLv2.0+ +LGPL-2.1 LGPLv2.1 +LGPL-2.1+ LGPLv2.1+ +LGPL-2.1+ LGPLv2+ +LGPL-3.0 LGPLv3 +LGPL-3.0+ LGPLv3+ +GPL-2.0+ libGeoIPUpdate is GPLv2 or later +Libpng Libpng +LPL-1.02 LPL-1.02 +LPPL-1.3c LPPL .. +LPPL-1.0 LPPL-1.0 +LPPL-1.1 LPPL-1.1 +LPPL-1.2 LPPL-1.2 +LPPL-1.3c LPPL-1.3c +MirOS MirOS +MIT MIT +MIT MIT licence +MIT MIT license +MIT MIT License +MIT MIT License (or similar) +MIT MIT-Licence +MIT MIT/X Consortium License +MIT MIT/X License +MIT MIT/X11 +Motosoto Motosoto +MPL-1.1 MOZILLA PUBLIC LICENSE (MPL/NPL) +MPL-1.1 Mozilla Public License 1.1 +SUSE-MPL-1.1+ MPL 1.1 or later +MPL-1.0 MPL-1.0 +MPL-1.1 MPL-1.1 +MPL-1.0 MPLv1.0 +MPL-1.1 MPLv1.1 +MPL-1.1 MPLv1.1 .. +SUSE-MPL-1.1+ MPLv1.1+ +MS-PL Ms-Pl +MS-PL MS-PL +MS-RL MS-RL +Multics Multics +SPDX Name in Spec File +NASA-1.3 NASA-1.3 +Naumen Naumen +NCSA NCSA +NGPL NGPL +Nokia Nokia +NPOSL-3.0 NPOSL-3.0 +NTP NTP +OCLC-2.0 OCLC-2.0 +ODbL-1.0 ODbL-1.0 +OFL-1.1 OFL +OFL-1.1 OFL-1.1 +OGTSL OGTSL +OLDAP-2.8 OLDAP-2.8 +OFL-1.1 Open Font License +OLDAP-2.8 openldap 2.8 +OpenSSL OpenSSL +OSL-1.0 OSL-1.0 +OSL-2.0 OSL-2.0 +OSL-3.0 OSL-3.0 +PDDL-1.0 PDDL-1.0 +Artistic-1.0 or GPL-1.0+ Perl License +PHP-3.0.1 PHP License +PostgreSQL PostgreSQL +SUSE-Public-Domain Public domain +SUSE-Public-Domain Public Domain +SUSE-Public-Domain Public Domain, Freeware +SUSE-Public-Domain Public Domain. See http://www.sentex.ca/~mw +Python-2.0 Python +Python-2.0 Python .. +Python-2.0 Python Copyright +Python-2.0 Python License .. +Python-2.0 Python Software Foundation License +Python-2.0 Python-2.0 +QPL-1.0 QPL +QPL-1.0 QPL .. +QPL-1.0 QPL-1.0 +RHeCos-1.1 RHeCos-1.1 +RPL-1.5 RPL-1.5 +RPSL-1.0 RPSL-1.0 +RSCPL RSCPL +Ruby Ruby +SAX-PD SAX-PD +IPA see IPA_Font_License_Agreement_v1.0.txt +OFL-1.1 SIL Open Font License +OFL-1.1 SIL Open Font License 1.1 +SimPL-2.0 SimPL-2.0 +Sleepycat Sleepycat +SPL-1.0 SPL-1.0 +SugarCRM-1.1.3 SugarCRM-1.1.3 +LPPL-1.3c TeX-License .. +Apache-2.0 The Apache Software License +PHP-3.0.1 The PHP License, version 3.01 +VSL-1.0 VSL-1.0 +W3C W3C +W3C W3C Software License +Watcom-1.0 Watcom-1.0 +WXwindows WXwindows +MIT X11 +MIT X11 (BSD like) +MIT X11 MIT +MIT X11/MIT +XFree86-1.1 XFree86-1.1 +Xnet Xnet +YPL-1.1 YPL-1.1 +Zimbra-1.3 Zimbra-1.3 +Zlib Zlib +Zlib zlib +Zlib Zlib License +Zlib zlib/libpng License +ZPL-2.0 Zope Public License +ZPL-2.0 ZPL +ZPL-2.1 ZPL 2.1 +ZPL-1.1 ZPL-1.1 +ZPL-2.0 ZPL-2.0 +ZPL-2.1 ZPL-2.1 diff --git a/obs-service-format_spec_file.changes b/obs-service-format_spec_file.changes index 1aa0934..3e8307b 100644 --- a/obs-service-format_spec_file.changes +++ b/obs-service-format_spec_file.changes @@ -1,3 +1,8 @@ +------------------------------------------------------------------- +Wed Dec 7 08:22:29 UTC 2011 - coolo@suse.com + +- another update from git to replace way more licenses (0.4) + ------------------------------------------------------------------- Tue Dec 6 08:50:41 UTC 2011 - coolo@suse.com diff --git a/obs-service-format_spec_file.spec b/obs-service-format_spec_file.spec index 4463c72..3e352a1 100644 --- a/obs-service-format_spec_file.spec +++ b/obs-service-format_spec_file.spec @@ -17,14 +17,16 @@ Name: obs-service-format_spec_file -Summary: An OBS source service: reformats a spec file to SUSE standard. +Summary: An OBS source service: reformats a spec file to SUSE standard License: GPL-2.0+ Group: Development/Tools/Building -Version: 0.3 +Version: 0.4 Release: 0 Source: format_spec_file Source1: format_spec_file.service Source2: prepare_spec +Source3: patch_license +Source4: licenses_changes.txt Requires: osc-source_validator BuildRoot: %{_tmppath}/%{name}-%{version}-build BuildArch: noarch @@ -48,7 +50,8 @@ spec file instead of creating a new one. mkdir -p $RPM_BUILD_ROOT/usr/lib/obs/service/format_spec_file.files install -m 0755 %{SOURCE0} $RPM_BUILD_ROOT/usr/lib/obs/service install -m 0644 %{SOURCE1} $RPM_BUILD_ROOT/usr/lib/obs/service -install -m 0755 %{SOURCE2} $RPM_BUILD_ROOT/usr/lib/obs/service/format_spec_file.files +install -m 0755 %{SOURCE2} %{SOURCE3} $RPM_BUILD_ROOT/usr/lib/obs/service/format_spec_file.files +install -m 0644 %{SOURCE4} $RPM_BUILD_ROOT/usr/lib/obs/service/format_spec_file.files %files %defattr(-,root,root) diff --git a/patch_license b/patch_license new file mode 100644 index 0000000..6cdb58a --- /dev/null +++ b/patch_license @@ -0,0 +1,564 @@ +#! /usr/bin/perl -w +# +# vim:sw=2:et +# + +BEGIN { + unshift @INC, "."; + unshift @INC, "/usr/lib/build/"; +} + +use Time::localtime; +use Data::Dumper; +use strict; + +my @oldspec = (); +my @newspec = (); +my $base_package = ""; +my $icecreamforbuild = ""; +my @copyrights = (); +my $needsrootforbuild = 0; +my $needsbinariesforbuild = 0; +my $nodebuginfo = 0; +my $vim_modeline; +my $nosrc_result = 0; +my $current_section = "header"; +my $had_debug_package = 0; +my %pkg_version = (); +my $main_license; +my %seen_licenses = (); +my $main_group; +my %seen_groups = (); +my $build_root = $ENV{'BUILD_ROOT'}; +my $disabled_packs; +my $ifhandler; +my $definelist; +my $debug = 0; + +my @global_tags_list = +( + 'Autoreq', + 'Autoreqprov', + 'BuildArch', + 'BuildArchitectures', + 'BuildRequires', + 'Conflicts', + 'DocDir', + 'Enhances', + 'Enhances', + 'EssentialFor', + 'ExcludeArch', + 'ExclusiveArch', + 'Freshens', + 'Group', + 'Name', + 'NoPatch', + 'NoSource', + 'Obsoletes', + 'Patch\d*', + 'Prefix', + 'PreReq', + 'Provides', + 'Recommends', + 'Requires', + 'Source\d*', + 'Suggests', + 'Summary', + 'Supplements', + 'Url', +); + +my $global_tags_re = '^\s*(' . join("|", @global_tags_list) . ')\s*:'; + +my $section_tags_re ='^\s*%(?:clean|check|prep|build|install|pre|post|preun|postun|posttrans|package|' . + 'description|files|triggerin|triggerun|triggerpostun)\b'; + +sub unify { + my %h = map {$_ => 1} @_; + return grep(delete($h{$_}), @_); +} + +sub capitalize_case($) +{ + my ($tag) = @_; + + $tag = lc($tag); + + $tag =~ s/docdir/DocDir/i; + $tag =~ s/arch/Arch/i; + $tag =~ s/patch/Patch/i; + $tag =~ s/source/Source/i; + $tag =~ s/req/Req/i; + $tag =~ s/prov/Prov/i; + $tag =~ s/^(\w)/uc($1)/e; + + return $tag; +} + +sub compare_arrays { + my ($first, $second) = @_; + return 0 unless @$first == @$second; + for (my $i = 0; $i < @$first; $i++) { + return 0 if $first->[$i] ne $second->[$i]; + } + return 1; +} + +sub maybe_add_empty_line() +{ + push @oldspec, "XXXBLANKLINE" + if ($current_section ne "description" && $oldspec[-1] !~ /^\s*$/ && $oldspec[-1] !~ /^[#%]/); +} + +sub change_section($) +{ + my ($new_section) = @_; + + maybe_add_empty_line(); + + $current_section = $new_section; + warn "section changed to $current_section\n" if $debug; +} + +my %license_replace = (); +use File::Basename; + +sub load_license_map() +{ + return if defined $license_replace{"GPL-2.0"}; + my $scriptdir = File::Basename::dirname($0); + open(MAP, "$scriptdir/licenses_changes.txt") || die "can't open licenses_changes.txt"; + # ignore header + readline(*MAP); + my %spdx; + while () { + chomp; + my ($license, $oldstring) = split(/\t/, $_, 2); + #$license =~ s,\s*$,,; + #$oldstring =~ s,\s*$,,; + next unless length($license); + #print STDERR "$license\t$oldstring\n"; + die "$oldstring is given twice in $_" if defined $license_replace{$oldstring}; + $license_replace{$oldstring} = $license; + $spdx{$license} = 1; + } + close(MAP); + for (keys %spdx) { + $license_replace{$_} = $_; + } +} + +sub replace_single_spdx($) +{ + my ($l) = @_; + + return '' if $l eq ''; + + load_license_map(); + $l =~ s,ORlater,or later,g; + $l =~ s,ORsim,or similar,g; + $l =~ s,^\s+,,; + $l =~ s,\s+$,,; + + if (defined $license_replace{$l}) { + $l = $license_replace{$l}; + } else { + print STDERR "Unknown license '$l'\n"; + exit(1); + } + return $l; +} + +sub replace_spdx_and($); +sub replace_spdx_and($) +{ + my ($license) = @_; + + # special case as or later is common in our spec files + $license =~ s,or later,ORlater,g; + $license =~ s,or similar,ORsim,g; + + #print STDERR "ORIG '$license'\n"; + my @licenses = (); + if ( $license =~ /^(.*?)\(([^)]*)\)(.*?)$/ ) { + my ($head, $paren, $tail) = ($1, $2, $3); + if ($paren =~ /and|or/) { + $head = replace_spdx_and($head); + $tail = replace_spdx_and($tail); + $paren = replace_spdx_and($paren); + #print STDERR "AFTE '$head($paren)$tail'\n"; + return "$head($paren)$tail"; + } + } + + for (split(/(\s+(?:and|or)\s+)/, $license, -1)) { + $_ = replace_single_spdx($_) unless $_ eq '' || /(\s+(?:and|or)\s+)/; + s/\s+/ /g; + push @licenses, $_; + } + #print STDERR "AFTE '" . join('', @licenses) . "'\n"; + return join('', @licenses); +} + +sub replace_spdx($) +{ + my ($license) = @_; + + my @licenses = (); + for (split(/\s*;\s*/, $license)) { + push @licenses, replace_spdx_and($_); + } + return join(' ; ', @licenses); +} + +sub set_current_pkg { + my ( $arg ) = @_; + print "DEBUG: set_current_pkg receiving $arg\n" if $debug; + my ( @argarray ) = split ( '\s+' , $arg ); + my $curpack = $base_package; + my $curlang = ""; + while (my $carg = shift @argarray) { + next if ($carg eq "%description" || $carg eq "%package" || $carg eq "%prep"); + if ($carg eq "-l") { + $curlang = shift @argarray; + } elsif ($carg eq "-n") { + $curpack = shift @argarray; + } else { + $curpack = "$base_package-" if $base_package; + $curpack .= $carg; + } + } + print "DEBUG: set_current_pkg returning $curpack, $curlang\n" if $debug; + return ($curpack, $curlang); +} + +sub read_and_parse_old_spec { + my ( $specfile, $base_package ) = @_; + my $current_package = $base_package; + my $current_lang = ""; + my $check_printed = "false"; + my $print_comments = "false"; + my %version; + my $ifhandler; + $ifhandler->{"disabled"} = 0; + + my @readspec; + open ( SPEC , "$specfile" ) || die "can't read specfile"; + @readspec = ; + close SPEC; + chomp @readspec; + + while (@readspec) { + $_ = shift @readspec; + + if ( /^\s*$/ && $current_section ne "description") { + # stop preamble parsing on two blank lines + if ($print_comments eq "false" && $oldspec[0] && $oldspec[-1] eq "XXXBLANKLINE") { + $print_comments = "true"; + push @oldspec, "XXXDOUBLELINE"; + next; + } + push @oldspec, "XXXBLANKLINE"; + next; + } + + if ( /^# vim:/ ) { + $vim_modeline = $_; + next; + } + + if ( /^#\s*needsrootforbuild\s*$/ ) { + $needsrootforbuild = 1; + next; + } + if ( /^#\s*needsbinariesforbuild\s*$/ ) { + $needsbinariesforbuild = 1; + next; + } + if ( /^#\s*norootforbuild/ ) { + next; + } + + if ( /^#\s*nodebuginfo\s*$/ ) { + $nodebuginfo = 1; + next; + } + if ( /^#\s*icecream/ ) { + $icecreamforbuild = $_; + $icecreamforbuild =~ s/^#\s*icecream\s*//; + next; + } + if ( /^#\s*Copyright\s*/ ) { + my $lastlineblank = 0; + for (;;) + { + # check if line is ONLY a standard copyright line, if so, ignore. + my $c = $_; + $c =~ s{\s*(\d+|copyrights?|\(c\)|suse|linux|products|gmbh|nuremberg|n..?rnberg|germany|\W+)\s*}{}gi; + push(@copyrights, $_) if length $c > 5; + last if length $readspec[0] < 10 || $readspec[0] =~ m{modifications and additions}i || $readspec[0] !~ /^[\#\s]/ + || grep { $readspec[0] =~ /^#\s*$_/ } ("needsrootforbuild","needsbinariesforbuild","nodebuginfo","icecream","usedforbuild","Commandline","MD5SUM","!BuildIgnore"); + $_ = shift @readspec; + } + next; + } + # evil epoch removal + next if ( /^Epoch:/ ); + $_ =~ s/%{?epoch}?[:-]//g; + $_ =~ s/ 0:/ /g if ( /^requires/i || /^buildreq/i ); + + if ( /^BuildRequires:/ ) { + my $cur_buildreq = $_; + $cur_buildreq =~ s/^BuildRequires:\s*//; + my %aa; + while ($cur_buildreq =~ m{([^,\s]+(\s*[<=>]+\s*[^,\s]+)?)}g) { + $aa{$1}=1; + } + # ignore line if it looks like a "usedforbuild" line, i.e. + # if it contains too many base packages + next if (grep {$aa{$_}} qw{gcc rpm glibc bash}) > 2; + for my $br (sort keys(%aa)) { + push @oldspec, "BuildRequires: $br"; + } + next; + } + next if ( /^#\s*usedforbuild/ ); + if ( /^%\?__\*BuildRequires:/ ) { + push @oldspec, $_; + next; + } + if ( /^#!__\*BuildRequires:/ ) { + push @oldspec, $_; + next; + } + if ( /^#!BuildIgnore:/ ) { + push @oldspec, $_; + next; + } + + if ( /^#/ && $current_section ne "description") { + warn "$_ $current_section\n" if $debug; + if ( $print_comments eq "true" || $readspec[0] =~ /^%define/ || $readspec[0] =~ /^%if/) { + push @oldspec, $_; + } + next; + } + + if ( /^%debug_package/ ) { + # remove, we add this ourselves + next; + } + $print_comments = "true" unless /^#/; + + if ( /^%define\s*vendor\s/ || /^%define\s*distribution\s/ ) { + next; + } + + if ( /^\s*%if/ || /^\s*%\{/ || /^\s*%define/ || /^\s*%el/ || /^\s*%endif/ ) { + change_section("header") if ($current_section eq "description"); + push @oldspec, $_; + if ( /^\s*%if\s/ ) { + my @args = split (/\s+/,$_); + $_ =~ s/[\{\}\"]//g for (@args); + $ifhandler->{"last_if_disabled"} = 0; + $ifhandler->{"last_if_if"} = 1; + $ifhandler->{"depth"}++; + my $if_not = 0; + if ( $args[1] =~ /^\!/ ) { + $args[1] =~ s/^\!//; + $if_not = 1; + } + $args[2] = "" unless $args[2]; + if ( ($args[1] eq "0") + || ($args[1] eq "%name" && $args[2] eq "!=" && $args[3] eq $base_package) + || ($args[1] eq "%name" && $args[2] eq "==" && $args[3] ne $base_package) + || ($args[1] && !$args[3] && !$if_not && $definelist->{$args[1]} && $definelist->{$args[1]} eq "0") + || ($args[2] eq "==" && $args[3] ne "0" && $definelist->{$args[1]} && $definelist->{$args[1]} eq "0") + || ($args[2] eq "!=" && $args[3] eq "0" && $definelist->{$args[1]} && $definelist->{$args[1]} eq "0") + || ($args[1] && !$args[3] && $if_not && $definelist->{$args[1]} && $definelist->{$args[1]} eq "1") + || ($args[1] && $args[2] eq "!=" && $args[3] eq "1" && $definelist->{$args[1]} && $definelist->{$args[1]} eq "1") ) { + $ifhandler->{"disabled"} = $ifhandler->{"depth"}; + $ifhandler->{"last_if_disabled"} = 1; + } + } elsif ( /^\s*%if/ ) { + $ifhandler->{"last_if_disabled"} = 0; + $ifhandler->{"last_if_if"} = 0; + $ifhandler->{"depth"}++; + } elsif ( /^\s*%endif/ ) { + $ifhandler->{"disabled"} = 0 if $ifhandler->{"disabled"} == $ifhandler->{"depth"}; + $ifhandler->{"depth"}--; + } elsif ( /^\s*%else/ ) { + if ($ifhandler->{"disabled"} == $ifhandler->{"depth"} && $ifhandler->{"last_if_disabled"} == 1) { + $ifhandler->{"disabled"} = 0; + } elsif ($ifhandler->{"disabled"} == 0 && $ifhandler->{"depth"} == 1 && $ifhandler->{"last_if_if"} == 1) { + $ifhandler->{"disabled"} = 1; + } + } elsif ( /^\s*%define\s/ ) { + my @args = split (/\s+/,$_); + $_ =~ s/[\{\}\"]//g for (@args); + $args[2] =~ s/\Q$_\E/$definelist->{$_}/g for sort { length($b) <=> length($a) } keys (%{$definelist}); + if ( $args[2] !~ /[\(\)\{\}\@\%\"\\]/ ) { + $definelist->{"%".$args[1]} = $args[2] if $ifhandler->{"disabled"} == 0; + $definelist->{"%{".$args[1]."}"} = $args[2] if $ifhandler->{"disabled"} == 0; + $definelist->{"%{?".$args[1]."}"} = $args[2] if $ifhandler->{"disabled"} == 0; + } + while ($_ =~ /\\$/) { + $_ = shift @readspec; + push @oldspec, $_; + } + } + next; + } + if ( /^%package\b/i or /^%prep\b/i ) { + if (/^%package\b/i) { + change_section("header"); + } else { + change_section("prep"); + } + $_ =~ s/^(%\w+)/lc($1)/e; + if ($debug) { + warn "key: $_ value: $definelist->{$_}\n" for (sort { length($b) <=> length($a) } keys (%{$definelist})); + } + push @oldspec, $_; + for my $xx (sort { length($b) <=> length($a) } keys (%{$definelist})) { + $_ =~ s/\Q$xx\E/$definelist->{$xx}/; + } + $_ =~ s/%{\?[^\}]*}//; + if ($debug) { + warn "after: $_\n"; + } + ($current_package, $current_lang) = set_current_pkg ( $_ ); + if ($ifhandler->{"disabled"}) { + $disabled_packs->{$current_package} = 1; + warn "$current_package is disabled\n" if $debug; + } + next; + } + if ( /^%description\b/i ) { + change_section("description"); + push @oldspec, $_; + next; + } + if ( /^%install\b/i ) { + change_section("install"); + push @oldspec, $_; + next; + } + if ( /^%changelog\b/i ) { + change_section("changelog"); + # changelog comes always from *.changes. Skip what is in spec file + # at the moment. + next; + } + if (/^%files\b/i) { + change_section("files"); + $current_section = "files"; + } + if ( /^%/ ) { + if ( m/$section_tags_re/oi ) { + $_ =~ s/^(%\w+)/lc($1)/e; + change_section("header") if (! m/\s*%files/i && !m/\s*%build/i); + change_section("build") if m/\s*%build/i; + warn "changed to $current_section for $_\n" if $debug; + } + + push @oldspec, "$_"; + next; + } + + if ($current_section eq "header") { + my $c_pack = $current_package; + $c_pack .= "_disabled" if $ifhandler->{"disabled"}; + + if ( /^Vendor:/ || /^Distribution:/ || /^Packager:/ ) { + next; + } + # remove default value of Autoreqprov + if ( /^Autoreqprov\s*:\s*(.*)/i ) { + next if ( lc($1) eq "on" || lc($1) eq "yes"); + } + # reset Release + if ( /^Release\s*:\s*(.*)/i ) { + # will be after Version + next; + } + if ( /^Summary\s*:\s*(.*)\s*$/i ) { + push @oldspec, sprintf("%-16s%s", "Summary:", $1); + push @oldspec, "XXXPOSTSUMMARY $current_package"; + next; + } + + # remove license and print out after license later + if ( /^License\s*:\s*(.*)\s*$/i || /^Copyright\s*:\s*(.*)\s*$/i ) { + my $license = replace_spdx($1); + $main_license = $license if (!$main_license); + $seen_licenses{$current_package} = $license; + next; + } + + # remove groups and print out after summary later + if ( /^Group\s*:\s*(.*)\s*$/i ) { + my $group = $1; + $main_group = $group if (!$main_group); + $seen_groups{$current_package} = $group; + next; + } + + if ( /^BuildArchitectures\s*:/i ) { + $_ =~ s/^[^:]+:/BuildArch:/; + } + + if ( /^BuildRoot\s*:/i ) { + push @oldspec, "BuildRoot: %{_tmppath}/%{name}-%{version}-build"; + next; + } + + if ( m/$global_tags_re\s*(.*)/oi ) { + my ($tag, $value) = ($1, $2); + $nosrc_result = 1 if ($tag =~ /(?:nosource|nopatch)/i); + push @oldspec, sprintf("%-16s%s", capitalize_case($tag) . ":", $value); + next; + } + if ( /^Version:/ ) { + warn "found Version, section = $current_section\n" if $debug; + $version{$c_pack} = $_; + $version{$c_pack} =~ s/^Version:\s*(.*)\s*/$1/; + push @oldspec, sprintf("%-16s%s","Version:",$version{$c_pack}); + push @oldspec, sprintf("%-16s%s","Release:", "0"); + next; + } + } + if ( $current_section ne "changelog" ) { + push @oldspec, $_; + next; + } + } + +} + +my $specfile = shift ( @ARGV ); +if ( ! stat($specfile) ) { + die "$specfile is no file"; +} + + +my @specpath = split ('/' ,$specfile); +my $specbase = pop @specpath; +my $specdir = join ('/', @specpath); + +if ( $specdir eq "" ) { + $specdir = "."; +} +my $xdefinelist; +my $seen_name = 0; +open ( SPE , "$specfile" ); +while ( ) { + chomp; + + if ( m/^License\s*:\s*(.*)\s*$/ ) { + printf("%-16s%s\n","License:", replace_spdx($1)); + } else { + print "$_\n"; + } +} + diff --git a/prepare_spec b/prepare_spec index 43615d0..c954a9d 100644 --- a/prepare_spec +++ b/prepare_spec @@ -120,136 +120,83 @@ sub change_section($) warn "section changed to $current_section\n" if $debug; } +my %license_replace = (); +use File::Basename; + +sub load_license_map() +{ + return if defined $license_replace{"GPL-2.0"}; + my $scriptdir = File::Basename::dirname($0); + open(MAP, "$scriptdir/licenses_changes.txt") || die "can't open licenses_changes.txt"; + # ignore header + readline(*MAP); + my %spdx; + while () { + chomp; + my ($license, $oldstring) = split(/\t/, $_, 2); + #$license =~ s,\s*$,,; + #$oldstring =~ s,\s*$,,; + next unless length($license); + #print STDERR "$license\t$oldstring\n"; + die "$oldstring is given twice in $_" if defined $license_replace{$oldstring}; + $license_replace{$oldstring} = $license; + $spdx{$license} = 1; + } + close(MAP); + for (keys %spdx) { + $license_replace{$_} = $_; + } +} + sub replace_single_spdx($) { my ($l) = @_; - my %replace = ( - "lgplv2.1only" =>"LGPL-2.1", - "lgplv2.1orlater" => "LGPL-2.1+", - "lgplv2.1+" => "LGPL-2.1+", - "lgplv2.1" => "LGPL-2.1", - "lgplv2.0+" => "LGPL-2.0+", - "lgplv2.0" => "LGPL-2.0", - "lgplv2+" => "LGPL-2.1+", + return '' if $l eq ''; - 'lgplv3' => "LGPL-3.0", - 'lgplv3+' => "LGPL-3.0+", - 'gnulgplv2.1orlater' => "LGPL-2.1+", - 'gnulgplv2.1' => "LGPL-2.1", - 'lgplv2.0orlater' => 'LGPL-2.0+', - 'lgplv2orlater' => 'LGPL-2.0+', + load_license_map(); + $l =~ s,ORlater,or later,g; + $l =~ s,ORsim,or similar,g; + $l =~ s,^\s+,,; + $l =~ s,\s+$,,; - "lgplv3only" => "LGPL-3.0", - "lgplv3orlater" => "LGPL-3.0+", - - "gpl" => "GPL-1.0", - "gpl+" => "GPL-1.0+", - "gplv2only" => "GPL-2.0", - "gplv2" => "GPL-2.0", - "gpl2" => "GPL-2.0", - "gplv2orlater" => "GPL-2.0+", - "gplv2.0orlater" => "GPL-2.0+", - "gplv2+" => "GPL-2.0+", - "gpl-2+" => "GPL-2.0+", - "gplv3only" => "GPL-3.0", - "gplv3orlater" => "GPL-3.0+", - "gplv3+" => "GPL-3.0+", - "gplv3" => "GPL-3.0", - "gpl-3+" => "GPL-3.0+", - "gnugplversion3" => "GPL-3.0", - - "fdl1.1" => "GFDL-1.1", - "gfdlv1.1" => "GFDL-1.1", - 'gnufreedocumentationlicense,version1.1(fdl1.1)' => "GFDL-1.1", - 'gnufreedocumentationlicense,version1.1(gfdl1.1)' => "GFDL-1.1", - "fdl1.2" => "GFDL-1.2", - "gfdl1.2" => "GFDL-1.2", - "gfdlv1.2" => "GFDL-1.2", - 'gnufreedocumentationlicense,version1.2(fdl1.2)' => "GFDL-1.2", - 'gnufreedocumentationlicense,version1.2(gfdl1.2)' => "GFDL-1.2", - "fdl1.3" => "GFDL-1.3", - - "bsd-2c" => "BSD-2-Clause", - "bsd3-clause" => "BSD-3-Clause", - "bsd3c" => "BSD-3-Clause", - "bsd3c(orsimilar)" => "BSD-3-Clause", - "bsd3-clause(orsimilar)" => "BSD-3-Clause", - - "bsd4c" => "BSD-4-Clause", - "bsd4c(orsimilar)" => "BSD-4-Clause", - - "x11/mit" => "MIT", - "X11mit" => "MIT", - "mitlicense(orsimilar)" => "MIT", - - "asl2.0" => "Apache-2.0", - 'apachelicense2.0' => "Apache-2.0", - 'apachelicense' => "Apache-2.0", - 'theapachesoftwarelicense' => "Apache-2.0", - "apachesoftwarelicense.." => "Apache-2.0", - 'apachesoftware license..' => "Apache-2.0", - 'aslv..' => "Apache-2.0", - 'aslv2' => "Apache-2.0", - - "artistic" => "Artistic-1.0", - "artistic2.0" => "Artistic-2.0", - - "thephplicense,version3.01" => "PHP-3.01", - "phplicense" => "PHP-3.01", - "mplv1.0" => "MPL-1.0", - "mplv1.1" => "MPL-1.1", - - "ibmpubliclicense.." => "IPL-1.0", - "ibmpl" => "IPL-1.0", - - "eclipsepubliclicense" => "EPL-1.0", - - "openldap2.8" => "OLDAP-2.8", - - "zliblicense" => "Zlib" - - ); - - my $tl = lc $l; - $tl =~ s, ,,g; - if (defined $replace{$tl}) { - $l = $replace{$tl}; + if (defined $license_replace{$l}) { + $l = $license_replace{$l}; } else { - my @m = grep(lc($_) eq lc($l), values(%replace)); - if (@m) { - $l = $m[0]; - } else { - print STDERR "unknown license '$l'\n"; - } + print STDERR "Unknown license '$l'\n"; } return $l; } -sub replace_spdx_or($) -{ - my ($license) = @_; - - # special case as or later is common in our spec files - $license =~ s, or later, orlater,g; - - my @licenses = (); - for (split(/\s+or\s+/, $license)) { - push @licenses, replace_single_spdx($_); - } - - return join(' or ', sort(@licenses)); -} - +sub replace_spdx_and($); sub replace_spdx_and($) { my ($license) = @_; + # special case as or later is common in our spec files + $license =~ s,or later,ORlater,g; + $license =~ s,or similar,ORsim,g; + + #print STDERR "ORIG '$license'\n"; my @licenses = (); - for (split(/\s*and\s*/, $license)) { - push @licenses, replace_spdx_or($_); + if ( $license =~ /^(.*?)\(([^)]*)\)(.*?)$/ ) { + my ($head, $paren, $tail) = ($1, $2, $3); + if ($paren =~ /and|or/) { + $head = replace_spdx_and($head); + $tail = replace_spdx_and($tail); + $paren = replace_spdx_and($paren); + #print STDERR "AFTE '$head($paren)$tail'\n"; + return "$head($paren)$tail"; + } } - return join(' and ', sort(@licenses)); + + for (split(/(\s+(?:and|or)\s+)/, $license, -1)) { + $_ = replace_single_spdx($_) unless $_ eq '' || /(\s+(?:and|or)\s+)/; + s/\s+/ /g; + push @licenses, $_; + } + #print STDERR "AFTE '" . join('', @licenses) . "'\n"; + return join('', @licenses); } sub replace_spdx($) @@ -260,7 +207,7 @@ sub replace_spdx($) for (split(/\s*;\s*/, $license)) { push @licenses, replace_spdx_and($_); } - return join(' ; ', sort(@licenses)); + return join(' ; ', @licenses); } sub set_current_pkg { From 9174eae52602fe370f798d02564a62091847c2c51b960de857975b9ff67372c8 Mon Sep 17 00:00:00 2001 From: Stephan Kulow Date: Wed, 7 Dec 2011 08:28:39 +0000 Subject: [PATCH 4/9] add url OBS-URL: https://build.opensuse.org/package/show/openSUSE:Tools/obs-service-format_spec_file?expand=0&rev=28 --- _service:format_spec_file:obs-service-format_spec_file.spec | 1 + obs-service-format_spec_file.spec | 1 + 2 files changed, 2 insertions(+) diff --git a/_service:format_spec_file:obs-service-format_spec_file.spec b/_service:format_spec_file:obs-service-format_spec_file.spec index c61d7c8..45028e2 100644 --- a/_service:format_spec_file:obs-service-format_spec_file.spec +++ b/_service:format_spec_file:obs-service-format_spec_file.spec @@ -23,6 +23,7 @@ License: GPL-2.0+ Group: Development/Tools/Building Version: 0.4 Release: 0 +Url: https://github.com/openSUSE/obs-service-format_spec_file Source: format_spec_file Source1: format_spec_file.service Source2: prepare_spec diff --git a/obs-service-format_spec_file.spec b/obs-service-format_spec_file.spec index 3e352a1..cf1b31f 100644 --- a/obs-service-format_spec_file.spec +++ b/obs-service-format_spec_file.spec @@ -22,6 +22,7 @@ License: GPL-2.0+ Group: Development/Tools/Building Version: 0.4 Release: 0 +Url: https://github.com/openSUSE/obs-service-format_spec_file Source: format_spec_file Source1: format_spec_file.service Source2: prepare_spec From 996a0af0afece3eaec228abc49f7f372d34c87f97b726fd2eca219716c02b217 Mon Sep 17 00:00:00 2001 From: Stephan Kulow Date: Wed, 7 Dec 2011 14:05:00 +0000 Subject: [PATCH 5/9] - move pkgconfig() and co to the end of the buildrequires OBS-URL: https://build.opensuse.org/package/show/openSUSE:Tools/obs-service-format_spec_file?expand=0&rev=29 --- licenses_changes.txt | 2 +- obs-service-format_spec_file.changes | 5 +++++ prepare_spec | 16 ++++++++++++++-- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/licenses_changes.txt b/licenses_changes.txt index 7aeebb7..c2ee98a 100644 --- a/licenses_changes.txt +++ b/licenses_changes.txt @@ -1,3 +1,4 @@ +SPDX Name in Spec File AAL AAL AFL-2.1 Academic Free License 2.1 AGPL-3.0 Affero GPL @@ -288,7 +289,6 @@ MS-PL Ms-Pl MS-PL MS-PL MS-RL MS-RL Multics Multics -SPDX Name in Spec File NASA-1.3 NASA-1.3 Naumen Naumen NCSA NCSA diff --git a/obs-service-format_spec_file.changes b/obs-service-format_spec_file.changes index 3e8307b..b3b8073 100644 --- a/obs-service-format_spec_file.changes +++ b/obs-service-format_spec_file.changes @@ -1,3 +1,8 @@ +------------------------------------------------------------------- +Wed Dec 7 14:04:46 UTC 2011 - coolo@suse.com + +- move pkgconfig() and co to the end of the buildrequires + ------------------------------------------------------------------- Wed Dec 7 08:22:29 UTC 2011 - coolo@suse.com diff --git a/prepare_spec b/prepare_spec index c954a9d..6393469 100644 --- a/prepare_spec +++ b/prepare_spec @@ -231,6 +231,18 @@ sub set_current_pkg { return ($curpack, $curlang); } +sub sort_buildrequires_helper { + if (($a =~ /^[^#]*\(/) != ($b =~ /^[^#]*\(/)) { + if ($a =~ /^[^#]*\(/) { + 1; + } else { + -1; + } + } else { + $a cmp $b; + } +} + sub read_and_parse_old_spec { my ( $specfile, $base_package ) = @_; my $current_package = $base_package; @@ -614,9 +626,9 @@ while ($linesmoved) { } else { # if there are already buildrequires, we need to sort and exit if (@buildrequires > 0) { - my @sortedbrs = sort(@buildrequires); + my @sortedbrs = sort sort_buildrequires_helper @buildrequires; $linesmoved = !compare_arrays(\@buildrequires, \@sortedbrs); - @oldspec = (@firstlines, sort(@buildrequires), $l, @oldspec); + @oldspec = (@firstlines, @sortedbrs, $l, @oldspec); @firstlines = (); @buildrequires = (); last; From 6385ac95fba1f107b7e461163623694b1023b81c8051fba7242da1da995822af Mon Sep 17 00:00:00 2001 From: Stephan Kulow Date: Mon, 12 Dec 2011 10:29:11 +0000 Subject: [PATCH 6/9] - preserve release tag if it's more than a number OBS-URL: https://build.opensuse.org/package/show/openSUSE:Tools/obs-service-format_spec_file?expand=0&rev=30 --- obs-service-format_spec_file.changes | 5 +++++ prepare_spec | 9 +++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/obs-service-format_spec_file.changes b/obs-service-format_spec_file.changes index b3b8073..aedbff9 100644 --- a/obs-service-format_spec_file.changes +++ b/obs-service-format_spec_file.changes @@ -1,3 +1,8 @@ +------------------------------------------------------------------- +Mon Dec 12 10:28:57 UTC 2011 - coolo@suse.com + +- preserve release tag if it's more than a number + ------------------------------------------------------------------- Wed Dec 7 14:04:46 UTC 2011 - coolo@suse.com diff --git a/prepare_spec b/prepare_spec index 6393469..1b3a643 100644 --- a/prepare_spec +++ b/prepare_spec @@ -24,7 +24,6 @@ my $vim_modeline; my $nosrc_result = 0; my $current_section = "header"; my $had_debug_package = 0; -my %pkg_version = (); my $main_license; my %seen_licenses = (); my $main_group; @@ -490,6 +489,10 @@ sub read_and_parse_old_spec { } # reset Release if ( /^Release\s*:\s*(.*)/i ) { + if ($1 !~ m/^[0-9]*$/ && $oldspec[-1] eq "XXXRELEASE") { + pop @oldspec; + push @oldspec, sprintf("%-16s%s","Release:", $1); + } # will be after Version next; } @@ -535,7 +538,7 @@ sub read_and_parse_old_spec { $version{$c_pack} = $_; $version{$c_pack} =~ s/^Version:\s*(.*)\s*/$1/; push @oldspec, sprintf("%-16s%s","Version:",$version{$c_pack}); - push @oldspec, sprintf("%-16s%s","Release:", "0"); + push @oldspec, "XXXRELEASE"; next; } } @@ -688,6 +691,8 @@ while (@oldspec) { print "\n" unless $oldspec[0] && ($oldspec[0] =~ m/^XXX.*LINE/ || $oldspec[0] =~ /^\s*$/ || $oldspec[0] =~ /^\n/); } elsif ($line eq "XXXDOUBLELINE") { print "\n\n" unless $oldspec[0] && ($oldspec[0] =~ m/^XXX.*LINE/ || $oldspec[0] =~ /^\s*$/ || $oldspec[0] =~ /^\n/); + } elsif ($line eq "XXXRELEASE") { + printf("%-16s%s\n", "Release:", "0") ; } elsif ($line =~ m/XXXPOSTSUMMARY (.*)$/) { my $current_package = $1; my $license = $seen_licenses{$current_package} || $main_license; From 29b0028bca515054cb88ecea717a1fcba9625c86b18774de47a33615724083e9 Mon Sep 17 00:00:00 2001 From: OBS User buildservice-autocommit Date: Mon, 12 Dec 2011 15:58:19 +0000 Subject: [PATCH 7/9] Accepting request 95751 from openSUSE:Tools baserev update by copy to link target OBS-URL: https://build.opensuse.org/request/show/95751 OBS-URL: https://build.opensuse.org/package/show/openSUSE:Tools/obs-service-format_spec_file?expand=0&rev=32 --- ...pec_file:obs-service-format_spec_file.spec | 63 ------------------- 1 file changed, 63 deletions(-) delete mode 100644 _service:format_spec_file:obs-service-format_spec_file.spec diff --git a/_service:format_spec_file:obs-service-format_spec_file.spec b/_service:format_spec_file:obs-service-format_spec_file.spec deleted file mode 100644 index 45028e2..0000000 --- a/_service:format_spec_file:obs-service-format_spec_file.spec +++ /dev/null @@ -1,63 +0,0 @@ -# -# spec file for package obs-service-format_spec_file -# -# Copyright (c) 2011 SUSE LINUX Products GmbH, Nuernberg, Germany. -# -# All modifications and additions to the file contributed by third parties -# remain the property of their copyright owners, unless otherwise agreed -# upon. The license for this file, and modifications and additions to the -# file, is the same license as for the pristine package itself (unless the -# license for the pristine package is not an Open Source License, in which -# case the license is the MIT License). An "Open Source License" is a -# license that conforms to the Open Source Definition (Version 1.9) -# published by the Open Source Initiative. - -# Please submit bugfixes or comments via http://bugs.opensuse.org/ -# - - - -Name: obs-service-format_spec_file -Summary: An OBS source service: reformats a spec file to SUSE standard -License: GPL-2.0+ -Group: Development/Tools/Building -Version: 0.4 -Release: 0 -Url: https://github.com/openSUSE/obs-service-format_spec_file -Source: format_spec_file -Source1: format_spec_file.service -Source2: prepare_spec -Source3: patch_license -Source4: licenses_changes.txt -Requires: osc-source_validator -BuildRoot: %{_tmppath}/%{name}-%{version}-build -BuildArch: noarch - -%description -This is a source service for openSUSE Build Service. - -This source service is formating the spec file to SUSE standard. The rational -behind is to make it easier to review spec files from unknown packagers. - -This should be used in "trylocal" mode, so that osc is adapting the existing -spec file instead of creating a new one. - -%prep - -%setup -q -D -T 0 -n . - -%build - -%install -mkdir -p $RPM_BUILD_ROOT/usr/lib/obs/service/format_spec_file.files -install -m 0755 %{SOURCE0} $RPM_BUILD_ROOT/usr/lib/obs/service -install -m 0644 %{SOURCE1} $RPM_BUILD_ROOT/usr/lib/obs/service -install -m 0755 %{SOURCE2} %{SOURCE3} $RPM_BUILD_ROOT/usr/lib/obs/service/format_spec_file.files -install -m 0644 %{SOURCE4} $RPM_BUILD_ROOT/usr/lib/obs/service/format_spec_file.files - -%files -%defattr(-,root,root) -%dir /usr/lib/obs -/usr/lib/obs/service - -%changelog From b47e2c0c1a400b2d145d8240e2e1676b829e5cc2145e967ca23ecd51237daa86 Mon Sep 17 00:00:00 2001 From: Stephan Kulow Date: Thu, 15 Dec 2011 14:00:23 +0000 Subject: [PATCH 8/9] - more licenses for SUSE-* OBS-URL: https://build.opensuse.org/package/show/openSUSE:Tools/obs-service-format_spec_file?expand=0&rev=33 --- ...pec_file:obs-service-format_spec_file.spec | 63 +++++++++++++++++++ licenses_changes.txt | 7 ++- obs-service-format_spec_file.changes | 5 ++ 3 files changed, 74 insertions(+), 1 deletion(-) create mode 100644 _service:format_spec_file:obs-service-format_spec_file.spec diff --git a/_service:format_spec_file:obs-service-format_spec_file.spec b/_service:format_spec_file:obs-service-format_spec_file.spec new file mode 100644 index 0000000..45028e2 --- /dev/null +++ b/_service:format_spec_file:obs-service-format_spec_file.spec @@ -0,0 +1,63 @@ +# +# spec file for package obs-service-format_spec_file +# +# Copyright (c) 2011 SUSE LINUX Products GmbH, Nuernberg, Germany. +# +# All modifications and additions to the file contributed by third parties +# remain the property of their copyright owners, unless otherwise agreed +# upon. The license for this file, and modifications and additions to the +# file, is the same license as for the pristine package itself (unless the +# license for the pristine package is not an Open Source License, in which +# case the license is the MIT License). An "Open Source License" is a +# license that conforms to the Open Source Definition (Version 1.9) +# published by the Open Source Initiative. + +# Please submit bugfixes or comments via http://bugs.opensuse.org/ +# + + + +Name: obs-service-format_spec_file +Summary: An OBS source service: reformats a spec file to SUSE standard +License: GPL-2.0+ +Group: Development/Tools/Building +Version: 0.4 +Release: 0 +Url: https://github.com/openSUSE/obs-service-format_spec_file +Source: format_spec_file +Source1: format_spec_file.service +Source2: prepare_spec +Source3: patch_license +Source4: licenses_changes.txt +Requires: osc-source_validator +BuildRoot: %{_tmppath}/%{name}-%{version}-build +BuildArch: noarch + +%description +This is a source service for openSUSE Build Service. + +This source service is formating the spec file to SUSE standard. The rational +behind is to make it easier to review spec files from unknown packagers. + +This should be used in "trylocal" mode, so that osc is adapting the existing +spec file instead of creating a new one. + +%prep + +%setup -q -D -T 0 -n . + +%build + +%install +mkdir -p $RPM_BUILD_ROOT/usr/lib/obs/service/format_spec_file.files +install -m 0755 %{SOURCE0} $RPM_BUILD_ROOT/usr/lib/obs/service +install -m 0644 %{SOURCE1} $RPM_BUILD_ROOT/usr/lib/obs/service +install -m 0755 %{SOURCE2} %{SOURCE3} $RPM_BUILD_ROOT/usr/lib/obs/service/format_spec_file.files +install -m 0644 %{SOURCE4} $RPM_BUILD_ROOT/usr/lib/obs/service/format_spec_file.files + +%files +%defattr(-,root,root) +%dir /usr/lib/obs +/usr/lib/obs/service + +%changelog diff --git a/licenses_changes.txt b/licenses_changes.txt index c2ee98a..ebd97a8 100644 --- a/licenses_changes.txt +++ b/licenses_changes.txt @@ -1,4 +1,4 @@ -SPDX Name in Spec File +SPDX Name in Spec File AAL AAL AFL-2.1 Academic Free License 2.1 AGPL-3.0 Affero GPL @@ -138,6 +138,7 @@ EUPL-1.1 EUPL-1.1 MIT Expat MIT Expat License Fair Fair +SUSE-FLTK Fltk SUSE-GFDL-1.1 FDL v1.1 or later SUSE-GFDL-1.2+ FDL-1.2+ SUSE-GFDL-1.3+ FDL-1.3+ @@ -221,7 +222,9 @@ GPL-2.0+ GPLv2+ GPL-3.0 GPLv3 GPL-3.0+ GPLv3+ gSOAP-1.3b gSOAP-1.3b +SUSE-Gnuplot Gnuplot HPND HPND +SUSE-IJG JPEG License IPL-1.0 IBM PL IPL-1.0 IBM Public License IPL-1.0 IBM Public License .. @@ -364,3 +367,5 @@ ZPL-2.1 ZPL 2.1 ZPL-1.1 ZPL-1.1 ZPL-2.0 ZPL-2.0 ZPL-2.1 ZPL-2.1 +SUSE-Firmware Firmware license, redistributable unmodified +SUSE-Permissive Must not be copyleft. Must not contain patent clauses of any nature. Most not limit ability to copy, modifiy, distribute (through multiple tiers of distribution) and distribute modified versions. Must not impose obligations such as 'advertising clauses' or anything that could be viewed as an 'additional restriction' under GPL-2.0+ or GPL-3.0+. Must not impose obligations such as modification by patch only, or reciprocal clauses. \ No newline at end of file diff --git a/obs-service-format_spec_file.changes b/obs-service-format_spec_file.changes index aedbff9..b66f81d 100644 --- a/obs-service-format_spec_file.changes +++ b/obs-service-format_spec_file.changes @@ -1,3 +1,8 @@ +------------------------------------------------------------------- +Thu Dec 15 13:59:55 UTC 2011 - coolo@suse.com + +- more licenses for SUSE-* + ------------------------------------------------------------------- Mon Dec 12 10:28:57 UTC 2011 - coolo@suse.com From 8ca6ced9070a80939e70542323b87d55ec4a175300e0b2839114eacb36a2de9a Mon Sep 17 00:00:00 2001 From: Stephan Kulow Date: Mon, 19 Dec 2011 08:42:52 +0000 Subject: [PATCH 9/9] - put groups in subpackages unconditionally to leave sle11 support intact OBS-URL: https://build.opensuse.org/package/show/openSUSE:Tools/obs-service-format_spec_file?expand=0&rev=34 --- obs-service-format_spec_file.changes | 6 ++++++ prepare_spec | 2 ++ 2 files changed, 8 insertions(+) diff --git a/obs-service-format_spec_file.changes b/obs-service-format_spec_file.changes index b66f81d..0729f76 100644 --- a/obs-service-format_spec_file.changes +++ b/obs-service-format_spec_file.changes @@ -1,3 +1,9 @@ +------------------------------------------------------------------- +Mon Dec 19 08:40:02 UTC 2011 - coolo@suse.com + +- put groups in subpackages unconditionally to leave sle11 support + intact + ------------------------------------------------------------------- Thu Dec 15 13:59:55 UTC 2011 - coolo@suse.com diff --git a/prepare_spec b/prepare_spec index 1b3a643..b100e5a 100644 --- a/prepare_spec +++ b/prepare_spec @@ -682,6 +682,8 @@ while ($oldspec[0] eq "XXXBLANKLINE") { my $license_unique = !grep { $_ ne $main_license } values %seen_licenses; my $groups_unique = !grep { $_ ne $main_group } values %seen_groups; +# we need to have unique groups in the spec file as long as we support SLE11 ;( +$groups_unique = 0; my $first_summary = 1; my $line;