Permalink
Browse files

Add a post_fetch phase, allow fetch to be a lambda,

allow use_source to be a hash with different values for platforms.
  • Loading branch information...
1 parent 26c4cfe commit 10d0bb2708ab46e8882e20dcee643373d985c765 @durand durand committed Oct 3, 2011
Showing with 83 additions and 37 deletions.
  1. +46 −24 ports/Impl/builder.rb
  2. +37 −13 ports/bakery.rb
View
@@ -40,21 +40,16 @@ def system *args
end
class Builder
- def cache_dir
- @cache_dir
- end
-
- def toolchain
- @toolchain
- end
+ attr_reader(:platform, :cache_dir, :toolchain)
def __checkSym map, sym
if !map || !map.has_key?(sym)
throw "recipe for #{@pkg} is incomplete: missing ':#{sym}' key"
end
end
- def initialize pkg, verbose, output_dir, cmake_gen, cache_dir, wintools_dir, recipe_location = nil
+ def initialize pkg, verbose, output_dir, cmake_gen, cache_dir,
+ wintools_dir, recipe_location = nil
# capture the top level portDir
@port_dir = File.expand_path(File.dirname(File.dirname(__FILE__)))
@@ -95,7 +90,8 @@ def initialize pkg, verbose, output_dir, cmake_gen, cache_dir, wintools_dir, rec
@logdir_path = File.join(@workdir_path, "logs")
# create and define directories where ports should put stuff
- @wintools_dir = wintools_dir ? wintools_dir : File.join(@port_dir, "WinTools")
+ @wintools_dir = wintools_dir ? wintools_dir : File.join(@port_dir,
+ "WinTools")
# create and define directories where ports should put stuff
@output_dir = output_dir ? output_dir : File.join(@port_dir, "dist")
@@ -127,7 +123,8 @@ def initialize pkg, verbose, output_dir, cmake_gen, cache_dir, wintools_dir, rec
@sevenZCmd = File.expand_path(File.join(@port_dir, "WinTools", "7z.exe"))
# on windows, patch is called ptch since an exe named "patch" will
# cause a UAC on Vista
- @patch_cmd = File.expand_path(File.join(@port_dir, "WinTools", "ptch.exe"))
+ @patch_cmd = File.expand_path(File.join(@port_dir, "WinTools",
+ "ptch.exe"))
# determine what Visual Studio we are using
foo=`devenv.com /?`
@@ -147,14 +144,15 @@ def initialize pkg, verbose, output_dir, cmake_gen, cache_dir, wintools_dir, rec
@platform = :MacOSX
@platlookup = [ @platform, :Unix, :All ]
- # Compiler/linker flags needed for backward compatibility. The surrounding
- # spaces are important, don't be tempted to remove them.
+ # Compiler/linker flags needed for backward compatibility.
+ # The surrounding spaces are important, don't be tempted to remove them.
#
# Backward compatibility is painful, see
# http://developer.apple.com/releasenotes/Darwin/SymbolVariantsRelNotes/index
- # In general, we must get these flags to the compiler and linker to tell it
- # what sdk to use. In addition, source which defines any of the preprocessor
- # symbols mentioned in the above article will be problematic.
+ # In general, we must get these flags to the compiler and linker
+ # to tell it what sdk to use. In addition, source which defines
+ # any of the preprocessor symbols mentioned in the above article
+ # will be problematic.
#
# Kinda skanky, switch on an env var for 10.4 builds.
@@ -218,7 +216,9 @@ def initialize pkg, verbose, output_dir, cmake_gen, cache_dir, wintools_dir, rec
user = uri.host
# it's time to build a url
@url = "http://github.com/#{user}/#{project}/tarball/#{sha256}"
- @tarball = File.expand_path(File.join(@distfiles_path, "#{user}-#{project}-#{sha256}.tgz"))
+ @tarball = File.expand_path(
+ File.join(@distfiles_path,
+ "#{user}-#{project}-#{sha256}.tgz"))
else
tarball = File.basename(uri.path)
@tarball = File.expand_path(File.join(@distfiles_path, tarball))
@@ -262,17 +262,17 @@ def initialize pkg, verbose, output_dir, cmake_gen, cache_dir, wintools_dir, rec
FileUtils.mkdir_p(@receipts_dir)
@receipt_path = File.join(@receipts_dir, "#{@pkg}.yaml")
- # port md5 calculation is expensive. we only calculate it once per invocation
- # using this member as a cache
+ # port md5 calculation is expensive. we only calculate it once per
+ # invocation using this member as a cache
@port_md5 = nil
end
def deps
@deps
end
- # fetch the current contents of one of the subdirs of output_dir (like lib/ include/
- # share/ or bin/
+ # fetch the current contents of one of the subdirs of output_dir
+ # (like lib/ include/ share/ or bin/)
def __output_contents
oc = Set.new
Dir.glob(File.join(@output_dir, "*")).each { |p|
@@ -281,7 +281,11 @@ def __output_contents
next if prefix == 'receipts'
if File.directory? p
oc.merge(Dir.chdir(p) {
- Dir.glob("**/*").reject { |f| File.directory?(f) }.collect { |f| File.join(prefix, f ) } })
+ Dir.glob("**/*").reject { |f|
+ File.directory?(f) }.collect { |f|
+ File.join(prefix, f)
+ }
+ })
else
oc.add(prefix)
end
@@ -354,8 +358,8 @@ def clean
# for purposes of receipts, let's take a snapshot of the lib directory
@output_dir_before = __output_contents
- # the total set of files that were installed, populated during write_receipts
- # phase.
+ # the total set of files that were installed, populated during
+ # write_receipts phase.
@files_installed = Array.new
end
@@ -381,6 +385,15 @@ def checkMD5
end
def fetch
+ # is fetch a lamda?
+ if @recipe[:fetch].kind_of?(Proc)
+ @build_dir = File.join(@workdir_path, "src")
+ @conf[:src_dir] = @build_dir
+ FileUtils.mkdir_p(@build_dir)
+ invokeLambda(:fetch, @recipe, :fetch)
+ return
+ end
+
if @url == nil
log_with_time " nothing to fetch for this port"
return
@@ -566,6 +579,11 @@ def patch
end
end
+ def post_fetch
+ @build_dir = @src_dir # yes martha, that's a hack
+ invokeLambda(:post_fetch, @recipe, :post_fetch)
+ end
+
def post_patch
@build_dir = @src_dir # yes martha, that's a hack
invokeLambda(:post_patch, @recipe, :post_patch)
@@ -721,7 +739,11 @@ def save_to_cache
@files_installed.add Pathname.new(@receipt_path).relative_path_from(Pathname.new(@output_dir)).to_s
filelist = File.join(@workdir_path, "filelist.txt")
- File.open(filelist, "w+") { |f| @files_installed.each { |fi| f.puts fi } }
+ File.open(filelist, "w+") { |f|
+ @files_installed.each { |fi|
+ f.puts fi
+ }
+ }
if @platform == :Windows
system("\"#{@sevenZCmd}\" a -y \"#{fname}\" @\"#{filelist}\"")
else
View
@@ -25,6 +25,7 @@ def tsort_each_child(node, &block)
end
end
+
class Bakery
@@distfiles_dir = File.join(File.dirname(__FILE__), "distfiles")
@@work_dir = File.join(File.dirname(__FILE__), "work")
@@ -55,48 +56,67 @@ def initialize order
next if fullDeps.has_key? p
recipe = nil
recipe = @use_recipe[p] if @use_recipe && @use_recipe.has_key?(p)
- b = Builder.new(p, @verbose, @output_dir, @cmake_generator, @cache_dir, @wintools_dir, recipe)
+ b = Builder.new(p, @verbose, @output_dir, @cmake_generator,
+ @cache_dir, @wintools_dir, recipe)
fullDeps[p] = b.deps
b.deps.each { |d| stack.push d }
end
# topological sort
@packages = fullDeps.tsort
end
+
def build
log_with_time "building #{@packages.length} packages:" if @verbose
@packages.each { |p|
recipe = nil
recipe = @use_recipe[p] if @use_recipe && @use_recipe.has_key?(p)
log_with_time "--- building #{p}#{recipe ? (" (" + recipe + ")") : ""} ---" if @verbose
- b = Builder.new(p, @verbose, @output_dir, @cmake_generator, @cache_dir, @wintools_dir, recipe)
+ b = Builder.new(p, @verbose, @output_dir, @cmake_generator,
+ @cache_dir, @wintools_dir, recipe)
if !b.needsBuild
- log_with_time " - skipping #{p}, already built!" if @verbose
+ log_with_time " - skipping #{p}, already built!" if @verbose
next
end
+
log_with_time " - cleaning #{p}" if @verbose
b.clean
+
# if we've got the built bits in the cache, then let's use em
# and call it a day!
log_with_time " - checking cache for built pkg" if @verbose
if b.install_from_cache
log_with_time " Installed from cache! all done." if @verbose
next
+ end
+
# if use_source is specified for this package it short circuts
# fetch and unpack
- elsif @use_source && @use_source.has_key?(p)
- log_with_time " - copying local source for #{p} (#{@use_source[p]})" if @verbose
- b.use_source @use_source[p]
+ useSourcePath = nil
+ if @use_source && @use_source.has_key?(p)
+ if @use_source[p].kind_of?(Hash) && @use_source[p].has_key?(b.platform)
+ useSourcePath = @use_source[p][b.platform]
+ elsif @use_source[p].kind_of?(String)
+ useSourcePath = @use_source[p]
+ end
+ end
+ if useSourcePath
+ log_with_time " - copying local source for #{p} (#{useSourcePath})" if @verbose
+ b.use_source useSourcePath
else
log_with_time " - fetching #{p}" if @verbose
b.fetch
log_with_time " - unpacking #{p}" if @verbose
b.unpack
end
+ log_with_time " - post-fetch #{p}" if @verbose
+ b.post_fetch
+
log_with_time " - patching #{p}" if @verbose
b.patch
log_with_time " - post-patch #{p}" if @verbose
b.post_patch
+
@build_types.each { |bt|
log_with_time " - pre_build step for #{p} (#{bt})" if @verbose
b.pre_build bt
@@ -106,10 +126,10 @@ def build
b.build
log_with_time " - installing #{p} (#{bt})" if @verbose
b.install
- log_with_time " - running post_install for #{p} (#{bt})" if @verbose
+ log_with_time " - running post_install for #{p} (#{bt})" if @verbose
b.post_install
}
- log_with_time " - running post_install_common for #{p}" if @verbose
+ log_with_time " - running post_install_common for #{p}" if @verbose
b.post_install_common
log_with_time " - cleaning up #{p}" if @verbose
b.dist_clean
@@ -120,6 +140,7 @@ def build
}
end
+
def check
# an array populated with warnings as we check the bakery
state = {
@@ -144,16 +165,17 @@ def check
Dir.glob(File.join(@output_dir, "receipts", "*.yaml")).each { |rp|
pkg = File.basename(rp, ".yaml")
recipe = nil
- recipe = @use_recipe[pkg] if @use_recipe && @use_recipe.has_key?(pkg)
- b = Builder.new(pkg, @verbose, @output_dir, @cmake_generator, @cache_dir, @wintools_dir, recipe)
+ recipe = @use_recipe[pkg] if @use_recipe && @use_recipe.has_key?(pkg)
+ b = Builder.new(pkg, @verbose, @output_dir, @cmake_generator,
+ @cache_dir, @wintools_dir, recipe)
state[:info].push "#{pkg} is out of date, and needs to be built" if b.needsBuild
# now load up the receipts
receipts[pkg] = File.open( rp ) { |yf| YAML::load( yf ) }
}
- # first let's ensure there's no files owned by multiple ports while we build up a
- # set of all owned files
+ # first let's ensure there's no files owned by multiple ports
+ # while we build up a set of all owned files
allOwnedFiles = Hash.new
mycombinations(receipts.collect{ |pkg, rcpt|
rcpt[:files].each { |a| allOwnedFiles[a[0]] = a[1] }
@@ -164,7 +186,8 @@ def check
state[:error].push "#{a[0]} & #{b[0]} both think they own certain files (vewy, vewy, bad): #{c.to_a.join(', ')}" if c.size > 0
}
- # iterate through all files in output dir, make sure they're owned by a pkg and the md5 matches
+ # iterate through all files in output dir, make sure they're
+ # owned by a pkg and the md5 matches
contents.each { |f, md5|
if !allOwnedFiles.has_key? f
state[:error].push "file '#{f}' is not owned by any package!"
@@ -180,6 +203,7 @@ def check
state
end
+
def __output_contents
oc = Hash.new
Dir.glob(File.join(@output_dir, "*")).each { |p|

0 comments on commit 10d0bb2

Please sign in to comment.