Class: Rake::Delphi::Android::SDK

Inherits:
Dcc32Tool show all
Defined in:
lib/rake/delphi/android/sdk.rb

Direct Known Subclasses

DCC32SDKOptions, JavaSDK, PAClientSDKOptions

Constant Summary collapse

PROPERTIES =
{
  :linker => 'NDKArmLinuxAndroidFile',
  :lib => 'DelphiNDKLibraryPath',
  :linker_option => 'DelphiNDKLibraryPath',
  :stripdebug => 'NDKArmLinuxAndroidStripFile',
  :aapt => 'SDKAaptPath',
  :platform => 'SDKApiLevelPath',
  :keystore => nil,
  :zipalign => 'SDKZipAlignPath',
  :jdk_path => 'JDKJarsignerPath'
}

Constants inherited from CustomDelphiTool

CustomDelphiTool::BDSRegRoot, CustomDelphiTool::DelphiRegRoot, CustomDelphiTool::EDSRegRoot, CustomDelphiTool::EmbarcaderoRegRoot

Instance Attribute Summary

Attributes inherited from Dcc32Tool

#env

Instance Method Summary collapse

Methods inherited from Dcc32Tool

#delphidir, #delphilib, #init_env, #readLibraryPaths, toolName

Methods inherited from CustomDelphiTool

checkToolFailure, #delphidir, find, #options, readDelphiDir, readUserOption, #regroot, reinit, rootForVersion, toolName, #toolpath, #version, version4version, #versionInfoClass

Methods inherited from CustomExec

#execute, #to_system_path

Methods inherited from BasicTask

#trace?

Constructor Details

#initializeSDK



26
27
28
29
# File 'lib/rake/delphi/android/sdk.rb', line 26

def initialize
  super(false)
  read_properties
end

Instance Method Details

#aaptObject



121
122
123
124
125
# File 'lib/rake/delphi/android/sdk.rb', line 121

def aapt
  @aapt = ENV['DELPHI_ANDROID_SDK_BUILD_TOOLS_PATH'] || @aapt
  warn 'Please, set DELPHI_ANDROID_SDK_BUILD_TOOLS_PATH to path where aapt.exe is located' unless @aapt
  @aapt
end

#keystoreObject



133
134
135
136
137
# File 'lib/rake/delphi/android/sdk.rb', line 133

def keystore
  @keystore = ENV['DELPHI_ANDROID_KEYSTORE'] || @keystore
  warn 'Please, set DELPHI_ANDROID_KEYSTORE to the path where a keystore (to sign an application) is located' unless @keystore
  @keystore
end

#libObject



103
104
105
106
107
# File 'lib/rake/delphi/android/sdk.rb', line 103

def lib
  @lib = ENV['DELPHI_ANDROID_SDK_LIBPATH'] || @lib
  warn 'Please, define DELPHI_ANDROID_SDK_LIBPATH environment variable' unless @lib
  @lib
end

#lib=(value) ⇒ Object



88
89
90
# File 'lib/rake/delphi/android/sdk.rb', line 88

def lib=(value)
  @lib, null  = value.split(';', 2)
end

#linkerObject



97
98
99
100
101
# File 'lib/rake/delphi/android/sdk.rb', line 97

def linker
  @linker = ENV['DELPHI_ANDROID_SDK_LINKER'] || @linker
  warn "Please, define DELPHI_ANDROID_SDK_LINKER environment variable.\n Otherwise you may get 'File not found: ldandroid.exe' error" unless @linker
  @linker
end

#linker_optionObject



109
110
111
112
113
# File 'lib/rake/delphi/android/sdk.rb', line 109

def linker_option
  @linker_option = ENV['DELPHI_ANDROID_SDK_LINKER_OPTION'] || @linker_option
  warn 'Please, define DELPHI_ANDROID_SDK_LINKER_OPTION environment variable' unless @linker_option
  @linker_option
end

#linker_option=(value) ⇒ Object



