Skip to content

Commit 11e55ee

Browse files
committed
Create a Ruby library for building linux packages
1 parent c7d1e18 commit 11e55ee

File tree

5 files changed

+106
-2
lines changed

5 files changed

+106
-2
lines changed

RbkitClient.pro

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ SUBDIRS = \
1414

1515
CONFIG += ordered
1616
CONFIG += c++11
17+
CONFIG += static

rbkit-app/rbkit-app.pro

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ TEMPLATE = app
88
SOURCES += main.cpp
99

1010
CONFIG += c++11
11+
CONFIG += static
1112
ICON = rbkit.icns
1213

1314
# Include rbkit related include and lib paths

tools/deployqt.rb

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
#!/usr/bin/env ruby
2+
3+
require "fileutils"
4+
require "pry"
5+
6+
class DeployQt
7+
attr_accessor :qt_home, :executable, :dst
8+
def initialize(executable)
9+
@pwd = ENV["PWD"]
10+
@executable = File.expand_path(File.join(@pwd, executable))
11+
@qt_home = "#{ENV['QT_HOME']}/5.4/gcc_64"
12+
@dst = File.expand_path(File.join(@pwd, "/rbkit"))
13+
remove_existing_files
14+
@platform_plugin = File.expand_path(File.join(@qt_home, "/plugins/platforms/libqxcb.so"))
15+
@sql_driver_path = File.expand_path(File.join(@qt_home, "/plugins/sqldrivers/libqsqlite.so"))
16+
FileUtils.mkdir_p(@dst)
17+
make_required_dirs
18+
end
19+
20+
def make_required_dirs
21+
FileUtils.mkdir_p("#{dst}/fonts")
22+
FileUtils.mkdir_p("#{dst}/libs")
23+
FileUtils.mkdir_p("#{dst}/platforms")
24+
FileUtils.mkdir_p("#{dst}/sqldrivers")
25+
end
26+
27+
def remove_existing_files
28+
FileUtils.rm_rf(dst)
29+
FileUtils.rm_rf("rbkit.tar.gz")
30+
end
31+
32+
def create_archive
33+
copy_app_libs
34+
copy_lib_dependencies
35+
copy_sql_dependencies
36+
make_executable
37+
create_tar_file
38+
end
39+
40+
def create_tar_file
41+
FileUtils.cd(@pwd) do
42+
system("tar -zcvf rbkit.tar.gz rbkit")
43+
end
44+
end
45+
46+
def copy_sql_dependencies
47+
FileUtils.cp(@sql_driver_path, "#{dst}/sqldrivers")
48+
end
49+
50+
def copy_app_libs
51+
puts "Copying application dependencies for #{executable}"
52+
`ldd #{executable}`.tap do |deps|
53+
deps_array = deps.split("\n")
54+
deps_array.each { |deps_element| verify_and_copy(deps_element) }
55+
end
56+
end
57+
58+
def copy_lib_dependencies
59+
FileUtils.cp(@platform_plugin, "#{dst}/platforms")
60+
`ldd #{@platform_plugin}`.tap do |deps|
61+
deps_array = deps.split("\n")
62+
deps_array.each { |deps_element| verify_and_copy(deps_element) }
63+
end
64+
end
65+
66+
def make_executable
67+
exec_string =<<-EOD
68+
#!/bin/sh
69+
export LD_LIBRARY_PATH=\`pwd\`/libs
70+
export QT_QPA_FONTDIR=\`pwd\`/fonts
71+
./#{File.basename(executable)}
72+
EOD
73+
FileUtils.cp(executable, dst)
74+
File.open("#{dst}/rbkit", "w") do |fl|
75+
fl.puts(exec_string)
76+
end
77+
system("chmod +x #{dst}/rbkit")
78+
end
79+
80+
private
81+
82+
def verify_and_copy(deps_element)
83+
dep_path = deps_element.split("=>").last.split("(").first.strip
84+
if !dep_path.empty? && dep_path.match(/^#{ENV['HOME']}/)
85+
FileUtils.cp(File.expand_path(dep_path), "#{dst}/libs")
86+
end
87+
end
88+
end
89+
90+
DeployQt.new(ARGV[0]).create_archive

tools/deployqtapp.sh

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ executable=$1
4343
distro=`lsb_release -d | awk '{print $2$3$4}' | sed 's/\./_/g'`
4444

4545
# Create the directory that will be tarred up for distribution.
46-
tardir=`echo $executable"_"$distro | awk '{print tolower($0)}'`
46+
tardir="rbkit"
4747
mkdir $tardir
4848
echo "Created tar ball directory: "$tardir
4949

@@ -77,6 +77,12 @@ cp -r $qtfontsdir/* $fontsdir
7777

7878
# You will need to change this to point to wherever libqxcb.so lives on your PC.
7979
qtplatformplugin=$QT_HOME/5.4/gcc_64/plugins/platforms/libqxcb.so
80+
for dep in `ldd $qtplatformplugin | awk '{print $3}' | grep -v "("`
81+
do
82+
cp $dep $libsdir
83+
echo "Copied dependency "$dep" to "$libsdir
84+
done
85+
8086
qtplatformplugindir=$tardir/platforms
8187
mkdir $qtplatformplugindir
8288
echo "Created platforms directory: "$qtplatformplugindir
@@ -161,7 +167,7 @@ cp $qtsqliteplugin $qtsqliteplugindir
161167
echo "Copied "$qtsqliteplugin" to "$qtsqliteplugindir
162168

163169
# Create the run script.
164-
execscript=$tardir/"run$executable.sh"
170+
execscript=$tardir/"rbkit"
165171
echo "Created run script: "$execscript
166172

167173
echo "#!/bin/sh" > $execscript

tools/print_dep.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
executable=$1
2+
echo $executable
3+
for dep in `ldd $executable | awk '{print $3}' | grep -v "("`
4+
do
5+
echo "Copied dependency "$dep" to "$libsdir
6+
done

0 commit comments

Comments
 (0)