Module: Buildr::AS3::Compiler::CompilerUtils

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.get_output(project, target, package, options) ⇒ Object



41
42
43
44
45
46
# File 'lib/buildr/as3/compiler.rb', line 41

def self.get_output(project, target, package, options)
  return options[:output] if options.has_key? :output
  return "#{target}/#{File.basename(options[:main].to_s, File.extname(options[:main].to_s))}.swf" if package == :swf
  return "#{target}/#{project.name.gsub(":", "-")}.swc" if package == :swc
  fail("Could not guess output file.")
end

Instance Method Details

#append_args(cmd_args, append_args) ⇒ Object



33
34
35
36
37
38
39
# File 'lib/buildr/as3/compiler.rb', line 33

def append_args( cmd_args, append_args )
  unless append_args.nil? || append_args.empty?
    append_args.each do |arg|
      cmd_args << arg
    end
  end
end

#get_last_modified(dir) ⇒ Object



79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/buildr/as3/compiler.rb', line 79

def get_last_modified(dir)
  file_mtimes = []
  dirs = Dir.new(dir).select { |file| file!= '.' && file!='..' && File.directory?(dir+"/"+file)==true }
  dirs = dirs.collect { |subdir| dir+"/"+subdir }
  dirs.each { |subdir| file_mtimes << get_last_modified(subdir) }
  files = Dir.new(dir).select { |file| file!= '.' && file!='..' && File.directory?(dir+"/"+file)==false }
  files = files.collect { |file| dir+'/'+file }
  files.each { |file| file_mtimes << File.mtime(file) }
  file_mtimes.sort!
  file_mtimes.reverse!
  file_mtimes.length > 0 ? file_mtimes.first : Time.at(0)
end

#is_output_outdated?(output, file_to_check) ⇒ Boolean

Returns:

  • (Boolean)


66
67
68
69
# File 'lib/buildr/as3/compiler.rb', line 66

def is_output_outdated?(output, file_to_check)
  return true unless File.exists? output
  older(output, file_to_check)
end

#move_dependency_dirs_to_source(sources, dependencies) ⇒ Object



92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/buildr/as3/compiler.rb', line 92

def move_dependency_dirs_to_source( sources, dependencies )
  moves = []
  dependencies.each do |dependency|
    if File.directory? dependency
      moves << dependency
    end
  end
  moves.each do |move|
    dependencies.delete move
    sources << move
  end
end

#needed?(sources, target, dependencies) ⇒ Boolean

Returns:

  • (Boolean)


48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/buildr/as3/compiler.rb', line 48

def needed?(sources, target, dependencies)
  output = CompilerUtils::get_output(project, target, project.compile.packaging, options)
  sources.each do |source|
    if is_output_outdated?(output, source)
      puts "Recompile of #{project.name} needed: Sources are newer than target"
      return true
    end
  end
  dependencies.each do |dependency|
    if is_output_outdated?(output, dependency)
      puts "Recompile of #{project.name} needed: Dependencies are newer than target"
      return true
    end
  end
  puts "Recompile of #{project.name} not needed."
  false
end

#older(a, b) ⇒ Object

a older than b



71
72
73
# File 'lib/buildr/as3/compiler.rb', line 71

def older(a, b) # a older than b
  timestamp_from_file(a) < timestamp_from_file(b)
end

#reserved_optionsObject



29
30
31
# File 'lib/buildr/as3/compiler.rb', line 29

def reserved_options
  [:flexsdk, :main, :apparat, :output, :append]
end

#timestamp_from_file(file) ⇒ Object



75
76
77
# File 'lib/buildr/as3/compiler.rb', line 75

def timestamp_from_file(file)
  File.directory?(file) ? get_last_modified(file) : File.mtime(file)
end