92
93
94
95
# File 'lib/rake/delphi/android/sdk.rb', line 92

def linker_option=(value)
  null, @linker_option = value.split(';', 2)
  @linker_option = ' -L \"' + @linker_option + '\"'
end

#platformObject



127
128
129
130
131
# File 'lib/rake/delphi/android/sdk.rb', line 127

def platform
  @platform = ENV['DELPHI_ANDROID_SDK_PLATFORM_PATH'] || @platform
  warn 'Please, set DELPHI_ANDROID_SDK_PLATFORM_PATH to the path where android.jar is located' unless @platform
  @platform
end

#read_default_configObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/rake/delphi/android/sdk.rb', line 31

def read_default_config
  begin
    require 'win32/registry'
    @reg_keys = {::Win32::Registry::HKEY_CURRENT_USER => 'HKCU',
      ::Win32::Registry::HKEY_LOCAL_MACHINE => 'HKLM'}

    [::Win32::Registry::HKEY_CURRENT_USER, \
        ::Win32::Registry::HKEY_LOCAL_MACHINE].each do |regRoot|
      begin
        key = 'Default_Android'
        Logger.trace(Logger::DEBUG, "Finding #{@reg_keys[regRoot]}\\#{@platform_SDKs}\\#{key}")
        regRoot.open(@platform_SDKs) do |reg|
            reg_typ, reg_val = reg.read(key)
          Logger.trace(Logger::DEBUG, "Found '#{reg_val}'")
          return reg_val
        end
      rescue ::Win32::Registry::Error
        Logger.trace(Logger::DEBUG, "No reg key '#{regRoot}'?!")
      end
    end
    return nil
  rescue LoadError
    Logger.trace(Logger::DEBUG, 'No `win32/registry` gem?!')
    return nil
  end
end

#read_propertiesObject



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/rake/delphi/android/sdk.rb', line 58

def read_properties
  @platform_SDKs = @@regroot + '\\PlatformSDKs'
  default_android = read_default_config
  return unless default_android
  reg_default = @platform_SDKs + '\\' + default_android
  begin
    PROPERTIES.each do |prop, reg_key|
      next unless reg_key
      # current user values have precedence over local machine
      [::Win32::Registry::HKEY_CURRENT_USER, \
         ::Win32::Registry::HKEY_LOCAL_MACHINE].each do |regRoot|
        begin
          Logger.trace(Logger::DEBUG, "Finding '#{reg_key}' for '#{prop}' in '#{@reg_keys[regRoot]}\\#{reg_default}'")
          regRoot.open(reg_default) do |reg|
            reg_typ, reg_val = reg.read(reg_key)
            Logger.trace(Logger::DEBUG, "Value=#{reg_val}")
            send "#{prop}=", reg_val
          end
          # if value found (in CU) there is no reason to search in LM
          break
        rescue ::Win32::Registry::Error
          Logger.trace(Logger::DEBUG, "No reg key '#{regRoot}'?!")
        end
      end
    end
  rescue LoadError
    Logger.trace(Logger::DEBUG, 'No `win32/registry` gem?!')
  end
end

#stripdebugObject



115
116
117
118
119
# File 'lib/rake/delphi/android/sdk.rb', line 115

def stripdebug
  @stripdebug = ENV['DELPHI_ANDROID_SDK_STRIPDEBUG'] || @stripdebug
  warn 'Please, set DELPHI_ANDROID_SDK_STRIPDEBUG to path where arm-linux-androideabi-strip.exe is located' unless @stripdebug
  @stripdebug
end

#zipalignObject



139
140
141
142
143
# File 'lib/rake/delphi/android/sdk.rb', line 139

def zipalign
  @zipalign = ENV['DELPHI_ANDROID_SDK_PLATFORM_TOOLS'] || @zipalign
  warn 'Please, set DELPHI_ANDROID_SDK_PLATFORM_TOOLS to the path where zipalign.exe is located' unless @zipalign
  @zipalign
end