class Object
Public Instance Methods
add_line_if_no_comment(array, str)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# File lib/bake/util.rb, line 56 def integrateDocu(tcs, docu) tcs[:DOCU] = docu.name if docu.name != "" end
integrateLinker(tcs, linker)
click to toggle source
# 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)
click to toggle source
# 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
longname(short_name)
click to toggle source
# File lib/blocks/compile.rb, line 22 def longname short_name max_path = 1024 long_name = " " * max_path lfn_size = Kernel32.GetLongPathName(short_name, long_name, max_path) return long_name[0..lfn_size-1] end
puts(o)
click to toggle source
Calls superclass method
# File lib/common/ext/stdout.rb, line 60 def puts(o) tmp = Thread.current[:stdout] tmp ? tmp.puts(o) : super(o) end
realname(file)
click to toggle source
# File lib/blocks/compile.rb, line 36 def realname file x = longname(shortname(file)) end
remove_empty_strings_and_join(a, j=' ')
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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
shortname(long_name)
click to toggle source
# File lib/blocks/compile.rb, line 29 def shortname long_name max_path = 1024 short_name = " " * max_path lfn_size = Kernel32.GetShortPathName(long_name, short_name, max_path) return short_name[0..lfn_size-1] end