Class: GameMachine::Console::Build

Inherits:
Object
  • Object
show all
Defined in:
server/lib/game_machine/console/build.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv, bundle = false) ⇒ Build

Returns a new instance of Build


7
8
9
10
# File 'server/lib/game_machine/console/build.rb', line 7

def initialize(argv,bundle=false)
  @bundle = bundle
  @command = argv.shift || ''
end

Instance Attribute Details

#bundleObject (readonly)

Returns the value of attribute bundle


6
7
8
# File 'server/lib/game_machine/console/build.rb', line 6

def bundle
  @bundle
end

#commandObject (readonly)

Returns the value of attribute command


6
7
8
# File 'server/lib/game_machine/console/build.rb', line 6

def command
  @command
end

Instance Method Details

#build(clean = false) ⇒ Object


70
71
72
73
74
75
76
# File 'server/lib/game_machine/console/build.rb', line 70

def build(clean=false)
  if clean
    cmd = "cd #{java_root} && #{gradlew} clean assemble install_libs installDist"
  else
    cmd = "cd #{java_root} && #{gradlew} assemble install_libs"
  end
end

#bundle_commandsObject


78
79
80
81
82
83
# File 'server/lib/game_machine/console/build.rb', line 78

def bundle_commands
  gm_path = File.join(ENV['APP_ROOT'],'.game_machine')
  FileUtils.mkdir_p(gm_path)
  vendor_path = File.join(gm_path,'vendor','bundle')
  cmd = "cd #{ENV['APP_ROOT']} && bundle install --path=#{vendor_path}"
end

#copy_process_managerObject


24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'server/lib/game_machine/console/build.rb', line 24

def copy_process_manager
 
  FileUtils.rm_rf File.join(ENV['APP_ROOT'],'process_manager','bin')
  FileUtils.rm_rf File.join(ENV['APP_ROOT'],'process_manager','lib')
  FileUtils.mv  File.join(java_root,'build','install','server','bin'), File.join(ENV['APP_ROOT'],'process_manager')
  FileUtils.mv  File.join(java_root,'build','install','server','lib'), File.join(ENV['APP_ROOT'],'process_manager')
    
  FileUtils.mv File.join(ENV['APP_ROOT'],'process_manager','bin','server.bat'),
    File.join(ENV['APP_ROOT'],'process_manager','bin','process_manager.bat')
    
  FileUtils.mv File.join(ENV['APP_ROOT'],'process_manager','bin','server'),
            File.join(ENV['APP_ROOT'],'process_manager','bin','process_manager')
end

#generate_codeObject


61
62
63
64
# File 'server/lib/game_machine/console/build.rb', line 61

def generate_code
  generate_java_code
  #generate_csharp_code
end

#generate_csharp_codeObject


39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'server/lib/game_machine/console/build.rb', line 39

def generate_csharp_code
  protogen_path = File.join(ENV['APP_ROOT'],'mono','bin','csharp','protogen_csharp.exe')
  proto_file = File.join(ENV['APP_ROOT'],'config','combined_messages.proto')
  proto_path = File.join(ENV['APP_ROOT'],'config')
  messages_out_file =  File.join(ENV['APP_ROOT'],'messages.cs')
  
  # Yet another .NET tool that assumes the whole world is windows.  In this case it embeds a 
  # windows protoc.exe, so we have to compile differently on non windows platforms
  if Config::CONFIG['target_os'].match(/mswin/)
    cmd = "#{protogen_path} -i:#{proto_file} -o:#{messages_out_file}"
  else
    bin_out_file =  File.join(ENV['APP_ROOT'],'messages.bin')
    cmd = "protoc -I#{proto_path} #{proto_file} -o#{bin_out_file}; mono #{protogen_path} -i:#{bin_out_file} -o:#{messages_out_file};rm -f #{bin_out_file}"
  end
  return cmd
end

#generate_java_codeObject


56
57
58
59
# File 'server/lib/game_machine/console/build.rb', line 56

def generate_java_code
  protogen = GameMachine::Protobuf::Generate.new(ENV['APP_ROOT'])
  protogen.generate
end

#gradlewObject


20
21
22
# File 'server/lib/game_machine/console/build.rb', line 20

def gradlew
  File.join(java_root,'gradlew')
end

#java_libObject


16
17
18
# File 'server/lib/game_machine/console/build.rb', line 16

def java_lib
  File.join(java_root,'lib')
end

#java_rootObject


12
13
14
# File 'server/lib/game_machine/console/build.rb', line 12

def java_root
  ENV['JAVA_ROOT']
end

#remove_libsObject


66
67
68
# File 'server/lib/game_machine/console/build.rb', line 66

def remove_libs
  FileUtils.rm Dir.glob(File.join(java_lib,'*.jar'))
end

#run!Object


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
# File 'server/lib/game_machine/console/build.rb', line 91

def run!
  commands = []

  if bundle
    commands << generate_code
    remove_libs
    commands << build(true)
    commands << bundle_commands
    run_commands(commands)
    bundler_path = File.join(ENV['APP_ROOT'],'.bundle')
    FileUtils.rm_rf(bundler_path)
  else
    if command == 'messages'
      commands << generate_code
      commands << build(false)
      run_commands(commands)
    elsif command == 'compile'
      commands << build(false)
      run_commands(commands)
    elsif command == 'clean'
      commands << generate_code
      remove_libs
      commands << build(true)
      run_commands(commands)
      copy_process_manager
    else
      commands << generate_code
      commands << build(false)
      run_commands(commands)
      copy_process_manager
    end
  end
end

#run_commands(commands) ⇒ Object


85
86
87
88
89
# File 'server/lib/game_machine/console/build.rb', line 85

def run_commands(commands)
  commands.each do |command|
    system(command)
  end
end