From f168e4f455207a483d6351868616a63c6e29ddb1 Mon Sep 17 00:00:00 2001 From: Sungho Park Date: Mon, 27 Feb 2012 21:23:01 +0900 Subject: [PATCH] Initialize --- AUTHORS | 5 + LICENSE | 202 ++++++++ NOTICE | 1 + bin/controllers/SBS/controller.rb | 341 +++++++++++++ bin/controllers/SBS/sbs_config | 1 + bin/controllers/SBSTools/controller.rb | 268 ++++++++++ bin/controllers/SBSTools/sbs_config | 1 + bin/default_controller.rb | 43 ++ bin/default_generator.rb | 14 + bin/generators/TizenBase/generator.rb | 144 ++++++ bin/generators/TizenPlatform/generator.rb | 136 +++++ bin/generators/TizenPlatform/pkginfo.manifest | 7 + bin/generators/TizenPlatformToolchain/generator.rb | 141 +++++ .../TizenPlatformToolchain/pkginfo.manifest | 8 + bin/generators/TizenPublic/analyzer.rb | 566 +++++++++++++++++++++ bin/generators/TizenPublic/devpackage.rb | 16 + bin/generators/TizenPublic/framework | 51 ++ bin/generators/TizenPublic/generator.rb | 239 +++++++++ bin/generators/TizenPublic/headerfile.rb | 16 + bin/generators/TizenPublic/package.rb | 19 + bin/generators/TizenPublic/pcfile.rb | 107 ++++ bin/generators/TizenPublic/pkginfo.manifest | 7 + bin/generators/TizenPublic/temp.rb | 22 + bin/image.rb | 25 + bin/optparser.rb | 236 +++++++++ bin/package.rb | 39 ++ bin/pkginfo.manifest | 7 + bin/rogen.cfg | 2 + bin/rogen.rb | 49 ++ bin/rootstrap.rb | 51 ++ bin/rootstrapmanager.rb | 158 ++++++ bin/util.rb | 62 +++ package/.log | 4 + package/build.linux | 39 ++ package/pkginfo.manifest | 7 + workspace/.sbs_config_ori | 1 + 36 files changed, 3035 insertions(+) create mode 100644 AUTHORS create mode 100644 LICENSE create mode 100644 NOTICE create mode 100644 bin/controllers/SBS/controller.rb create mode 100644 bin/controllers/SBS/sbs_config create mode 100644 bin/controllers/SBSTools/controller.rb create mode 100644 bin/controllers/SBSTools/sbs_config create mode 100644 bin/default_controller.rb create mode 100644 bin/default_generator.rb create mode 100644 bin/generators/TizenBase/generator.rb create mode 100644 bin/generators/TizenPlatform/generator.rb create mode 100644 bin/generators/TizenPlatform/pkginfo.manifest create mode 100644 bin/generators/TizenPlatformToolchain/generator.rb create mode 100644 bin/generators/TizenPlatformToolchain/pkginfo.manifest create mode 100644 bin/generators/TizenPublic/analyzer.rb create mode 100644 bin/generators/TizenPublic/devpackage.rb create mode 100644 bin/generators/TizenPublic/framework create mode 100644 bin/generators/TizenPublic/generator.rb create mode 100644 bin/generators/TizenPublic/headerfile.rb create mode 100644 bin/generators/TizenPublic/package.rb create mode 100644 bin/generators/TizenPublic/pcfile.rb create mode 100644 bin/generators/TizenPublic/pkginfo.manifest create mode 100644 bin/generators/TizenPublic/temp.rb create mode 100644 bin/image.rb create mode 100644 bin/optparser.rb create mode 100644 bin/package.rb create mode 100644 bin/pkginfo.manifest create mode 100644 bin/rogen.cfg create mode 100755 bin/rogen.rb create mode 100644 bin/rootstrap.rb create mode 100644 bin/rootstrapmanager.rb create mode 100644 bin/util.rb create mode 100644 package/.log create mode 100755 package/build.linux create mode 100644 package/pkginfo.manifest create mode 100644 workspace/.sbs_config_ori diff --git a/AUTHORS b/AUTHORS new file mode 100644 index 0000000..9589ae0 --- /dev/null +++ b/AUTHORS @@ -0,0 +1,5 @@ +DongHee Yang +Taejun Ha +Jiil Hyoun +Donghyuk Yang +HyunGoo Kang diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..d645695 --- /dev/null +++ b/LICENSE @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/NOTICE b/NOTICE new file mode 100644 index 0000000..4297ee3 --- /dev/null +++ b/NOTICE @@ -0,0 +1 @@ +Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. diff --git a/bin/controllers/SBS/controller.rb b/bin/controllers/SBS/controller.rb new file mode 100644 index 0000000..278e192 --- /dev/null +++ b/bin/controllers/SBS/controller.rb @@ -0,0 +1,341 @@ +require 'fileutils' + +class RootstrapController + @@installed = false + @@apt_get_initiated = false + + @rootstrap = nil + + # install SBS itself + def initialize + # if SBS is not install, install it first + if not @@installed then + $log.info "Start to install SBS..." + install_SBS + @@installed = true + else + $log.info "Skip to install SBS..." + end + + # update environment variables + $log.info "export PATH=#{$HOME}/sbs-install/bin:$PATH" + system "export PATH=#{$HOME}/sbs-install/bin:$PATH" + end + + + # install SBS + def install_SBS + # clean up + FileUtils.rm_rf "#{$HOME}/sbs-install" + FileUtils.rm_rf "#{$HOME}/sbs" + + # get git repository path + git_path = get_value_from_file(File.dirname(__FILE__) + "/sbs_config", "GIT_REPOSITORY") + if git_path.empty? then + raise "Invalid GIT repository path or \".sbs_config\" not found" + end + + # make temp directory + FileUtils.rm_rf $WORKING_DIR + "/.temp" + FileUtils.mkdir $WORKING_DIR + "/.temp" + + # git clone + FileUtils.cd $WORKING_DIR + "/.temp" + $log.info "git clone #{git_path}" + system "git clone #{git_path}" + + # install SBS + #system "git reset --hard origin" + FileUtils.cd "sbs" + system "./install-sbs" + + FileUtils.cd $WORKING_DIR + end + + + # create new rootstrap + def create_new_rootstrap( rootstrap ) + @rootstrap = rootstrap + + # create SBS default target + arch = @rootstrap.arch + if arch == "arm" then + $log.info "#{$HOME}/sbs-install/bin/sbs -c" + system "#{$HOME}/sbs-install/bin/sbs -c" + else + $log.info "#{$HOME}/sbs-install/bin/sbs -c -A #{arch}" + system "#{$HOME}/sbs-install/bin/sbs -c -A #{arch}" + end + + # check if base target image exists + if arch == "arm" then + arch = "armel" + end + if not File.exist?("#{$HOME}/sbs/target-#{arch}.tgz") then + raise IOError, "raw sysroot file does not exist" + end + + # extract base image into rootstrap path + path = @rootstrap.path + FileUtils.rm_rf path + FileUtils.mkdir path + system "fakeroot tar -xpf #{$HOME}/sbs/target-#{arch}.tgz -C #{path}" + + # create new SBOX2 target + create_new_sbox2_target + end + + + # install packages + def install_packages + # install new packages + pkg_list = @rootstrap.base_pkg_list + pkg_list.each do |pkg| + case pkg.protocol + when "deb" then install_using_apt_get pkg + when "scp" then install_using_dpkg pkg + when "cp" then install_using_dpkg pkg + else $log.warn "pkg protocol is unknown #{pkg.protocol}" + end + end + #remove cache + system "rm -rf #{@rootstrap.path}/var/cache/apt/archives/*.deb" + # TODO: return installed package list + end + + def reload ( rootstrap ) + @rootstrap = rootstrap + create_new_sbox2_target + end + + # get all package list installed + def get_all_installed_packages + result = [] + command_and_return("dpkg -l").each_line do |line| + if line.start_with? "ii" then + result.push line.strip.split[1] + end + end + + return result + end + + + # get all file list in package + def get_all_package_files(pkg_name) + result = [] + command_and_return("dpkg -L #{pkg_name}").each_line do |line| + file_path = line.strip! + result.push file_path + end + + return result + end + + + # get all dependent packages + def get_all_dependent_packages(pkg_name) + result = [] + command_and_return("apt-cache show #{pkg_name}").each_line do |line| + if line.start_with? "Depends:" then + #remove "Depends: (xxx) , " + line.gsub(/\([^)]*\)/,"").tr(',','').split(':')[1].split.each do |package| + result.push package + end + end + end + + return result + end + + + # get include search paths of package + def get_include_search_paths_using_pkgconfig(pc_list) + result = [] + + # default search path + result = ["/usr/include"] + + # get package Include list using pkg-config + pc_list.each do |x| + result = result | + ((command_and_return "pkg-config --cflags-only-I #{x}").split.map {|i| i.sub("-I","")}) + end + + # remove dup + result.uniq! + + return result + end + + + # make ld.so.2.13 prelinked + def make_ldso_prelinked + command "prelink /lib/ld-2.13.so" + $log.info "/lib/ld-2.13.so is prelinked" + end + + + # write self information to file that will save + def write_info ( file_path ) + if not File.exist? "#{$HOME}/sbs-install/versions" then + $log.error "sbs is not installed " + exit 1 + end + + line = [] + File.open( "#{$HOME}/sbs-install/versions", "r") do |r| + r.each_line do |info| + line.push info.strip + end + end + + File.open( file_path, "w") do |w| + line.each do |info| + w.puts info + end + end + end + + + # compare saved information file with self + def same_as? ( file_path ) + if not File.exist? "#{$HOME}/sbs-install/versions" then + $log.error "sbs is not installed " + exit 1 + end + + o = [] + File.open( "#{$HOME}/sbs-install/versions", "r") do |origin| + origin.each_line do |l| + o.push l.strip + end + end + + s = [] + File.open( file_path, "r") do |saved| + saved.each_line do |l| + s.push l.strip + end + end + + return o.sort == s.sort + end + + + # PRIVATE METHODS/VARIABLES + private + + # create new SBOX2 target + def create_new_sbox2_target + # remove old target if exists + name = @rootstrap.name + sbox2_target_config_path = "#{$HOME}/.scratchbox2/#{name}" + if File.exist?(sbox2_target_config_path) then + FileUtils.rm_rf sbox2_target_config_path + end + # get CPU transparency command of architecure + arch = @rootstrap.arch + if arch == "armel" then + arch = "arm" + end + transp = "" + case arch + when "arm","armel" then + if not File.exist? "#{$HOME}/sbs-install/bin/qemu-arm" then + #$log.error "qemu-arm is not exist in ~/sbs-install/bin/" + #raise RuntimeError, "qemu-arm is not exist in ~/sbs-install/bin/" + end + transp = "-c #{$HOME}/sbs-install/bin/qemu-arm" + when "i386" then + else + #$log.error "rootstrap.rb:load_sysroot: ERROR #{@arch} is invalid architecture" + #raise RuntimeError, "rootstrap.rb:load_sysroot: ERROR #{@arch} is invalid architecture" + end + + # create/initialze SBOX2 target + path = @rootstrap.path + FileUtils.cd path + $log.info "sb2-init -N -n -m slp2 #{transp} -t /bin -A #{arch} #{name} /bin/false" + system "sb2-init -N -n -m slp2 #{transp} -t /bin -A #{arch} #{name} /bin/false" + FileUtils.cd "#{$WORKING_DIR}" + + # setup package server + #set pin priority + + #link .ssh folder + if File.exist? "#{$HOME}/.ssh" then + FileUtils.mkdir_p "#{name}/root" + FileUtils.rm_rf "#{name}/root/.ssh" + FileUtils.ln_sf "#{$HOME}/.ssh", "#{name}/root" + end + + #update repository data + command "apt-get update" + command "apt-get upgrade --force-yes -y" + end + + + # apt-get install ... + def install_using_apt_get pkg + # prepare for installation if first entered + if not @@apt_get_initiated then + initiated_deb_installation(pkg.protocol, pkg.url) + @@apt_get_initiated = true + end + + # execute apt-get command + name = pkg.name + $log.info "apt-get install #{pkg.name}" + command "apt-get install --force-yes -y #{pkg.name}" + end + + + # dpkg -i ... + def install_using_dpkg pkg + # execute apt-get command + file = download_file_from_url pkg.protocol, pkg.url + if not file.empty? then + $log.info "dpkg -i #{file}" + command "dpkg -i #{file}" + end + end + + + + # step for preparation + def initiated_deb_installation (protocol, url) + + #set pin priority + name = @rootstrap.name + repo = url.split('/')[2] + File.open("#{name}/etc/apt/preferences.d/slp","w") do |f| + f.puts "Package: *\nPin: origin #{repo}\nPin-Priority: 1500\n" + end + + # create source list + File.open("#{name}/etc/apt/sources.list","w") do |f| + f.puts "#{protocol} #{url}" + end + + # update/upgrade system + command "apt-get update" + command "apt-get upgrade --force-yes -y" + end + + + # command to SBOX2 target + def command(cmd) + name = @rootstrap.name + $log.info "sb2 -R -t #{name} -m emulate -- #{cmd}" + system "export LC_ALL=\"C\"; sb2 -R -t #{name} -m emulate -- #{cmd}" + end + + + # return result of command + def command_and_return(cmd) + name = @rootstrap.name + return `export LC_ALL=\"C\"; sb2 -R -t #{name} -m emulate -- #{cmd}` + end +end + diff --git a/bin/controllers/SBS/sbs_config b/bin/controllers/SBS/sbs_config new file mode 100644 index 0000000..085a1c8 --- /dev/null +++ b/bin/controllers/SBS/sbs_config @@ -0,0 +1 @@ +GIT_REPOSITORY = git@165.213.180.234:slp/tools/sbs diff --git a/bin/controllers/SBSTools/controller.rb b/bin/controllers/SBSTools/controller.rb new file mode 100644 index 0000000..12634f6 --- /dev/null +++ b/bin/controllers/SBSTools/controller.rb @@ -0,0 +1,268 @@ +require 'fileutils' + +class RootstrapController + @@installed = false + @@apt_get_initiated = false + + @rootstrap = nil + + # install SBS itself + def initialize + # if SBS is not install, install it first + if not @@installed then + $log.info "Start to install SBS..." + install_SBS + @@installed = true + else + $log.info "Skip to install SBS..." + end + + # update environment variables + $log.info "export PATH=#{$HOME}/sbs-install/bin:$PATH" + system "export PATH=#{$HOME}/sbs-install/bin:$PATH" + end + + + # install SBS + def install_SBS + # clean up + FileUtils.rm_rf "#{$HOME}/sbs-install" + FileUtils.rm_rf "#{$HOME}/sbs" + + # get git repository path + git_path = get_value_from_file(File.dirname(__FILE__) + "/sbs_config", "GIT_REPOSITORY") + if git_path.empty? then + raise "Invalid GIT repository path or \".sbs_config\" not found" + end + + # make temp directory + FileUtils.rm_rf $WORKING_DIR + "/.temp" + FileUtils.mkdir $WORKING_DIR + "/.temp" + + # git clone + FileUtils.cd $WORKING_DIR + "/.temp" + $log.info "git clone #{git_path}" + system "git clone #{git_path}" + + # install SBS + #system "git reset --hard origin" + FileUtils.cd "sbs" + system "./install-sbs" + + FileUtils.cd $WORKING_DIR + end + + + # create new rootstrap + def create_new_rootstrap( rootstrap ) + @rootstrap = rootstrap + + # create SBS default target + $log.info "#{$HOME}/sbs-install/bin/sbs -c" + system "#{$HOME}/sbs-install/bin/sbs -c" + + # check if base target image exists + if not File.exist?("#{$HOME}/sbs/tools") then + raise IOError, "raw tools directory does not exist" + end + + # extract base image into rootstrap path + path = @rootstrap.path + $log.info "Copying #{$HOME}/sbs/tools to #{path}" + FileUtils.rm_rf path + system "cp -rf #{$HOME}/sbs/tools #{path}" + + # create new SBOX2 target + create_new_sbox2_target + end + + + # install packages + def install_packages + # install new packages + pkg_list = @rootstrap.base_pkg_list + pkg_list.each do |pkg| + case pkg.protocol + when "deb" then install_using_apt_get pkg + when "scp" then install_using_dpkg pkg + when "cp" then install_using_dpkg pkg + else $log.warn "pkg protocol is unknown #{pkg.protocol}" + end + end + #remove cache + system "rm -rf #{@rootstrap.path}/var/cache/apt/archives/*.deb" + # TODO: return installed package list + end + + def reload ( rootstrap ) + @rootstrap = rootstrap + create_new_sbox2_target + end + + # get all package list installed + def get_all_installed_packages + result = [] + command_and_return("dpkg -l").each_line do |line| + if line.start_with? "ii" then + result.push line.strip.split[1] + end + end + + return result + end + + + # get all file list in package + def get_all_package_files(pkg_name) + result = [] + command_and_return("dpkg -L #{pkg_name}").each_line do |line| + file_path = line.strip! + result.push file_path + end + + return result + end + + + # get all dependent packages + def get_all_dependent_packages(pkg_name) + result = [] + command_and_return("apt-cache show #{pkg_name}").each_line do |line| + if line.start_with? "Depends:" then + #remove "Depends: (xxx) , " + line.gsub(/\([^)]*\)/,"").tr(',','').split(':')[1].split.each do |package| + result.push package + end + end + end + + return result + end + + + # write self information to file that will save + def write_info ( file_path ) + if not File.exist? "#{$HOME}/sbs-install/versions" then + $log.error "sbs is not installed " + exit 1 + end + + line = [] + File.open( "#{$HOME}/sbs-install/versions", "r") do |r| + r.each_line do |info| + line.push info.strip + end + end + + File.open( file_path, "w") do |w| + line.each do |info| + w.puts info + end + end + end + + + # compare saved information file with self + def same_as? ( file_path ) + if not File.exist? "#{$HOME}/sbs-install/versions" then + $log.error "sbs is not installed " + exit 1 + end + + o = [] + File.open( "#{$HOME}/sbs-install/versions", "r") do |origin| + origin.each_line do |l| + o.push l.strip + end + end + + s = [] + File.open( file_path, "r") do |saved| + saved.each_line do |l| + s.push l.strip + end + end + + return o.sort == s.sort + end + + + # PRIVATE METHODS/VARIABLES + private + + # create new SBOX2 target + def create_new_sbox2_target + # remove old target if exists + name = @rootstrap.name + sbox2_target_config_path = "#{$HOME}/.scratchbox2/#{name}" + if File.exist?(sbox2_target_config_path) then + FileUtils.rm_rf sbox2_target_config_path + end + # get CPU transparency command of architecure + transp = "" + arch = @rootstrap.arch + + # create/initialze SBOX2 target + path = @rootstrap.path + FileUtils.cd path + $log.info "sb2-init -N -n -m slp2 #{transp} -t /bin -A #{arch} #{name} /bin/false" + system "sb2-init -N -n -m slp2 #{transp} -t /bin -A #{arch} #{name} /bin/false" + FileUtils.cd "#{$WORKING_DIR}" + + #link .ssh folder + if File.exist? "#{$HOME}/.ssh" then + FileUtils.mkdir_p "#{name}/root" + FileUtils.rm_rf "#{name}/root/.ssh" + FileUtils.ln_sf "#{$HOME}/.ssh", "#{name}/root" + end + end + + + # apt-get install ... + def install_using_apt_get pkg + # prepare for installation if first entered + if not @@apt_get_initiated then + initiated_deb_installation(pkg.protocol, pkg.url) + @@apt_get_initiated = true + end + + # execute apt-get command + name = pkg.name + $log.info "apt-get install #{pkg.name}" + command "apt-get install --force-yes -y #{pkg.name}" + end + + + # dpkg -i ... + def install_using_dpkg pkg + # execute apt-get command + file = download_file_from_url pkg.protocol, pkg.url + if not file.empty? then + $log.info "dpkg -i #{file}" + command "dpkg -i #{file}" + end + end + + + + # step for preparation + def initiated_deb_installation (protocol, url) + + end + + + # command to SBOX2 target + def command(cmd) + name = @rootstrap.name + $log.info "sb2 -R -t #{name} -m emulate -- #{cmd}" + system "export LC_ALL=\"C\"; sb2 -R -t #{name} -m emulate -- #{cmd}" + end + + + # return result of command + def command_and_return(cmd) + name = @rootstrap.name + return `export LC_ALL=\"C\"; sb2 -R -t #{name} -m emulate -- #{cmd}` + end +end + diff --git a/bin/controllers/SBSTools/sbs_config b/bin/controllers/SBSTools/sbs_config new file mode 100644 index 0000000..085a1c8 --- /dev/null +++ b/bin/controllers/SBSTools/sbs_config @@ -0,0 +1 @@ +GIT_REPOSITORY = git@165.213.180.234:slp/tools/sbs diff --git a/bin/default_controller.rb b/bin/default_controller.rb new file mode 100644 index 0000000..5f11492 --- /dev/null +++ b/bin/default_controller.rb @@ -0,0 +1,43 @@ +class RootstrapController + @rootstrap = nil + + # create new rootstrap + def create_new_rootstrap ( rootstrap ) + @rootstrap = rootstrap + end + + # install packages + def install_packages + raise "You must overide this method!" + end + + # get all package list installed + def get_all_installed_packages + raise "You must overide this method!" + end + + # get all file list in package + def get_all_package_files(pkg_name) + raise "You must overide this method!" + end + + # get all dependent packages + def get_all_dependent_packages(pkg_name) + raise "You must overide this method!" + end + + # recreate using saved rootstrap + def reload ( rootstrap ) + raise "You must overide this method!" + end + + # write self information to file that will save + def write_info ( file_path ) + raise "You must overide this method!" + end + + # compare saved information file with self + def same_as? ( file_path ) + raise "You must overide this method!" + end +end diff --git a/bin/default_generator.rb b/bin/default_generator.rb new file mode 100644 index 0000000..3a4542a --- /dev/null +++ b/bin/default_generator.rb @@ -0,0 +1,14 @@ +class ImageGenerator + @rootstrap = nil + + # + def post_process( rootstrap ) + @rootstrap = rootstrap + end + + # + def zip (rootstrap) + @rootstrap = rootstrap + raise "You must ovride this method!" + end +end diff --git a/bin/generators/TizenBase/generator.rb b/bin/generators/TizenBase/generator.rb new file mode 100644 index 0000000..6ea4139 --- /dev/null +++ b/bin/generators/TizenBase/generator.rb @@ -0,0 +1,144 @@ +class ImageGenerator + @analyzer = nil + @image = nil + @rootstrap = nil + + # process rootstrap + def post_process(image) + @image = image + @rootstrap = @image.rootstrap + + # remove unnecessary files + remove_files + + # fix symbolic links + fix_symbolic_links + + # change sources.list + change_sources_list + end + + + # make package + def zip + # install files + install_files + + # generate package for linux + if @image.os == "linux" or @image.os == "all" then + build_package "linux" + end + + # generate package for windows + if @image.os == "windows" or @image.os == "all" then + build_package "windows" + end + end + + + + # + # PRIVATE + # + private + + # fix symbolic links + def fix_symbolic_links + + #delete toolchain link + FileUtils.cd @rootstrap.name + + #show link type + links = `find -type l` + links.each_line do |f| + l = `file #{f}`.split(':') + link = l[0] + if not l[1].include? "`" then next end + src = l[1].split('`')[1].strip[0..-2] + + #fix link only absolute path link + if src.start_with? "/" then + FileUtils.rm_rf link + depth = "/.." * (link.count("/") -1) + FileUtils.ln_s ".#{depth}#{src}", link + end + end + FileUtils.cd ".." + end + + + # remove unnecessary files + def remove_files + #remove aclocal m4 files + #ls -F show when link file with @ character at last + aclocal = `ls -F #{@rootstrap.name}/usr/share/aclocal/*` + aclocal.each_line do |ac| + if ac.include? "@" then + FileUtils.rm_rf ac.strip[0..-2] + end + end + + #remove static libray files when dynamic library is exist + d = Dir.entries("#{@rootstrap.name}/usr/lib") + s = d.select {|a| a.include? ".a" or a.include? ".la" } + s.each do |a| + if File.exist? "#{@rootstrap.name}/usr/lib/#{a.sub(/\.l*a/,".so")}" then + FileUtils.rm_rf "#{@rootstrap.name}/usr/lib/#{a}" + end + end + end + + + def change_sources_list + if File.exist? "#{@rootstrap.name}/etc/apt/sources.list" then + case @rootstrap.arch + when "armel" then + File.open "#{@rootstrap.name}/etc/apt/sources.list","w" do |x| + x.puts "" + end + when "arm" then + File.open "#{@rootstrap.name}/etc/apt/sources.list","w" do |x| + x.puts "" + end + when "i386" then + File.open "#{@rootstrap.name}/etc/apt/sources.list","w" do |x| + x.puts "deb http://source.tizen.org/home/tizen/apt.sbs/i386 slp2-target main contrib non-free" + end + else $log.error "rootstrap architecture is :[#{@rootstrap.arch}]" + end + end + end + + + # install files + def install_files + # clean + FileUtils.rm_rf "package" + + # install rootstraps + FileUtils.mkdir_p "package/data/SDK/build-system/rootstraps" + FileUtils.mv "#{@rootstrap.name}", "package/data/SDK/build-system/rootstraps" + + end + + + # build package + def build_package(platform) + FileUtils.cd "package" + + #Get package Version + package_version = "#{@image.ver}" + + # In case of windows, symbolic link must be duplicated + if platform == "windows" then + system "tar chf data.tar *" + system "rm -rf data" + system "tar xf data.tar" + system "rm -rf data.tar" + end + + system "zip -r -y -q ../rootstrap-#{@rootstrap.name}_#{package_version}_#{platform}.zip *" + $log.info "Result file is rootstrap-#{@rootstrap.name}_#{package_version}_#{platform}.zip" + FileUtils.cd ".." + end +end diff --git a/bin/generators/TizenPlatform/generator.rb b/bin/generators/TizenPlatform/generator.rb new file mode 100644 index 0000000..7e94462 --- /dev/null +++ b/bin/generators/TizenPlatform/generator.rb @@ -0,0 +1,136 @@ +class ImageGenerator + @image = nil + @rootstrap = nil + + # process rootstrap + def post_process(image) + @image = image + @rootstrap = @image.rootstrap + + # Add more preprocessing code here + + # change sources.list + change_sources_list + + end + + + # make package + def zip + # install files + install_files + + # add remove scripts + add_remove_script + + # generate pkginfo.manifest + generate_package_info + + # zipping + build_package + end + + + # PRIVATE + private + + def change_sources_list + if File.exist? "#{@rootstrap.name}/etc/apt/sources.list" then + case @rootstrap.arch + when "armel" then + File.open "#{@rootstrap.name}/etc/apt/sources.list","w" do |x| + x.puts "" + end + when "arm" then + File.open "#{@rootstrap.name}/etc/apt/sources.list","w" do |x| + x.puts "" + end + when "i386" then + File.open "#{@rootstrap.name}/etc/apt/sources.list","w" do |x| + x.puts "deb http://source.tizen.org/home/tizen/apt.sbs/i386 slp2-target main contrib non-free" + end + else $log.error "rootstrap architecture is :[#{@rootstrap.arch}]" + end + end + end + + + # install files + def install_files + # clean + FileUtils.rm_rf "package" + + # install rootstraps + FileUtils.mkdir_p "package/data/SDK/build-system/rootstraps" + FileUtils.mv "#{@rootstrap.name}", "package/data/SDK/build-system/rootstraps" + + # install sbi rootstrap plugin + FileUtils.mkdir_p "package/data/SDK/build-system/plugins" + FileUtils.cp "#{@rootstrap.name}.xml", "package/data/SDK/build-system/plugins/#{@rootstrap.name}.xml" + end + + + # generate package info + def generate_package_info + + # Error CHECK + if not File.exist?(File.dirname(__FILE__) + "/pkginfo.manifest") + raise RuntimeError,"File does not exist [#{File.dirname(__FILE__)}/pkginfo.manifest]" + end + + # modify pkginfo.manifest + p = [] + File.open( File.dirname(__FILE__) + "/pkginfo.manifest","r") do |f| + f.each_line do |line| + line.gsub!("@name@",@rootstrap.name) + line.gsub!("@version@",@image.ver) + line.gsub!("@arch@",@rootstrap.arch) + line.gsub!("@platform@",@image.os) + line.gsub!("@remove_script@","remove.sh") if @image.os == "linux" + line.gsub!("@remove_script@","remove.bat") if @image.os == "windows" + p.push line + end + end + + # write pkginfo.manaifest + File.open("package/pkginfo.manifest","w") do |f| + p.each do |line| + f.puts line + end + end + end + + + # add remove scripts + def add_remove_script + platform = @image.os + # add removescript + if platform == "linux" then + File.open("package/remove.sh","w") do |f| + f.puts "#!/bin/sh -e" + f.puts "" + f.puts "rm -rf ${INSTALLED_PATH}/SDK/build-system/rootstraps/#{@rootstrap.name}" + end + elsif platform == "windows" then + File.open("package/remove.bat","w") do |f| + f.puts ":: delims is a TAB followed by a space" + f.puts "SET installed_path=%INSTALLED_PATH%" + f.puts "" + f.puts "RMDIR /S /Q %installed_path%\\SDK\\build-system\\rootstraps\\#{@rootstrap.name}" + end + end + end + + + # build package + def build_package + FileUtils.cd "package" + + #Get package Version + package_version = "#{@image.ver}" + + system "zip -r -y -q ../rootstrap-#{@rootstrap.name}_#{package_version}_#{@image.os}.zip *" + $log.info "Result file is rootstrap-#{@rootstrap.name}_#{package_version}_#{@image.os}.zip" + FileUtils.cd ".." + end +end diff --git a/bin/generators/TizenPlatform/pkginfo.manifest b/bin/generators/TizenPlatform/pkginfo.manifest new file mode 100644 index 0000000..9017ab0 --- /dev/null +++ b/bin/generators/TizenPlatform/pkginfo.manifest @@ -0,0 +1,7 @@ +Package : rootstrap-@name@ +Version : @version@ +Maintainer : hyoun jiil +Description : @arch@ rootstrap for SLP SDK +Depends : +Category : SDK/build-system/rootstraps +Remove-script: @remove_script@ diff --git a/bin/generators/TizenPlatformToolchain/generator.rb b/bin/generators/TizenPlatformToolchain/generator.rb new file mode 100644 index 0000000..0a0a4de --- /dev/null +++ b/bin/generators/TizenPlatformToolchain/generator.rb @@ -0,0 +1,141 @@ +class ImageGenerator + @image = nil + @rootstrap = nil + + # process rootstrap + def post_process(image) + @image = image + @rootstrap = @image.rootstrap + + # Add more preprocessing code here + #remove autoconf.m4f + system "rm -rf #{@rootstrap.name}/usr/share/autoconf/autoconf/autoconf.m4f" + end + + + # make package + def zip + # install files + install_files + + # generate pkginfo.manifest + generate_package_info "linux" + + # generate remove script + add_remove_script "linux" + + # zipping + build_package + end + + + # PRIVATE + private + + # install files + def install_files + # clean + FileUtils.rm_rf "package2" + + # install toolchain + FileUtils.mkdir_p "package2/data/SDK/build-system/toolchains" + FileUtils.mv "#{@rootstrap.name}", "package2/data/SDK/build-system/toolchains/" + + # install scratchbox2 + print "Installing ScratchBox2..." + FileUtils.mkdir_p "package2/data/SDK/build-system/toolchains/scratchbox2" + FileUtils.rm_rf "scratchbox2" + system "git clone git@165.213.180.234:/slp/tools/scratchbox2" + FileUtils.cd "scratchbox2" + system "make clean" + system "./autogen.sh && .configure && make" + system "make install prefix=#{$WORKING_DIR}/package2/data/SDK/build-system/toolchains/scratchbox2" + FileUtils.cd ".." + print "OK\n" + + # install QEMU + print "Installing QEMU..." + FileUtils.rm_rf "qemu" + system "git clone git@165.213.180.234:slp/tools/qemu" + FileUtils.cd "qemu" + system "git checkout debian-sbs" + system "git pull" + system "make clean" + system "./configure --target-list=arm-linux-user,i386-linux-user --disable-blobs --disable-uuid && make" + system "make install prefix=#{$WORKING_DIR}/package2/data/SDK/build-system/toolchains/scratchbox2" + FileUtils.cd ".." + print "OK\n" + + # install sbi rootstrap plugin + print "Copying SBI toolchain plugins..." + FileUtils.mkdir_p "package2/data/SDK/build-system/plugins" + FileUtils.cp "gcc45sbox2.armel.cdeb.xml", "package2/data/SDK/build-system/plugins/gcc45sbox2.armel.cdeb.xml" + FileUtils.cp "gcc45sbox2.i386.cdeb.xml", "package2/data/SDK/build-system/plugins/gcc45sbox2.i386.cdeb.xml" + print "OK\n" + + # installing i386-gdb + #print "Copying i386-linux-gnueabi-gdb..." + #FileUtils.cp "#{$WORKING_DIR}/i386-linux-gnueabi-gdb", "package/data/SDK/build-system/toolchains/#{@rootstrap.name}/usr/bin/gdb" + #print "OK\n" + + end + + + # generate package info + def generate_package_info(platform) + + print "Generating pkginfo.manifest..." + # Error CHECK + if not File.exist?(File.dirname(__FILE__) + "/pkginfo.manifest") + raise RuntimeError,"File does not exist [#{File.dirname(__FILE__)}/pkginfo.manifest]" + end + + # modify pkginfo.manifest + p = [] + File.open( File.dirname(__FILE__) + "/pkginfo.manifest","r") do |f| + f.each_line do |line| + line.gsub!("@name@",@rootstrap.name) + line.gsub!("@version@",@image.ver) + line.gsub!("@remove_script@","remove.sh") if platform == "linux" + line.gsub!("@remove_script@","remove.bat") if platform == "windows" + p.push line + end + end + + # write pkginfo.manaifest + File.open("package2/pkginfo.manifest","w") do |f| + p.each do |line| + f.puts line + end + end + print "OK\n" + end + + + # add remove scripts + def add_remove_script(platform) + # add removescript + print "Generating remove.sh..." + File.open("package2/remove.sh","w") do |f| + f.puts "#!/bin/sh -e" + f.puts "" + f.puts "rm -rf ${INSTALLED_PATH}/SDK/build-system/toolchains/#{@rootstrap.name}" + f.puts "rm -rf ${INSTALLED_PATH}/SDK/build-system/toolchains/scratchbox2" + end + print "OK\n" + end + + + # build package + def build_package + $log.info "Zipping ..." + FileUtils.cd "package2" + + #Get package Version + package_version = "#{@image.ver}" + + system "zip -r -y -q ../toolchain-#{@rootstrap.name}_#{package_version}_#{@image.os}.zip *" + $log.info "Result file is toolchain-#{@rootstrap.name}_#{package_version}_#{@image.os}.zip" + FileUtils.cd ".." + end +end diff --git a/bin/generators/TizenPlatformToolchain/pkginfo.manifest b/bin/generators/TizenPlatformToolchain/pkginfo.manifest new file mode 100644 index 0000000..6be9b0d --- /dev/null +++ b/bin/generators/TizenPlatformToolchain/pkginfo.manifest @@ -0,0 +1,8 @@ +Package : toolchain-@name@ +Version : @version@ +Maintainer : hyoun jiil +Description : Scratchbox2 tool for Tizen SDK +Depends : +Category : SDK/build-system/toolchains-scratchbox2 +Default : true +Remove-script : remove.sh diff --git a/bin/generators/TizenPublic/analyzer.rb b/bin/generators/TizenPublic/analyzer.rb new file mode 100644 index 0000000..07a2521 --- /dev/null +++ b/bin/generators/TizenPublic/analyzer.rb @@ -0,0 +1,566 @@ +require File.dirname(__FILE__) + "/pcfile" +require File.dirname(__FILE__) + "/package" +require File.dirname(__FILE__) + "/headerfile" +require File.dirname(__FILE__) + "/devpackage" + + +class TizenPublicFrameworkAnalyzer + @rootstrap = nil + # pkg_name -> package + @package_list = {} + @header_list = {} + @pc_list = {} + @devpackage_list = [] + @public_package_list = [] + + # category_name -> package list + @framework = {} + + # packagke_name -> package name + @substitutes = {} + + def initialize( rootstrap ) + @rootstrap = rootstrap + end + + + # analyze + def analyze + # scan all packages => @package_list + scan_all_packages + + # initialize framework structure => @framework, @substitutes + generate_framework_structure + + # generate header to header dependency => @header2header, @pkg2header, @pkg2pkg + generate_header2header_dependency + + # generate dev packages + generate_dev_packages + end + + + def write_dev_package_xml + File.open("#{@rootstrap.name}/DevPackages.xml","w") do |f| + f.puts "" + @devpackage_list.each do |devPackage| + devpackage_attr = " " + f.puts devpackage_attr + + if devPackage.is_virtual then + if devPackage.include_devpackage_list.empty? then + $log.error "ERROR! devPackage[#{devPackage.name}] is virtual but there has not include_devpackage_list" + f.puts " " + next + end + + devPackage.include_devpackage_list.each do |include_devpackage| + f.puts " #{include_devpackage}" + end + else + if not devPackage.include_path_list.empty? then + devPackage.include_path_list.each do |inc_path| + f.puts " #{inc_path}" + end + end + + if not devPackage.other_cflag_list.empty? then + devPackage.other_cflag_list.each do |c_flag| + f.puts " #{c_flag}" + end + end + + if not devPackage.other_lflag_list.empty? then + devPackage.other_lflag_list.each do |l_flag| + f.puts " #{l_flag}" + end + end + + if not devPackage.library_list.empty? then + devPackage.library_list.each do |library| + f.puts " #{library}" + end + end + + if not devPackage.library_path_list.empty? then + devPackage.library_path_list.each do |library_path| + f.puts " #{library_path}" + end + end + + if not devPackage.dependency_list.empty? then + devPackage.dependency_list.each do |dependency| + f.puts " #{dependency}" + end + end + + if not devPackage.description.empty? then + f.puts " #{devPackage.description}" + end + end + f.puts " " + end + + f.puts "" + end + end + + + # get un-used header file path + # these will be removed + def get_unused_header_list + + # get all header list + result = @header_list.values.map {|h| h.path} + + # get valid header list + used = [] + @package_list.values.each do |pkg| + if @public_package_list.include? pkg then + used = used | pkg.header_list.map { |h| h.path } + used = used | pkg.priv_header_list.map { |h| h.path } + end + end + + # remove dup + used.uniq! + + # remove used list for total + result = result - used + + return result + end + + + + + private + + + # scan packages and create package map + def scan_all_packages + $log.info "Scanning all installed Packages..." + + @package_list = {} + @header_list = {} + @pc_list = {} + + # for all packages + @rootstrap.get_all_installed_packages.each do |pkg_name| + $log.info "Scanning... #{pkg_name}" + pkg = DebPackage.new(pkg_name) + + # for all files in the package + @rootstrap.get_all_package_files(pkg_name).each do |rpath| + if rpath.end_with?(".pc") then + + #add pc_file + pc = PcFile.new(rpath) + pc.parent = pkg + pkg.pc_list.push pc + + # extract pc info + abs_path = "#{@rootstrap.path}#{rpath}" + abs_path.gsub!("//","/") + pc.load_from_file(abs_path) + + # add to global header list + @pc_list[pc.name] = pc + + elsif rpath.end_with?(".h") or + rpath.end_with?(".x") or + rpath.end_with?(".def") then + + # add pkg2headers + h = HeaderFile.new(rpath) + h.parent = pkg + pkg.header_list.push h + + # extract include statement from header file + abs_path = "#{@rootstrap.path}#{rpath}" + abs_path.gsub!("//","/") + h.include_list = extract_include_stmt(abs_path) + + # add to global header list + @header_list[rpath] = h + else + next + end + end + + # add package to map , if valid + if not pkg.pc_list.empty? or not pkg.header_list.empty? then + @package_list[pkg.name] = pkg + end + end + end + + + # extract #include + # TODO: should be refactored + def extract_include_stmt(src) + return `sed -n "H; /\\*\\// {g; s/\\/\\*.*\\*\\///g;p;n;h;}; $ {g;p;}" #{src} | grep "^[[:space:]]*#[[:space:]]*include[[:space:]]*[<\\"]" | cut -d"e" -f2- | sed -e "s/[ \\t]*//g" -e "s/\\/\\/.*$//g" -e "s/^[<\\"]//g" -e "s/[>\\"].*//g"`.split + end + + + # generate framework structure + def generate_framework_structure + # load "framework" skelecton file + load_framework_skelecton + + # append "CAPI" frameworks + append_capi_frameworks + end + + + + # load framework skelcton file + def load_framework_skelecton + @framework = {} + @substitutes = {} + File.open(File.dirname(__FILE__) + "/framework","r") do |f| + category = "" + f.each_line do |l| + if l.start_with? "/" then + category = l.strip + @framework[category] = [] + + # if "*", then add to replace list + elsif l.start_with? "*" then + org = l.strip.sub("*","").split[0] + replace = l.strip.sub("*","").split[1] + + if @substitutes[org].nil? then + @substitutes[org]=[replace] + else + @substitutes[org].push replace + end + else + pkg_name = l.strip + pkg = @package_list[pkg_name] + + if not pkg.nil? then + @framework[category].push pkg + end + end + end + end + end + + + # append capi frameworks + def append_capi_frameworks + #make capi package contents list + (@package_list.keys.select {|x| x =~ /capi-.*-dev/}).each do |package| + # capi-appfw-xxx-yyy + case package.split('-')[1] + when "appfw" then category = "/Application" + when "media" then category = "/Multimedia" + when "ui" then category = "/UI" + when "uix" then category = "/UIX" + else category = "/" + package.split('-')[1].capitalize + end + + # append the packages to frameworks + pkg = @package_list[package] + if not pkg.nil? then + if @framework.has_key? category then + @framework[category].push pkg + else + @framework[category] = [pkg] + end + end + end + end + + + # generate header to header dependency + def generate_header2header_dependency + + # for all packages in list + @package_list.each_value do |pkg| + $log.info "Analyzing...#{pkg.name}" + + # get include path list(used SBS specialized function) + pc_list = pkg.pc_list.map {|pc| pc.name} + include_search_paths = @rootstrap.ctrl.get_include_search_paths_using_pkgconfig pc_list + # check all ( include option + dependent header files) combination paths + pkg.header_list.each do |header| + + # all #include statement in the header file + for dpath in header.include_list + for ipath in include_search_paths + abs_path = @rootstrap.path + ipath + "/" + dpath + abs_path.gsub!("//","/") + # check the combination path exists, if exists, add pkg2pkg dependency + if File.file? abs_path then + + # set header to header dependency + path = (ipath + "/" + dpath).gsub("//","/") + dep_header = @header_list[path] + header.dep_header_list.push dep_header + + # set required include search path + header.req_incpath_list.push ipath + + # if different package, update other dependency info + dep_pkg = dep_header.parent + if not pkg.equal? dep_pkg then + pkg.dep_package_list.push dep_pkg + pkg.dep_header_list.push dep_header + end + break + end + end + end + + # remove dup + header.dep_header_list.uniq! + end + + # remove dup + pkg.dep_package_list.uniq! + pkg.dep_header_list.uniq! + + end + end + + + # create dev packages + def generate_dev_packages + # init + @devpackage_list = [] + @public_package_list = [] + + # for all framework + @framework.each do |category,package_list| + + # process category + c = add_category_node category + + # for all packages in category + package_list.each do |pkg| + # add public package list + @public_package_list.push pkg + + # for all pc name + pkg.pc_list.each do |pc| + name = pc.name + + # if there is alias name, skip + if is_alias_name? name then next end + + # if has alias names, + if has_alias_name? name then + add_leaf_node(get_alias_name(name), pc,c) + else + add_leaf_node(name,pc,c) + end + end + end + end + + # set pc dependency + set_dev_package_dependency + + # resolve private header issue + resolve_private_headers + end + + + # add new category node + def add_category_node(category_pattern) + + parent_pattern = nil + name = category_pattern + if category_pattern.count("/") > 1 then + name = category_pattern.split("/")[-1] + new_index = category_pattern.length - (1 + name.length) - 1 + parent_pattern = category_pattern[0..new_index] + c = DevPackage.new(name, false, true) + else + name = category_pattern[1..-1] + c = DevPackage.new(name, true, true) + end + + # if already exists in list, return + devpkg = get_node(name) + if not devpkg.nil? then + return devpkg + end + + # if parent exist, set parent + if not parent_pattern.nil? then + parent = add_category_node( parent_pattern ) + parent.include_devpackage_list.push name + end + + # add dev list + @devpackage_list.push c + $log.info "Framework category added: #{name}" + + return c + end + + + + # get dev package + def get_node(name) + for devpkg in @devpackage_list + if devpkg.name == name then + return devpkg + end + end + return nil + end + + + # add new leaf node + def add_leaf_node(name, pc, parent) + # create new + p = DevPackage.new(name, false, false) + + # set info + pc.cflags_I.each {|x| p.include_path_list.push x } + pc.cflags_other.each {|x| p.other_cflag_list.push x } + pc.lflags_l.each {|x| p.library_list.push x } + pc.lflags_L.each {|x| p.library_path_list.push x } + pc.lflags_other.each {|x| p.other_lflag_list.push x } + p.description = pc.description + + # set parent + parent.include_devpackage_list.push name + + # add dev list + @devpackage_list.push p + end + + + def is_alias_name? name + if @substitutes.values.include? name then + return true + else + return false + end + end + + + def has_alias_name? name + aliases = @substitutes[name] + if aliases.nil? or aliases.empty? then + return false + else + return true + end + end + + + def get_alias_name name + aliases = @substitutes[name] + if aliases.nil? then + return name + else + return aliases[0] + end + end + + + def get_original_pc_name aname + org_name = aname + @substitutes.each do |key,values| + org_name = key if values.include? aname and not @pc_list[key].nil? + end + + return org_name + end + + + # set dev package dependency + def set_dev_package_dependency + private_headers = {} + + # for all dev packages + for dev_pc in @devpackage_list + # if not leaf node, skip + if dev_pc.is_virtual then next end + + # get real name + pc_name = get_original_pc_name dev_pc.name + # for all dependent headers + pkg = @pc_list[pc_name].parent + for header in pkg.dep_header_list + # get public pc list and private header list + tmp = propagate_header(header) + + # add public pc dependency + dev_pc.dependency_list=dev_pc.dependency_list | tmp[0] + + # add private headers + pkg.priv_header_list = pkg.priv_header_list | tmp[1] + end + + # remove dup + dev_pc.dependency_list.uniq! + pkg.priv_header_list.uniq! + end + end + + + # get public pc list and private header list + def propagate_header(header) + public_pc_list = [] + private_header_list = [] + + # if public package header, add its pcs + pkg = header.parent + if @public_package_list.include? pkg then + pkg.pc_list.each do |x| + public_pc_list.push get_alias_name(x.name) + end + # otherwise, identify + else + # add into list + private_header_list.push header + + # propagate sub dependent headers + for dep_header in header.dep_header_list + # call recursive and get results + result_pair = propagate_header(dep_header) + public_pc_list = public_pc_list | result_pair[0] + private_header_list = private_header_list | result_pair[1] + end + end + + public_pc_list.uniq! + private_header_list.uniq! + + return [public_pc_list, private_header_list] + end + + + # if private headers exist, add inclcude search path to devpackage + def resolve_private_headers + # for all dev packages + for dev_pc in @devpackage_list + # if not leaf node, skip + if dev_pc.is_virtual then next end + + # get parent package name + pc_name = get_original_pc_name dev_pc.name + pkg = @pc_list[pc_name].parent + + # skip, if empty + if pkg.priv_header_list.empty? then next end + + # for each private header + for private_header in pkg.priv_header_list + dev_pc.include_path_list=dev_pc.include_path_list | private_header.req_incpath_list + end + + # remove dup + dev_pc.include_path_list.uniq! + end + end +end diff --git a/bin/generators/TizenPublic/devpackage.rb b/bin/generators/TizenPublic/devpackage.rb new file mode 100644 index 0000000..b61edc8 --- /dev/null +++ b/bin/generators/TizenPublic/devpackage.rb @@ -0,0 +1,16 @@ +class DevPackage + attr_accessor :name, :is_framework, :is_virtual, :include_path_list, :other_cflag_list, :library_list, :library_path_list, :other_lflag_list, :description, :include_devpackage_list, :dependency_list + def initialize (name, is_framework, is_virtual) + @name = name + @is_framework = is_framework + @is_virtual = is_virtual + @include_devpackage_list = [] + @include_path_list = [] + @other_cflag_list = [] + @library_list = [] + @library_path_list = [] + @other_lflag_list = [] + @dependency_list = [] + @description = "" + end +end diff --git a/bin/generators/TizenPublic/framework b/bin/generators/TizenPublic/framework new file mode 100644 index 0000000..b8b72bf --- /dev/null +++ b/bin/generators/TizenPublic/framework @@ -0,0 +1,51 @@ +/Base + dlog-dev + libdbus-1-dev + libsqlite3-dev + libxml2-dev + libssl-dev + libjson-glib-dev + libc6-dev + linux-libc-dev + libstdc++6-4.5-dev +/Base/Glib2.0 + libglib2.0-dev +/Base/ICU + libicu + libicu-dev +/Multimedia + libfreealut-dev + libopenal-soft-dev +/Network + libsoup2.4-dev + libcurl-dev + libcurl4-openssl-dev +/UI + libedje-dev + libeina-dev + libelm-dev + libeet-dev + libelm-webview-dev + libwebkit-engine-dev +/UI/Cairo + libcairo2-dev +/UI/Edbus + libedbus-dev +/UI/Efreet + libefreet-dev +/UI/Ecore + libecore-dev +/UI/Ethumb + libethumb-dev +/UI/Evas + libevas-dev +/UI/OpenGL + opengl-es-virtual-drv-dev + simulator-opengl-dev +/Uncategorized + gtest-for-arm + gtest-for-i386 +*gles11 opengl-es-11 +*gles20 opengl-es-20 +*opengl opengl-es-11 +*opengl2 opengl-es-20 diff --git a/bin/generators/TizenPublic/generator.rb b/bin/generators/TizenPublic/generator.rb new file mode 100644 index 0000000..33e900f --- /dev/null +++ b/bin/generators/TizenPublic/generator.rb @@ -0,0 +1,239 @@ +require File.dirname(__FILE__) + "/analyzer" + +class ImageGenerator + @analyzer = nil + @image = nil + @rootstrap = nil + + # process rootstrap + def post_process(image) + @image = image + @rootstrap = @image.rootstrap + + # generate "DevPackages.xml" + @analyzer = TizenPublicFrameworkAnalyzer.new(@rootstrap) + @analyzer.analyze + @analyzer.write_dev_package_xml + + # overwrite prelinked ld.so if ARM + if @rootstrap.arch == "arm" then + make_ldso_prelinked + end + + # remove unnecessary files + remove_files + + # fix symbolic links + fix_symbolic_links + + # change sources.list + change_sources_list + end + + + # make package + def zip + # install files + install_files + + # generate package for linux + if @image.os == "linux" or @image.os == "all" then + add_remove_script "linux" + generate_package_info "linux" + build_package "linux" + end + + # generate package for windows + if @image.os == "windows" or @image.os == "all" then + add_remove_script "windows" + generate_package_info "windows" + build_package "windows" + end + end + + + + # + # PRIVATE + # + private + + + # strip unnecessary section in binary files + def strip_binary_files + sos = `find #{@rootstrap.name}/usr/lib -name *.so` + sos.each_line do |so| + system "strip -R .text -R .ARM.exidx -s #{so}" + end + end + + + # remove unnecessary files + def remove_files + #remove aclocal m4 files + #ls -F show when link file with @ character at last + aclocal = `ls -F #{@rootstrap.name}/usr/share/aclocal/*` + aclocal.each_line do |ac| + if ac.include? "@" then + FileUtils.rm_rf ac.strip[0..-2] + end + end + + #remove static libray files when dynamic library is exist + d = Dir.entries("#{@rootstrap.name}/usr/lib") + s = d.select {|a| a.include? ".a" or a.include? ".la" } + s.each do |a| + if File.exist? "#{@rootstrap.name}/usr/lib/#{a.sub(/\.l*a/,".so")}" then + FileUtils.rm_rf "#{@rootstrap.name}/usr/lib/#{a}" + end + end + + #remove invalid_header_lists + invalid_header_list = @analyzer.get_unused_header_list + invalid_header_list.each do |i| + $log.info "Removing a unused header file ... #{i}" + abs_path = @rootstrap.path + i + abs_path.gsub!("//","/") + FileUtils.rm_rf abs_path + end + end + + + def change_sources_list + if File.exist? "#{@rootstrap.name}/etc/apt/sources.list" then + case @rootstrap.arch + when "armel" then + File.open "#{@rootstrap.name}/etc/apt/sources.list","w" do |x| + x.puts "" + end + when "arm" then + File.open "#{@rootstrap.name}/etc/apt/sources.list","w" do |x| + x.puts "" + end + when "i386" then + File.open "#{@rootstrap.name}/etc/apt/sources.list","w" do |x| + x.puts "deb http://source.tizen.org/home/tizen/apt.sbs/i386 slp2-target main contrib non-free" + end + else $log.error "rootstrap architecture is :[#{@rootstrap.arch}]" + end + end + end + + + # fix symbolic links + def fix_symbolic_links + + #delete toolchain link + FileUtils.cd @rootstrap.name + + #show link type + links = `find -type l` + links.each_line do |f| + l = `file #{f}`.split(':') + link = l[0] + if not l[1].include? "`" then next end + src = l[1].split('`')[1].strip[0..-2] + + #fix link only absolute path link + if src.start_with? "/" then + FileUtils.rm_rf link + depth = "/.." * (link.count("/") -1) + FileUtils.ln_s ".#{depth}#{src}", link + end + end + FileUtils.cd ".." + end + + + # prelink ld.so for compatibility to ARM device + def make_ldso_prelinked + @rootstrap.ctrl.make_ldso_prelinked + end + + # install files + def install_files + # clean + FileUtils.rm_rf "package" + + # install rootstraps + FileUtils.mkdir_p "package/data/SDK/build-system/rootstraps" + FileUtils.mv "#{@rootstrap.name}", "package/data/SDK/build-system/rootstraps" + + # install sbi rootstrap plugin + FileUtils.mkdir_p "package/data/SDK/build-system/plugins" + FileUtils.cp "#{@rootstrap.name}.xml", "package/data/SDK/build-system/plugins/#{@rootstrap.name}.xml" + end + + + # generate package info + def generate_package_info(platform) + + # Error CHECK + if not File.exist?(File.dirname(__FILE__) + "/pkginfo.manifest") + raise RuntimeError,"File does not exist [#{File.dirname(__FILE__)}/pkginfo.manifest]" + end + + # modify pkginfo.manifest + p = [] + File.open( File.dirname(__FILE__) + "/pkginfo.manifest","r") do |f| + f.each_line do |line| + line.gsub!("@name@",@rootstrap.name) + line.gsub!("@version@",@image.ver) + line.gsub!("@arch@",@rootstrap.arch) + #line.gsub!("@type@",@type) + line.gsub!("@platform@",platform) + line.gsub!("@remove_script@","remove.sh") if platform == "linux" + line.gsub!("@remove_script@","remove.bat") if platform == "windows" + p.push line + end + end + + # write pkginfo.manaifest + File.open("package/pkginfo.manifest","w") do |f| + p.each do |line| + f.puts line + end + end + end + + + # add remove scripts + def add_remove_script(platform) + # add removescript + if platform == "linux" then + File.open("package/remove.sh","w") do |f| + f.puts "#!/bin/sh -e" + f.puts "" + f.puts "rm -rf ${INSTALLED_PATH}/SDK/build-system/rootstraps/#{@rootstrap.name}" + end + elsif platform == "windows" then + File.open("package/remove.bat","w") do |f| + f.puts ":: delims is a TAB followed by a space" + f.puts "SET installed_path=%INSTALLED_PATH%" + f.puts "" + f.puts "RMDIR /S /Q %installed_path%\\SDK\\build-system\\rootstraps\\#{@rootstrap.name}" + end + end + end + + + # build package + def build_package(platform) + FileUtils.cd "package" + + #Get package Version + package_version = "#{@image.ver}" + + # In case of windows, symbolic link must be duplicated + if platform == "windows" then + system "tar chf data.tar *" + system "rm -rf data" + system "tar xf data.tar" + system "rm -rf data.tar" + end + + system "zip -r -y -q ../rootstrap-#{@rootstrap.name}_#{package_version}_#{platform}.zip *" + $log.info "Result file is rootstrap-#{@rootstrap.name}_#{package_version}_#{platform}.zip" + FileUtils.cd ".." + end +end diff --git a/bin/generators/TizenPublic/headerfile.rb b/bin/generators/TizenPublic/headerfile.rb new file mode 100644 index 0000000..d377b0f --- /dev/null +++ b/bin/generators/TizenPublic/headerfile.rb @@ -0,0 +1,16 @@ +class HeaderFile + attr_accessor :path + attr_accessor :include_list + attr_accessor :dep_header_list + attr_accessor :req_incpath_list + attr_accessor :parent + + def initialize(path) + @path = path + @include_list = [] + @dep_header_list = [] + @req_incpath_list = [] + @parent = nil + end + +end diff --git a/bin/generators/TizenPublic/package.rb b/bin/generators/TizenPublic/package.rb new file mode 100644 index 0000000..5445a05 --- /dev/null +++ b/bin/generators/TizenPublic/package.rb @@ -0,0 +1,19 @@ +class DebPackage + attr_accessor :name + attr_accessor :header_list # list of HeaderFile + attr_accessor :pc_list # list of PcFile + attr_accessor :dep_header_list # list of dependent HeaderFile + attr_accessor :dep_package_list # list of dependent DebPackage + attr_accessor :priv_header_list # private header list + + + def initialize ( name ) + @name = name + @pc_list = [] + @header_list = [] + @dep_header_list = [] + @dep_package_list = [] + @priv_header_list = [] + end + +end diff --git a/bin/generators/TizenPublic/pcfile.rb b/bin/generators/TizenPublic/pcfile.rb new file mode 100644 index 0000000..0325982 --- /dev/null +++ b/bin/generators/TizenPublic/pcfile.rb @@ -0,0 +1,107 @@ +class PcFile + attr_accessor :name, :cflags_I, :cflags_other, :lflags_l, :lflags_L, :lflags_other, :description + attr_accessor :parent # ref of parent package + attr_accessor :alias_name # alias name + attr_accessor :ignored # ignored or not in public frameworks pages + + def initialize (pc_file_path) + @name = pc_file_path.split('/')[-1][0..-4] #basename remove extension (.pc) + @cflags_I = [] + @cflags_other = [] + @lflags_l = [] + @lflags_L = [] + @lflags_other = [] + @description = "" + @alias_name = @name + @ignored = false + @parent = nil + end + + + def load_from_file(pc_file_path) + + File.open(pc_file_path,"r") do |f| + doc = [] + f.each_line do |line| + if line =~ /^\s*#/ then next end + + doc.each do |d| + line.gsub!(d[0],d[1]) if line.include? d[0] + end + # if line is macro like this "dest=src" + if line =~ /=/ then + l = line.strip.split('=') + # about dest + l[0] = "${" + l[0].strip + "}" + + # about src + if l[1].nil? then + l[1] = "" + else + l[1] = l[1].strip + end + + #then l is likt this [${dest},src] + doc.push l + end + + #line is Cflags: xxxx then + line_split = line.split(":") + if line_split[1].nil? then next end + line_split[1].gsub!(","," ") + line_split[1].strip! + + case line_split[0].strip + when "Cflags" then + line_split[1].split.each do |c| + if c.strip.start_with?("-I") then + include_path = c.strip.sub("-I","") + @cflags_I.push include_path + else + @cflags_other.push c.strip + end + end + when "Libs" then + line_split[1].split.each do |l| + if l.strip.start_with?("-l") then + library = "lib" + l.strip.sub("-l","") + ".so" + @lflags_l.push library + elsif l.strip.start_with?("-L") then + library_path = l.strip.sub("-L","") + @lflags_L.push library_path + else + @lflags_other.push l.strip + end + end + when "Description" then + @description = line.sub(/Description[\t\s]*:/,"").strip + end + end + @cflags_I.uniq! + @cflags_other.uniq! + @lflags_l.uniq! + @lflags_L.uniq! + @lflags_other.uniq! + end + end + + def print + $log.info "name: #{@name}" + $log.info "cflags_I: #{@cflags_I}" + $log.info "cflag_other: #{@cflags_other}" + $log.info "lflags_l: #{@lflags_l}" + $log.info "lflags_L: #{@lflags_L}" + $log.info "lflags_other: #{@lflags_other}" + $log.info "description: #{@description}" + end + + #def macro_resolving(line) + # if (has_macro? line) then + # macro.each do |mac| + # if line.contain(mac) then + # line.gsub(mac.key,mac.value) + # end + # end + # end + #end +end diff --git a/bin/generators/TizenPublic/pkginfo.manifest b/bin/generators/TizenPublic/pkginfo.manifest new file mode 100644 index 0000000..9017ab0 --- /dev/null +++ b/bin/generators/TizenPublic/pkginfo.manifest @@ -0,0 +1,7 @@ +Package : rootstrap-@name@ +Version : @version@ +Maintainer : hyoun jiil +Description : @arch@ rootstrap for SLP SDK +Depends : +Category : SDK/build-system/rootstraps +Remove-script: @remove_script@ diff --git a/bin/generators/TizenPublic/temp.rb b/bin/generators/TizenPublic/temp.rb new file mode 100644 index 0000000..dd98761 --- /dev/null +++ b/bin/generators/TizenPublic/temp.rb @@ -0,0 +1,22 @@ +require 'fileutils' + +#delete toolchain link + + #show link type + links = `find -type l` + links.each_line do |f| + l = `file #{f}`.split(':') + link = l[0] + if not l[1].include? "`" then next end + src = l[1].split('`')[1].strip[0..-2] + + #fix link only absolute path link + if src.start_with? "/" then + puts " fix link src : #{src}" + FileUtils.rm_rf link + depth = "/.." * (link.count("/") -1) + FileUtils.ln_s ".#{depth}#{src}", link + else + puts " ignored src : #{src}" + end + end diff --git a/bin/image.rb b/bin/image.rb new file mode 100644 index 0000000..570719b --- /dev/null +++ b/bin/image.rb @@ -0,0 +1,25 @@ +require File.dirname(__FILE__) + "/default_generator" + +class Image + attr_accessor :rootstrap, :ver, :os, :wrapper + @rootstrap = nil + @ver = nil + @os = nil + @wrapper = nil + @zipped = false + + # init + def initialize (t, ver, os, generator) + @rootstrap = t + @ver = ver + @os = os + @generator = generator + end + + + # build package + def build + @generator.post_process(self) + @generator.zip + end +end diff --git a/bin/optparser.rb b/bin/optparser.rb new file mode 100644 index 0000000..f90f6f6 --- /dev/null +++ b/bin/optparser.rb @@ -0,0 +1,236 @@ +require 'optparse' + +def read_cfg (options) + if options[:name].nil? then + options[:name] = get_value_from_file options[:cfg], "name" + + if options[:name].empty? + options[:name] = "tizen-emulator-1.0.sb2" + end + end + if options[:version].nil? then + options[:version] = get_value_from_file options[:cfg], "version" + + if options[:version].empty? + options[:version] = "0.17.0" + end + end + if options[:arch].nil? then + options[:arch] = get_value_from_file options[:cfg], "arch" + + if options[:arch].empty? + options[:arch] = "i386" + end + end + if options[:os].nil? then + options[:os] = get_value_from_file options[:cfg], "os" + + if options[:os].empty? + options[:os] = "linux" + end + end + if options[:pkglist].nil? then + options[:pkglist] = get_value_from_file options[:cfg], "pkglist" + + if options[:pkglist].empty? + options[:pkglist] = "./pkglist_arm" + end + end + if options[:gen].nil? then + options[:gen] = get_value_from_file options[:cfg], "generator" + + if options[:gen].empty? + options[:gen] = "TizenPlatform" + end + end + if options[:ctrl].nil? then + options[:ctrl] = get_value_from_file options[:cfg], "controller" + + if options[:ctrl].empty? + options[:ctrl] = "SBS" + end + end + if options[:protocol].nil? then + options[:protocol] = get_value_from_file options[:cfg], "default_protocol" + + if options[:protocol].empty? + options[:protocol] = "deb" + end + end + if options[:url].nil? then + options[:url] = get_value_from_file options[:cfg], "default_url" + + if options[:url].empty? + options[:url] = "ssh://165.213.180.233/home/slp2.0/debian/www/apt.open.test/i386 slp2-target main contrib non-free" + end + end +end + +def set_default (options) + if options[:name].nil? then + options[:name] = "slp-emulator-1.0.sb2" + end + if options[:version].nil? then + options[:version] = "0.17.0" + end + if options[:arch].nil? then + options[:arch] = "i386" + end + if options[:os].nil? then + options[:os] = "linux" + end + if options[:pkglist].nil? then + options[:pkglist] = "./pkglist_arm" + end + if options[:gen].nil? then + options[:gen] = "TizenPlatform" + end + if options[:ctrl].nil? then + options[:ctrl] = "SBS" + end + if options[:protocol].nil? then + options[:protocol] = "deb" + end + if options[:url].nil? then + options[:url] = "ssh://165.213.180.233/home/slp2.0/debian/www/apt.open.test/i386 slp2-target main contrib non-free" + end +end +def option_parse + options = {} + optparse = OptionParser.new do|opts| + # Set a banner, displayed at the top + # of the help screen. + opts.banner = "Usage: rootstrap-gnerator -n -v -a -o -l -g -t -u -p -c " + + # Define the options, and what they do + opts.on( '-n', '--name ', 'name' ) do|name| + options[:name] = name + end + + opts.on( '-v', '--version <001>', 'minor version information' ) do|version| + options[:version] = version + end + + opts.on( '-a', '--arch ', 'architecture ' ) do|arch| + options[:arch] = arch + end + + opts.on( '-o', '--os ', 'operating system type' ) do|platform| + options[:os] = platform + end + + opts.on( '-l', '--pkglist ', 'package list file' ) do|pkglist| + options[:pkglist] = pkglist + end + + opts.on( '-g', '--gen ', 'image generator type' ) do|gen| + options[:gen] = gen + end + + opts.on( '-t', '--ctrl ', 'rootstrap controller type' ) do|ctrl| + options[:ctrl] = ctrl + end + + opts.on( '-u', '--default_url ', 'apt-get repository') do|url| + options[:url] = url + end + + opts.on( '-p', '--default_protocol ', 'how to get package' ) do|protocol| + options[:protocol] = protocol + end + + opts.on( '-c', '--config ', 'config file' ) do|cfg| + options[:cfg] = cfg + end + + # This displays the help screen, all programs are + # assumed to have this option. + opts.on( '-h', '--help', 'Display this information ' ) do + puts opts + exit + end + end + + $log.info "option parsing start" + $log.info "option is : " + ARGV * "," + + optparse.parse! + + $log.info "option parsing end" + + ################# parameter error check start ###################### + + options_path = $WORKING_DIR + "/" + if not options[:cfg].nil? then + if File.exist?(options[:cfg]) then + $log.info "cfg file path is [#{options[:cfg]}]" + read_cfg options + options_path = File.dirname(options[:cfg]) + "/" + else + $log.error "cfg file is not exist input : [#{options[:cfg]}]" + raise ArgumentError, "cfg file does not exist, your input is [#{options[:cfg]}]" + end + else + $log.info options_path + set_default options + end + + if options[:name].nil? or options[:name].empty? then + $log.error "-n option is not setted" + raise ArgumentError, "-n option is not setted" + end + + if options[:version].nil? or options[:version].empty? then + $log.error "-v option is not setted" + raise ArgumentError, "-v option is not setted" + else + $log.info "version is #{options[:version]} " + end + + if options[:arch].nil? or options[:arch].empty? then + $log.error "-a option is not setted" + raise ArgumentError, "-a option is not setted" + end + + if options[:os] == "linux" || options[:os] == "windows" || options[:os] == "all" then + options[:os].downcase! + else + $log.error "os option is invalid : #{options[:os]}" + raise ArgumentError, "os option is only valid is linux/windows/all : input is [#{options[:os]}]" + end + + if File.exist?(options_path + options[:pkglist]) then + $log.info "pkglist file path is [#{options[:pkglist]}]" + else + $log.error "pkglist file is not exist input : [#{options[:pkglist]}]" + raise ArgumentError, "pkglist file does not exist, your input is [#{options[:pkglist]}]" + end + + if File.directory?(File.dirname(__FILE__) + "/generators/#{options[:gen]}") then + $log.info "generator path is [#{options[:gen]}]" + else + $log.error " generator path is not exist input : [#{options[:gen]}]" + raise ArgumentError, "generator path path does not exist, your input is [#{options[:gen]}]" + end + + if File.directory?(File.dirname(__FILE__) + "/controllers/#{options[:ctrl]}") then + $log.info "controller path is [#{options[:ctrl]}]" + else + $log.error "controller path is not exist input : [#{options[:ctrl]}]" + raise ArgumentError, "controller path does not exist, your input is [#{options[:ctrl]}]" + end + + if options[:url].nil? or options[:url].empty? then + $log.error "-u option is not setted" + raise ArgumentError, "-u option is not setted" + else + $log.info "default sources.list [deb " + options[:url] + "]" + end + + if options[:protocol].nil? or options[:protocol].empty? then + $log.error "-p option is not setted" + raise ArgumentError, "-p option is not setted" + end + + return options +end diff --git a/bin/package.rb b/bin/package.rb new file mode 100644 index 0000000..819e98d --- /dev/null +++ b/bin/package.rb @@ -0,0 +1,39 @@ +class Package + attr_accessor :name, :url, :header_list, :pc_file_list, :require_package_list, :protocol + def initialize ( name, protocol ,url ) + @name = name + @url = url + @protocol = protocol + @pc_file_list = [] + @header_list = [] + @require_package_list = [] + end + + def Package.load_package_list_from_file (file, protocol, url) + list = [] + File.open(file,"r") do |f| + f.each_line do |line| + l = line.split(',') + if l[0].empty? then + $log.warn "blank is set in pkg_list" + elsif l[1].nil? then + p = Package.new l[0].strip, protocol.strip, url.strip + list.push p + elsif l[2].nil? then + p = Package.new l[0].strip, l[1].strip, url.strip + list.push p + else + p = Package.new l[0].strip, l[1].strip, l[2].strip + list.push p + end + end + end + return list + end + + def ==(other) + if @name == other.name and @url == other.url and @protocol == other.protocol then return true + else return false + end + end +end diff --git a/bin/pkginfo.manifest b/bin/pkginfo.manifest new file mode 100644 index 0000000..911d3ce --- /dev/null +++ b/bin/pkginfo.manifest @@ -0,0 +1,7 @@ +Package : rootstrap-@name +Version : 0.18.@version +Maintainer : hyoun jiil +Description : @arch rootstrap for SLP SDK for @type +Depends : +Category : SDK/build-system/rootstraps +Remove-script: @remove_script diff --git a/bin/rogen.cfg b/bin/rogen.cfg new file mode 100644 index 0000000..1cc64e7 --- /dev/null +++ b/bin/rogen.cfg @@ -0,0 +1,2 @@ +local_save_path = ~/image-pool/ +#remote_save_path = buildsystem:~/image-pool/ diff --git a/bin/rogen.rb b/bin/rogen.rb new file mode 100755 index 0000000..a3c0690 --- /dev/null +++ b/bin/rogen.rb @@ -0,0 +1,49 @@ +#!/usr/bin/ruby +# A script that will pretend to resize a number of images +require 'fileutils' +require 'logger' + +#library +require File.dirname(__FILE__) + "/util" +require File.dirname(__FILE__) + "/optparser" +require File.dirname(__FILE__) + "/rootstrapmanager" +require File.dirname(__FILE__) + "/package" +require File.dirname(__FILE__) + "/rootstrap" +require File.dirname(__FILE__) + "/image" + + + +# set global variable +$HOME = `echo $HOME`.strip +$WORKING_DIR = `pwd`.strip + +$log = Logger.new STDOUT + +# This hash will hold all of the option +# parsed from the command-line by +# OptionParser. +begin + option = option_parse +rescue => e + $log.info "\n=============== Option parsing Error ========================" + $log.info e.message + $log.info "=============================================================\n\n" + exit 0 +end + +# Load package list +pkglist = Package.load_package_list_from_file( option[:pkglist], option[:protocol], option[:url] ) + +# create rootstrap +t = RootstrapManager.create(option[:name], option[:arch], pkglist, option[:ctrl]) + +# load generator class +load File.dirname(__FILE__) + "/generators/" + option[:gen] + "/generator.rb" + +# create new image +r = Image.new( t, option[:version] , option[:os], ImageGenerator.new ) +r.build + +$log.info "!!!Image is generated!!!" +$log.info "========================================================" + diff --git a/bin/rootstrap.rb b/bin/rootstrap.rb new file mode 100644 index 0000000..c672a74 --- /dev/null +++ b/bin/rootstrap.rb @@ -0,0 +1,51 @@ +require 'fileutils' + +require File.dirname(__FILE__) + "/default_controller" + +class Rootstrap + attr_accessor :name, :path, :arch, :base_pkg_list, :ctrl + @name = "" + @arch = "" + @base_pkg_list = [] + @path = "" + @ctrl = nil + + # initialize rootstrap + def initialize ( name, arch, pkg_list, ctrl ) + @name = name + @arch = arch + @base_pkg_list = pkg_list + @path = $WORKING_DIR + "/" + name + @ctrl = ctrl + end + + # get all package list installed + def get_all_installed_packages + ctrl.get_all_installed_packages + end + + + # get all file list in package + def get_all_package_files(pkg_name) + ctrl.get_all_package_files pkg_name + end + + + # get all dependent packages + def get_all_dependent_packages(pkg_name) + ctrl.get_all_dependent_packages pkg_name + end + + def generate() + $log.info "initialize rootstrap using controller" + @ctrl.create_new_rootstrap( self ) + + $log.info "install packages" + @ctrl.install_packages + end + + def regenerate() + $log.info "reinitialize rootstrap using controller" + @ctrl.reload( self ) + end +end diff --git a/bin/rootstrapmanager.rb b/bin/rootstrapmanager.rb new file mode 100644 index 0000000..f029b09 --- /dev/null +++ b/bin/rootstrapmanager.rb @@ -0,0 +1,158 @@ + +class RootstrapManager + def RootstrapManager.create (name, arch, pkglist, ctrl) + load File.dirname(__FILE__) + "/controllers/" + ctrl + "/controller.rb" + + ctrl = RootstrapController.new + saved_rootstrap = get_saved_rootstrap_name(name, arch, pkglist, ctrl) + $log.info "saved rootstrap exist #{saved_rootstrap.join(" : ")}" + + if saved_rootstrap.empty? + rootstrap = Rootstrap.new(name, arch, pkglist, ctrl) + rootstrap.generate + save_rootstrap rootstrap + else + load_saved_rootstrap saved_rootstrap + rootstrap = Rootstrap.new(name, arch, pkglist, ctrl) + rootstrap.regenerate + end + + return rootstrap + end + + def RootstrapManager.get_saved_rootstrap_name (name, arch, pkglist, ctrl) + saved_rootstrap = [] + + local_save = get_local_save(name, arch, pkglist, ctrl) + if not local_save.empty? then + saved_rootstrap = ["local", local_save] + else + remote_save = get_remote_save(name, arch, pkglist, ctrl) + if not remote_save.empty? then + saved_rootstrap = ["remote", remote_save] + end + end + + return saved_rootstrap + end + + def RootstrapManager.get_local_save (name, arch, pkglist, ctrl) + #get local_save_path from rogen.cfg + local_save_path = "#{get_value_from_file File.dirname(__FILE__) + "/rogen.cfg", "local_save_path"}".sub(/^~/,$HOME) + if not local_save_path.empty? then + FileUtils.mkdir_p local_save_path + #get contents of local_save_path + local_save_list = `ls #{local_save_path}`.split + + #check _ctrl, and _pkglist and .zip + (local_save_list.select {|x| x =~ /#{name}-#{arch}-.*_ctrl$/}).each do |l| + if local_save_list.include? l.sub(/_ctrl$/,"_pkglist") and local_save_list.include? l.sub(/_ctrl$/,".zip") then + save_name = l.sub(/_ctrl$/,"") + + #check ctrl + if ctrl.same_as? local_save_path + "/" + save_name + "_ctrl" then + + #check pkglist + local_pkglist = Package.load_package_list_from_file local_save_path + "/" + save_name + "_pkglist", "", "" + + if local_pkglist == pkglist then + return save_name + ".zip" + end + end + end + end + else + $log.warn "local save path is not set in rogen.cfg" + end + return "" + end + + def RootstrapManager.get_remote_save (name, arch, pkglist, ctrl) + #get remote_save_path from rogen.cfg + remote_save_path = "#{get_value_from_file File.dirname(__FILE__) +"/rogen.cfg", "remote_save_path"}" + if not remote_save_path.empty? then + #get contents of local_save_path + r = remote_save_path.split(":") + remote_save_list = `ssh #{r[0]} \"ls #{r[1]}\"`.split + + #check _ctrl, and _pkglist and .zip + (remote_save_list.select {|x| x =~ /#{name}-#{arch}-.*_ctrl$/}).each do |l| + save_name = l.sub(/_ctrl$/,"") + if remote_save_list.include? save_name + "_pkglist" and remote_save_list.include? save_name + ".zip" then + + #check ctrl + system "scp #{remote_save_path}/#{save_name}_ctrl ." + if ctrl.same_as? "./#{save_name}_ctrl" then + FileUtils.rm save_name + "_ctrl" + + #check pkglist + system "scp #{remote_save_path}/#{save_name}_pkglist ." + remote_pkglist = Package.load_package_list_from_file save_name + "_pkglist", "", "" + FileUtils.rm save_name + "_pkglist" + + if remote_pkglist == pkglist then + return save_name + ".zip" + end + else + FileUtils.rm save_name + "_ctrl" + end + end + end + else + $log.warn "remote save path is not set in rogen.cfg" + end + return "" + end + + def RootstrapManager.load_saved_rootstrap (saved_rootstrap) + case saved_rootstrap[0] + when "local" then + local_save_path = "#{get_value_from_file File.dirname(__FILE__) + "/rogen.cfg", "local_save_path"}".sub(/^~/,$HOME) + $log.info "download from #{local_save_path}/#{saved_rootstrap[1]}" + $log.info "unzip -q #{local_save_path}/#{saved_rootstrap[1]} -d #{$WORKING_DIR}" + system "unzip -q #{local_save_path}/#{saved_rootstrap[1]} -d #{$WORKING_DIR}" + when "remote" then + remote_save_path = "#{get_value_from_file File.dirname(__FILE__) + "/rogen.cfg", "remote_save_path"}".split(":") + #download rootstrap file from remote server + $log.info "download from #{remote_save_path.join(":")}/#{saved_rootstrap[1]}" + system "scp #{remote_save_path.join(":")}/#{saved_rootstrap[1]} ." + system "unzip -q #{saved_rootstrap[1]} -d #{$WORKING_DIR}" + else + raise RuntimeError, "internal error from RootstrapManager.load_saved_rootstrap" + end + end + + def RootstrapManager.save_rootstrap (rootstrap) + #save local save path + local_save_path = "#{get_value_from_file File.dirname(__FILE__) + "/rogen.cfg", "local_save_path"}".sub(/^~/,$HOME) + remote_save_path = "#{get_value_from_file File.dirname(__FILE__) + "/rogen.cfg", "remote_save_path"}" + + if local_save_path.empty? and remote_save_path.empty? then return "" end + local_save_path = "." if local_save_path.empty? + + $log.info "save rootstrap to local #{local_save_path}" + save_rootstrap_name = "#{rootstrap.name}-#{rootstrap.arch}-#{Time.now.usec}" + + #save rootstrap + system "zip -q -r -y #{local_save_path}/#{save_rootstrap_name}.zip #{rootstrap.name}" + + #save pkglist + File.open("#{save_rootstrap_name}_pkglist", "w") do |f| + rootstrap.base_pkg_list.each do |l| + f.puts l.name.strip + ", " + l.protocol.strip + ", " + l.url.strip + end + end + FileUtils.cp "#{save_rootstrap_name}_pkglist", "#{local_save_path}" + + #save ctrl + rootstrap.ctrl.write_info "#{local_save_path}/#{save_rootstrap_name}_ctrl" + + #save remote save path + if not remote_save_path.empty? then + $log.info "save rootstrap to remote #{remote_save_path}" + system "scp #{local_save_path}/#{save_rootstrap_name}.zip #{remote_save_path}" + system "scp #{local_save_path}/#{save_rootstrap_name}_ctrl #{remote_save_path}" + system "scp #{local_save_path}/#{save_rootstrap_name}_pkglist #{remote_save_path}" + end + end +end diff --git a/bin/util.rb b/bin/util.rb new file mode 100644 index 0000000..dfea9d4 --- /dev/null +++ b/bin/util.rb @@ -0,0 +1,62 @@ +def make_sourceslist (repository, snapshot) + #open repository to modify snapshot information + p = [] + File.open(repository,"r") do |f| + f.each_line do |line| + if snapshot.empty? then + line.gsub!("@snapshot@","") + else + line.gsub!("@snapshot@","/snapshots/" + snapshot) + end + p.push line + end + end + + if p.length > 1 then + $log.error "ropository information is too much" + end + return p[0] +end + +def get_value_from_file (file, key) + if not File.exist? file then raise RuntimeError, "file #{file} is not exist" end + regexp = Regexp.new("^[ \t]*#{key}[ \t]*=",Regexp::EXTENDED|Regexp::IGNORECASE|Regexp::MULTILINE) + File.open(file) do |f| + f.each_line do |l| + if l.strip =~ regexp then + return l.sub(regexp,"").strip + end + end + return "" + end +end + +def download_file_from_url (protocol,url) + case protocol + when "cp" then + if File.exist? url then + return url + end + when "scp" then + # url = tizen-apt:~/xxx/yyy/zzz.deb + _url = url.split(':') + domain = _url[0] # tizen-apt + location = _url[1] # ~/xxx/yyy/zzz.deb + file = _url[1].split('/')[-1] # zzz.deb + + # if find file then download it using scp + if file.empty? then + $log.error "cat't find file frome #{url} " + else + system "scp #{url} ." + end + + if File.exist? file then + return file + end + else + $log.warn "unknown download protocol #{protocol}" + end + return "" +end + diff --git a/package/.log b/package/.log new file mode 100644 index 0000000..d739a34 --- /dev/null +++ b/package/.log @@ -0,0 +1,4 @@ +# Logfile created on Mon Feb 06 23:18:31 +0900 2012 by logger.rb/22285 +I, [2012-02-06T23:18:31.266112 #30127] INFO -- : option parsing start +I, [2012-02-06T23:18:31.266200 #30127] INFO -- : option is : -u,http://172.21.111.132/testserver/unstable +I, [2012-02-06T23:18:31.266322 #30127] INFO -- : option parsing end diff --git a/package/build.linux b/package/build.linux new file mode 100755 index 0000000..ff0d3f4 --- /dev/null +++ b/package/build.linux @@ -0,0 +1,39 @@ +#!/bin/sh -x +# clean +clean() +{ + make clean + rm -rf $SRCDIR/*.zip + rm -rf $SRCDIR/*.tar.gz + rm -rf $SRCDIR/workspace/*.zip + rm -rf $SRCDIR/workspace/*_pkglist + rm -rf $SRCDIR/workspace/gcc-* + rm -rf $SRCDIR/workspace/qemu* + rm -rf $SRCDIR/workspace/scratchbox2 + rm -rf $SRCDIR/workspace/.temp + rm -rf $SRCDIR/workspace/package/data +} + +# build +build() +{ + echo; +} + +# install +install() +{ + BIN_DIR=$SRCDIR/package/image-creator.package.${BUILD_TARGET_OS}/data/SDK/build-system/image-creator/bin + DOC_DIR=$SRCDIR/package/image-creator.package.${BUILD_TARGET_OS}/data/SDK/build-system/image-creator/doc + mkdir -p $BIN_DIR + mkdir -p $DOC_DIR + cp -rf $SRCDIR/bin/* $BIN_DIR/ + cp -rf $SRCDIR/doc/* $DOC_DIR/ +} + + + +[ "$1" = "clean" ] && clean +[ "$1" = "build" ] && build +[ "$1" = "install" ] && install +exit 0 diff --git a/package/pkginfo.manifest b/package/pkginfo.manifest new file mode 100644 index 0000000..9455626 --- /dev/null +++ b/package/pkginfo.manifest @@ -0,0 +1,7 @@ +Package : image-creator +Version : 0.20.12 +OS : linux +Build-host-os : linux +Source : image-creator +Maintainer : Taejun Ha , Jiil Hyoun , Donghyuk Yang , Donghee Yang +Description : Image creator for Tizen SDK diff --git a/workspace/.sbs_config_ori b/workspace/.sbs_config_ori new file mode 100644 index 0000000..50f9ec9 --- /dev/null +++ b/workspace/.sbs_config_ori @@ -0,0 +1 @@ +GIT_REPOSITORY=taebaek:slp/tools/sbs -- 2.7.4