Class: Cbt::Checkout
Instance Attribute Summary
Attributes inherited from App
Instance Method Summary collapse
- #add_copy_list(sfile, tfile) ⇒ Object
-
#copy_assets!(comp, ws_dir) ⇒ Object
copy asset files for all components.
-
#copy_require!(comp, ws_dir) ⇒ Object
copy required component assets and files.
-
#cp_file(s, t) ⇒ Object
copy file from s to t, use luobo if convert class defined.
-
#process! ⇒ Object
wrap for all components.
-
#process_component!(comp) ⇒ Object
copy lua/spec files for a component.
Methods inherited from App
#current_component_names, #error, #info, #initialize, #tags, #warn
Constructor Details
This class inherits a constructor from Cbt::App
Instance Method Details
#add_copy_list(sfile, tfile) ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/cbt/checkout.rb', line 32 def add_copy_list sfile, tfile # only add source file that has changed unless no_consistency_check @file_list[sfile] = tfile if [:no_consistency_check] or @digester.changed?(sfile) if @file_list[sfile] and @digester.changed?(tfile) and File.exists? tfile error "target file #{tfile} changed. use --force to force overwrite" unless [:force] end end |
#copy_assets!(comp, ws_dir) ⇒ Object
copy asset files for all components
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/cbt/checkout.rb', line 41 def copy_assets! comp, ws_dir comp.assets.each do |aname, asset| comp_dir = comp.dir([:components_dir]) # detect if an asset file saved both in global and component space sfile = asset.path([comp_dir], [:platform]) global_file = asset.path([[:assets_dir]], [:platform]) warn "#{sfile} will overwrite #{global_file}" if sfile and global_file sfile = global_file unless sfile error "asset file for #{aname}, component #{comp.name} not found" unless sfile tfile = m.target(ws_dir) add_copy_list sfile, tfile end end |
#copy_require!(comp, ws_dir) ⇒ Object
copy required component assets and files
59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/cbt/checkout.rb', line 59 def copy_require! comp, ws_dir comp.modules.each do |mname, m| next if mname == 'main' # skip main file from the application core component comp_dir = comp.dir([:components_dir]) sfile = m.path([comp_dir], [:require_platform]) tfile = m.target(ws_dir) error "no file find for module lua file #{mname}, component #{comp.name}" unless sfile # add lua module file int copy waiting list add_copy_list sfile, tfile end # copy all end |
#cp_file(s, t) ⇒ Object
copy file from s to t, use luobo if convert class defined
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/cbt/checkout.rb', line 7 def cp_file s, t converted = false if /\.(?<ext_>\w+)$/ =~ s if ext_ begin klass = Module.const_get(ext_.capitalize + 'Luobo') rescue Exception => e end if klass and klass.is_a?(Class) info "Use #{klass} to convert #{s}" klass.cp! s, t, [:platform] converted = true end end end # if no any luobo class converted the file, copy as it is FileUtils.cp s, t unless converted # add to consistency list @digester.add_history s @digester.add_history t end |
#process! ⇒ Object
wrap for all components
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/cbt/checkout.rb', line 137 def process! unless File.directory? [:workspace_dir] info "create workspace directory #{@options[:workspace_dir]}" FileUtils.mkdir_p [:workspace_dir] end if [:build] == true warn "set require platform to #{@options[:platform]}" unless [:require_platform] == [:platform] [:require_platform] = [:platform] end # process for all component current_component_names.each do |cname| comp = @components[cname] process_component! comp end end |
#process_component!(comp) ⇒ Object
copy lua/spec files for a component
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/cbt/checkout.rb', line 75 def process_component! comp info "checkout component #{comp.name}" # the copy candidate files list @file_list = Hash.new comp_dir = comp.dir([:components_dir]) ws_dir = comp.ws_dir([:workspace_dir], [:platform]) unless File.directory? ws_dir info "create workspace directory #{ws_dir}" FileUtils.mkdir_p ws_dir end @digester = Digester.new(ws_dir + ".yml") # copy assets files for all components @components.each do |cname, c| copy_assets! c, ws_dir unless cname == comp.name end copy_assets! comp, ws_dir # copy the current component at last # copy require files for all components other than current component @components.each do |cname, c| copy_require! c, ws_dir unless cname == comp.name end # for each lua module, error if no file comp.modules['main'] = LuaModule.new(comp.name, 'main') unless comp.modules['main'] comp.modules.each do |mname, m| sfile = m.path([comp_dir], [:platform]) tfile = m.target(ws_dir) error "no file find for module lua file #{mname}, component #{comp.name}" unless sfile # add lua module file int copy waiting list add_copy_list sfile, tfile end # for all spec files spec_dir = comp_dir spec_dir = [:components_dir] if [:all_spec] Dir[spec_dir + "/*_spec.lua"].each do |lua| add_copy_list lua, File.join(ws_dir, File.basename(lua)) end # check if t registered twice tlist = Hash.new @file_list.each do |s,t| warn "#{s} will overwrite #{tlist[t]} (for #{t})" if tlist[t] tlist[t] = s if [:simulation] puts "#{s} -> #{t}" else info "copy #{s} -> #{t}" cp_file s, t @digester.add_history s @digester.add_history t end end end |