Class: DyCI::InstallCommand

Inherits:
Object
  • Object
show all
Defined in:
lib/dyci/commands/install_command.rb

Class Method Summary collapse

Class Method Details

.backup_clangObject



59
60
61
62
63
64
65
66
67
# File 'lib/dyci/commands/install_command.rb', line 59

def backup_clang
  clang_path = clang_location
  clang_backup_path = "#{clang_path}.backup"
  unless File.exists? clang_backup_path
    puts "Create clang backup"
    puts "#{clang_path} => #{clang_backup_path}"
    %x[ sudo cp #{clang_path} #{clang_backup_path} ]
  end
end

.clang_locationObject



83
84
85
86
# File 'lib/dyci/commands/install_command.rb', line 83

def clang_location
  developer_path = %x[ xcode-select -print-path ].chomp
  "#{developer_path}/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang"
end

.install_app_codeObject



47
48
49
50
51
52
53
54
55
56
57
# File 'lib/dyci/commands/install_command.rb', line 47

def install_app_code
  app_code_path = "#{File.expand_path '~'}/Library/Preferences/appCode10"
  if Dir.exists? app_code_path
    puts "AppCode preferences was not found at path '#{app_code_path}'"
    return
  end
  app_code_plugin_path = "#{app_code_path}/tools/"
  FileUtils.mkdir_p app_code_plugin_path
  app_code_plugin = "#{self.root_path}/pligins/AppCode/DyCIPlugin.xml"
  FileUtils.cp app_code_plugin, app_code_plugin_path
end

.install_as_pluginObject



37
38
39
40
# File 'lib/dyci/commands/install_command.rb', line 37

def install_as_plugin
  self.install_helper
  self.install_xcode_plugin 'DyCIFakeClang'
end

.install_as_proxyObject



42
43
44
45
# File 'lib/dyci/commands/install_command.rb', line 42

def install_as_proxy
  self.install_helper
  self.replace_clang
end

.install_helperObject



33
34
35
# File 'lib/dyci/commands/install_command.rb', line 33

def install_helper
  self.install_xcode_plugin 'DyCIHelper'
end

.install_xcode_plugin(plugin_name) ⇒ Object



78
79
80
81
# File 'lib/dyci/commands/install_command.rb', line 78

def install_xcode_plugin plugin_name
  puts "Install #{plugin_name}"
  FileUtils.cp_r "#{self.root_path}/lib/plugins/#{plugin_name}.xcplugin", "#{self.plugins_dir}/"
end

.plugins_dirObject



88
89
90
91
92
93
# File 'lib/dyci/commands/install_command.rb', line 88

def plugins_dir
  user_dir = File.expand_path("~")
  plugins_dir = "#{user_dir}/Library/Application Support/Developer/Shared/Xcode/Plug-ins"
  FileUtils.mkdir_p plugins_dir
  plugins_dir
end

.replace_clangObject



69
70
71
72
73
74
75
76
# File 'lib/dyci/commands/install_command.rb', line 69

def replace_clang
  self.backup_clang
  proxy_path = Gem.bin_path 'dyci-compiler', 'dyci-compiler'
  clang_path = clang_location
  puts "Replace clang with proxy script"
  puts "#{proxy_path} => #{clang_path}"
  %x[ sudo cp #{proxy_path} #{clang_path} ]
end

.root_pathObject



95
96
97
# File 'lib/dyci/commands/install_command.rb', line 95

def root_path
  File.expand_path "../../../..", __FILE__
end

.run(args) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/dyci/commands/install_command.rb', line 6

def run args
  if args.count.zero?
    usage
    exit 0
  end
  args.each do | arg | 
    command = "install_#{arg}".to_sym
    if self.respond_to? command
      self.send command
    else
      puts "Unknown command '#{command}'"
    end
  end
end

.usageObject



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/dyci/commands/install_command.rb', line 21

def usage
  puts <<-EOF
Usage: 
  dyci install parameter

Available parameters:
  as_plugin - install XCode compiler plugin
  as_proxy - replace current clang with fake clang script
  app_code - install AppCode DyCI plugin
EOF
end