1 require "cruxutils/ohash.rb"
8 COMMENT_MAP = OHash.new
9 COMMENT_MAP["Description"] = :description
10 COMMENT_MAP["URL"] = :url
11 COMMENT_MAP["Packager"] = :packager
12 COMMENT_MAP["Maintainer"] = :maintainer
13 COMMENT_MAP["Depends on"] = :dependencies
14 COMMENT_MAP["Group"] = :group
15 COMMENT_MAP["Nice to have"] = :nice_to_have
23 def Port.find(pattern)
24 PORTDIRS.inject([]) do |memo, pd|
25 tmp = Dir["#{pd}/#{pattern}"].map { |d| Port.new(d) }
33 @attribs = Hash.new { |h, k| h[k] = "" }
35 @attribs[:dependencies] = Dependencies.new
36 @attribs[:source] = Sources.new
37 @attribs[:build] = BuildFunc.new
42 def method_missing(meth, *args)
43 if meth.to_s.match(/=$/) then
44 m2 = meth.to_s[0...-1].to_sym
45 @attribs[m2] = (args.length < 2 ? args.first : args)
52 @attribs[:dependencies].uniq!
53 @attribs[:dependencies]
57 File.exist?(footprint)
65 Tempfile.open("pkgfile") do |file|
66 COMMENT_MAP.each do |key, symbol|
67 value = @attribs[symbol]
70 file << "# #{key}: " << value << "\n"
75 vars = [:name, :version, :release, :source]
81 file << "\n" << build << "\n"
84 FileUtils.cp(file.path, pkgfile)
90 vars = [:name, :version, :release]
93 cmt_map = OHash.new.replace(COMMENT_MAP)
95 File.read(pkgfile).split("\n").each do |line|
98 cmt_map.each do |key, symbol|
99 md = line.match(/^#\s*#{key}: (.+)$/)
101 @attribs[symbol].replace(md.captures.first.strip)
107 md = line.match(/^#{var}=(.+)$/)
109 @attribs[var] = $1.strip
114 # handle source array
115 section = :void if line.match(/^\s*$/) && section != :build
117 if section == :source && line.match(/(.+)\)$/)
118 @attribs[:source] << $1.strip
119 elsif section == :source && line.match(/(.+)\\$/)
120 @attribs[:source] << $1.strip
121 elsif line.match(/^source=\((.+)\)$/)
122 @attribs[:source] << $1.strip
123 elsif line.match(/^source=\((.+)\\$/)
124 @attribs[:source] << $1.strip
128 section = :end unless line.match(/^\}/).nil?
130 # remove initial indentation
131 tmp = line.sub(/^( |\t)/, "")
133 @attribs[:build] << (tmp || "")
135 section = :build unless line.match(/^build/).nil?
140 File.join(@dir, "Pkgfile")
144 File.join(@dir, ".footprint")
148 File.join(@dir, ".md5sum")
152 class Dependencies < Array
163 arg.split(", ").each { |d| self << d.strip }
172 class Sources < Array
174 indent = " " * "source=(".length
175 "(" + join(" \\\n" + indent) + ")"
179 class BuildFunc < Array
181 inject("build() {\n") do |a, line|