Skip to content
This repository has been archived by the owner on Jun 23, 2020. It is now read-only.

Commit

Permalink
Merge 5bdf8ab into 8c19023
Browse files Browse the repository at this point in the history
  • Loading branch information
movitto committed Feb 17, 2016
2 parents 8c19023 + 5bdf8ab commit d845826
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 4 deletions.
17 changes: 17 additions & 0 deletions lib/polisher/rpm/condition.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Polisher RPM Conditon (%if / %endif block
#
# Licensed under the MIT license
# Copyright (C) 2016 Red Hat, Inc.

module Polisher
module RPM
class Condition
attr_accessor :str, :parent

def initialize(args = {})
@str = args[:str]
@parent = args[:parent]
end
end
end # module RPM
end # module Polisher
2 changes: 2 additions & 0 deletions lib/polisher/rpm/requirement.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ def initialize(args = {})
@condition = args[:condition]
@version = args[:version]

@spec_condition = args[:spec_condition]

@name.strip! unless @name.nil?
@condition.strip! unless @condition.nil?
@version.strip! unless @version.nil?
Expand Down
4 changes: 4 additions & 0 deletions lib/polisher/rpm/spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

require "active_support/core_ext/hash/except"

require 'polisher/rpm/spec/conditions'
require 'polisher/rpm/spec/requirements'
require 'polisher/rpm/spec/files'
require 'polisher/rpm/spec/subpackages'
Expand All @@ -21,6 +22,7 @@
module Polisher
module RPM
class Spec
include SpecConditions
include SpecRequirements
include SpecFiles
include SpecSubpackages
Expand Down Expand Up @@ -53,6 +55,8 @@ class Spec
SPEC_GEM_REQ_MATCHER = /^.*\s*#{requirement_prefix}\((.*)\)(\s*(.*))?$/
SPEC_SUBPACKAGE_MATCHER = /^%package\s(.*)$/
SPEC_DOC_SUBPACKAGE_MATCHER = /^%package\sdoc$/
SPEC_CONDITION_MATCHER = /^%if(.*)$/
SPEC_CONDITION_END_MATCHER = /^%endif(.*)$/
SPEC_CHANGELOG_MATCHER = /^%changelog$/
SPEC_FILES_MATCHER = /^%files$/
SPEC_SUBPKG_FILES_MATCHER = /^%files\s*(.*)$/
Expand Down
19 changes: 19 additions & 0 deletions lib/polisher/rpm/spec/conditions.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# RPM Spec Conditions Mixin
#
# Licensed under the MIT license
# Copyright (C) 2016 Red Hat, Inc.

require 'polisher/rpm/condition'

module Polisher
module RPM
module SpecConditions
def self.included(base)
base.extend(ClassMethods)
end

module ClassMethods
end
end # module SpecConditions
end # module RPM
end # module Polisher
18 changes: 16 additions & 2 deletions lib/polisher/rpm/spec/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ def self.included(base)
module ClassMethods
def default_metadata
{:contents => "",
:conditions => [],
:requires => [],
:build_requires => [],
:pkg_excludes => {},
Expand All @@ -35,6 +36,7 @@ def parse(spec)
subpkg_name = nil
meta = default_metadata.merge(:contents => spec)
macros = {}
condition_stack = []
spec.each_line do |l|
if l =~ RPM::Spec::COMMENT_MATCHER

Expand Down Expand Up @@ -62,11 +64,23 @@ def parse(spec)
subpkg_name = $1.strip
in_subpackage = true

elsif l =~ RPM::Spec::SPEC_CONDITION_MATCHER
condition_string = $1.strip
parent = condition_stack.empty? ? nil : condition_stack.first
condition = Condition.new(:str => condition_string,
:parent => parent)
meta[:conditions] << condition if condition_stack.empty?
condition_stack.unshift condition


elsif l =~ RPM::Spec::SPEC_CONDITION_END_MATCHER
condition_stack.shift

elsif l =~ RPM::Spec::SPEC_REQUIRES_MATCHER && !in_subpackage
meta[:requires] << RPM::Requirement.parse($1.strip)
meta[:requires] << RPM::Requirement.parse($1.strip, :spec_condition => condition_stack.first)

elsif l =~ RPM::Spec::SPEC_BUILD_REQUIRES_MATCHER && !in_subpackage
meta[:build_requires] << RPM::Requirement.parse($1.strip)
meta[:build_requires] << RPM::Requirement.parse($1.strip, :spec_condition => condition_stack.first)

elsif l =~ RPM::Spec::SPEC_CHANGELOG_MATCHER
in_changelog = true
Expand Down
4 changes: 2 additions & 2 deletions lib/polisher/rpm/spec/requirements.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# RPM Has Requirements Mixin
# RPM RPM Spec Requirements Mixin
#
# Licensed under the MIT license
# Copyright (C) 2013-2014 Red Hat, Inc.
# Copyright (C) 2013-2016 Red Hat, Inc.

require 'polisher/rpm/requirement'

Expand Down

0 comments on commit d845826

Please sign in to comment.