Class: GameMachine::Console::Build
- Inherits:
-
Object
- Object
- GameMachine::Console::Build
- Defined in:
- lib/game_machine/console/build.rb
Instance Attribute Summary collapse
-
#bundle ⇒ Object
readonly
Returns the value of attribute bundle.
-
#command ⇒ Object
readonly
Returns the value of attribute command.
Instance Method Summary collapse
- #build(clean = false) ⇒ Object
- #bundle_commands ⇒ Object
- #generate_code ⇒ Object
- #generate_csharp_code ⇒ Object
- #generate_java_code ⇒ Object
- #gradlew ⇒ Object
-
#initialize(argv, bundle = false) ⇒ Build
constructor
A new instance of Build.
- #java_lib ⇒ Object
- #java_root ⇒ Object
- #remove_libs ⇒ Object
- #run! ⇒ Object
- #run_commands(commands) ⇒ Object
Constructor Details
#initialize(argv, bundle = false) ⇒ Build
Returns a new instance of Build.
7 8 9 10 |
# File 'lib/game_machine/console/build.rb', line 7 def initialize(argv,bundle=false) @bundle = bundle @command = argv.shift || '' end |
Instance Attribute Details
#bundle ⇒ Object (readonly)
Returns the value of attribute bundle.
6 7 8 |
# File 'lib/game_machine/console/build.rb', line 6 def bundle @bundle end |
#command ⇒ Object (readonly)
Returns the value of attribute command.
6 7 8 |
# File 'lib/game_machine/console/build.rb', line 6 def command @command end |
Instance Method Details
#build(clean = false) ⇒ Object
55 56 57 58 59 60 61 |
# File 'lib/game_machine/console/build.rb', line 55 def build(clean=false) if clean cmd = "cd #{java_root} && #{gradlew} clean build install_libs" else cmd = "cd #{java_root} && #{gradlew} build install_libs" end end |
#bundle_commands ⇒ Object
63 64 65 66 67 68 |
# File 'lib/game_machine/console/build.rb', line 63 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 |
#generate_code ⇒ Object
46 47 48 49 |
# File 'lib/game_machine/console/build.rb', line 46 def generate_code generate_java_code generate_csharp_code end |
#generate_csharp_code ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/game_machine/console/build.rb', line 24 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') = 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:#{}" 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:#{};rm -f #{bin_out_file}" end return cmd end |
#generate_java_code ⇒ Object
41 42 43 44 |
# File 'lib/game_machine/console/build.rb', line 41 def generate_java_code protogen = GameMachine::Protobuf::Generate.new(ENV['APP_ROOT']) protogen.generate end |
#gradlew ⇒ Object
20 21 22 |
# File 'lib/game_machine/console/build.rb', line 20 def gradlew File.join(java_root,'gradlew') end |
#java_lib ⇒ Object
16 17 18 |
# File 'lib/game_machine/console/build.rb', line 16 def java_lib File.join(java_root,'lib') end |
#java_root ⇒ Object
12 13 14 |
# File 'lib/game_machine/console/build.rb', line 12 def java_root ENV['JAVA_ROOT'] end |
#remove_libs ⇒ Object
51 52 53 |
# File 'lib/game_machine/console/build.rb', line 51 def remove_libs FileUtils.rm Dir.glob(File.join(java_lib,'*.jar')) end |
#run! ⇒ Object
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 |
# File 'lib/game_machine/console/build.rb', line 76 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 == 'clean' commands << generate_code remove_libs commands << build(true) run_commands(commands) else commands << generate_code commands << build(false) run_commands(commands) end end end |
#run_commands(commands) ⇒ Object
70 71 72 73 74 |
# File 'lib/game_machine/console/build.rb', line 70 def run_commands(commands) commands.each do |command| system(command) end end |