Class: Bake::Configs::Checks

Inherits:
Object
  • Object
show all
Defined in:
lib/bake/config/checks.rb

Constant Summary collapse

@@warnedCase =
[]

Class Method Summary collapse

Class Method Details

.cleanupWarningsObject



8
9
10
# File 'lib/bake/config/checks.rb', line 8

def self.cleanupWarnings
  @@warnedCase.clear
end

.commonMetamodelCheck(configs, filename, isAdapt = false) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
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
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
# File 'lib/bake/config/checks.rb', line 50

def self.commonMetamodelCheck(configs, filename, isAdapt = false)

  if configs.length == 0 && !isAdapt
    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 [:CPP,:C,:ASM].none? {|t| t == c.ctype}
          Bake.formatter.printError("Type of compiler must be CPP, C or ASM", c)
          ExitHelper.exit(1)
        end
        if not c.internalDefines.nil? and c.internalDefines != ""
          Bake.formatter.printError("InternalDefines only allowed in DefaultToolchain", c.internalDefines)
          ExitHelper.exit(1)
        end
        if c.fileEndings && c.fileEndings.endings.empty?
          Bake.formatter.printError("FileEnding must not be empty.", c.fileEndings)
          ExitHelper.exit(1)
        end
      end
      config.toolchain.lintPolicy.each do |l|
        Bake.formatter.printWarning("Lint support was removed. Please delete LintPolicy from Project.meta.", l)
      end
    end
    if config.respond_to?("defaultToolchain") and config.defaultToolchain
      config.defaultToolchain.lintPolicy.each do |l|
        Bake.formatter.printWarning("Lint support was removed. Please delete LintPolicy from Project.meta.", l)
      end
      config.defaultToolchain.compiler.each do |c|
        if [:CPP,:C,:ASM].none? {|t| t == c.ctype}
          Bake.formatter.printError("Type of compiler must be CPP, C or ASM", c)
          ExitHelper.exit(1)
        end
        if c.fileEndings && c.fileEndings.endings.empty?
          Bake.formatter.printError("FileEnding must not be empty.", c.fileEndings)
          ExitHelper.exit(1)
        end
      end
    end

    config.includeDir.each do |inc|
      if not ["front", "back", ""].include?inc.inject
        Bake.formatter.printError("inject of IncludeDir must be 'front' or 'back'", inc)
        ExitHelper.exit(1)
      end
      if not ["front", "back", ""].include?inc.infix
        Bake.formatter.printError("infix of IncludeDir must be 'front' or 'back'", inc)
        ExitHelper.exit(1)
      end
      if (inc.infix != "" and inc.inject != "")
        Bake.formatter.printError("IncludeDir must have inject OR infix (deprecated)", inc)
        ExitHelper.exit(1)
      end
      if (inc.name.empty? || inc.name[0] == " ")
        Bake.formatter.printError("IncludeDir must not be empty or start with a space", inc)
        ExitHelper.exit(1)
      end
    end if config.respond_to?("includeDir")

    if not ["", "yes", "no", "all"].include?config.mergeInc
      Bake.formatter.printError("Allowed modes are 'all', 'yes', 'no' and unset.",config)
      ExitHelper.exit(1)
    end

  end

end

.sanityFolderName(dorg) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/bake/config/checks.rb', line 29

def self.sanityFolderName(dorg)
  return if !Bake.options.caseSensitivityCheck
  return if Bake.options.verbose < 1
  d = dorg
  while (d != File.dirname(d))
    b = File.basename(d)
    dnew = File.dirname(d)
    Dir.chdir(dnew) do
      files = Dir.glob("*")
      if !files.include?(b)
        possible = files.select{ |f| f.casecmp(b)==0 }
        if possible.length > 0 && !@@warnedCase.include?(d)
          @@warnedCase << d
          Bake.formatter.printWarning("Warning: '#{b}' not found in '#{dnew}'. Alternatives: #{possible.map{|p| "'#{p}'"}.join(", ")}. Maybe a typo happened while entering a folder in the shell?")
        end
      end
    end
    d = dnew
  end
end

.symlinkCheck(filename) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/bake/config/checks.rb', line 12

def self.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