From: Ronan Le Martret Date: Tue, 25 Jun 2013 07:39:07 +0000 (+0200) Subject: - move spec2yocto. X-Git-Tag: rev_0.4~322 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=086bd00fd10dfc5b62e34837b44b22d919c2b054;p=scm%2Fbb%2Ftizen.git - move spec2yocto. --- diff --git a/Tizen_TZ_package/spec2yocto.py b/Tizen_TZ_package/spec2yocto.py deleted file mode 100755 index bc8f499..0000000 --- a/Tizen_TZ_package/spec2yocto.py +++ /dev/null @@ -1,1728 +0,0 @@ -#!/usr/bin/python - -# -# Copyright 2013, Intel Inc. -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; version 2 of the License. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Library General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -# -''' -Created on 05 fevr. 2013 - -@author: ronan@fridu.net -''' -import os -import errno - -RECIPES_SOURCE_DIR = os.path.dirname( os.path.realpath( __file__ ) ) -RECIPES_DIR_DEST = os.path.join( RECIPES_SOURCE_DIR, "../meta-tizen-ivi" ) -GIT_COMMAND = "git://review.tizen.org/%s;protocol=ssh;tag=%s" - -import sys -import platform - -import fcntl - -import subprocess -import shlex - -import re -import select - -import tempfile - -import ConfigParser - -# Very useful to debug spec2yocto, print the subprocess EXEC_COMMAND line. -DEBUG_RUN = False - - -class Spec2yoctoConfig( object ): - ''' - Parse the file "spec2yocto_configure", - - ''' - def __init__( self ): - self.__config_parser = ConfigParser.ConfigParser() - self.__config_file = open( os.path.join( RECIPES_SOURCE_DIR, - "TizenGroup-IVI-Wayland/spec2yocto_configure" ) - , 'rw' ) - - self.__config_parser.readfp( self.__config_file ) - - def __get_list( self, section, option, default_value ): - ''' - generic fonction to get list value. - ''' - if ( section in self.__config_parser.sections() ) and \ - ( option in self.__config_parser.options( section ) ): - tmp_res = str( self.__config_parser.get( section, option ) ) - return tmp_res.split( "," ) - else: - return default_value - - def __get_value( self, section, option, default_value ): - ''' - generic fonction to get value. - ''' - if ( section in self.__config_parser.sections() ) and \ - ( option in self.__config_parser.options( section ) ): - tmp_res = self.__config_parser.get( section, option ) - return tmp_res - else: - return default_value - - def get_recipes_sources_directory( self ): - ''' - return a list of the recipes directory needed to build the image. - ''' - return self.__get_list( 'recipes_sources', 'directory', [] ) - - def get_bb_autoreconf_blacklist( self ): - ''' - return a list of package with no autoreconf. - ''' - return self.__get_list( 'recipes_autoreconf', 'blacklist', [] ) - - def get_target_cpu( self ): - ''' - return target cpu. - ''' - return self.__get_value( 'target', 'cpu' , "" ) - - def get_ignore_depend( self ): - ''' - return the ignore package to ignore for depends (build require). - ''' - return self.__get_list( 'depends', 'ignore', [] ) - - def get_ignore_rdepend( self ): - ''' - return the ignore package to ignore for rdepends (require). - ''' - return self.__get_list( 'rdepends', 'ignore', [] ) - - def get_native_depend( self ): - ''' - some buildRequire mean depends on native package not runtime. - ''' - return self.__get_list( 'depends', 'native', [] ) - - def get_libtool_cross( self ): - ''' - some buildRequire mean depends on libtool-cross package not runtime. - ''' - return self.__get_list( 'depends', 'libtool_cross', [] ) - - def get_inherit_gettext( self ): - ''' - some buildRequire mean inherit_gettext package not depends runtime. - ''' - return self.__get_list( 'depends', 'inherit_gettext', [] ) - -SPEC2YOCTO_CONFIG = Spec2yoctoConfig() - - - - -class SubprocessCrt( object ): - ''' - usefull class to control subprocess - ''' - def __init__( self ): - ''' - Initialize subprocess. - ''' - self.output_res = "" - self.__idle_time = 0 - - def get_last_res( self ): - ''' - return the last subprocess output. - ''' - return self.output_res - - def __read_subprocess_output( self, outputs, f_stdout, f_stderr ): - ''' - read the stdout, stderr of the subprocess - ''' - timed_out = True - select_timeout = 60 - for file_d in select.select( [f_stdout, f_stderr], [], [], select_timeout )[0]: - timed_out = False - output = file_d.read() - if f_stdout == file_d: - self.output_res += output - else: - if DEBUG_RUN and ( len( output ) > 0 ): - print "ERROR ****", output, len( output ) - - for line in output.split( "\n" ): - if not line == b"" or not output.endswith( "\n" ): - outputs[file_d]["EOF"] = False - - if line == b"" and not output.endswith( "\n" ): - outputs[file_d]["EOF"] = True - elif line != "" : - res_clean = line.decode( "utf8", "replace" ).rstrip() - if DEBUG_RUN: - print res_clean - - if timed_out: - self.__idle_time += select_timeout - else: - self.__idle_time = 0 - - - - def exec_subprocess( self, command ): - ''' - Execute the "command" in a sub process, - the "command" must be a valid bash command. - _args and _kwargs are for compatibility. - ''' - - self.output_res = "" - - # need Python 2.7.3 to do shlex.split(command) - splitted_command = shlex.split( str( command ) ) - a_process = subprocess.Popen( splitted_command, - stdout = subprocess.PIPE, - stderr = subprocess.PIPE ) - f_stdout = a_process.stdout - f_stderr = a_process.stderr - - flags = fcntl.fcntl( f_stdout, fcntl.F_GETFL ) - if not f_stdout.closed: - fcntl.fcntl( f_stdout, fcntl.F_SETFL, flags | os.O_NONBLOCK ) - - flags = fcntl.fcntl( f_stderr, fcntl.F_GETFL ) - if not f_stderr.closed: - fcntl.fcntl( f_stderr, fcntl.F_SETFL, flags | os.O_NONBLOCK ) - - outputs = {f_stdout: {"EOF": False}, - f_stderr: {"EOF": False}} - - - while ( ( not outputs[f_stdout]["EOF"] and - not outputs[f_stderr]["EOF"] ) or - ( a_process.poll() == None ) ): - try: - self.__read_subprocess_output( outputs, f_stdout, f_stderr ) - except select.error as error: - # see http://bugs.python.org/issue9867 - if error.args[0] == errno.EINTR: - print "Got select.error: %s" % unicode( error ) - continue - else: - raise Exception() - - # maybe a_process.wait() is better ? - poll_res = a_process.poll() - if poll_res != 0: - return poll_res - return self.output_res - -class RePattern: - ''' - def of usefull re pattern to parse spec file. - ''' - pattern_patch = r'([pP]atch[\d]*)[\s]*:[\s]*.*' - patternUrlSourceFile = r'Source[\d]*[\s]*:[\s]*([http,ftp].*/)(.*)' - patternUrlPatchFile = r'Patch[\d]*[\s]*:[\s]*([http,ftp].*/)(.*)' - - patternPatch = r'[pP]atch([\d]*)[\s]*:[\s]*(.*)' - patternSource = r'Source([\d]*)[\s]*:[\s]*(.*)' - - patternPatchCommand = r'#(patch)([\d]*)(.*)' - - patternDescription = r'^Summary:\s*(.*)' - patternUrl = r'^Url:\s*(.*)' - patternGroup = r'^Group:\s*(.*)' - patternLicense = r'^License:\s*(.*)' - - patternFiles = r'^%files\s*(.*)' - - patternName = r'^Name:\s*(.*)' - - patternPackage = r'^%package\s*(.*)' - provides_package = r'^Provides:\s*(.*)' - - buildPkgconfig = r'pkgconfig\((.*)\).*' - - pkgRe = r'([^ \t\n\r\f\v,]+)(?:\s+(<|>|<=|>=|=|==)\s+([^ \t\n\r\f\v,]+))?' - - buildRequiresPackage = r'^BuildRequires:\s*(.*)' - requiresPackage = r'^Requires(?:\(\w+\))?:\s*(.*)' - - paternDevel = "(.*)-devel" - - def __init__( self ): - ''' - init RePattern - ''' - -def get_macro_directory_path( current_cpu ): - ''' - return all the valid macro directory. - ''' - macro_paths = "" - for macro_dir in ["lib/*", - "lib/fileattrs/*", - "lib/platform/%s-linux/macros" % current_cpu, - "lib/tizen/*", - "etc/*", - "user/.rpmmacros", - "yocto/*"]: - macro_paths += os.path.join( "/usr/share/spec2yocto/macro", macro_dir ) + " " - return macro_paths - -class SpecParser: - ''' - spec file parser - ''' - mPkgConfigDico = {} - msubprocess = SubprocessCrt() - def __init__( self, package_spec_path, package_pn = None ): - ''' - init the SpecParser - ''' - self.__introduction_section = "introduction_section" - self.__package = "%package" - self.__description = "%description" - self.__prep_flag = "%prep" - self.__build_flag = "%build" - self.__install_flag = "%install" - self.__clean_flag = "%clean" - self.__files_flag = "%files" - self.__check_flag = "%check" - self.__post_flag = "%post" - self.__preun_flag = "%preun" - self.__postun_flag = "%postun" - self.__pre_flag = "%pre" - self.__verifyscript_flag = "%verifyscript" - self.__changelog_flag = "%changelog" - self.__list_section = [self.__package, - self.__description, - self.__prep_flag, - self.__build_flag, - self.__install_flag, - self.__clean_flag, - self.__files_flag, - self.__check_flag, - self.__post_flag, - self.__preun_flag, - self.__postun_flag, - self.__pre_flag, - self.__verifyscript_flag, - self.__changelog_flag] - - self.__package_spec_path = package_spec_path - self.__package_pn = package_pn - - self.__parsed_spec_file = None - self.__order_list = [] - self.__spect_dico = {} - self.__patchs = [] - - self.__order_raw_list = [] - self.__raw_spect_dico = {} - - self.__cpu = SPEC2YOCTO_CONFIG.get_target_cpu() - self.__cpu_native = platform.machine() - - self.__convert_spec_file() - self.__parse_parsed_spec_file() - self.__base_name = self.get_name() - - def __find_patch( self ): - ''' - find the patchs of the spec file. - ''' - self.__patchs = [] - with open( self.__package_spec_path ) as file_d: - spec_file = file_d.read() - res_tmp = re.findall( RePattern.pattern_patch, spec_file ) - for a_res in res_tmp: - self.__patchs.append( a_res.replace( "Patch", "patch" ) ) - - def __is_native_build( self ): - ''' - return True if the package is native. - ''' - res_1 = ( self.__package_pn is not None ) - if not res_1: - return res_1 - - res_2 = self.__package_pn.endswith( "-native" ) - - return res_2 - - def init_rpmspec_command( self ): - ''' - init rpmspec_command to parse spec file. - ''' - rpmspec_command = "rpmspec " - - if self.__is_native_build(): - current_cpu = self.__cpu_native - else: - current_cpu = self.__cpu - - rpmspec_command += " --macros=\"%s\" " % get_macro_directory_path( current_cpu ) - - rpmspec_command += " --define='buildroot ${D}' " - if self.__is_native_build(): - # Not the better way to do this - rpmspec_command += " --define='basearch i386' " - # I guess other tool must be set for native build. - rpmspec_command += " --define='__cc gcc' " - # the default value of the macro is %{nil} - base_prefix = os.getenv( "base_prefix" ) - if ( base_prefix != "" ) and ( base_prefix is not None ): - rpmspec_command += " --define='_buildPrefix %s' " % base_prefix - - rpmspec_command += " --define='%find_lang echo no find_lang for package native'" - - rpmspec_command += " --define='setup #setup' " - rpmspec_command += " --define='setup0 #setup0' " - - package_dir = os.path.dirname( self.__package_spec_path ) - - rpmspec_command += " --define='SOURCES %s' " % package_dir - rpmspec_command += " --define='_sourcedir %s' " % package_dir - - rpmspec_command += " --define='BUILD_BASENAME %{basename}' " - - rpmspec_command += " --target='%s' " % current_cpu - # need to be change. - package_name = os.path.basename( self.__package_spec_path )[:-5] - - if package_name in SPEC2YOCTO_CONFIG.get_bb_autoreconf_blacklist() : - oe_runconf2 = '''oe_runconf2''' - rpmspec_command += " --define='%%_configure %s'" % oe_runconf2 - - return rpmspec_command - - - def __convert_spec_file( self ): - ''' - init convert spec to expand spec file. - ''' - tmp_package_spec_path = self.__package_spec_path - - # we can't use python rpm API to parse the spec file so we need to exec rpmspec\ - # in a subprocess and parse the result. - rpmspec_command = self.init_rpmspec_command() - - # it's import to remove all "Source" url because if rpm dan't find the source,\ - # it try to downloads the file from the url. - with open( tmp_package_spec_path, 'r' ) as current_spec_file: - current_spec_string = current_spec_file.read() - res_url_source_files = re.findall( RePattern.patternUrlSourceFile, current_spec_string ) - - if len( res_url_source_files ) > 0: - for res_url in res_url_source_files: - long_url = res_url[0] + res_url[1] - short_url = res_url[1] - current_spec_string = current_spec_string.replace( long_url, short_url ) - - with tempfile.NamedTemporaryFile( mode = 'w', - suffix = '.tmp', - prefix = os.path.basename( tmp_package_spec_path ) + ".", - dir = os.path.dirname( tmp_package_spec_path ), - delete = False ) as tmp_spec_file: - tmp_spec_file.write( current_spec_string ) - tmp_package_spec_path = tmp_spec_file.name - - # same case as "Source" - with open( tmp_package_spec_path, 'r' ) as current_spec_file: - current_spec_string = current_spec_file.read() - res_url_patch_file = re.findall( RePattern.patternUrlPatchFile, current_spec_string ) - - if len( res_url_patch_file ) > 0: - for res_url in res_url_patch_file: - long_url = res_url[0] + res_url[1] - short_url = res_url[1] - current_spec_string = current_spec_string.replace( long_url, short_url ) - if ( tmp_package_spec_path != self.__package_spec_path ) \ - and os.path.isfile( tmp_package_spec_path ) \ - and not DEBUG_RUN: - os.remove( tmp_package_spec_path ) - with tempfile.NamedTemporaryFile( mode = 'w', - suffix = '.tmp', - prefix = os.path.basename( tmp_package_spec_path ) + ".", - dir = os.path.dirname( tmp_package_spec_path ), - delete = False ) as tmp_spec_file: - tmp_spec_file.write( current_spec_string ) - tmp_package_spec_path = tmp_spec_file.name - - self.__find_patch() - - for a_patch in self.__patchs: - if a_patch == "patch0": - rpmspec_command += " --define='%patch #patch' " - - rpmspec_command += " --define='%s #%s' " % ( a_patch, a_patch ) - - rpmspec_command += " --define='debug_package %{nil}'" - - rpmspec_command += " --parse %s " % tmp_package_spec_path - if DEBUG_RUN: - print "rpmspec_command :", rpmspec_command - - - self.__parsed_spec_file = SpecParser.msubprocess.exec_subprocess( rpmspec_command ) - if ( tmp_package_spec_path != self.__package_spec_path ) \ - and os.path.isfile( tmp_package_spec_path ) \ - and not DEBUG_RUN: - os.remove( tmp_package_spec_path ) - - if self.__parsed_spec_file == 1: - print >> sys.stderr, "parse error for spec file %s" % ( tmp_package_spec_path ) - self.__parsed_spec_file = None - return 1 - - if DEBUG_RUN: - if self.__package_pn is None: - tmp_path = os.path.basename( self.__package_spec_path ) - package_parsed_spec_path = os.path.join( "/tmp/parsed_spec", tmp_path ) - else: - tmp_path = "%s.spec" % self.__package_pn - package_parsed_spec_path = os.path.join( "/tmp/parsed_spec", tmp_path ) - - with open( package_parsed_spec_path, "w" ) as file_d: - file_d.write( self.__parsed_spec_file ) - - - def __test_section( self, line ): - ''' - test if the line is the start of a new section. - ''' - for sect in self.__list_section: - if line.startswith( sect ): - return True - return False - - def __parse_parsed_spec_file( self ): - ''' - parse a spec file by section after rpmspec. - ''' - # ordered dico is not provide yet... - self.__order_list = [] - self.__spect_dico = {} - - current_section = self.__introduction_section - self.__spect_dico[current_section] = [] - self.__order_list.append( current_section ) - - if self.__parsed_spec_file is None: - return 1 - - for line in self.__parsed_spec_file.split( "\n" ): - - if self.__test_section( line ) : - if line in self.__spect_dico.keys(): - print "line %s" % line - print "--------------------------------------" - print "parsedSpecFile: %s" % self.__package_spec_path - print "--------------------------------------" - error_msg = "ERROR for the spec file \"%s\" this section \"%s\" is not unique." - print error_msg % ( self.__parsed_spec_file, line ) - # raise Exception() - - current_section = line - self.__spect_dico[current_section] = [] - self.__order_list.append( current_section ) - - self.__spect_dico[current_section].append( line ) - - def parse_raw_spec_file( self ): - ''' - parse a spec file by section before rpmspec. - ''' - # need to be rewrite - # ordered dico is not provide yet... - self.__order_raw_list = [] - self.__raw_spect_dico = {} - - current_section = self.__introduction_section - self.__raw_spect_dico[current_section] = [] - self.__order_raw_list.append( current_section ) - - with open( self.__package_spec_path, "r" ) as file_d: - parsed_raw_spec_file = file_d.read() - - for line in parsed_raw_spec_file.split( "\n" ): - if self.__test_section( line ) : - if line in self.__raw_spect_dico.keys(): - print "line %s" % line - print "--------------------------------------" - print "parsedSpecFile: %s" % self.__package_spec_path - print "--------------------------------------" - error_msg = "ERROR for the spec file \"%s\" this section \"%s\" is not unique." - print error_msg % ( self.__parsed_spec_file, line ) - raise Exception() - - current_section = line - self.__raw_spect_dico[current_section] = [] - self.__order_raw_list.append( current_section ) - - self.__raw_spect_dico[current_section].append( line ) - - - def get_prep_section( self ): - ''' - return the prep section of the spec file. - ''' - res_prep_section = "" - - pattern_patch_dico = {} - pattern_source_dico = {} - - for line in self.__spect_dico[self.__introduction_section][1:]: - for patch_id, files_name in re.findall( RePattern.patternPatch, line ): - if patch_id == "": - patch_id = "0" - pattern_patch_dico[patch_id] = files_name - - for source_id, files_name in re.findall( RePattern.patternSource, line ): - if source_id == "": - source_id = "0" - pattern_source_dico[source_id] = files_name - - for line in self.__spect_dico[self.__prep_flag][1:]: - if line.startswith( "#setup" ): - splited_line = line.split() - for i in range( len( splited_line ) ): - if splited_line[i].startswith( "-a" ): - if len( splited_line[i] ) > len( "-a" ): - setup_id = splited_line[i].replace( "-a", "" ) - else: - setup_id = splited_line[i + 1] - res_prep_section += "#extracte source %s \n" % setup_id - res_prep_section += "pushd ${S}\n" - source = os.path.basename( pattern_source_dico[setup_id] ) - # not a good way to do this - if source.endswith( "rpmlintrc" ): - res_prep_section += "cp ${PACKAGING}/packaging/%s .\n" % source - else: - file_name = os.path.basename( pattern_source_dico[setup_id] ) - res_prep_section += "unp ${PACKAGING}/packaging/%s \n" % file_name - res_prep_section += "popd \n" - - elif splited_line[i].startswith( "-b" ): - if len( splited_line[i] ) > len( "-b" ): - setup_id = splited_line[i].replace( "-b", "" ) - else: - setup_id = splited_line[i + 1] - - res_prep_section += "#extracte source %s \n" % ( setup_id ) - res_prep_section += "pushd ${S}/../\n" - source = os.path.basename( pattern_source_dico[setup_id] ) - if source.endswith( "rpmlintrc" ): - res_prep_section += "cp ${PACKAGING}/packaging/%s .\n" % source - else: - res_prep_section += "unp ${PACKAGING}/packaging/%s \n" % source - res_prep_section += "popd \n" - - res_prep_section += "chmod -Rf a+rX,u+w,g-w,o-w ${PACKAGING}\n" - - - elif line.startswith( "#patch" ): - res_findall = re.findall( RePattern.patternPatchCommand, line ) - # should be rewrite - for patch_name, patch_id, EXEC_COMMAND in res_findall: - if patch_id == '': - patch_id = "0" - - files_name = pattern_patch_dico[patch_id] - - if "-p" not in EXEC_COMMAND: - EXEC_COMMAND += " -p0" - - if files_name.endswith( ".bz2" ): - bzcat_cmd = "bzcat ${PACKAGING}/packaging/%s | patch -s %s --fuzz=2\n" - bzcat_val = ( files_name, EXEC_COMMAND.replace( " -b", " -b --suffix" ) ) - res_prep_section += bzcat_cmd % bzcat_val - else: - cat_cmd = "cat ${PACKAGING}/packaging/%s | patch -s %s --fuzz=2\n" - cat_val = ( files_name, EXEC_COMMAND.replace( " -b", " -b --suffix" ) ) - res_prep_section += cat_cmd % cat_val - - res_prep_section += line + "\n" - return res_prep_section - - def get_build_section( self ): - ''' - return the build section of the spec file. - ''' - res_build_section = "" - if self.__build_flag not in self.__spect_dico.keys(): - return 1 - - for line in self.__spect_dico[self.__build_flag][1:]: - if ( "mkdir" in line ) and ( not "-p" in line ): - line = line.replace( "mkdir", "mkdir -p" ) - res_build_section += line + "\n" - - return res_build_section - - def get_raw_build_section( self ): - ''' - return the raw build section of the spec file. - ''' - res_raw_build_section = "" - if self.__build_flag not in self.__spect_dico.keys(): - return "" - for line in self.__raw_spect_dico[self.__build_flag][1:]: - res_raw_build_section += line + "\n" - return res_raw_build_section - - def get_clean_raw( self ): - ''' - clean the raw spec file to generate spec file for yocto packaging. - ''' - - res_clean_raw = "" - for sect in self.__order_raw_list: - if sect == self.__introduction_section: - for line in self.__raw_spect_dico[sect]: - have_findall_source = len( re.findall( RePattern.patternSource , line ) ) > 0 - have_findall_patch = len( re.findall( RePattern.patternPatch, line ) ) > 0 - if not( have_findall_source or have_findall_patch ): - res_clean_raw += line + "\n" - - elif sect == self.__prep_flag: - res_clean_raw += line + "%prep\n" - res_clean_raw += line + "#FAKE\n" - elif sect == self.__build_flag: - res_clean_raw += line + "%build\n" - res_clean_raw += line + "#FAKE\n" - elif sect == self.__install_flag: - res_clean_raw += line + "%install\n" - res_clean_raw += line + "#FAKE\n" - elif sect == self.__clean_flag: - pass - elif sect == self.__changelog_flag: - pass - - elif sect.startswith( "%files" ): - for line in self.__raw_spect_dico[sect]: - if line.startswith( '%manifest ' ): - pass - elif line.startswith( '%doc ' ): - pass - elif line.startswith( '%ghost ' ): - pass - elif line.startswith( '%exclude ' ): - pass - else: - res_clean_raw += line + "\n" - - else: - for line in self.__raw_spect_dico[sect]: - res_clean_raw += line + "\n" - - clean_raw_command = self.init_rpmspec_command() - - tmp_package_spec_path = self.__package_spec_path - with tempfile.NamedTemporaryFile( mode = 'w', - suffix = '.tmp', - prefix = os.path.basename( tmp_package_spec_path ) + ".", - dir = os.path.dirname( tmp_package_spec_path ), - delete = False ) as tmp_spec_file: - tmp_spec_file.write( res_clean_raw ) - tmp_package_spec_path = tmp_spec_file.name - - clean_raw_command += " --define='debug_package %{nil}'" - clean_raw_command += " --define='docs_package %{nil}'" - - clean_raw_command += " --parse %s " % tmp_package_spec_path - if DEBUG_RUN: - print "clean_raw_command :", clean_raw_command - - parsed_spec_file = SpecParser.msubprocess.exec_subprocess( clean_raw_command ) - - if os.path.isfile( tmp_package_spec_path ) and not DEBUG_RUN: - os.remove( tmp_package_spec_path ) - - if parsed_spec_file == 1: - print >> sys.stderr, "parse error for spec file %s" % ( tmp_package_spec_path ) - parsed_spec_file = None - return 1 - - fake_dbg = ''' -%%package -n %s-dbg -Summary: #FAKE - Debugging files -Group: devel - -%%description -n %s-dbg -#FAKE - - -%%files -n %s-dbg -%%defattr(-,-,-,-) -''' % ( self.__base_name, self.__base_name, self.__base_name ) - work_dir = os.getenv( "WORKDIR" ) - - if work_dir is None: - return parsed_spec_file - - base_root = os.path.join( work_dir, "package" ) - for root, dirs, files in os.walk( base_root ): - if root.endswith( ".debug" ): - if DEBUG_RUN: - print "find directory %s " % dirs - for a_file in files: - fake_dbg += os.path.join( root, a_file ).replace( base_root, "" ) + "\n" - - return parsed_spec_file + fake_dbg - - def have_macro_configure( self ): - ''' - return the number of macro %configure used inn the spec file. - ''' - res_macro_configure = 0 - raw_build_section = self.get_raw_build_section() - configure_count = raw_build_section.count( "%configure" ) - res_macro_configure += configure_count - return res_macro_configure - - def have_macro_reconfigure( self ): - ''' - return the number of macro %reconfigure used inn the spec file. - ''' - res_have_macro_reconfigure = 0 - raw_build_section = self.get_raw_build_section() - reconfigure_count = raw_build_section.count( "%reconfigure" ) - - res_have_macro_reconfigure += reconfigure_count - return res_have_macro_reconfigure - - def get_install_section( self ): - ''' - return the install section. - ''' - res_install_section = "" - - for line in self.__spect_dico[self.__install_flag][1:]: - res_install_section += line + "\n" - return res_install_section - - def get_description( self ): - ''' - return the description of the spec file. - ''' - for line in self.__spect_dico[self.__introduction_section] : - description = re.findall( RePattern.patternDescription, line ) - if len( description ) > 0: - return description[0] - return "" - - def get_homepage( self ): - ''' - return the homepage of the spec file project. - ''' - for line in self.__spect_dico[self.__introduction_section] : - description = re.findall( RePattern.patternUrl, line ) - if len( description ) > 0: - return description[0] - return "" - - def get_section( self ): - ''' - return the section of the spec file project. - ''' - for line in self.__spect_dico[self.__introduction_section] : - description = re.findall( RePattern.patternGroup, line ) - if len( description ) > 0: - return description[0] - return "System/Base" - - def get_license( self ): - ''' - return the licence of the package. - ''' - for line in self.__spect_dico[self.__introduction_section] : - description = re.findall( RePattern.patternLicense, line ) - if len( description ) > 0: - res_license = description[0] - if ";" in res_license: - res_license = res_license.replace( ";", "" ) - - if res_license in ["MIT/X11", 'X11/MIT']: - res_license = "MIT" - elif res_license in ['LGPLv2, AFLv2']: - res_license = 'LGPLv2' - elif res_license in ["Apache License, Version 2.0"]: - res_license = 'Apache' - elif res_license in ["AFL/GPL"]: - res_license = 'GPLv2+ or AFL' - return res_license - return "" - - def get_file_section_key( self ): - ''' - return the list of file section of the spec file. - ''' - res_file_list = [] - for section_key in self.__spect_dico.keys(): - # should use re. - if section_key.startswith( "%files" ): - res_file_list.append( section_key ) - return res_file_list - - def get_files_list_from_section( self, package_section_name ): - ''' - return a list of file - ''' - res_list = [] - for line in self.__spect_dico[package_section_name][1:]: - if not line.startswith( "%" ) and not line == "": - line = line.replace( "//", "/" ) - res_list.append( line ) - elif line.startswith( "%doc " ): - line = line.replace( "//", "/" ) - res_list.append( line.replace( "%doc ", "" ) ) - elif line.startswith( "%dir " ): - line = line.replace( "//", "/" ) - res_list.append( line.replace( "%dir ", "" ) ) - elif line.startswith( "%config " ): - line = line.replace( "//", "/" ) - res_list.append( line.replace( "%config ", "" ) ) - elif line.startswith( "%manifest " ): - line = line.replace( "//", "/" ) - res_list.append( line.replace( "%manifest ", "" ) ) - elif line.startswith( "%config(noreplace) " ): - line = line.replace( "//", "/" ) - res_list.append( line.replace( "%config(noreplace) ", "" ) ) - else: - pass - return res_list - - def get_files_packages( self ): - ''' - return a dictinaire with package for key and list of files fo value. - ''' - res_dico = {} - - for package_section_name in self.get_file_section_key(): - tmp_package_name = package_section_name - # Need to get info of the first line. - if "-f" in tmp_package_name: - tmp_split = tmp_package_name.split( "-f" ) - tmp_package_name = tmp_split[0] - - package = re.findall( RePattern.patternFiles, tmp_package_name ) - if len( package ) > 0: - if "-n " in package[0]: - package_name = package[0].replace( "-n", "" ) - else: - package_name = self.__base_name - pkg_ext = package[0].replace( " ", "" ) - if len( pkg_ext ) > 0: - package_name += "-" + pkg_ext - else: - package_name = self.__base_name - - package_name = package_name.replace( " ", "" ) - res_files_list = self.get_files_list_from_section( package_section_name ) - res_dico[ package_name ] = res_files_list - - return res_dico - - def get_name( self ): - ''' - return the name of the package - ''' - for line in self.__spect_dico[self.__introduction_section]: - description = re.findall( RePattern.patternName, line ) - if len( description ) > 0: - return description[0] - return "" - - def get_provides( self ): - ''' - return all provide service by each package of the spec file. - ''' - provide_res = {} - provide_res[self.__base_name] = [] - provide_res[self.__base_name].append( [self.__base_name] ) - - for k in self.__spect_dico.keys(): - package = re.findall( RePattern.patternPackage, k ) - if len( package ) > 0: - package_name = self.__clean_package_name( package[0] ) - provide_res[ package_name ] = [] - provide_res[ package_name ].append( [package_name] ) - - if len( package ) > 0 or ( k == self.__introduction_section ): - for line in self.__spect_dico[k]: - provides = re.findall( RePattern.provides_package, line ) - for provides_line in provides: - for tmp_clean in self.__clean_package_line( provides_line ): - if k == self.__introduction_section: - provide_res[self.__base_name].append( tmp_clean ) - else: - provide_res[package_name].append( tmp_clean ) - return provide_res - - def __clean_package_name( self, package_name ): - ''' - return the package name from spec declaration. - ''' - # re should be better. - if "-n " in package_name: - package_name = package_name.replace( "-n", "" ).replace( " ", "" ) - else: - package_name = self.__base_name + "-" + package_name - - return package_name - - def get_rdepends( self ): - ''' - return all require service by each package of the spec file. - ''' - rdepends_res = {} - - for k in self.__spect_dico.keys(): - package = re.findall( RePattern.patternPackage, k ) - - if len( package ) > 0: - package_name = self.__clean_package_name( package[0] ) - else: - package_name = self.__base_name - - if len( package ) > 0 or ( k == self.__introduction_section ): - requires_list = self.get_requires( self.__spect_dico[k] ) - rdepends_res[package_name] = requires_list - return rdepends_res - - - def get_depends( self ): - ''' - return all build require service by each package of the spec file. - ''' - depends_res = {} - - for k in self.__spect_dico.keys(): - package = re.findall( RePattern.patternPackage, k ) - if len( package ) > 0: - package_name = self.__clean_package_name( package[0] ) - - if len( package ) > 0 or ( k == self.__introduction_section ): - build_requires_list = self.get_build_requires( self.__spect_dico[k] ) - if ( k == self.__introduction_section ): - depends_res[self.__base_name] = build_requires_list - else: - depends_res[package_name] = build_requires_list - - return depends_res - - def __clean_package_line( self, package_line ): - ''' - return package list from package declaration in spec file. - ''' - res_first = re.findall( RePattern.pkgRe, package_line ) - if len( res_first ) == 0: - print "__clean_package_line faild for %s" % self.__package_spec_path - raise Exception() - # should be rewrite cleaner. - res_final = [] - for init_res in res_first: - init_res = list( init_res ) - init_res[0] = init_res[0].replace( ",", "" ) - res_re = re.findall( RePattern.buildPkgconfig, init_res[0] ) - if len( res_re ) > 0: - for pkg in SpecParser.mPkgConfigDico.keys(): - if res_re[0] in SpecParser.mPkgConfigDico[pkg]: - init_res[0] = pkg - break - else: - init_res[0] = res_re[0] - res_final.append( init_res ) - return res_final - - def get_build_requires( self, lines ): - ''' - return the line of every build requires. - ''' - build_requires_res = [] - for line in lines: - build_requires = re.findall( RePattern.buildRequiresPackage, line ) - for tmp_res in build_requires: - for tmp_clean in self.__clean_package_line( tmp_res ): - if len( tmp_clean ) >= 1: - build_requires_res.append( tmp_clean ) - return build_requires_res - - def get_requires( self, lines ): - ''' - return the line of every requires. - ''' - requires_res = [] - for line in lines: - build_requires = re.findall( RePattern.requiresPackage, line ) - for tmp_res in build_requires: - for tmp_clean in self.__clean_package_line( tmp_res ): - if len( tmp_clean ) >= 1: - requires_res.append( tmp_clean ) - - return requires_res - -class MetaSpec: - ''' - meta spec file for generate yocto bb. - ''' - mProvidesDico = {} - mExtraRProvidesDico = {} - - mCrossPackageBlacklist = [] - mInitialPackageBlacklist = [] - mNativePackageBlacklist = [] - mOePackageBlacklist = [] - - def __init__( self, - package_recipes_dir, - package_name, - package_spec_path, - package_git_command, - package_git_tag ): - ''' - init the MetaSpec class - ''' - self.__package_recipes_dir = package_recipes_dir - self.__package_name = package_name - self.__package_git_command = package_git_command - self.__package_spec_path = package_spec_path - self.__git_tag = package_git_tag - - self.__spec_parser = SpecParser( self.__package_spec_path ) - - self.__packages_dico = self.__spec_parser.get_files_packages() - self.__provides_dico = self.__spec_parser.get_provides() - self.setm_provided_dico() - self.__rdepends_dico = self.__spec_parser.get_rdepends() - - self.__base_file = self.__package_name + ".inc" - self.__base_depends_file = self.__package_name + "-depends.inc" - self.__base_rdepends_file = self.__package_name + "-rdepends.inc" - self.__base_provides_file = self.__package_name + "-rprovides.inc" - - self.__extra_conf_file = self.__package_name + "-extraconf.inc" - self.__extra_native_conf_file = self.__package_name + "-native-extraconf.inc" - self.__extra_oe_conf_file = self.__package_name + "-oe-extraconf.inc" - - self.__git_native_file = self.__package_name + "-native_git.bb" - self.__git_oe_file = self.__package_name + "_git.bb" - - self.__createRecipes() - - def setm_provided_dico( self ): - ''' - add provides_list for package_name to mProvidesDico - ''' - provides_list = [] - for k_provide in self.__provides_dico.keys(): - for p_provide in self.__provides_dico[k_provide]: - provides_list.append( p_provide[0] ) - for p_provide in self.__packages_dico.keys(): - provides_list.extend( self.__packages_dico[p_provide] ) - MetaSpec.mProvidesDico[self.__package_name] = provides_list - - def set_mextra_provided_dico( self ): - ''' - add provides_list for package_name to mExtraRProvidesDico - ''' - provides_list = [] - for k_provide in self.__provides_dico.keys(): - for p_provide in self.__provides_dico[k_provide]: - provides_list.append( p_provide[0] ) - for p_provide in self.__packages_dico.keys(): - provides_list.extend( self.__packages_dico[p_provide] ) - - MetaSpec.mExtraRProvidesDico[self.__package_name] = provides_list - - def __create_base_file( self ): - ''' - create the base file of the bb file. - ''' - bb_path = os.path.join( self.__package_recipes_dir, self.__base_file ) - with open( bb_path, "w" ) as file_d: - - _description = self.__spec_parser.get_description() - _homepage = self.__spec_parser.get_homepage() - _section = self.__spec_parser.get_section() - _priority = "10" - _license = self.__spec_parser.get_license() - - file_d.write( "DESCRIPTION = \"%s\"\n" % _description ) - if len( _homepage ) < 2: - _homepage = "http://nohomepage.org" - file_d.write( "HOMEPAGE = \"%s\"\n" % _homepage ) - file_d.write( "SECTION = \"%s\"\n" % _section ) - - file_d.write( "LICENSE = \"%s\"\n" % _license ) - file_d.write( "\n" ) - - file_d.write( "PROVIDES = \"\"\n" ) - file_d.write( "\n" ) - - file_d.write( "PACKAGES = \"\"\n" ) - for package in self.__packages_dico.keys(): - file_d.write( "PACKAGES += \"%s\"\n" % package ) - file_d.write( "\n" ) - package_name = self.__spec_parser.get_name() - - for package in self.__packages_dico.keys(): - file_d.write( "%s_files = \"\"\n" % package ) - if "-debugsource" in package: - file_d.write( "%s_files += \"%s\"\n" % ( package, "/usr/src/debug" ) ) - elif "-debuginfo" in package: - file_d.write( "%s_files += \"%s\"\n" % ( package, "/usr/bin/.debug" ) ) - file_d.write( "%s_files += \"%s\"\n" % ( package, "/bin/.debug" ) ) - file_d.write( "%s_files += \"%s\"\n" % ( package, "/lib/.debug" ) ) - file_d.write( "%s_files += \"%s\"\n" % ( package, "/usr/lib/.debug" ) ) - file_d.write( "%s_files += \"%s\"\n" % ( package, "/sbin/.debug" ) ) - file_d.write( "%s_files += \"%s\"\n" % ( package, "/usr/sbin/.debug" ) ) - elif "-docs" in package: - file_d.write( "%s_files += \"%s\"\n" % ( package, "/usr/share/info" ) ) - file_d.write( "%s_files += \"%s\"\n" % ( package, "/usr/share/man" ) ) - - for pkg_f in self.__packages_dico[package]: - file_d.write( "%s_files += \"%s\"\n" % ( package, pkg_f ) ) - file_d.write( "\n" ) - - for package in self.__packages_dico.keys(): - p_parse = package.replace( package_name, "${PN}" ) - file_d.write( "FILES_%s = \"${%s_files}\"\n" % ( p_parse, package ) ) - - file_d.write( "\n" ) - spec_path = os.path.basename( self.__package_spec_path ) - file_d.write( "SPECFILES = \"packaging/%s\"\n" % spec_path ) - file_d.write( "\n" ) - - file_d.write( "SRC_URI = \"\"\n" ) - file_d.write( "\n" ) - - file_d.write( "inherit tizenBuildUtils\n" ) - file_d.write( "\n" ) - - file_d.write( "S = \"${WORKDIR}/git\"\n" ) - file_d.write( "\n" ) - - file_d.write( "require %s\n" % self.__base_rdepends_file ) - file_d.write( "require %s\n" % self.__base_depends_file ) - file_d.write( "require %s\n" % self.__extra_conf_file ) - - def __create_provides_file( self ): - ''' - generate provide file. - ''' - provide_path = os.path.join( self.__package_recipes_dir, self.__base_provides_file ) - with open( provide_path, "w" ) as file_d: - - for k_provide in self.__provides_dico.keys(): - if len( self.__provides_dico[k_provide] ) > 0: - file_d.write( "#PROVIDES by %s \n" % k_provide ) - - for p_provide in self.__provides_dico[k_provide]: - pkg = p_provide[0] - if not len( p_provide ) == 1: - provide_text = "# the PROVIDES rules is ignore \"%s %s %s\"\n" - file_d.write( provide_text % ( pkg, p_provide[1], p_provide[2] ) ) - - if ( pkg == "mktemp" and self.__package_name == "tizen-coreutils" ): - continue - - file_d.write( "PROVIDES += \"%s\"\n" % ( pkg ) ) - file_d.write( "RPROVIDES_%s += \"%s\"\n" % ( k_provide, pkg ) ) - - for res_pkg_devel in re.findall( RePattern.paternDevel, pkg ): - rprovide_text = "RPROVIDES_%s += \"%s\"\n" - file_d.write( rprovide_text % ( k_provide, res_pkg_devel + "-dev" ) ) - - if len( self.__provides_dico[k_provide] ) > 0: - file_d.write( "\n" ) - - - def __create_git_native_file( self ): - ''' - create bb native file. - ''' - bb_native_path = os.path.join( self.__package_recipes_dir, self.__git_native_file ) - with open( bb_native_path, "w" ) as file_d: - file_d.write( "require %s\n" % self.__base_file ) - file_d.write( "\n" ) - file_d.write( "PRIORITY = \"9\"\n" ) - file_d.write( "\n" ) - file_d.write( "inherit native\n" ) - file_d.write( "\n" ) - file_d.write( "S = \"${WORKDIR}/git\"\n" ) - file_d.write( "\n" ) - - md5_value = "801f80980d171dd6425610833a22dbe6" - file_value = "${COMMON_LICENSE_DIR}/GPL-2.0" - file_chksum_text = "LIC_FILES_CHKSUM ??= \"file://%s;md5=%s\"\n" - # should be generat - file_d.write( file_chksum_text % ( file_value, md5_value ) ) - file_d.write( "\n" ) - command_source = "SRC_URI += \"%s\"\n" % GIT_COMMAND - file_d.write( command_source % ( self.__package_git_command, self.__git_tag ) ) - file_d.write( "require %s\n" % self.__extra_native_conf_file ) - file_d.write( "\n" ) - - def __create_git_oe_file( self ): - ''' - generate bb file. - ''' - bb_path = os.path.join( self.__package_recipes_dir, self.__git_oe_file ) - with open( bb_path, "w" ) as file_d: - file_d.write( "require %s\n" % self.__base_file ) - file_d.write( "require %s\n" % self.__base_provides_file ) - file_d.write( "\n" ) - file_d.write( "PRIORITY = \"10\"\n" ) - file_d.write( "\n" ) - md5_value = "801f80980d171dd6425610833a22dbe6" - file_value = "${COMMON_LICENSE_DIR}/GPL-2.0" - file_chksum_text = "LIC_FILES_CHKSUM ??= \"file://%s;md5=%s\"\n" - # should be generat - file_d.write( file_chksum_text % ( file_value, md5_value ) ) - file_d.write( "\n" ) - command_source = "SRC_URI += \"" + GIT_COMMAND + "\"\n" - file_d.write( command_source % ( self.__package_git_command, self.__git_tag ) ) - file_d.write( "require %s\n" % self.__extra_oe_conf_file ) - file_d.write( "\n" ) - - def __createRecipes( self ): - ''' - generate all bb file. - ''' - if self.__package_recipes_dir is None: - return - - if not os.path.isdir( self.__package_recipes_dir ): - os.mkdir( self.__package_recipes_dir ) - - # Just touch a file - rdepends_path = os.path.join( self.__package_recipes_dir, self.__base_rdepends_file ) - open( rdepends_path, "a" ).close() - depends_path = os.path.join( self.__package_recipes_dir, self.__base_depends_file ) - open( depends_path, "a" ).close() - provides_path = os.path.join( self.__package_recipes_dir, self.__base_provides_file ) - open( provides_path, "a" ).close() - - extra_conf_file_path = os.path.join( self.__package_recipes_dir, self.__extra_conf_file ) - open( extra_conf_file_path, "a" ).close() - - extranative_path = os.path.join( self.__package_recipes_dir, self.__extra_native_conf_file ) - open( extranative_path, "a" ).close() - extra_oe_conf_path = os.path.join( self.__package_recipes_dir, self.__extra_oe_conf_file ) - open( extra_oe_conf_path, "a" ).close() - - self.__create_base_file() - - if self.__package_name not in MetaSpec.mNativePackageBlacklist: - self.__create_git_native_file() - else: - bb_native_path = os.path.join( self.__package_recipes_dir, self.__git_native_file ) - if os.path.isfile( bb_native_path ): - os.unlink( bb_native_path ) - - self.__create_provides_file() - - if self.__package_name not in MetaSpec.mOePackageBlacklist: - self.__create_git_oe_file() - else: - bb_oe_path = os.path.join( self.__package_recipes_dir, self.__git_oe_file ) - if os.path.isfile( bb_oe_path ): - os.unlink( bb_oe_path ) - - def create_rdepends( self ): - ''' - generate rdepends file. - ''' - if self.__package_recipes_dir is None: - return - - if not os.path.isdir( self.__package_recipes_dir ): - os.mkdir( self.__package_recipes_dir ) - - rdepends_path = os.path.join( self.__package_recipes_dir, self.__base_rdepends_file ) - with open( rdepends_path, "w" ) as file_d: - file_d.write( "RDEPENDS = \"\"\n" ) - - for k_provide in self.__rdepends_dico.keys(): - res_rdepends = set() - if len( self.__rdepends_dico[k_provide] ) > 0: - file_d.write( "#RDEPENDS of %s \n" % k_provide ) - - for provide in self.__rdepends_dico[k_provide]: - package_provide = provide[0] - - res = None - - for k_package_provide in MetaSpec.mExtraRProvidesDico.keys(): - - if package_provide in MetaSpec.mExtraRProvidesDico[k_package_provide] \ - or package_provide == k_package_provide: - res = k_package_provide - break - if res is None: - res = package_provide - - res_rdepends.add( res ) - - for pkg in res_rdepends: - res_pkg_devel = re.findall( RePattern.paternDevel, pkg ) - - if len( res_pkg_devel ) > 0: - rdepends_value = "RDEPENDS_%s += \"%s\"\n" - file_d.write( rdepends_value % ( k_provide, res_pkg_devel[0] + "-dev" ) ) - else: - if not pkg in SPEC2YOCTO_CONFIG.get_ignore_rdepend(): - file_d.write( "RDEPENDS_%s += \"%s\"\n" % ( k_provide, pkg ) ) - - if len( self.__rdepends_dico[k_provide] ) > 0: - file_d.write( "\n" ) - - file_d.write( "\n" ) - - def create_all_depends( self ): - ''' - create rdepends and depends file. - ''' - self.create_rdepends() - self.create_depends() - - def create_depends( self ): - ''' - create depends file. - ''' - if self.__package_recipes_dir is None: - return - - if not os.path.isdir( self.__package_recipes_dir ): - os.mkdir( self.__package_recipes_dir ) - - depends_dico = self.__spec_parser.get_depends() - depends_path = os.path.join( self.__package_recipes_dir, self.__base_depends_file ) - with open( depends_path, "w" ) as file_d: - file_d.write( "DEPENDS = \"\"\n" ) - - res_depends = set() - for k_provide in depends_dico.keys(): - if len( depends_dico[k_provide] ) > 0: - file_d.write( "#DEPENDS of %s \n" % k_provide ) - - for p_provide in depends_dico[k_provide]: - pp_provide = p_provide[0] - - res = None - for k in MetaSpec.mProvidesDico.keys(): - if pp_provide in MetaSpec.mProvidesDico[k] or pp_provide == k: - res = k - break - if res is None: - erro_msg = "No direct provider for package DEPENDS %s : %s" - print erro_msg % ( self.__package_name, pp_provide ) - res = pp_provide - if res != self.__package_name : - res_depends.add( res ) - - # should be from a configue file. - for res in res_depends: - if res in SPEC2YOCTO_CONFIG.get_inherit_gettext(): - file_d.write( "#Replace \"DEPENDS\" on gettext by \"inherit gettext\"\n" ) - file_d.write( "inherit gettext\n" ) - elif res in SPEC2YOCTO_CONFIG.get_native_depend(): - file_d.write( "DEPENDS += \"%s-native\"\n" % res ) - elif res in SPEC2YOCTO_CONFIG.get_ignore_depend(): - pass - elif res in SPEC2YOCTO_CONFIG.get_libtool_cross(): - file_d.write( "DEPENDS += \"libtool-cross\"\n" ) - else: - file_d.write( "DEPENDS += \"%s\"\n" % res ) - - -class PackagesCollection: - ''' - class for all package in a distro. - ''' - def __init__( self ): - ''' - init PackagesCollection. - ''' - self.__recipes_source_dir = RECIPES_SOURCE_DIR - self.__recipes_list = SPEC2YOCTO_CONFIG.get_recipes_sources_directory() - self.__init_package_provide_dico() - self.__recipes_dir_dest = os.path.join( RECIPES_DIR_DEST, "recipes-tizen" ) - if not os.path.isdir( self.__recipes_dir_dest ): - os.mkdir( self.__recipes_dir_dest ) - - self.__meta_spec_dico = {} - self.__meta_spec_boot_strap_dico = {} - self.__init_package() - self.__init_depends() - - def save_package_provided_file( self ): - ''' - save all provided file. - ''' - package_provided_path = os.path.join( self.__recipes_source_dir, "package-provided" ) - # init package_provided_file - with open( package_provided_path, "w" ) as package_provided_file: - for k in MetaSpec.mProvidesDico.keys(): - provided_val = "%s::::%s\n" % ( k, " ".join( MetaSpec.mProvidesDico[k] ) ) - package_provided_file.write( provided_val ) - - pkg_extra_rprovided_path = os.path.join( self.__recipes_source_dir, - "package-Extra-rprovided" ) - # init package_provided_file - with open( pkg_extra_rprovided_path, "w" ) as package_extra_rprovided_file: - for k in MetaSpec.mExtraRProvidesDico.keys(): - extra_rprovides_text = "%s::::%s\n" - extra_rprovides_value = ( k, " ".join( MetaSpec.mExtraRProvidesDico[k] ) ) - package_extra_rprovided_file.write( extra_rprovides_text % extra_rprovides_value ) - - - def __init_package_provide_dico( self ): - ''' - init package_provide_dico - ''' - for recipes_dir in self.__recipes_list: - pkgconfig_provider_path = os.path.join( RECIPES_SOURCE_DIR, - recipes_dir, - "pkgconfigProvider" ) - with open( pkgconfig_provider_path, "r" ) as package_provide_file: - for line in package_provide_file: - pkgline = line.replace( "\n", "" ).split( "::::" ) - - SpecParser.mPkgConfigDico[pkgline[0]] = pkgline[1].split() - - def __init_package( self ): - ''' - init package - ''' - for recipe_dir in self.__recipes_list: - self.__init_meta_spec_dico( recipe_dir ) - - def __list_package( self, recipes_dir_dest, specfile_dir, package_config, meta_spec_dico ): - ''' - create a dico for all package. - ''' - with open( package_config, "r" ) as file_d: - for line in file_d: - line = line.replace( "\n", "" ) - pkg_name, pkg_spec_initial, pkg_git_command, pkg_git_tag = line.split() - package_spec_path = os.path.join( specfile_dir, pkg_spec_initial ) - if os.path.isfile( package_spec_path ): - package_recipes_dir = os.path.join( recipes_dir_dest, pkg_name ) - - meta_spec_dico[pkg_name] = MetaSpec( package_recipes_dir, - pkg_name, - package_spec_path, - pkg_git_command, - pkg_git_tag ) - else: - print "package_spec_path :\"%s\" not exist" % package_spec_path - - def __init_meta_spec_dico( self, recipe_dir ): - ''' - init meta_spec_dico. - ''' - if not os.path.isdir( os.path.join( self.__recipes_source_dir, recipe_dir ) ): - return - spec_file_dir = os.path.join( self.__recipes_source_dir, - recipe_dir, - "specfile-initial" ) - package_git_sources = os.path.join( self.__recipes_source_dir, - recipe_dir, - "package-git-config" ) -# packageConfigBootstrap=os.path.join(self.__recipes_source_dir, -# recipe_dir, -# "package-config-initial-bootstrap") - - package_yocto_cross_path = os.path.join( self.__recipes_source_dir, - recipe_dir, - "package-yocto-cross" ) - self.__add_cross_package_blacklist( package_yocto_cross_path ) - - package_yocto_initial_path = os.path.join( self.__recipes_source_dir, - recipe_dir, - "package-yocto-initial" ) - self.__add_initial_package_blacklist( package_yocto_initial_path ) - - package_yocto_native_path = os.path.join( self.__recipes_source_dir, - recipe_dir, - "package-yocto-native" ) - self.__add_native_package_blacklist( package_yocto_native_path ) - - package_yocto_oe_path = os.path.join( self.__recipes_source_dir, - recipe_dir, - "package-yocto-oe" ) - self.__add_oe_package_blacklist( package_yocto_oe_path ) - - self.__list_package( self.__recipes_dir_dest, - spec_file_dir, - package_git_sources, - self.__meta_spec_dico ) - - - - def __add_cross_package_blacklist( self, package_yocto_cross_path ): - ''' - load package cross - ''' - list_package_cross = self.__load_list_from_file( package_yocto_cross_path ) - MetaSpec.mCrossPackageBlacklist.extend( list_package_cross ) - - def __add_initial_package_blacklist( self, package_yocto_initial_path ): - ''' - load package blacklist - ''' - list_package = self.__load_list_from_file( package_yocto_initial_path ) - MetaSpec.mInitialPackageBlacklist.extend( list_package ) - - def __add_native_package_blacklist( self, package_yocto_native_path ): - ''' - load native_package_blacklist - ''' - list_package = self.__load_list_from_file( package_yocto_native_path ) - MetaSpec.mNativePackageBlacklist.extend( list_package ) - - def __add_oe_package_blacklist( self, package_yocto_oe_path ): - ''' - load oe_package_blacklist - ''' - list_package = self.__load_list_from_file( package_yocto_oe_path ) - MetaSpec.mOePackageBlacklist.extend( list_package ) - - - def __load_list_from_file( self, path ): - ''' - should be remove - ''' - res = [] - with open( path, "r" ) as file_d: - for line in file_d: - line = line.replace( "\n", "" ).replace( " ", "" ) - if not line.startswith( "#" ) and line != "": - res.append( line ) - return res - - def __init_depends( self ): - ''' - init depends - ''' - self.__load_package_provided_extra() - for meta_spec_boot_strap in self.__meta_spec_boot_strap_dico.values(): - meta_spec_boot_strap.set_mextra_provided_dico() - for meta_spec in self.__meta_spec_dico.values(): - meta_spec.create_all_depends() - - def __load_package_provided_extra( self ): - ''' - load_package_provided_extra - ''' - for recipes_dir in self.__recipes_list: - package_provided_extra_file = os.path.join( RECIPES_SOURCE_DIR, recipes_dir, - "package-provided-extra" ) - - if os.path.isfile( package_provided_extra_file ): - with open( package_provided_extra_file, "r" ) as file_d: - for line in file_d: - line = line.replace( "\n", "" ) - if "::::" in line: - k_package, raw_list = line.split( "::::" ) - if k_package in MetaSpec.mProvidesDico.keys(): - MetaSpec.mProvidesDico[k_package].extend( raw_list.split( " " ) ) - else: - MetaSpec.mProvidesDico[k_package] = raw_list.split( " " ) - if k_package in MetaSpec.mExtraRProvidesDico.keys(): - list_split = raw_list.split( " " ) - MetaSpec.mExtraRProvidesDico[k_package].extend( list_split ) - else: - MetaSpec.mExtraRProvidesDico[k_package] = raw_list.split( " " ) - - - - -def main(): - ''' - main fonction of spec2yocto - ''' - command_list = ["prep", "compile", "install", "createRecipes", "generatePseudoSpecfile"] - - if len( sys.argv ) < 2 : - print "%s take on parameter \"%s\"." % ( sys.argv[0], ", ".join( command_list ) ) - sys.exit( 1 ) - - exec_command = sys.argv[1] - if len( sys.argv ) > 2: - spec_path = sys.argv[2] - spec_path = spec_path.replace( "\n", "" ) - - if len( sys.argv ) > 3: - package_pn = sys.argv[3] - else: - package_pn = None - - if exec_command == "prep": - print SpecParser( spec_path, package_pn = package_pn ).get_prep_section() - res = 0 - - elif exec_command == "compile": - res = SpecParser( spec_path, package_pn = package_pn ).get_build_section() - if res != 1: - print res - res = 0 - - elif exec_command == "install": - res = SpecParser( spec_path, package_pn = package_pn ).get_install_section() - print res - - elif exec_command == "generatePseudoSpecfile": - a_spec_parser = SpecParser( spec_path ) - a_spec_parser.parse_raw_spec_file() - res = a_spec_parser.get_clean_raw() - if res != 1: - print res - res = 0 - - elif exec_command == "have_macro_configure": - a_spec_parser = SpecParser( spec_path ) - a_spec_parser.parse_raw_spec_file() - print a_spec_parser.have_macro_configure() - res = 0 - - elif exec_command == "have_macro_reconfigure": - a_spec_parser = SpecParser( spec_path ) - a_spec_parser.parse_raw_spec_file() - print a_spec_parser.have_macro_reconfigure() - res = 0 - - - elif exec_command == "createRecipes": - pkg_co = PackagesCollection() - pkg_co.save_package_provided_file() - - else: - print exec_command, " is not a valid exec_command. \"", " ".join( command_list ), "\"" - - sys.exit( 0 ) - -if __name__ == '__main__': - main() -