Class: Rant::CSharp::BaseCompilerAdapter

Inherits:
Object
  • Object
show all
Defined in:
lib/rant/csharp/base_compiler_adapter.rb

Direct Known Subclasses

CscCompiler, McsCompiler

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(bin = "") ⇒ BaseCompilerAdapter

Returns a new instance of BaseCompilerAdapter.

Raises:

  • (Exception)


44
45
46
47
48
49
# File 'lib/rant/csharp/base_compiler_adapter.rb', line 44

def initialize bin = ""
  @bin = bin
  @switch_map = {}
  raise Exception.new("Must specify an executable") if !@bin || 
                                                        @bin.length == 0
end

Instance Attribute Details

#binObject

Returns the value of attribute bin.



41
42
43
# File 'lib/rant/csharp/base_compiler_adapter.rb', line 41

def bin
  @bin
end

#switch_mapObject

Returns the value of attribute switch_map.



42
43
44
# File 'lib/rant/csharp/base_compiler_adapter.rb', line 42

def switch_map
  @switch_map
end

Instance Method Details

#argument_prefixObject



97
98
99
# File 'lib/rant/csharp/base_compiler_adapter.rb', line 97

def argument_prefix
  ""
end

#boolean_argument(arg, on) ⇒ Object



82
83
84
85
86
# File 'lib/rant/csharp/base_compiler_adapter.rb', line 82

def boolean_argument arg, on
  switch = map_arg(arg)
  ret = "#{self.argument_prefix}#{switch}"
  ret += on ? "" : "-"
end

#cmd(target, cs_args, context) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/rant/csharp/base_compiler_adapter.rb', line 51

def cmd target, cs_args, context
  @context = context
  
  if !target || target.length == 0
    raise Exception.new("Target must be specified and have a length " +
                        "greater than 0")
  end
  
  # Generic argument processing
  args = []
  sources = cs_args.delete(:sources)
  cs_args[:target] ||= guess_target(target)
  
  cs_args.each_key do |key|
    args.push(cs_args[key].to_cs_arg(key, self))
  end

  src_list = sources.to_cmd_array(context)

  ([bin, outfile(target)] + args.flatten + src_list).join(' ')
end

#guess_target(outfile) ⇒ Object

Try to automatically guess the type of output file based on the extension



103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/rant/csharp/base_compiler_adapter.rb', line 103

def guess_target outfile
  target = "library"
  
  ext = outfile.match(/\.([^\.]+)$/)
  ext = ext[1] if ext
  
  if ext
    case ext.downcase
    when "netmodule"
      target = map_target("module")
    when "exe"
      target = map_target("winexe")
    end
  end
  target
end

#map_arg(arg) ⇒ Object

Map rant arguments to compiler arguments



74
75
76
# File 'lib/rant/csharp/base_compiler_adapter.rb', line 74

def map_arg arg
  switch_map[arg] ? switch_map[arg] : arg
end

#map_target(target) ⇒ Object

Allows subclasses to override default target names



121
122
123
# File 'lib/rant/csharp/base_compiler_adapter.rb', line 121

def map_target target
  target
end

#outfile(target) ⇒ Object



78
79
80
# File 'lib/rant/csharp/base_compiler_adapter.rb', line 78

def outfile target
  string_argument "out", target
end

#string_argument(arg, value) ⇒ Object



88
89
90
91
92
93
94
95
# File 'lib/rant/csharp/base_compiler_adapter.rb', line 88

def string_argument arg, value
  switch = map_arg(arg)
  # Assume all string arguments except target are
  # files
  value = @context.sys.sp(value) if arg != :target
 
  "#{self.argument_prefix}#{switch}:#{value}"
end