Class: Bake::Config
- Inherits:
-
Object
- Object
- Bake::Config
- Defined in:
- lib/bake/config/loader.rb
Instance Attribute Summary collapse
-
#referencedConfigs ⇒ Object
readonly
Returns the value of attribute referencedConfigs.
Instance Method Summary collapse
- #checkRoots ⇒ Object
- #filterStep(step, globalFilterStr) ⇒ Object
- #filterSteps ⇒ Object
-
#getFullProject(configs, configname) ⇒ Object
note: configs is never empty.
- #load ⇒ Object
- #loadMainMeta ⇒ Object
- #loadMeta(dep) ⇒ Object
- #loadProjMeta(filename) ⇒ Object
- #symlinkCheck(filename) ⇒ Object
- #validateDependencies(config) ⇒ Object
Instance Attribute Details
#referencedConfigs ⇒ Object (readonly)
Returns the value of attribute referencedConfigs.
6 7 8 |
# File 'lib/bake/config/loader.rb', line 6 def referencedConfigs @referencedConfigs end |
Instance Method Details
#checkRoots ⇒ Object
196 197 198 199 200 201 202 203 204 205 206 207 |
# File 'lib/bake/config/loader.rb', line 196 def checkRoots() @potentialProjs = [] Bake..roots.each do |r| if (r.length == 3 && r.include?(":/")) r = r + Bake..main_project_name # glob would not work otherwise on windows (ruby bug?) end r = r+"/**{,/*/**}/Project.meta" @potentialProjs.concat(Dir.glob(r)) end @potentialProjs = @potentialProjs.uniq.sort end |
#filterStep(step, globalFilterStr) ⇒ Object
210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 |
# File 'lib/bake/config/loader.rb', line 210 def filterStep(step, globalFilterStr) # 1st prio: explicit single filter if step.filter != "" return true if Bake..exclude_filter.include?step.filter return false if Bake..include_filter.include?step.filter end # 2nd prio: explicit global filter if globalFilterStr != nil return true if Bake..exclude_filter.include?globalFilterStr return false if Bake..include_filter.include?globalFilterStr end # 3nd prio: default return true if step.default == "off" false end |
#filterSteps ⇒ Object
229 230 231 232 233 234 235 236 237 238 239 240 241 |
# File 'lib/bake/config/loader.rb', line 229 def filterSteps @referencedConfigs.each do |projName, configs| configs.each do |config| config.startupSteps.step = config.startupSteps.step.delete_if { |step| filterStep(step, "STARTUP") } if config.startupSteps config.preSteps.step = config.preSteps.step.delete_if { |step| filterStep(step, "PRE") } if config.preSteps config.postSteps.step = config.postSteps.step.delete_if { |step| filterStep(step, "POST") } if config.postSteps config.exitSteps.step = config.exitSteps.step.delete_if { |step| filterStep(step, "EXIT") } if config.exitSteps if Metamodel::CustomConfig === config and config.step config.step = nil if filterStep(config.step, nil) end end end end |
#getFullProject(configs, configname) ⇒ Object
note: configs is never empty
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/bake/config/loader.rb', line 8 def getFullProject(configs, configname) # note: configs is never empty if (configname == "") if configs[0].parent.default != "" configname = configs[0].parent.default else Bake.formatter.printError("No default config specified", configs[0].file_name) ExitHelper.exit(1) end end config = nil configs.each do |c| if c.name == configname if config Bake.formatter.printError("Config '#{configname}' found more than once",config.file_name) ExitHelper.exit(1) end config = c end end if not config Bake.formatter.printError("Config '#{configname}' not found", configs[0].file_name) ExitHelper.exit(1) end if config.extends != "" parent,parentConfigName = getFullProject(configs, config.extends) MergeConfig.new(config, parent).merge() end [config, configname] end |
#load ⇒ Object
243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 |
# File 'lib/bake/config/loader.rb', line 243 def load() @loader = Loader.new cache = CacheAccess.new() @referencedConfigs = cache.load_cache unless Bake..nocache # cache invalid or forced to reload if @referencedConfigs.nil? loadMainMeta checkRoots while dep = @depsPending.shift loadMeta(dep) end filterSteps cache.write_cache(@project_files, @referencedConfigs) end end |
#loadMainMeta ⇒ Object
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 |
# File 'lib/bake/config/loader.rb', line 166 def loadMainMeta() mainMeta = Bake..main_dir+"/Project.meta" if not File.exist?(mainMeta) Bake.formatter.printError("Error: #{mainMeta} not found") ExitHelper.exit(1) end @project_files = [] configs = loadProjMeta(mainMeta) @loadedConfigs = {} @loadedConfigs[Bake..main_project_name] = configs if (Bake..build_config == "" and configs[0].parent.default == "") ConfigNames.print(configs, nil, mainMeta) end config, Bake..build_config = getFullProject(configs,Bake..build_config) @referencedConfigs = {} @referencedConfigs[Bake..main_project_name] = [config] if config.defaultToolchain == nil Bake.formatter.printError("Main project configuration must contain DefaultToolchain", config) ExitHelper.exit(1) end validateDependencies(config) @depsPending = config.dependency end |
#loadMeta(dep) ⇒ Object
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 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
# File 'lib/bake/config/loader.rb', line 106 def loadMeta(dep) dep_subbed = dep.name.gsub(/\\/,"/") if dep_subbed.include?":" or dep_subbed.include?"../" or dep_subbed.start_with?"/" or dep_subbed.end_with?"/" Bake.formatter.printError("#{dep.name} is invalid", dep) ExitHelper.exit(1) end dep_path, dismiss, dep_name = dep_subbed.rpartition("/") # file not loaded yet if not @loadedConfigs.include?dep_name = [] @potentialProjs.each do |pp| if pp.include?("/" + dep_subbed + "/Project.meta") or pp == (dep_subbed + "/Project.meta") << pp end end if .empty? Bake.formatter.printError("#{dep.name}/Project.meta not found", dep) ExitHelper.exit(1) end if .length > 1 Bake.formatter.printWarning("Project #{dep.name} exists more than once", dep) chosen = " (chosen)" .each do |f| Bake.formatter.printWarning(" #{File.dirname(f)}#{chosen}") chosen = "" end end @loadedConfigs[dep_name] = loadProjMeta([0]) else folder = @loadedConfigs[dep_name][0].get_project_dir if not folder.include?dep_subbed Bake.formatter.printError("Cannot load #{dep.name}, because #{folder} already loaded", dep) ExitHelper.exit(1) end end # get config config, dep.config = getFullProject(@loadedConfigs[dep_name], dep.config) dep.name = dep_name # config not referenced yet if not @referencedConfigs.include?dep_name @referencedConfigs[dep_name] = [config] elsif @referencedConfigs[dep_name].index { |c| c.name == dep.config } == nil @referencedConfigs[dep_name] << config else return end validateDependencies(config) @depsPending += config.dependency end |
#loadProjMeta(filename) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/bake/config/loader.rb', line 61 def loadProjMeta(filename) symlinkCheck(filename) @project_files << filename f = @loader.load(filename) config = nil if f.root_elements.length != 1 or not Metamodel::Project === f.root_elements[0] Bake.formatter.printError("Config file must have exactly one 'Project' element as root element", filename) ExitHelper.exit(1) end configs = f.root_elements[0].getConfig if configs.length == 0 Bake.formatter.printError("No config found", filename) ExitHelper.exit(1) end configs.each do |config| if config.respond_to?("toolchain") and config.toolchain config.toolchain.compiler.each do |c| if not c.internalDefines.nil? and c.internalDefines != "" Bake.formatter.printError("InternalDefines only allowed in DefaultToolchain", c.internalDefines) ExitHelper.exit(1) end end end end configs end |
#symlinkCheck(filename) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/bake/config/loader.rb', line 43 def symlinkCheck(filename) dirOfProjMeta = File.dirname(filename) Dir.chdir(dirOfProjMeta) do if Dir.pwd != dirOfProjMeta and File.dirname(Dir.pwd) != File.dirname(dirOfProjMeta) isSym = false begin isSym = File.symlink?(dirOfProjMeta) rescue end if isSym Bake.formatter.printError("Symlinks only allowed with the same parent dir as the target: #{dirOfProjMeta} --> #{Dir.pwd}", filename) ExitHelper.exit(1) end end end end |
#validateDependencies(config) ⇒ Object
96 97 98 99 100 101 102 103 104 |
# File 'lib/bake/config/loader.rb', line 96 def validateDependencies(config) config.dependency.each do |dep| if dep.name.include?"$" or dep.config.include?"$" Bake.formatter.printError("No variables allowed in Dependency definition", dep) ExitHelper.exit(1) end dep.name = config.parent.name if dep.name == "" end end |