Permalink
Browse files

More optimizations and bugfixes; build seems to work (but does it?)

  • Loading branch information...
1 parent 9c42732 commit 76b0bcea870cf00d3855930705ff1820237e904e @wycats wycats committed Aug 23, 2010
View
@@ -20,8 +20,6 @@ namespace :entry do
filename = entry[:filename]
raise "All entries must have a filename!" unless filename
- filename_parts = filename.split('/')
-
# If this is a composite entry, then the source_paths array should
# contain the staging_path from the source_entries. The source_path
# is simply the first source_paths.
@@ -41,13 +39,13 @@ namespace :entry do
# Otherwise, the source_path is where we will pull from and source_paths
# is simply the source_path in an array.
else
- entry[:source_path] ||= File.join(manifest[:source_root], filename_parts)
+ entry[:source_path] ||= File.join(manifest[:source_root], filename)
entry[:source_paths] ||= [entry[:source_path]]
end
# Construct some easier paths if needed
- entry[:build_path] ||= File.join(manifest[:build_root], filename_parts)
- entry[:url] ||= [manifest[:url_root], filename_parts].join('/')
+ entry[:build_path] ||= File.join(manifest[:build_root], filename)
+ entry[:url] ||= [manifest[:url_root], filename].join('/')
# Fill in a default build task
entry[:build_task] ||= 'build:copy'
@@ -60,10 +58,10 @@ namespace :entry do
if entry[:build_task] == 'build:copy'
entry[:staging_path] ||= entry[:source_path]
else
- entry[:staging_path] ||= manifest.unique_staging_path(File.join(manifest[:staging_root], filename_parts))
+ entry[:staging_path] ||= manifest.unique_staging_path(File.join(manifest[:staging_root], filename))
end
- entry[:cache_path] = manifest.unique_cache_path(File.join(manifest[:cache_root], filename_parts))
+ entry[:cache_path] = manifest.unique_cache_path(File.join(manifest[:cache_root], filename))
end
end
@@ -50,14 +50,17 @@ namespace :manifest do
manifest = env[:manifest]
source_root = target[:source_root]
- Dir.glob(File.join(source_root, '**', '*')).each do |path|
- next if !File.exist?(path) || File.directory?(path)
- next if target.target_directory?(path)
-
- # cut source root out to make filename. make sure path separators are /
- filename = path.sub /^#{Regexp.escape source_root}\//, ''
- filename = filename.split(::File::SEPARATOR).join('/')
- manifest.add_entry filename, :original => true # entry:prepare will fill in the rest
+
+ SC.profile("PROFILE_CATALOG") do
+ Dir["#{source_root}/**/*"].each do |path|
+ next unless File.file?(path)
+ next if target.target_directory?(path)
+
+ # cut source root out to make filename. make sure path separators are /
+ filename = path.sub /^#{Regexp.escape source_root}\//, ''
+ filename = filename.split(::File::SEPARATOR).join('/')
+ manifest.add_entry filename, :original => true # entry:prepare will fill in the rest
+ end
end
end
@@ -105,7 +108,7 @@ namespace :manifest do
# Is a localized resource!
if entry[:filename] =~ /^([^\/]+)\.lproj\/(.+)$/
entry[:language] = (SC::Target::LONG_LANGUAGE_MAP[$1.to_s.downcase.to_sym]) || $1.to_sym
- entry.localized = true
+ entry[:localized] = true
# remove .lproj dir from build paths as well..
lang_dir = "#{$1}.lproj/"
@@ -147,7 +150,7 @@ namespace :manifest do
namespace :prepare_build_tasks do
desc "main entrypoint for preparing all build tasks. This should invoke all needed tasks"
- task :all => %w(css javascript bundle_info bundle_loaded sass scss less combine html strings)
+ task :all => %w(css javascript bundle_info bundle_loaded sass scss less combine minify html strings tests packed)
desc "executes prerequisites needed before one of the subtasks can be invoked. All subtasks that have this as a prereq"
task :setup => %w(manifest:catalog manifest:hide_buildfiles manifest:localize)
@@ -462,10 +465,10 @@ namespace :manifest do
entries_by_resource = {}
entries.each do |entry|
- entry.entry_type = :html
- entry.resource = 'index'
+ entry[:entry_type] = :html
+ entry[:resource] = 'index'
- entry.render_task = case entry[:ext]
+ entry[:render_task] = case entry[:ext]
when 'rhtml'
'render:erubis'
when 'erb'
@@ -56,7 +56,7 @@ namespace :target do
(url_prefix || '').to_s.split('/'),
target[:target_name].to_s))
- target.build_number = target.compute_build_number
+ target[:build_number] = target.compute_build_number
# The target is loadable if it is an app
target[:loadable] = target[:target_type] == :app
View
@@ -102,7 +102,7 @@ def self.build_mode
def self.build_mode=(new_mode)
new_mode = new_mode.to_sym
new_mode = :debug if new_mode == :development
- env.build_mode = new_mode
+ env[:build_mode] = new_mode
self.build_mode
end
@@ -131,7 +131,7 @@ def self.load_project(path = nil, opts = {})
def self.yui_jar
@yui_jar ||= begin
- yui_root = File.expand_path("../vendor/yui-compressor", __FILE__)
+ yui_root = File.expand_path("../sproutcore/vendor/yui-compressor", __FILE__)
File.join(yui_root, 'yuicompressor-2.4.2.jar')
end
end
@@ -394,7 +394,7 @@ def project!; @is_project = true; end
# receiver
#
def add_proxy(proxy_path, opts={})
- @proxies[proxy_path] = HashStruct.new(opts)
+ @proxies[proxy_path.to_sym] = HashStruct.new(opts)
return self
end
@@ -182,18 +182,22 @@ def invoke_with_call_chain(task_args, invocation_chain) # :nodoc:
end
end
- t_start = Time.now.to_f * 1000
+ debug = SC.logger.debug?
+
+ t_start = Time.now.to_f * 1000 if debug
invocation_chain = invoke_prerequisites(task_args, invocation_chain)
@invoke_count += 1
execute(task_args) if needed?
- t_end = Time.now.to_f * 1000
- t_diff = t_end - t_start
+ if debug
+ t_end = Time.now.to_f * 1000
+ t_diff = t_end - t_start
- # ignore short tasks
- if t_diff > 10
- SC.logger.debug "#{indent}long task ~ #{name}: #{t_diff.to_i} msec"
+ # ignore short tasks
+ if t_diff > 10
+ SC.logger.debug "#{indent}long task ~ #{name}: #{t_diff.to_i} msec"
+ end
end
self.class.outdent_logs
@@ -17,7 +17,7 @@ class TaskArguments
# for compatibility with normal TaskArguments
def self.new(keys, values, parent = nil)
- args = super
+ args = super()
args.setup_with_arrays(keys, values, parent)
args
end
@@ -56,7 +56,7 @@ def new_scope(names)
# Find an argument value by name or index.
def [](index)
- lookup(index.to_sym)
+ lookup(index)
end
# Specify a hash of default values for task arguments. Use the
@@ -50,7 +50,9 @@ def to_hash
# Pass in any options you want set initially on the manifest entry.
def initialize(opts = {})
super()
- self.merge!(opts)
+ opts.each do |k,v|
+ self[k.to_sym] = v
+ end
end
# Allow for method-like access to hash also...
@@ -65,7 +67,8 @@ def method_missing(id, *args)
method_name = method_name[0..-2]
value = args[0]
end
- self[method_name] = value
+ print_first_caller(method_name)
+ self[method_name.to_sym] = value
# convert property? => !!self[:property]
elsif method_name =~ /\?$/
@@ -91,12 +94,13 @@ def print_first_caller(*extras)
# When using the optimized #[] lookup form,require a Symbol
# def [](key) super end
- def []=(key, value)
- sym_key = key.to_sym rescue nil
- raise "HashStruct cannot convert #{key} to symbol" if sym_key.nil?
-
- super(sym_key, value)
- end
+ #def []=(key, value)
+ # print_first_caller(key, value) unless key.is_a?(Symbol)
+ # sym_key = key.to_sym rescue nil
+ # raise "HashStruct cannot convert #{key} to symbol" if sym_key.nil?
+ #
+ # super(sym_key, value)
+ #end
# Reimplement merge! to go through the []=() method so that keys can be
# symbolized
@@ -15,18 +15,22 @@ module SC
# defined by the manifest build tasks.
#
class Manifest < HashStruct
-
attr_reader :target
def entries(opts = {})
- return @entries if (opts[:hidden] || false)
- @entries.reject { |e| e.hidden? }
+ opts[:hidden] ? @entries : @entries.visible
+ end
+
+ class EntryList < Array
+ def visible
+ each.reject { |entry| entry.hidden? }
+ end
end
def initialize(target, opts)
super(opts)
@target = target
- @entries = []
+ @entries = EntryList.new
@staging_uuid = 0
end
@@ -98,8 +102,7 @@ def built?; @is_built; end
#
def reset_entries!
@is_built = false
- @entries = []
- @filtered_entries = nil
+ @entries = EntryList.new
return self
end
@@ -143,10 +146,10 @@ def to_hash(opts={})
def load(hash)
merge!(hash)
entry_hashes = self.delete(:entries) || []
- @entries = entry_hashes.map do |opts|
- ManifestEntry.new(self, opts)
+ @entries = EntryList.new
+ entry_hashes.each do |opts|
+ @entries << ManifestEntry.new(self, opts)
end
- @filtered_entries = nil
return self
end
@@ -163,7 +166,6 @@ def load(hash)
def add_entry(filename, opts = {})
opts[:filename] = filename
@entries << (ret = ManifestEntry.new(self, opts)).prepare!
- @filtered_entries = nil
return ret
end
@@ -178,7 +180,6 @@ def add_composite(filename, opts = {})
opts[:source_entries] ||= []
opts[:composite] = true
@entries << (ret = ManifestEntry.new(self, opts)).prepare!
- @filtered_entries = nil
ret[:source_entries].each { |entry| entry.hide! } if should_hide_entries
return ret
@@ -324,44 +325,33 @@ def find_entry(fragment, opts = {}, seen=nil)
end
extname = File.extname(fragment)
+ extname = nil if extname.empty?
+
rootname = fragment.sub(/#{extname}$/, '')
# look on our own target only if target is named
- ret = cur_manifest.entries(opts).reject do |entry|
- if entry.has_options?(opts)
- entry_extname = File.extname(entry[:filename])
- entry_rootname = entry[:filename].sub(/#{entry_extname}$/,'')
- ext_match = (extname.nil? || extname.size == 0) || (entry_extname == extname)
- else
- ext_match = false
- end
+ ret = cur_manifest.entries(opts).find do |entry|
+ next unless entry.has_options?(opts)
+ next if extname && (entry.extension != extname)
- !(ext_match && (/#{rootname}$/ =~ entry_rootname))
+ entry.rootname[-rootname.length, rootname.length] == rootname
end
- ret = ret.first
+ return ret if ret
# if no match was found, search the same manifests in required targets
- if ret.nil?
- seen = Set.new if seen.nil?
- seen << cur_manifest.target
- cur_manifest.target.expand_required_targets(:theme => true).each do |t|
- next if seen.include?(t) # avoid recursion
-
- manifest = t.manifest_for(self.variation).build!
- ret = manifest.find_entry(fragment, opts, seen)
- break unless ret.nil?
- end
- end
- return ret
- end
+ seen ||= Set.new
+ seen << cur_manifest.target
- def unique_path(key, path)
- paths = entries(:hidden => true).map { |e| e[keys] }
- while paths.include?(path)
- path = path.sub(/(__\$[0-9]+)?(\.\w+)?$/,"__#{next_staging_uuid}\\2")
+ cur_manifest.target.expand_required_targets(:theme => true).each do |t|
+ next if seen.include?(t) # avoid recursion
+
+ manifest = t.manifest_for(self.variation).build!
+ ret = manifest.find_entry(fragment, opts, seen)
+ return ret if ret
end
- return path
+
+ nil
end
# Finds a unique staging path starting with the root proposed staging
@@ -20,7 +20,6 @@ class Tools
MANIFEST_OPTIONS.merge(:entries => :string, :clean => false))
def build(*targets)
-
# Copy some key props to the env
SC.env.build_prefix = options.buildroot if options.buildroot
SC.env.staging_prefix = options.stageroot if options.stageroot
@@ -95,7 +94,7 @@ def build(*targets)
# I can't find a reasonable, commonly-
# installed, works-on-all-OSes solution.
SC.logger.info output
- if $?.exitstatus != 0
+ if $?.exitstatus != 0
SC.logger.fatal(output)
SC.logger.fatal("!!!!YUI compressor failed, please check that your js code is valid")
SC.logger.fatal("!!!!Failed compressing ... "+ $to_minify.join(','))

0 comments on commit 76b0bce

Please sign in to comment.