Skip to content

Commit

Permalink
Create a Ruby library for building linux packages
Browse files Browse the repository at this point in the history
  • Loading branch information
gnufied committed Jan 7, 2015
1 parent c7d1e18 commit 11e55ee
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 2 deletions.
1 change: 1 addition & 0 deletions RbkitClient.pro
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ SUBDIRS = \

CONFIG += ordered
CONFIG += c++11
CONFIG += static
1 change: 1 addition & 0 deletions rbkit-app/rbkit-app.pro
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ TEMPLATE = app
SOURCES += main.cpp

CONFIG += c++11
CONFIG += static
ICON = rbkit.icns

# Include rbkit related include and lib paths
Expand Down
90 changes: 90 additions & 0 deletions tools/deployqt.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
#!/usr/bin/env ruby

require "fileutils"
require "pry"

class DeployQt
attr_accessor :qt_home, :executable, :dst
def initialize(executable)
@pwd = ENV["PWD"]
@executable = File.expand_path(File.join(@pwd, executable))
@qt_home = "#{ENV['QT_HOME']}/5.4/gcc_64"
@dst = File.expand_path(File.join(@pwd, "/rbkit"))
remove_existing_files
@platform_plugin = File.expand_path(File.join(@qt_home, "/plugins/platforms/libqxcb.so"))
@sql_driver_path = File.expand_path(File.join(@qt_home, "/plugins/sqldrivers/libqsqlite.so"))
FileUtils.mkdir_p(@dst)
make_required_dirs
end

def make_required_dirs
FileUtils.mkdir_p("#{dst}/fonts")
FileUtils.mkdir_p("#{dst}/libs")
FileUtils.mkdir_p("#{dst}/platforms")
FileUtils.mkdir_p("#{dst}/sqldrivers")
end

def remove_existing_files
FileUtils.rm_rf(dst)
FileUtils.rm_rf("rbkit.tar.gz")
end

def create_archive
copy_app_libs
copy_lib_dependencies
copy_sql_dependencies
make_executable
create_tar_file
end

def create_tar_file
FileUtils.cd(@pwd) do
system("tar -zcvf rbkit.tar.gz rbkit")
end
end

def copy_sql_dependencies
FileUtils.cp(@sql_driver_path, "#{dst}/sqldrivers")
end

def copy_app_libs
puts "Copying application dependencies for #{executable}"
`ldd #{executable}`.tap do |deps|
deps_array = deps.split("\n")
deps_array.each { |deps_element| verify_and_copy(deps_element) }
end
end

def copy_lib_dependencies
FileUtils.cp(@platform_plugin, "#{dst}/platforms")
`ldd #{@platform_plugin}`.tap do |deps|
deps_array = deps.split("\n")
deps_array.each { |deps_element| verify_and_copy(deps_element) }
end
end

def make_executable
exec_string =<<-EOD
#!/bin/sh
export LD_LIBRARY_PATH=\`pwd\`/libs
export QT_QPA_FONTDIR=\`pwd\`/fonts
./#{File.basename(executable)}
EOD
FileUtils.cp(executable, dst)
File.open("#{dst}/rbkit", "w") do |fl|
fl.puts(exec_string)
end
system("chmod +x #{dst}/rbkit")
end

private

def verify_and_copy(deps_element)
dep_path = deps_element.split("=>").last.split("(").first.strip
if !dep_path.empty? && dep_path.match(/^#{ENV['HOME']}/)
FileUtils.cp(File.expand_path(dep_path), "#{dst}/libs")
end
end
end

DeployQt.new(ARGV[0]).create_archive
10 changes: 8 additions & 2 deletions tools/deployqtapp.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ executable=$1
distro=`lsb_release -d | awk '{print $2$3$4}' | sed 's/\./_/g'`

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

Expand Down Expand Up @@ -77,6 +77,12 @@ cp -r $qtfontsdir/* $fontsdir

# You will need to change this to point to wherever libqxcb.so lives on your PC.
qtplatformplugin=$QT_HOME/5.4/gcc_64/plugins/platforms/libqxcb.so
for dep in `ldd $qtplatformplugin | awk '{print $3}' | grep -v "("`
do
cp $dep $libsdir
echo "Copied dependency "$dep" to "$libsdir
done

qtplatformplugindir=$tardir/platforms
mkdir $qtplatformplugindir
echo "Created platforms directory: "$qtplatformplugindir
Expand Down Expand Up @@ -161,7 +167,7 @@ cp $qtsqliteplugin $qtsqliteplugindir
echo "Copied "$qtsqliteplugin" to "$qtsqliteplugindir

# Create the run script.
execscript=$tardir/"run$executable.sh"
execscript=$tardir/"rbkit"
echo "Created run script: "$execscript

echo "#!/bin/sh" > $execscript
Expand Down
6 changes: 6 additions & 0 deletions tools/print_dep.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
executable=$1
echo $executable
for dep in `ldd $executable | awk '{print $3}' | grep -v "("`
do
echo "Copied dependency "$dep" to "$libsdir
done

0 comments on commit 11e55ee

Please sign in to comment.