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
- #bailOutVer(reqVersion) ⇒ Object
- #checkRoots ⇒ Object
- #checkVer(reqVersion) ⇒ Object
- #checkVerFormat(ver) ⇒ Object
- #defaultConfigName ⇒ Object
- #getFullProject(projName, configs, configname, isMain) ⇒ Object
-
#getFullProjectInternal(configs, configname, isMain) ⇒ Object
note: configs is never empty.
-
#initialize ⇒ Config
constructor
A new instance of Config.
- #load(adaptConfigs) ⇒ Object
- #loadMainMeta ⇒ Object
- #loadMeta(dep) ⇒ Object
- #loadProjMeta(filename) ⇒ Object
- #printConfigNames ⇒ Object
- #printConfigs(adaptConfigs) ⇒ Object
- #resolveConfigName(configs, configname) ⇒ Object
- #showConfigNames? ⇒ Boolean
- #symlinkCheck(filename) ⇒ Object
- #validateDependencies(config) ⇒ Object
Constructor Details
#initialize ⇒ Config
Returns a new instance of Config.
10 11 12 13 14 15 |
# File 'lib/bake/config/loader.rb', line 10 def initialize() @fullProjects = {} @defaultToolchainName = "" @mainProjectName = "" @mainConfigName = "" end |
Instance Attribute Details
#referencedConfigs ⇒ Object (readonly)
Returns the value of attribute referencedConfigs.
8 9 10 |
# File 'lib/bake/config/loader.rb', line 8 def referencedConfigs @referencedConfigs end |
Instance Method Details
#bailOutVer(reqVersion) ⇒ Object
170 171 172 173 174 175 176 |
# File 'lib/bake/config/loader.rb', line 170 def bailOutVer(reqVersion) text1 = (reqVersion.minimum.empty? ? "" : "minimum = #{reqVersion.minimum}") text2 = ((reqVersion.minimum.empty? or reqVersion.maximum.empty?) ? "" : ", ") text3 = (reqVersion.maximum.empty? ? "" : "maximum = #{reqVersion.maximum}") Bake.formatter.printError("Not compatible with installed bake version: #{text1 + text2 + text3}", reqVersion) ExitHelper.exit(1) end |
#checkRoots ⇒ Object
348 349 350 351 352 353 354 355 356 357 358 359 360 |
# File 'lib/bake/config/loader.rb', line 348 def checkRoots() @potentialProjs = [] Bake..roots.each do |root| r = root.dir if (r.length == 3 && r.include?(":/")) r = r + Bake..main_project_name # glob would not work otherwise on windows (ruby bug?) end depthStr = root.depth.nil? ? "max" : root.depth.to_s puts "Checking root #{r} (depth: #{depthStr})" if Bake..verbose >= 1 @potentialProjs.concat(Root.search_to_depth(r, "Project.meta", root.depth)) end @potentialProjs.uniq! end |
#checkVer(reqVersion) ⇒ Object
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 |
# File 'lib/bake/config/loader.rb', line 178 def checkVer(reqVersion) return if reqVersion.nil? min = reqVersion.minimum.split(".") max = reqVersion.maximum.split(".") cur = Bake::Version.number.split(".") if !checkVerFormat(min) or !checkVerFormat(max) Bake.formatter.printError("Version must be <major>.<minor>.<patch> whereas minor and patch are optional and all numbers >= 0.", reqVersion) ExitHelper.exit(1) end [min,max,cur].each { |arr| arr.map! {|x| x.to_i} } min.each_with_index do |v,i| break if v < cur[i] bailOutVer(reqVersion) if v > cur[i] end max.each_with_index do |v,i| break if v > cur[i] bailOutVer(reqVersion) if v < cur[i] end end |
#checkVerFormat(ver) ⇒ Object
161 162 163 164 165 166 167 168 |
# File 'lib/bake/config/loader.rb', line 161 def checkVerFormat(ver) return true if ver.empty? return false if ver.length > 3 ver.each do |v| return false if not /\A\d+\z/.match(v) end true end |
#defaultConfigName ⇒ Object
362 363 364 |
# File 'lib/bake/config/loader.rb', line 362 def defaultConfigName @loadedConfigs[Bake..main_project_name].first.parent.default end |
#getFullProject(projName, configs, configname, isMain) ⇒ Object
72 73 74 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 135 136 137 138 139 140 141 142 |
# File 'lib/bake/config/loader.rb', line 72 def getFullProject(projName, configs, configname, isMain) configname = resolveConfigName(configs, configname) if @fullProjects.has_key?(projName + "," + configname) return @fullProjects[projName + "," + configname] end config, configname = getFullProjectInternal(configs, configname, isMain) if isMain @defaultToolchainName = config.defaultToolchain.basedOn unless config.defaultToolchain.nil? @mainProjectName = config.parent.name @mainConfigName = config.name end # check if config has to be manipulated @adaptConfigs.each do |c| projSplitted = c.project.split(";") confSplitted = c.name.split(";") projPatterns = projSplitted.map { |p| /\A#{p.gsub("*", "(\\w*)")}\z/ } confPatterns = confSplitted.map { |p| /\A#{p.gsub("*", "(\\w*)")}\z/ } if projPatterns.any? {|p| p.match(config.parent.name) } \ || (projName == Bake..main_project_name and projSplitted.any? {|p| p == "__MAIN__"}) \ || projSplitted.any? {|p| p == "__ALL__"} if confPatterns.any? {|p| p.match(config.name)} \ || (isMain and confSplitted.any? {|p| p == "__MAIN__"}) \ || confSplitted.any? {|p| p == "__ALL__"} adaptHash = c.parent.getHash configHash = { "toolchain" => [@defaultToolchainName], "os" => [Utils::OS.name], "mainProject" => [@mainProjectName], "mainConfig" => [@mainConfigName] } config.scopes.each do |s| configHash[s.name] = [] unless configHash.has_key?(s.name) configHash[s.name] += s.value.split(";") end checkCondition = lambda {|name,value| return true if adaptHash[name].empty? if !configHash.has_key?(name) return adaptHash[name].any?{|ah| ah.empty?} end adaptHash[name].any? { |ah| configHash[name].any?{|ch| ah.match(ch)}} } adaptCondition = adaptHash.all? {|name,value| checkCondition.call(name, value)} invertLogic = (Bake::Metamodel::Unless === c.parent) next if (adaptCondition && invertLogic) || (!adaptCondition && !invertLogic) MergeConfig.new(c, config).merge(c.type.to_sym) if isMain # can be changed after adapt @defaultToolchainName = config.defaultToolchain.basedOn unless config.defaultToolchain.nil? end end end end @fullProjects[projName + "," + configname] = [config, configname] [config, configname] end |
#getFullProjectInternal(configs, configname, isMain) ⇒ Object
note: configs is never empty
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/bake/config/loader.rb', line 29 def getFullProjectInternal(configs, configname, isMain) # note: configs is never empty configname = resolveConfigName(configs, configname) if isMain if Bake..qac configs.each do |c| if c.name == (configname + "Qac") configname = configname + "Qac" break end end 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 != "" config.extends.split(",").map {|ex| ex.strip}.reverse.each do |ex| if (ex != "") parent,parentConfigName = getFullProjectInternal(configs, ex, isMain) MergeConfig.new(config, parent).merge(:merge) end end end [config, configname] end |
#load(adaptConfigs) ⇒ Object
395 396 397 398 399 400 401 402 403 404 405 406 |
# File 'lib/bake/config/loader.rb', line 395 def load(adaptConfigs) @adaptConfigs = adaptConfigs @loader = Loader.new loadMainMeta printConfigNames if showConfigNames? # if neither config name nor default is set, list the configs with DefaultToolchain checkRoots while dep = @depsPending.shift loadMeta(dep) end return @referencedConfigs end |
#loadMainMeta ⇒ Object
325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 |
# File 'lib/bake/config/loader.rb', line 325 def loadMainMeta() mainMeta = Bake..main_dir+"/Project.meta" configs = loadProjMeta(mainMeta) @loadedConfigs = {} @loadedConfigs[Bake..main_project_name] = configs if not showConfigNames? config, Bake..build_config = getFullProject(Bake..main_project_name, configs,Bake..build_config, true) @referencedConfigs = {} @referencedConfigs[Bake..main_project_name] = [config] validateDependencies(config) @depsPending = config.dependency if Bake..build_config != "" and config.defaultToolchain == nil Bake.formatter.printError("Main project configuration must contain DefaultToolchain", config) ExitHelper.exit(1) end end end |
#loadMeta(dep) ⇒ Object
259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 |
# File 'lib/bake/config/loader.rb', line 259 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 if Bake..verbose >= 3 puts "First referenced by #{dep.parent.parent.name} (#{dep.parent.name}):" end = [] @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 if Bake..verbose >= 3 puts " #{dep_name} #{dep.config.empty? ? "<default>" : "("+dep.config+")"} referenced by #{dep.parent.parent.name} (#{dep.parent.name})" end config, dep.config = getFullProject(dep_name, @loadedConfigs[dep_name], dep.config, false) 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
200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 |
# File 'lib/bake/config/loader.rb', line 200 def loadProjMeta(filename) Bake::Configs::Checks.symlinkCheck(filename) f = @loader.load(filename) config = nil projRoots = f.root_elements.select { |re| Metamodel::Project === re } if projRoots.length != 1 Bake.formatter.printError("Config file must have exactly one 'Project' element as root element", filename) ExitHelper.exit(1) end proj = projRoots[0] reqVersion = proj.getRequiredBakeVersion checkVer(reqVersion) configs = proj.getConfig Bake::Configs::Checks::commonMetamodelCheck(configs, filename) configs.each do |c| if not c.project.empty? Bake.formatter.printError("Attribute 'project' must only be used in adapt config.",c) ExitHelper.exit(1) end if not c.type.empty? Bake.formatter.printError("Attribute 'type' must only be used in adapt config.",c) ExitHelper.exit(1) end end adaptRoots = f.root_elements.select { |re| Metamodel::Adapt === re } if adaptRoots.length > 0 adaptRoots.each do |adapt| adapt.mainProject = @mainProjectName if adapt.mainProject == "__THIS__" adaptConfigs = adapt.getConfig AdaptConfig.checkSyntax(adaptConfigs, filename, true) adaptConfigs.each do |ac| ac.project = proj.name if ac.project == "__THIS__" || ac.project == "" end @adaptConfigs.concat(adaptConfigs) end end configs end |
#printConfigNames ⇒ Object
370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 |
# File 'lib/bake/config/loader.rb', line 370 def printConfigNames mainConfigName = Bake..build_config != "" ? Bake..build_config : defaultConfigName configs = @loadedConfigs[Bake..main_project_name] foundValidConfig = false configs.each do |c| config, tmp = getFullProject(Bake..main_project_name, configs, c.name, c.name == mainConfigName) next if config.defaultToolchain.nil? Kernel.print "* #{config.name}" Kernel.print " (default)" if config.name == defaultConfigName Kernel.print ": #{config.description.text}" if config.description Kernel.print "\n" foundValidConfig = true end Bake.formatter.printWarning("No configuration with a DefaultToolchain found", Bake..main_dir+"/Project.meta") unless foundValidConfig ExitHelper.exit(0) end |
#printConfigs(adaptConfigs) ⇒ Object
388 389 390 391 392 393 |
# File 'lib/bake/config/loader.rb', line 388 def printConfigs(adaptConfigs) @adaptConfigs = adaptConfigs @loader = Loader.new loadMainMeta # note.in cache only needed configs are stored printConfigNames end |
#resolveConfigName(configs, configname) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/bake/config/loader.rb', line 17 def resolveConfigName(configs, configname) 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 return configname end |
#showConfigNames? ⇒ Boolean
366 367 368 |
# File 'lib/bake/config/loader.rb', line 366 def showConfigNames? Bake..showConfigs or (Bake..build_config == "" and defaultConfigName == "") end |
#symlinkCheck(filename) ⇒ Object
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
# File 'lib/bake/config/loader.rb', line 144 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
249 250 251 252 253 254 255 256 257 |
# File 'lib/bake/config/loader.rb', line 249 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 |