Top Level Namespace

Defined Under Namespace

Modules: Bake, RGen, RText Classes: Dir, File, SyncOut, ThreadOut

Instance Method Summary collapse

Instance Method Details

#add_line_if_no_comment(array, str) ⇒ Object



122
123
124
125
# File 'lib/bake/util.rb', line 122

def add_line_if_no_comment(array, str)
  s = str.split("#")[0].strip
  array << s unless s.empty?
end

#adjustFlags(orgStr, flags) ⇒ Object



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
# File 'lib/bake/util.rb', line 12

def adjustFlags(orgStr, flags)
  orgSplitted = Bake::Utils::flagSplit(orgStr, false)

  flags.each do |f|
    if f.overwrite != ""
      orgSplitted = Bake::Utils::flagSplit(f.overwrite, false)
    end
    if f.remove != ""
      rmSplitted = Bake::Utils::flagSplit(f.remove, false)
      orgSplitted.delete_if {|o| rmSplitted.any? { |r|
        begin
          o.match(/\A#{Regexp.escape(r)}\z/) || o.match(/\A#{r}\z/)
        rescue Exception => e
          Bake.formatter.printError(e.message, f)
          Bake::ExitHelper.exit(1)
        end
      }}
    end

    if f.add != ""
      Bake::Utils::flagSplit(f.add, false).each do |a|
        orgSplitted << a # allow duplicate flags # unless orgSplitted.any? { |o| o==a }
      end
    end

  end

  orgSplitted.join(" ")
end

#bake_format(data, output, indent) ⇒ Object



1
2
3
4
5
# File 'lib/format/bake_format.rb', line 1

def bake_format(data, output, indent)
  start_line = 0
  end_line = data.lines.count
  bake_format_in_range(data, output, indent, start_line, end_line)
end

#bake_format_in_range(data, output, indent, start_line, end_line) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/format/bake_format.rb', line 7

def bake_format_in_range(data, output, indent, start_line, end_line)
  indent_level = 0
  data.each_line.with_index do |l, index|
    opening = l.count('{')
    closing = l.count('}')
    old_indent_level = indent_level
    indent_level = indent_level + opening - closing

    prefix =
      if indent_level > old_indent_level
        indent * old_indent_level
      else
        indent * indent_level
      end

    if index.between?(start_line, end_line)
      l = (prefix + l.strip).rstrip
    end

    output.puts(l)
  end
  output.close
end

#collect_args(x) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/format/options/options.rb', line 46

def collect_args(x)
  if @index == 0
    @input = x
  elsif @index == 1
    @output = x
  elsif
    Bake.formatter.printError("Error: wrong number of the arguments")
    ExitHelper.exit(1)
  end

  @index += 1
end

#fill_compiler_env(dt) ⇒ Object



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
# File 'lib/bake/util.rb', line 127

def fill_compiler_env(dt)
  env = ENV["BAKE_C_COMPILER"]
  dt[:COMPILER][:C][:COMMAND] = env if env && !env.empty?
  env = ENV["BAKE_CPP_COMPILER"]
  dt[:COMPILER][:CPP][:COMMAND] = env if env && !env.empty?
  env = ENV["BAKE_ASM_COMPILER"]
  dt[:COMPILER][:ASM][:COMMAND] = env if env && !env.empty?
  env = ENV["BAKE_ARCHIVER"]
  dt[:ARCHIVER][:COMMAND] = env if env && !env.empty?
  env = ENV["BAKE_LINKER"]
  dt[:LINKER][:COMMAND] = env if env && !env.empty?

  env = ENV["BAKE_C_FLAGS"]
  dt[:COMPILER][:C][:FLAGS] = env if env && !env.empty?
  env = ENV["BAKE_CPP_FLAGS"]
  dt[:COMPILER][:CPP][:FLAGS] = env if env && !env.empty?
  env = ENV["BAKE_ASM_FLAGS"]
  dt[:COMPILER][:ASM][:FLAGS] = env if env && !env.empty?
  env = ENV["BAKE_ARCHIVER_FLAGS"]
  dt[:ARCHIVER][:FLAGS] = env if env && !env.empty?
  env = ENV["BAKE_LINKER_FLAGS"]
  dt[:LINKER][:FLAGS] = env if env && !env.empty?

  return dt
end

#integrateArchiver(tcs, archiver) ⇒ Object



70
71
72
73
74
75
# File 'lib/bake/util.rb', line 70

def integrateArchiver(tcs, archiver)
  return tcs unless archiver
  tcs[:ARCHIVER][:COMMAND] = archiver.command if archiver.command != ""
  tcs[:ARCHIVER][:PREFIX] = archiver.prefix if archiver.prefix != ""
  tcs[:ARCHIVER][:FLAGS] = adjustFlags(tcs[:ARCHIVER][:FLAGS], archiver.flags)
end

#integrateCompiler(tcs, compiler, type) ⇒ Object



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/bake/util.rb', line 77

def integrateCompiler(tcs, compiler, type)
  return tcs unless compiler
  if compiler.respond_to?("command") && compiler.command != ""
    tcs[:COMPILER][type][:COMMAND] = compiler.command
  end
  if compiler.respond_to?("cuda") && compiler.command != ""
    tcs[:COMPILER][type][:CUDA] = compiler.cuda
  end
  if compiler.respond_to?("prefix") && compiler.prefix != ""
    tcs[:COMPILER][type][:PREFIX] = compiler.prefix
  end
  if compiler.respond_to?("fileEndings") && compiler.fileEndings && compiler.fileEndings.endings != ""
    tcs[:COMPILER][type][:SOURCE_FILE_ENDINGS] = compiler.fileEndings.endings.split(",").map{|e| e.strip}
  end

  tcs[:COMPILER][type][:FLAGS] = adjustFlags(tcs[:COMPILER][type][:FLAGS], compiler.flags)
  compiler.define.each do |d|
    tcs[:COMPILER][type][:DEFINES] << d.str unless tcs[:COMPILER][type][:DEFINES].include? d.str
  end
end

#integrateCompilerFile(tcs, compiler) ⇒ Object



98
99
100
101
102
103
# File 'lib/bake/util.rb', line 98

def integrateCompilerFile(tcs, compiler)
  [:CPP, :C, :ASM].each do |t|
    integrateCompiler(tcs, compiler, t)
  end
  return tcs
end

#integrateDocu(tcs, docu) ⇒ Object



56
57
58
# File 'lib/bake/util.rb', line 56

def integrateDocu(tcs, docu)
  tcs[:DOCU] = docu.name if docu.name != ""
end

#integrateLinker(tcs, linker) ⇒ Object



60
61
62
63
64
65
66
67
68
# File 'lib/bake/util.rb', line 60

def integrateLinker(tcs, linker)
  return tcs unless linker
  tcs[:LINKER][:COMMAND] = linker.command if linker.command != ""
  tcs[:LINKER][:LINK_ONLY_DIRECT_DEPS] = linker.onlyDirectDeps
  tcs[:LINKER][:PREFIX] = linker.prefix if linker.prefix != ""
  tcs[:LINKER][:FLAGS] = adjustFlags(tcs[:LINKER][:FLAGS], linker.flags)
  tcs[:LINKER][:LIB_PREFIX_FLAGS] = adjustFlags(tcs[:LINKER][:LIB_PREFIX_FLAGS], linker.libprefixflags)
  tcs[:LINKER][:LIB_POSTFIX_FLAGS] = adjustFlags(tcs[:LINKER][:LIB_POSTFIX_FLAGS], linker.libpostfixflags)
end

#integrateToolchain(tcs, toolchain) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/bake/util.rb', line 42

def integrateToolchain(tcs, toolchain)
  return tcs unless toolchain

  tcs[:KEEP_FILE_ENDINGS] = @mainConfig.defaultToolchain.keepObjFileEndings
  tcs[:OUTPUT_DIR] = toolchain.outputDir if toolchain.outputDir != ""
  tcs[:OUTPUT_DIR_POSTFIX] = toolchain.outputDirPostfix if toolchain.outputDirPostfix != ""
  integrateLinker(tcs, toolchain.linker) if toolchain.respond_to?"linker"
  integrateArchiver(tcs, toolchain.archiver)
  toolchain.compiler.each do |c|
    integrateCompiler(tcs, c, c.ctype)
  end
  integrateDocu(tcs, toolchain.docu) if toolchain.docu
end

#puts(o) ⇒ Object



60
61
62
63
# File 'lib/common/ext/stdout.rb', line 60

def puts(o)
  tmp = Thread.current[:stdout]
  tmp ? tmp.puts(o) : super(o)
end

#remove_empty_strings_and_join(a, j = ' ') ⇒ Object



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

def remove_empty_strings_and_join(a, j=' ')
  return a.reject{|e|e.to_s.empty?}.join(j)
end

#sanitize_filename(filename) ⇒ Object



106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/bake/util.rb', line 106

def sanitize_filename(filename)
  filename.strip do |name|
   # NOTE: File.basename doesn't work right with Windows paths on Unix
   # get only the filename, not the whole path
   name.gsub! /^.*(\\|\/)/, ''

   # Finally, replace all non alphanumeric, underscore
   # or periods with underscore
   # name.gsub! /[^\w\.\-]/, '_'
   # Basically strip out the non-ascii alphabets too
   # and replace with x.
   # You don't want all _ :)
   name.gsub!(/[^0-9A-Za-z.\-]/, 'x')
  end
end

#set_lines(lines) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/format/options/options.rb', line 59

def set_lines(lines)
  m = lines.match(/(?<start_line>\d*):(?<end_line>\d*)/)

  if m == nil
    Bake.formatter.printError("Error: \"#{line}\" has invalid format")
    ExitHelper.exit(1)
  end

  @start_line = m[:start_line].to_i
  @end_line = m[:end_line].to_i

end

#set_loglevel(level) ⇒ Object



40
41
42
43
44
45
46
47
# File 'lib/rtext-service/options/options.rb', line 40

def set_loglevel(level)
  unless level.match(/^debug|info|warn|error|fatal$/)
    Bake.formatter.printError("Error: \"#{level}\" is wrong log level type")
    Bake::ExitHelper.exit(1)
  end

  @loglevel = level
end