summaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorPaul Eggleton <paul.eggleton@linux.intel.com>2014-04-22 12:07:35 +0100
committerRichard Purdie <richard.purdie@linuxfoundation.org>2014-06-25 13:51:45 +0100
commit2b4e1506f054fded57dd361c347bdb25ddd9e245 (patch)
tree3572b1196bac1686df976507e0081e76de9dd2e7 /scripts
parent3c7b5ec1cae6186a64e0be2c05b64b05add08c97 (diff)
downloadpoky-2b4e1506f054fded57dd361c347bdb25ddd9e245.tar.gz
scripts: consolidate code to find bitbake path
Several of these scripts were using duplicated code (and slightly different methods) to find the path to bitbake and add its lib subdirectory to the Python import path. Add some common code to do this and change the scripts to use it. Fixes [YOCTO #5076]. (From OE-Core rev: 0b5e94e168819134dcda0433c8ae893df4ab13ce) Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/bitbake-whatchanged18
-rwxr-xr-xscripts/buildhistory-diff28
-rwxr-xr-xscripts/contrib/list-packageconfig-flags.py29
-rw-r--r--scripts/lib/scriptpath.py42
4 files changed, 74 insertions, 43 deletions
diff --git a/scripts/bitbake-whatchanged b/scripts/bitbake-whatchanged
index e4497e03a8..55cfe4b234 100755
--- a/scripts/bitbake-whatchanged
+++ b/scripts/bitbake-whatchanged
@@ -27,17 +27,17 @@ import warnings
27import subprocess 27import subprocess
28from optparse import OptionParser 28from optparse import OptionParser
29 29
30# Figure out where is the bitbake/lib/bb since we need bb.siggen and bb.process 30scripts_path = os.path.abspath(os.path.dirname(os.path.abspath(sys.argv[0])))
31p = subprocess.Popen("bash -c 'echo $(dirname $(which bitbake-diffsigs | grep -v \'^alias\'))/../lib'", 31lib_path = scripts_path + '/lib'
32 shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) 32sys.path = sys.path + [lib_path]
33 33
34err = p.stderr.read() 34import scriptpath
35if err:
36 print("ERROR: Failed to locate bitbake-diffsigs:", file=sys.stderr)
37 print(err, file=sys.stderr)
38 sys.exit(1)
39 35
40sys.path.insert(0, p.stdout.read().rstrip('\n')) 36# Figure out where is the bitbake/lib/bb since we need bb.siggen and bb.process
37bitbakepath = scriptpath.add_bitbake_lib_path()
38if not bitbakepath:
39 sys.stderr.write("Unable to find bitbake by searching parent directory of this script or PATH\n")
40 sys.exit(1)
41 41
42import bb.siggen 42import bb.siggen
43import bb.process 43import bb.process
diff --git a/scripts/buildhistory-diff b/scripts/buildhistory-diff
index ad50414bce..dfebcddf72 100755
--- a/scripts/buildhistory-diff
+++ b/scripts/buildhistory-diff
@@ -50,24 +50,20 @@ def main():
50 parser.print_help() 50 parser.print_help()
51 sys.exit(1) 51 sys.exit(1)
52 52
53 scripts_path = os.path.abspath(os.path.dirname(os.path.abspath(sys.argv[0])))
54 lib_path = scripts_path + '/lib'
55 sys.path = sys.path + [lib_path]
56
57 import scriptpath
58
53 # Set path to OE lib dir so we can import the buildhistory_analysis module 59 # Set path to OE lib dir so we can import the buildhistory_analysis module
54 basepath = os.path.abspath(os.path.dirname(os.path.abspath(sys.argv[0])) + '/..') 60 scriptpath.add_oe_lib_path()
55 newpath = basepath + '/meta/lib'
56 # Set path to bitbake lib dir so the buildhistory_analysis module can load bb.utils 61 # Set path to bitbake lib dir so the buildhistory_analysis module can load bb.utils
57 if os.path.exists(basepath + '/bitbake/lib/bb'): 62 bitbakepath = scriptpath.add_bitbake_lib_path()
58 bitbakepath = basepath + '/bitbake' 63 if not bitbakepath:
59 else: 64 sys.stderr.write("Unable to find bitbake by searching parent directory of this script or PATH\n")
60 # look for bitbake/bin dir in PATH 65 sys.exit(1)
61 bitbakepath = None 66
62 for pth in os.environ['PATH'].split(':'):
63 if os.path.exists(os.path.join(pth, '../lib/bb')):
64 bitbakepath = os.path.abspath(os.path.join(pth, '..'))
65 break
66 if not bitbakepath:
67 sys.stderr.write("Unable to find bitbake by searching parent directory of this script or PATH\n")
68 sys.exit(1)
69
70 sys.path[0:0] = [newpath, bitbakepath + '/lib']
71 import oe.buildhistory_analysis 67 import oe.buildhistory_analysis
72 68
73 fromrev = 'build-minus-1' 69 fromrev = 'build-minus-1'
diff --git a/scripts/contrib/list-packageconfig-flags.py b/scripts/contrib/list-packageconfig-flags.py
index 371033a3d8..615f91fdc7 100755
--- a/scripts/contrib/list-packageconfig-flags.py
+++ b/scripts/contrib/list-packageconfig-flags.py
@@ -23,26 +23,19 @@ import sys
23import getopt 23import getopt
24import os 24import os
25 25
26def search_bitbakepath(): 26
27 bitbakepath = "" 27scripts_path = os.path.abspath(os.path.dirname(os.path.abspath(sys.argv[0])))
28 28lib_path = os.path.abspath(scripts_path + '/../lib')
29 # Search path to bitbake lib dir in order to load bb modules 29sys.path = sys.path + [lib_path]
30 if os.path.exists(os.path.join(os.path.dirname(sys.argv[0]), '../../bitbake/lib/bb')): 30
31 bitbakepath = os.path.join(os.path.dirname(sys.argv[0]), '../../bitbake/lib') 31import scriptpath
32 bitbakepath = os.path.abspath(bitbakepath)
33 else:
34 # Look for bitbake/bin dir in PATH
35 for pth in os.environ['PATH'].split(':'):
36 if os.path.exists(os.path.join(pth, '../lib/bb')):
37 bitbakepath = os.path.abspath(os.path.join(pth, '../lib'))
38 break
39 if not bitbakepath:
40 sys.stderr.write("Unable to find bitbake by searching parent directory of this script or PATH\n")
41 sys.exit(1)
42 return bitbakepath
43 32
44# For importing the following modules 33# For importing the following modules
45sys.path.insert(0, search_bitbakepath()) 34bitbakepath = scriptpath.add_bitbake_lib_path()
35if not bitbakepath:
36 sys.stderr.write("Unable to find bitbake by searching parent directory of this script or PATH\n")
37 sys.exit(1)
38
46import bb.cache 39import bb.cache
47import bb.cooker 40import bb.cooker
48import bb.providers 41import bb.providers
diff --git a/scripts/lib/scriptpath.py b/scripts/lib/scriptpath.py
new file mode 100644
index 0000000000..d00317e18d
--- /dev/null
+++ b/scripts/lib/scriptpath.py
@@ -0,0 +1,42 @@
1# Path utility functions for OE python scripts
2#
3# Copyright (C) 2012-2014 Intel Corporation
4# Copyright (C) 2011 Mentor Graphics Corporation
5#
6# This program is free software; you can redistribute it and/or modify
7# it under the terms of the GNU General Public License version 2 as
8# published by the Free Software Foundation.
9#
10# This program is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13# GNU General Public License for more details.
14#
15# You should have received a copy of the GNU General Public License along
16# with this program; if not, write to the Free Software Foundation, Inc.,
17# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18
19import sys
20import os
21import os.path
22
23def add_oe_lib_path():
24 basepath = os.path.abspath(os.path.dirname(__file__) + '/../..')
25 newpath = basepath + '/meta/lib'
26 sys.path.insert(0, newpath)
27
28def add_bitbake_lib_path():
29 basepath = os.path.abspath(os.path.dirname(__file__) + '/../..')
30 bitbakepath = None
31 if os.path.exists(basepath + '/bitbake/lib/bb'):
32 bitbakepath = basepath + '/bitbake'
33 else:
34 # look for bitbake/bin dir in PATH
35 for pth in os.environ['PATH'].split(':'):
36 if os.path.exists(os.path.join(pth, '../lib/bb')):
37 bitbakepath = os.path.abspath(os.path.join(pth, '..'))
38 break
39
40 if bitbakepath:
41 sys.path.insert(0, bitbakepath + '/lib')
42 return bitbakepath