Top Level Namespace

Defined Under Namespace

Modules: Cairo

Instance Method Summary collapse

Instance Method Details

#install_missing_native_package(native_package_info) ⇒ Object



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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
# File 'ext/cairo/extconf.rb', line 77

def install_missing_native_package(native_package_info)
  platform = package_platform
  native_package_info = normalize_native_package_info(native_package_info)
  package = native_package_info[platform]
  return false if package.nil?

  need_super_user_priviledge = true
  case platform
  when :debian
    install_command = "apt-get install -V -y #{package}"
  when :fedora, :redhat
    install_command = "yum install -y #{package}"
  when :homebrew
    need_super_user_priviledge = false
    install_command = "brew install #{package}"
  when :macports
    install_command = "port install -y #{package}"
  else
    return false
  end

  have_priviledge = (not need_super_user_priviledge or super_user?)
  unless have_priviledge
    sudo = find_executable("sudo")
  end

  installing_message = "installing '#{package}' native package... "
  message("%s", installing_message)
  failed_to_get_super_user_priviledge = false
  if have_priviledge
    succeeded = xsystem(install_command)
  else
    if sudo
      install_command = "#{sudo} #{install_command}"
      succeeded = xsystem(install_command)
    else
      succeeded = false
      failed_to_get_super_user_priviledge = true
    end
  end

  if failed_to_get_super_user_priviledge
    result_message = "require super user privilege"
  else
    result_message = succeeded ? "succeeded" : "failed"
  end
  Logging.postpone do
    "#{installing_message}#{result_message}\n"
  end
  message("#{result_message}\n")

  error_message = nil
  unless succeeded
    if failed_to_get_super_user_priviledge
      error_message = <<-EOM
'#{package}' native package is required.
run the following command as super user to install required native package:
  \# #{install_command}
EOM
    else
      error_message = <<-EOM
failed to run '#{install_command}'.
EOM
    end
  end
  if error_message
    message("%s", error_message)
    Logging.message("%s", error_message)
  end

  Logging.message("--------------------\n\n")

  succeeded
end

#normalize_native_package_info(native_package_info) ⇒ Object



70
71
72
73
74
75
# File 'ext/cairo/extconf.rb', line 70

def normalize_native_package_info(native_package_info)
  native_package_info ||= {}
  native_package_info = native_package_info.dup
  native_package_info[:fedora] ||= native_package_info[:redhat]
  native_package_info
end

#package_platformObject



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'ext/cairo/extconf.rb', line 50

def package_platform
  if File.exist?("/etc/debian_version")
    :debian
  elsif File.exist?("/etc/fedora-release")
    :fedora
  elsif File.exist?("/etc/redhat-release")
    :redhat
  elsif find_executable("brew")
    :homebrew
  elsif find_executable("port")
    :macports
  else
    :unknown
  end
end

#required_pkg_config_package(package_info, native_package_info = nil) ⇒ Object



152
153
154
155
156
157
158
159
160
161
162
163
164
# File 'ext/cairo/extconf.rb', line 152

def required_pkg_config_package(package_info, native_package_info=nil)
  if package_info.is_a?(Array)
    required_package_info = package_info
  else
    required_package_info = [package_info]
  end
  return true if PKGConfig.have_package(*required_package_info)

  native_package_info ||= {}
  return false unless install_missing_native_package(native_package_info)

  PKGConfig.have_package(*required_package_info)
end

#super_user?Boolean

Returns:

  • (Boolean)


66
67
68
# File 'ext/cairo/extconf.rb', line 66

def super_user?
  Process.uid.zero?
end