2015-05-18 15:15:06 +00:00
import os
import logging
import tempfile
2016-05-20 10:57:44 +00:00
import urllib . parse
2015-05-18 15:15:06 +00:00
2015-05-18 15:15:07 +00:00
from oeqa . utils . commands import runCmd , bitbake , get_bb_var , create_temp_layer
2015-05-18 15:15:06 +00:00
from oeqa . utils . decorators import testcase
2015-07-16 19:35:58 +00:00
from oeqa . selftest import devtool
2015-05-18 15:15:06 +00:00
2015-07-16 23:22:22 +00:00
templayerdir = None
2015-05-18 15:15:07 +00:00
2015-07-16 19:35:58 +00:00
2015-05-18 15:15:07 +00:00
def setUpModule ( ) :
global templayerdir
templayerdir = tempfile . mkdtemp ( prefix = ' recipetoolqa ' )
create_temp_layer ( templayerdir , ' selftestrecipetool ' )
2015-07-16 19:35:58 +00:00
runCmd ( ' bitbake-layers add-layer %s ' % templayerdir )
2015-05-18 15:15:07 +00:00
def tearDownModule ( ) :
runCmd ( ' bitbake-layers remove-layer %s ' % templayerdir , ignore_status = True )
runCmd ( ' rm -rf %s ' % templayerdir )
2015-07-16 19:35:58 +00:00
class RecipetoolBase ( devtool . DevtoolBase ) :
2015-05-18 15:15:06 +00:00
def setUpLocal ( self ) :
2015-07-16 23:22:22 +00:00
self . templayerdir = templayerdir
2015-05-18 15:15:06 +00:00
self . tempdir = tempfile . mkdtemp ( prefix = ' recipetoolqa ' )
self . track_for_cleanup ( self . tempdir )
2015-05-18 15:15:07 +00:00
self . testfile = os . path . join ( self . tempdir , ' testfile ' )
with open ( self . testfile , ' w ' ) as f :
f . write ( ' Test file \n ' )
def tearDownLocal ( self ) :
2015-07-16 23:22:22 +00:00
runCmd ( ' rm -rf %s /recipes-* ' % self . templayerdir )
2015-05-18 15:15:07 +00:00
2015-07-16 19:35:58 +00:00
def _try_recipetool_appendcmd ( self , cmd , testrecipe , expectedfiles , expectedlines = None ) :
result = runCmd ( cmd )
2015-05-18 15:15:07 +00:00
self . assertNotIn ( ' Traceback ' , result . output )
2015-07-16 19:35:58 +00:00
2015-05-18 15:15:07 +00:00
# Check the bbappend was created and applies properly
recipefile = get_bb_var ( ' FILE ' , testrecipe )
2015-07-16 23:22:22 +00:00
bbappendfile = self . _check_bbappend ( testrecipe , recipefile , self . templayerdir )
2015-07-16 19:35:58 +00:00
2015-05-18 15:15:07 +00:00
# Check the bbappend contents
2015-07-16 19:35:58 +00:00
if expectedlines is not None :
with open ( bbappendfile , ' r ' ) as f :
self . assertEqual ( expectedlines , f . readlines ( ) , " Expected lines are not present in %s " % bbappendfile )
2015-05-18 15:15:07 +00:00
# Check file was copied
filesdir = os . path . join ( os . path . dirname ( bbappendfile ) , testrecipe )
for expectedfile in expectedfiles :
self . assertTrue ( os . path . isfile ( os . path . join ( filesdir , expectedfile ) ) , ' Expected file %s to be copied next to bbappend, but it wasn \' t ' % expectedfile )
2015-07-16 19:35:58 +00:00
2015-05-18 15:15:07 +00:00
# Check no other files created
createdfiles = [ ]
for root , _ , files in os . walk ( filesdir ) :
for f in files :
createdfiles . append ( os . path . relpath ( os . path . join ( root , f ) , filesdir ) )
self . assertTrue ( sorted ( createdfiles ) , sorted ( expectedfiles ) )
2015-07-16 19:35:58 +00:00
2015-05-18 15:15:07 +00:00
return bbappendfile , result . output
2015-07-16 19:35:58 +00:00
class RecipetoolTests ( RecipetoolBase ) :
@classmethod
def setUpClass ( cls ) :
# Ensure we have the right data in shlibs/pkgdata
logger = logging . getLogger ( " selftest " )
logger . info ( ' Running bitbake to generate pkgdata ' )
bitbake ( ' -c packagedata base-files coreutils busybox selftest-recipetool-appendfile ' )
@classmethod
def tearDownClass ( cls ) :
# Shouldn't leave any traces of this artificial recipe behind
bitbake ( ' -c cleansstate selftest-recipetool-appendfile ' )
def _try_recipetool_appendfile ( self , testrecipe , destfile , newfile , options , expectedlines , expectedfiles ) :
2015-07-16 23:22:22 +00:00
cmd = ' recipetool appendfile %s %s %s %s ' % ( self . templayerdir , destfile , newfile , options )
2015-07-16 19:35:58 +00:00
return self . _try_recipetool_appendcmd ( cmd , testrecipe , expectedfiles , expectedlines )
2015-05-18 15:15:07 +00:00
def _try_recipetool_appendfile_fail ( self , destfile , newfile , checkerror ) :
2015-07-16 23:22:22 +00:00
cmd = ' recipetool appendfile %s %s %s ' % ( self . templayerdir , destfile , newfile )
2015-05-18 15:15:07 +00:00
result = runCmd ( cmd , ignore_status = True )
self . assertNotEqual ( result . status , 0 , ' Command " %s " should have failed but didn \' t ' % cmd )
self . assertNotIn ( ' Traceback ' , result . output )
for errorstr in checkerror :
self . assertIn ( errorstr , result . output )
2015-06-29 12:18:41 +00:00
@testcase ( 1177 )
2015-05-18 15:15:07 +00:00
def test_recipetool_appendfile_basic ( self ) :
# Basic test
expectedlines = [ ' FILESEXTRAPATHS_prepend := " $ {THISDIR} /$ {PN} : " \n ' ,
' \n ' ]
_ , output = self . _try_recipetool_appendfile ( ' base-files ' , ' /etc/motd ' , self . testfile , ' ' , expectedlines , [ ' motd ' ] )
self . assertNotIn ( ' WARNING: ' , output )
2015-06-29 12:18:41 +00:00
@testcase ( 1183 )
2015-05-18 15:15:07 +00:00
def test_recipetool_appendfile_invalid ( self ) :
# Test some commands that should error
self . _try_recipetool_appendfile_fail ( ' /etc/passwd ' , self . testfile , [ ' ERROR: /etc/passwd cannot be handled by this tool ' , ' useradd ' , ' extrausers ' ] )
self . _try_recipetool_appendfile_fail ( ' /etc/timestamp ' , self . testfile , [ ' ERROR: /etc/timestamp cannot be handled by this tool ' ] )
self . _try_recipetool_appendfile_fail ( ' /dev/console ' , self . testfile , [ ' ERROR: /dev/console cannot be handled by this tool ' ] )
2015-06-29 12:18:41 +00:00
@testcase ( 1176 )
2015-05-18 15:15:07 +00:00
def test_recipetool_appendfile_alternatives ( self ) :
# Now try with a file we know should be an alternative
# (this is very much a fake example, but one we know is reliably an alternative)
self . _try_recipetool_appendfile_fail ( ' /bin/ls ' , self . testfile , [ ' ERROR: File /bin/ls is an alternative possibly provided by the following recipes: ' , ' coreutils ' , ' busybox ' ] )
corebase = get_bb_var ( ' COREBASE ' )
# Need a test file - should be executable
testfile2 = os . path . join ( corebase , ' oe-init-build-env ' )
testfile2name = os . path . basename ( testfile2 )
expectedlines = [ ' FILESEXTRAPATHS_prepend := " $ {THISDIR} /$ {PN} : " \n ' ,
' \n ' ,
' SRC_URI += " file:// %s " \n ' % testfile2name ,
' \n ' ,
' do_install_append() { \n ' ,
' install -d $ {D} $ {base_bindir} \n ' ,
' install -m 0755 $ {WORKDIR} / %s $ {D} $ {base_bindir} /ls \n ' % testfile2name ,
' } \n ' ]
self . _try_recipetool_appendfile ( ' coreutils ' , ' /bin/ls ' , testfile2 , ' -r coreutils ' , expectedlines , [ testfile2name ] )
# Now try bbappending the same file again, contents should not change
bbappendfile , _ = self . _try_recipetool_appendfile ( ' coreutils ' , ' /bin/ls ' , self . testfile , ' -r coreutils ' , expectedlines , [ testfile2name ] )
# But file should have
copiedfile = os . path . join ( os . path . dirname ( bbappendfile ) , ' coreutils ' , testfile2name )
result = runCmd ( ' diff -q %s %s ' % ( testfile2 , copiedfile ) , ignore_status = True )
2015-07-16 13:20:24 +00:00
self . assertNotEqual ( result . status , 0 , ' New file should have been copied but was not %s ' % result . output )
2015-05-18 15:15:07 +00:00
2015-06-29 12:18:41 +00:00
@testcase ( 1178 )
2015-05-18 15:15:07 +00:00
def test_recipetool_appendfile_binary ( self ) :
# Try appending a binary file
2015-06-25 15:47:28 +00:00
# /bin/ls can be a symlink to /usr/bin/ls
2015-06-27 07:10:29 +00:00
ls = os . path . realpath ( " /bin/ls " )
2015-07-16 23:22:22 +00:00
result = runCmd ( ' recipetool appendfile %s /bin/ls %s -r coreutils ' % ( self . templayerdir , ls ) )
2015-05-18 15:15:07 +00:00
self . assertIn ( ' WARNING: ' , result . output )
self . assertIn ( ' is a binary ' , result . output )
2015-06-29 12:18:41 +00:00
@testcase ( 1173 )
2015-05-18 15:15:07 +00:00
def test_recipetool_appendfile_add ( self ) :
corebase = get_bb_var ( ' COREBASE ' )
# Try arbitrary file add to a recipe
expectedlines = [ ' FILESEXTRAPATHS_prepend := " $ {THISDIR} /$ {PN} : " \n ' ,
' \n ' ,
' SRC_URI += " file://testfile " \n ' ,
' \n ' ,
' do_install_append() { \n ' ,
' install -d $ {D} $ {datadir} \n ' ,
' install -m 0644 $ {WORKDIR} /testfile $ {D} $ {datadir} /something \n ' ,
' } \n ' ]
self . _try_recipetool_appendfile ( ' netbase ' , ' /usr/share/something ' , self . testfile , ' -r netbase ' , expectedlines , [ ' testfile ' ] )
# Try adding another file, this time where the source file is executable
# (so we're testing that, plus modifying an existing bbappend)
testfile2 = os . path . join ( corebase , ' oe-init-build-env ' )
testfile2name = os . path . basename ( testfile2 )
expectedlines = [ ' FILESEXTRAPATHS_prepend := " $ {THISDIR} /$ {PN} : " \n ' ,
' \n ' ,
' SRC_URI += " file://testfile \\ \n ' ,
' file:// %s \\ \n ' % testfile2name ,
' " \n ' ,
' \n ' ,
' do_install_append() { \n ' ,
' install -d $ {D} $ {datadir} \n ' ,
' install -m 0644 $ {WORKDIR} /testfile $ {D} $ {datadir} /something \n ' ,
' install -m 0755 $ {WORKDIR} / %s $ {D} $ {datadir} /scriptname \n ' % testfile2name ,
' } \n ' ]
self . _try_recipetool_appendfile ( ' netbase ' , ' /usr/share/scriptname ' , testfile2 , ' -r netbase ' , expectedlines , [ ' testfile ' , testfile2name ] )
2015-06-29 12:18:41 +00:00
@testcase ( 1174 )
2015-05-18 15:15:07 +00:00
def test_recipetool_appendfile_add_bindir ( self ) :
# Try arbitrary file add to a recipe, this time to a location such that should be installed as executable
expectedlines = [ ' FILESEXTRAPATHS_prepend := " $ {THISDIR} /$ {PN} : " \n ' ,
' \n ' ,
' SRC_URI += " file://testfile " \n ' ,
' \n ' ,
' do_install_append() { \n ' ,
' install -d $ {D} $ {bindir} \n ' ,
' install -m 0755 $ {WORKDIR} /testfile $ {D} $ {bindir} /selftest-recipetool-testbin \n ' ,
' } \n ' ]
_ , output = self . _try_recipetool_appendfile ( ' netbase ' , ' /usr/bin/selftest-recipetool-testbin ' , self . testfile , ' -r netbase ' , expectedlines , [ ' testfile ' ] )
self . assertNotIn ( ' WARNING: ' , output )
2015-06-29 12:18:41 +00:00
@testcase ( 1175 )
2015-05-18 15:15:07 +00:00
def test_recipetool_appendfile_add_machine ( self ) :
# Try arbitrary file add to a recipe, this time to a location such that should be installed as executable
expectedlines = [ ' FILESEXTRAPATHS_prepend := " $ {THISDIR} /$ {PN} : " \n ' ,
' \n ' ,
' PACKAGE_ARCH = " $ {MACHINE_ARCH} " \n ' ,
' \n ' ,
' SRC_URI_append_mymachine = " file://testfile " \n ' ,
' \n ' ,
' do_install_append_mymachine() { \n ' ,
' install -d $ {D} $ {datadir} \n ' ,
' install -m 0644 $ {WORKDIR} /testfile $ {D} $ {datadir} /something \n ' ,
' } \n ' ]
_ , output = self . _try_recipetool_appendfile ( ' netbase ' , ' /usr/share/something ' , self . testfile , ' -r netbase -m mymachine ' , expectedlines , [ ' mymachine/testfile ' ] )
self . assertNotIn ( ' WARNING: ' , output )
2015-06-29 12:18:41 +00:00
@testcase ( 1184 )
2015-05-18 15:15:07 +00:00
def test_recipetool_appendfile_orig ( self ) :
# A file that's in SRC_URI and in do_install with the same name
expectedlines = [ ' FILESEXTRAPATHS_prepend := " $ {THISDIR} /$ {PN} : " \n ' ,
' \n ' ]
_ , output = self . _try_recipetool_appendfile ( ' selftest-recipetool-appendfile ' , ' /usr/share/selftest-replaceme-orig ' , self . testfile , ' ' , expectedlines , [ ' selftest-replaceme-orig ' ] )
self . assertNotIn ( ' WARNING: ' , output )
2015-06-29 12:18:41 +00:00
@testcase ( 1191 )
2015-05-18 15:15:07 +00:00
def test_recipetool_appendfile_todir ( self ) :
# A file that's in SRC_URI and in do_install with destination directory rather than file
expectedlines = [ ' FILESEXTRAPATHS_prepend := " $ {THISDIR} /$ {PN} : " \n ' ,
' \n ' ]
_ , output = self . _try_recipetool_appendfile ( ' selftest-recipetool-appendfile ' , ' /usr/share/selftest-replaceme-todir ' , self . testfile , ' ' , expectedlines , [ ' selftest-replaceme-todir ' ] )
self . assertNotIn ( ' WARNING: ' , output )
2015-06-29 12:18:41 +00:00
@testcase ( 1187 )
2015-05-18 15:15:07 +00:00
def test_recipetool_appendfile_renamed ( self ) :
# A file that's in SRC_URI with a different name to the destination file
expectedlines = [ ' FILESEXTRAPATHS_prepend := " $ {THISDIR} /$ {PN} : " \n ' ,
' \n ' ]
_ , output = self . _try_recipetool_appendfile ( ' selftest-recipetool-appendfile ' , ' /usr/share/selftest-replaceme-renamed ' , self . testfile , ' ' , expectedlines , [ ' file1 ' ] )
self . assertNotIn ( ' WARNING: ' , output )
2015-06-29 12:18:41 +00:00
@testcase ( 1190 )
2015-05-18 15:15:07 +00:00
def test_recipetool_appendfile_subdir ( self ) :
# A file that's in SRC_URI in a subdir
expectedlines = [ ' FILESEXTRAPATHS_prepend := " $ {THISDIR} /$ {PN} : " \n ' ,
' \n ' ,
' SRC_URI += " file://testfile " \n ' ,
' \n ' ,
' do_install_append() { \n ' ,
' install -d $ {D} $ {datadir} \n ' ,
' install -m 0644 $ {WORKDIR} /testfile $ {D} $ {datadir} /selftest-replaceme-subdir \n ' ,
' } \n ' ]
_ , output = self . _try_recipetool_appendfile ( ' selftest-recipetool-appendfile ' , ' /usr/share/selftest-replaceme-subdir ' , self . testfile , ' ' , expectedlines , [ ' testfile ' ] )
self . assertNotIn ( ' WARNING: ' , output )
2015-06-29 12:18:41 +00:00
@testcase ( 1189 )
2015-05-18 15:15:07 +00:00
def test_recipetool_appendfile_src_glob ( self ) :
# A file that's in SRC_URI as a glob
expectedlines = [ ' FILESEXTRAPATHS_prepend := " $ {THISDIR} /$ {PN} : " \n ' ,
' \n ' ,
' SRC_URI += " file://testfile " \n ' ,
' \n ' ,
' do_install_append() { \n ' ,
' install -d $ {D} $ {datadir} \n ' ,
' install -m 0644 $ {WORKDIR} /testfile $ {D} $ {datadir} /selftest-replaceme-src-globfile \n ' ,
' } \n ' ]
_ , output = self . _try_recipetool_appendfile ( ' selftest-recipetool-appendfile ' , ' /usr/share/selftest-replaceme-src-globfile ' , self . testfile , ' ' , expectedlines , [ ' testfile ' ] )
self . assertNotIn ( ' WARNING: ' , output )
2015-06-29 12:18:41 +00:00
@testcase ( 1181 )
2015-05-18 15:15:07 +00:00
def test_recipetool_appendfile_inst_glob ( self ) :
# A file that's in do_install as a glob
expectedlines = [ ' FILESEXTRAPATHS_prepend := " $ {THISDIR} /$ {PN} : " \n ' ,
' \n ' ]
_ , output = self . _try_recipetool_appendfile ( ' selftest-recipetool-appendfile ' , ' /usr/share/selftest-replaceme-inst-globfile ' , self . testfile , ' ' , expectedlines , [ ' selftest-replaceme-inst-globfile ' ] )
self . assertNotIn ( ' WARNING: ' , output )
2015-06-29 12:18:41 +00:00
@testcase ( 1182 )
2015-05-18 15:15:07 +00:00
def test_recipetool_appendfile_inst_todir_glob ( self ) :
# A file that's in do_install as a glob with destination as a directory
expectedlines = [ ' FILESEXTRAPATHS_prepend := " $ {THISDIR} /$ {PN} : " \n ' ,
' \n ' ]
_ , output = self . _try_recipetool_appendfile ( ' selftest-recipetool-appendfile ' , ' /usr/share/selftest-replaceme-inst-todir-globfile ' , self . testfile , ' ' , expectedlines , [ ' selftest-replaceme-inst-todir-globfile ' ] )
self . assertNotIn ( ' WARNING: ' , output )
2015-06-29 12:18:41 +00:00
@testcase ( 1185 )
2015-05-18 15:15:07 +00:00
def test_recipetool_appendfile_patch ( self ) :
# A file that's added by a patch in SRC_URI
expectedlines = [ ' FILESEXTRAPATHS_prepend := " $ {THISDIR} /$ {PN} : " \n ' ,
' \n ' ,
' SRC_URI += " file://testfile " \n ' ,
' \n ' ,
' do_install_append() { \n ' ,
' install -d $ {D} $ {sysconfdir} \n ' ,
' install -m 0644 $ {WORKDIR} /testfile $ {D} $ {sysconfdir} /selftest-replaceme-patched \n ' ,
' } \n ' ]
_ , output = self . _try_recipetool_appendfile ( ' selftest-recipetool-appendfile ' , ' /etc/selftest-replaceme-patched ' , self . testfile , ' ' , expectedlines , [ ' testfile ' ] )
for line in output . splitlines ( ) :
2016-05-31 14:24:03 +00:00
if ' WARNING: ' in line :
2015-05-18 15:15:07 +00:00
self . assertIn ( ' add-file.patch ' , line , ' Unexpected warning found in output: \n %s ' % line )
break
else :
2015-08-05 13:37:13 +00:00
self . fail ( ' Patch warning not found in output: \n %s ' % output )
2015-05-18 15:15:07 +00:00
2015-06-29 12:18:41 +00:00
@testcase ( 1188 )
2015-05-18 15:15:07 +00:00
def test_recipetool_appendfile_script ( self ) :
# Now, a file that's in SRC_URI but installed by a script (so no mention in do_install)
expectedlines = [ ' FILESEXTRAPATHS_prepend := " $ {THISDIR} /$ {PN} : " \n ' ,
' \n ' ,
' SRC_URI += " file://testfile " \n ' ,
' \n ' ,
' do_install_append() { \n ' ,
' install -d $ {D} $ {datadir} \n ' ,
' install -m 0644 $ {WORKDIR} /testfile $ {D} $ {datadir} /selftest-replaceme-scripted \n ' ,
' } \n ' ]
_ , output = self . _try_recipetool_appendfile ( ' selftest-recipetool-appendfile ' , ' /usr/share/selftest-replaceme-scripted ' , self . testfile , ' ' , expectedlines , [ ' testfile ' ] )
self . assertNotIn ( ' WARNING: ' , output )
2015-06-29 12:18:41 +00:00
@testcase ( 1180 )
2015-05-18 15:15:07 +00:00
def test_recipetool_appendfile_inst_func ( self ) :
# A file that's installed from a function called by do_install
expectedlines = [ ' FILESEXTRAPATHS_prepend := " $ {THISDIR} /$ {PN} : " \n ' ,
' \n ' ]
_ , output = self . _try_recipetool_appendfile ( ' selftest-recipetool-appendfile ' , ' /usr/share/selftest-replaceme-inst-func ' , self . testfile , ' ' , expectedlines , [ ' selftest-replaceme-inst-func ' ] )
self . assertNotIn ( ' WARNING: ' , output )
2015-06-29 12:18:41 +00:00
@testcase ( 1186 )
2015-05-18 15:15:07 +00:00
def test_recipetool_appendfile_postinstall ( self ) :
# A file that's created by a postinstall script (and explicitly mentioned in it)
# First try without specifying recipe
self . _try_recipetool_appendfile_fail ( ' /usr/share/selftest-replaceme-postinst ' , self . testfile , [ ' File /usr/share/selftest-replaceme-postinst may be written out in a pre/postinstall script of the following recipes: ' , ' selftest-recipetool-appendfile ' ] )
# Now specify recipe
expectedlines = [ ' FILESEXTRAPATHS_prepend := " $ {THISDIR} /$ {PN} : " \n ' ,
' \n ' ,
' SRC_URI += " file://testfile " \n ' ,
' \n ' ,
' do_install_append() { \n ' ,
' install -d $ {D} $ {datadir} \n ' ,
' install -m 0644 $ {WORKDIR} /testfile $ {D} $ {datadir} /selftest-replaceme-postinst \n ' ,
' } \n ' ]
_ , output = self . _try_recipetool_appendfile ( ' selftest-recipetool-appendfile ' , ' /usr/share/selftest-replaceme-postinst ' , self . testfile , ' -r selftest-recipetool-appendfile ' , expectedlines , [ ' testfile ' ] )
2015-06-29 12:18:41 +00:00
@testcase ( 1179 )
2015-05-18 15:15:07 +00:00
def test_recipetool_appendfile_extlayer ( self ) :
# Try creating a bbappend in a layer that's not in bblayers.conf and has a different structure
exttemplayerdir = os . path . join ( self . tempdir , ' extlayer ' )
self . _create_temp_layer ( exttemplayerdir , False , ' oeselftestextlayer ' , recipepathspec = ' metadata/recipes/recipes-*/* ' )
result = runCmd ( ' recipetool appendfile %s /usr/share/selftest-replaceme-orig %s ' % ( exttemplayerdir , self . testfile ) )
self . assertNotIn ( ' Traceback ' , result . output )
createdfiles = [ ]
for root , _ , files in os . walk ( exttemplayerdir ) :
for f in files :
createdfiles . append ( os . path . relpath ( os . path . join ( root , f ) , exttemplayerdir ) )
createdfiles . remove ( ' conf/layer.conf ' )
expectedfiles = [ ' metadata/recipes/recipes-test/selftest-recipetool-appendfile/selftest-recipetool-appendfile.bbappend ' ,
' metadata/recipes/recipes-test/selftest-recipetool-appendfile/selftest-recipetool-appendfile/selftest-replaceme-orig ' ]
self . assertEqual ( sorted ( createdfiles ) , sorted ( expectedfiles ) )
2015-06-29 12:18:41 +00:00
@testcase ( 1192 )
2015-05-18 15:15:07 +00:00
def test_recipetool_appendfile_wildcard ( self ) :
def try_appendfile_wc ( options ) :
2015-07-16 23:22:22 +00:00
result = runCmd ( ' recipetool appendfile %s /etc/profile %s %s ' % ( self . templayerdir , self . testfile , options ) )
2015-05-18 15:15:07 +00:00
self . assertNotIn ( ' Traceback ' , result . output )
bbappendfile = None
2015-07-16 23:22:22 +00:00
for root , _ , files in os . walk ( self . templayerdir ) :
2015-05-18 15:15:07 +00:00
for f in files :
if f . endswith ( ' .bbappend ' ) :
bbappendfile = f
break
if not bbappendfile :
2015-08-05 13:37:13 +00:00
self . fail ( ' No bbappend file created ' )
2015-07-16 23:22:22 +00:00
runCmd ( ' rm -rf %s /recipes-* ' % self . templayerdir )
2015-05-18 15:15:07 +00:00
return bbappendfile
# Check without wildcard option
recipefn = os . path . basename ( get_bb_var ( ' FILE ' , ' base-files ' ) )
filename = try_appendfile_wc ( ' ' )
self . assertEqual ( filename , recipefn . replace ( ' .bb ' , ' .bbappend ' ) )
# Now check with wildcard option
filename = try_appendfile_wc ( ' -w ' )
self . assertEqual ( filename , recipefn . split ( ' _ ' ) [ 0 ] + ' _ % .bbappend ' )
2015-06-29 12:18:41 +00:00
@testcase ( 1193 )
2015-05-18 15:15:06 +00:00
def test_recipetool_create ( self ) :
# Try adding a recipe
tempsrc = os . path . join ( self . tempdir , ' srctree ' )
os . makedirs ( tempsrc )
recipefile = os . path . join ( self . tempdir , ' logrotate_3.8.7.bb ' )
srcuri = ' https://fedorahosted.org/releases/l/o/logrotate/logrotate-3.8.7.tar.gz '
result = runCmd ( ' recipetool create -o %s %s -x %s ' % ( recipefile , srcuri , tempsrc ) )
self . assertTrue ( os . path . isfile ( recipefile ) )
checkvars = { }
checkvars [ ' LICENSE ' ] = ' GPLv2 '
checkvars [ ' LIC_FILES_CHKSUM ' ] = ' file://COPYING;md5=18810669f13b87348459e611d31ab760 '
checkvars [ ' SRC_URI ' ] = ' https://fedorahosted.org/releases/l/o/logrotate/logrotate-$ {PV} .tar.gz '
checkvars [ ' SRC_URI[md5sum] ' ] = ' 99e08503ef24c3e2e3ff74cc5f3be213 '
checkvars [ ' SRC_URI[sha256sum] ' ] = ' f6ba691f40e30e640efa2752c1f9499a3f9738257660994de70a45fe00d12b64 '
self . _test_recipe_contents ( recipefile , checkvars , [ ] )
2015-06-29 12:18:41 +00:00
@testcase ( 1194 )
2015-05-18 15:15:06 +00:00
def test_recipetool_create_git ( self ) :
# Ensure we have the right data in shlibs/pkgdata
2016-01-18 11:18:26 +00:00
bitbake ( ' libpng pango libx11 libxext jpeg libxsettings-client libcheck ' )
2015-05-18 15:15:06 +00:00
# Try adding a recipe
tempsrc = os . path . join ( self . tempdir , ' srctree ' )
os . makedirs ( tempsrc )
recipefile = os . path . join ( self . tempdir , ' libmatchbox.bb ' )
srcuri = ' git://git.yoctoproject.org/libmatchbox '
result = runCmd ( ' recipetool create -o %s %s -x %s ' % ( recipefile , srcuri , tempsrc ) )
self . assertTrue ( os . path . isfile ( recipefile ) , ' recipetool did not create recipe file; output: \n %s ' % result . output )
checkvars = { }
checkvars [ ' LICENSE ' ] = ' LGPLv2.1 '
checkvars [ ' LIC_FILES_CHKSUM ' ] = ' file://COPYING;md5=7fbc338309ac38fefcd64b04bb903e34 '
checkvars [ ' S ' ] = ' $ {WORKDIR} /git '
2015-12-22 04:03:02 +00:00
checkvars [ ' PV ' ] = ' 1.11+git$ {SRCPV} '
2015-05-18 15:15:06 +00:00
checkvars [ ' SRC_URI ' ] = srcuri
2016-01-18 11:18:26 +00:00
checkvars [ ' DEPENDS ' ] = set ( [ ' libcheck ' , ' libjpeg-turbo ' , ' libpng ' , ' libx11 ' , ' libxsettings-client ' , ' libxext ' , ' pango ' ] )
2015-05-18 15:15:06 +00:00
inherits = [ ' autotools ' , ' pkgconfig ' ]
self . _test_recipe_contents ( recipefile , checkvars , inherits )
2015-07-16 19:36:28 +00:00
2016-01-05 09:42:13 +00:00
@testcase ( 1392 )
2015-12-22 04:03:18 +00:00
def test_recipetool_create_simple ( self ) :
# Try adding a recipe
temprecipe = os . path . join ( self . tempdir , ' recipe ' )
os . makedirs ( temprecipe )
pv = ' 1.7.3.0 '
srcuri = ' http://www.dest-unreach.org/socat/download/socat- %s .tar.bz2 ' % pv
result = runCmd ( ' recipetool create %s -o %s ' % ( srcuri , temprecipe ) )
dirlist = os . listdir ( temprecipe )
2016-03-13 19:59:03 +00:00
if len ( dirlist ) > 1 :
self . fail ( ' recipetool created more than just one file; output: \n %s \n dirlist: \n %s ' % ( result . output , str ( dirlist ) ) )
if len ( dirlist ) < 1 or not os . path . isfile ( os . path . join ( temprecipe , dirlist [ 0 ] ) ) :
2016-03-13 09:28:00 +00:00
self . fail ( ' recipetool did not create recipe file; output: \n %s \n dirlist: \n %s ' % ( result . output , str ( dirlist ) ) )
2016-03-13 19:59:03 +00:00
self . assertEqual ( dirlist [ 0 ] , ' socat_ %s .bb ' % pv , ' Recipe file incorrectly named ' )
2015-12-22 04:03:18 +00:00
checkvars = { }
2015-12-23 13:45:23 +00:00
checkvars [ ' LICENSE ' ] = set ( [ ' Unknown ' , ' GPLv2 ' ] )
checkvars [ ' LIC_FILES_CHKSUM ' ] = set ( [ ' file://COPYING.OpenSSL;md5=5c9bccc77f67a8328ef4ebaf468116f4 ' , ' file://COPYING;md5=b234ee4d69f5fce4486a80fdaf4a4263 ' ] )
2015-12-22 04:03:18 +00:00
# We don't check DEPENDS since they are variable for this recipe depending on what's in the sysroot
checkvars [ ' S ' ] = None
checkvars [ ' SRC_URI ' ] = srcuri . replace ( pv , ' $ {PV} ' )
inherits = [ ' autotools ' ]
self . _test_recipe_contents ( os . path . join ( temprecipe , dirlist [ 0 ] ) , checkvars , inherits )
2015-07-16 19:36:28 +00:00
2016-03-30 15:07:32 +00:00
@testcase ( 1418 )
2016-01-18 11:18:33 +00:00
def test_recipetool_create_cmake ( self ) :
# Try adding a recipe
temprecipe = os . path . join ( self . tempdir , ' recipe ' )
os . makedirs ( temprecipe )
recipefile = os . path . join ( temprecipe , ' navit_0.5.0.bb ' )
srcuri = ' http://downloads.sourceforge.net/project/navit/v0.5.0/navit-0.5.0.tar.gz '
result = runCmd ( ' recipetool create -o %s %s ' % ( temprecipe , srcuri ) )
self . assertTrue ( os . path . isfile ( recipefile ) )
checkvars = { }
checkvars [ ' LICENSE ' ] = set ( [ ' Unknown ' , ' GPLv2 ' , ' LGPLv2 ' ] )
checkvars [ ' SRC_URI ' ] = ' http://downloads.sourceforge.net/project/navit/v$ {PV} /navit-$ {PV} .tar.gz '
checkvars [ ' SRC_URI[md5sum] ' ] = ' 242f398e979a6b8c0f3c802b63435b68 '
checkvars [ ' SRC_URI[sha256sum] ' ] = ' 13353481d7fc01a4f64e385dda460b51496366bba0fd2cc85a89a0747910e94d '
checkvars [ ' DEPENDS ' ] = set ( [ ' freetype ' , ' zlib ' , ' openssl ' , ' glib-2.0 ' , ' virtual/libgl ' , ' virtual/egl ' , ' gtk+ ' , ' libpng ' , ' libsdl ' , ' freeglut ' , ' dbus-glib ' ] )
inherits = [ ' cmake ' , ' python-dir ' , ' gettext ' , ' pkgconfig ' ]
self . _test_recipe_contents ( recipefile , checkvars , inherits )
2015-07-16 19:36:28 +00:00
class RecipetoolAppendsrcBase ( RecipetoolBase ) :
def _try_recipetool_appendsrcfile ( self , testrecipe , newfile , destfile , options , expectedlines , expectedfiles ) :
2015-07-16 23:22:22 +00:00
cmd = ' recipetool appendsrcfile %s %s %s %s %s ' % ( options , self . templayerdir , testrecipe , newfile , destfile )
2015-07-16 19:36:28 +00:00
return self . _try_recipetool_appendcmd ( cmd , testrecipe , expectedfiles , expectedlines )
def _try_recipetool_appendsrcfiles ( self , testrecipe , newfiles , expectedlines = None , expectedfiles = None , destdir = None , options = ' ' ) :
if destdir :
options + = ' -D %s ' % destdir
if expectedfiles is None :
expectedfiles = [ os . path . basename ( f ) for f in newfiles ]
2015-07-16 23:22:22 +00:00
cmd = ' recipetool appendsrcfiles %s %s %s %s ' % ( options , self . templayerdir , testrecipe , ' ' . join ( newfiles ) )
2015-07-16 19:36:28 +00:00
return self . _try_recipetool_appendcmd ( cmd , testrecipe , expectedfiles , expectedlines )
def _try_recipetool_appendsrcfile_fail ( self , testrecipe , newfile , destfile , checkerror ) :
2015-07-16 23:22:22 +00:00
cmd = ' recipetool appendsrcfile %s %s %s %s ' % ( self . templayerdir , testrecipe , newfile , destfile or ' ' )
2015-07-16 19:36:28 +00:00
result = runCmd ( cmd , ignore_status = True )
self . assertNotEqual ( result . status , 0 , ' Command " %s " should have failed but didn \' t ' % cmd )
self . assertNotIn ( ' Traceback ' , result . output )
for errorstr in checkerror :
self . assertIn ( errorstr , result . output )
@staticmethod
def _get_first_file_uri ( recipe ) :
''' Return the first file:// in SRC_URI for the specified recipe. '''
src_uri = get_bb_var ( ' SRC_URI ' , recipe ) . split ( )
for uri in src_uri :
2016-05-20 10:57:44 +00:00
p = urllib . parse . urlparse ( uri )
2015-07-16 19:36:28 +00:00
if p . scheme == ' file ' :
return p . netloc + p . path
def _test_appendsrcfile ( self , testrecipe , filename = None , destdir = None , has_src_uri = True , srcdir = None , newfile = None , options = ' ' ) :
if newfile is None :
newfile = self . testfile
if srcdir :
if destdir :
expected_subdir = os . path . join ( srcdir , destdir )
else :
expected_subdir = srcdir
else :
options + = " -W "
expected_subdir = destdir
if filename :
if destdir :
destpath = os . path . join ( destdir , filename )
else :
destpath = filename
else :
filename = os . path . basename ( newfile )
if destdir :
destpath = destdir + os . sep
else :
destpath = ' . ' + os . sep
expectedlines = [ ' FILESEXTRAPATHS_prepend := " $ {THISDIR} /$ {PN} : " \n ' ,
' \n ' ]
if has_src_uri :
uri = ' file:// %s ' % filename
if expected_subdir :
uri + = ' ;subdir= %s ' % expected_subdir
expectedlines [ 0 : 0 ] = [ ' SRC_URI += " %s " \n ' % uri ,
' \n ' ]
return self . _try_recipetool_appendsrcfile ( testrecipe , newfile , destpath , options , expectedlines , [ filename ] )
def _test_appendsrcfiles ( self , testrecipe , newfiles , expectedfiles = None , destdir = None , options = ' ' ) :
if expectedfiles is None :
expectedfiles = [ os . path . basename ( n ) for n in newfiles ]
self . _try_recipetool_appendsrcfiles ( testrecipe , newfiles , expectedfiles = expectedfiles , destdir = destdir , options = options )
src_uri = get_bb_var ( ' SRC_URI ' , testrecipe ) . split ( )
for f in expectedfiles :
if destdir :
self . assertIn ( ' file:// %s ;subdir= %s ' % ( f , destdir ) , src_uri )
else :
self . assertIn ( ' file:// %s ' % f , src_uri )
recipefile = get_bb_var ( ' FILE ' , testrecipe )
2015-07-16 23:22:22 +00:00
bbappendfile = self . _check_bbappend ( testrecipe , recipefile , self . templayerdir )
2015-07-16 19:36:28 +00:00
filesdir = os . path . join ( os . path . dirname ( bbappendfile ) , testrecipe )
filesextrapaths = get_bb_var ( ' FILESEXTRAPATHS ' , testrecipe ) . split ( ' : ' )
self . assertIn ( filesdir , filesextrapaths )
class RecipetoolAppendsrcTests ( RecipetoolAppendsrcBase ) :
2015-10-23 12:07:51 +00:00
@testcase ( 1273 )
2015-07-16 19:36:28 +00:00
def test_recipetool_appendsrcfile_basic ( self ) :
self . _test_appendsrcfile ( ' base-files ' , ' a-file ' )
2015-10-23 12:07:51 +00:00
@testcase ( 1274 )
2015-07-16 19:36:28 +00:00
def test_recipetool_appendsrcfile_basic_wildcard ( self ) :
testrecipe = ' base-files '
self . _test_appendsrcfile ( testrecipe , ' a-file ' , options = ' -w ' )
recipefile = get_bb_var ( ' FILE ' , testrecipe )
2015-07-16 23:22:22 +00:00
bbappendfile = self . _check_bbappend ( testrecipe , recipefile , self . templayerdir )
2015-07-16 19:36:28 +00:00
self . assertEqual ( os . path . basename ( bbappendfile ) , ' %s _ %% .bbappend ' % testrecipe )
2015-10-23 12:07:51 +00:00
@testcase ( 1281 )
2015-07-16 19:36:28 +00:00
def test_recipetool_appendsrcfile_subdir_basic ( self ) :
self . _test_appendsrcfile ( ' base-files ' , ' a-file ' , ' tmp ' )
2015-10-23 12:07:51 +00:00
@testcase ( 1282 )
2015-07-16 19:36:28 +00:00
def test_recipetool_appendsrcfile_subdir_basic_dirdest ( self ) :
self . _test_appendsrcfile ( ' base-files ' , destdir = ' tmp ' )
2015-10-23 12:07:51 +00:00
@testcase ( 1280 )
2015-07-16 19:36:28 +00:00
def test_recipetool_appendsrcfile_srcdir_basic ( self ) :
testrecipe = ' bash '
srcdir = get_bb_var ( ' S ' , testrecipe )
workdir = get_bb_var ( ' WORKDIR ' , testrecipe )
subdir = os . path . relpath ( srcdir , workdir )
self . _test_appendsrcfile ( testrecipe , ' a-file ' , srcdir = subdir )
2015-10-23 12:07:51 +00:00
@testcase ( 1275 )
2015-07-16 19:36:28 +00:00
def test_recipetool_appendsrcfile_existing_in_src_uri ( self ) :
testrecipe = ' base-files '
filepath = self . _get_first_file_uri ( testrecipe )
self . assertTrue ( filepath , ' Unable to test, no file:// uri found in SRC_URI for %s ' % testrecipe )
self . _test_appendsrcfile ( testrecipe , filepath , has_src_uri = False )
2015-10-23 12:07:51 +00:00
@testcase ( 1276 )
2015-07-16 19:36:28 +00:00
def test_recipetool_appendsrcfile_existing_in_src_uri_diff_params ( self ) :
testrecipe = ' base-files '
subdir = ' tmp '
filepath = self . _get_first_file_uri ( testrecipe )
self . assertTrue ( filepath , ' Unable to test, no file:// uri found in SRC_URI for %s ' % testrecipe )
output = self . _test_appendsrcfile ( testrecipe , filepath , subdir , has_src_uri = False )
self . assertTrue ( any ( ' with different parameters ' in l for l in output ) )
2015-10-23 12:07:51 +00:00
@testcase ( 1277 )
2015-07-16 19:36:28 +00:00
def test_recipetool_appendsrcfile_replace_file_srcdir ( self ) :
testrecipe = ' bash '
filepath = ' Makefile.in '
srcdir = get_bb_var ( ' S ' , testrecipe )
workdir = get_bb_var ( ' WORKDIR ' , testrecipe )
subdir = os . path . relpath ( srcdir , workdir )
self . _test_appendsrcfile ( testrecipe , filepath , srcdir = subdir )
bitbake ( ' %s :do_unpack ' % testrecipe )
self . assertEqual ( open ( self . testfile , ' r ' ) . read ( ) , open ( os . path . join ( srcdir , filepath ) , ' r ' ) . read ( ) )
2015-10-23 12:07:51 +00:00
@testcase ( 1278 )
2015-07-16 19:36:28 +00:00
def test_recipetool_appendsrcfiles_basic ( self , destdir = None ) :
newfiles = [ self . testfile ]
for i in range ( 1 , 5 ) :
testfile = os . path . join ( self . tempdir , ' testfile %d ' % i )
with open ( testfile , ' w ' ) as f :
f . write ( ' Test file %d \n ' % i )
newfiles . append ( testfile )
self . _test_appendsrcfiles ( ' gcc ' , newfiles , destdir = destdir , options = ' -W ' )
2015-10-23 12:07:51 +00:00
@testcase ( 1279 )
2015-07-16 19:36:28 +00:00
def test_recipetool_appendsrcfiles_basic_subdir ( self ) :
self . test_recipetool_appendsrcfiles_basic ( destdir = ' testdir ' )