xref: /openbmc/openbmc/poky/scripts/lib/scriptpath.py (revision eb8dc403)
1*eb8dc403SDave Cobbley# Path utility functions for OE python scripts
2*eb8dc403SDave Cobbley#
3*eb8dc403SDave Cobbley# Copyright (C) 2012-2014 Intel Corporation
4*eb8dc403SDave Cobbley# Copyright (C) 2011 Mentor Graphics Corporation
5*eb8dc403SDave Cobbley#
6*eb8dc403SDave Cobbley# This program is free software; you can redistribute it and/or modify
7*eb8dc403SDave Cobbley# it under the terms of the GNU General Public License version 2 as
8*eb8dc403SDave Cobbley# published by the Free Software Foundation.
9*eb8dc403SDave Cobbley#
10*eb8dc403SDave Cobbley# This program is distributed in the hope that it will be useful,
11*eb8dc403SDave Cobbley# but WITHOUT ANY WARRANTY; without even the implied warranty of
12*eb8dc403SDave Cobbley# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13*eb8dc403SDave Cobbley# GNU General Public License for more details.
14*eb8dc403SDave Cobbley#
15*eb8dc403SDave Cobbley# You should have received a copy of the GNU General Public License along
16*eb8dc403SDave Cobbley# with this program; if not, write to the Free Software Foundation, Inc.,
17*eb8dc403SDave Cobbley# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18*eb8dc403SDave Cobbley
19*eb8dc403SDave Cobbleyimport sys
20*eb8dc403SDave Cobbleyimport os
21*eb8dc403SDave Cobbleyimport os.path
22*eb8dc403SDave Cobbley
23*eb8dc403SDave Cobbleydef add_oe_lib_path():
24*eb8dc403SDave Cobbley    basepath = os.path.abspath(os.path.dirname(__file__) + '/../..')
25*eb8dc403SDave Cobbley    newpath = basepath + '/meta/lib'
26*eb8dc403SDave Cobbley    sys.path.insert(0, newpath)
27*eb8dc403SDave Cobbley
28*eb8dc403SDave Cobbleydef add_bitbake_lib_path():
29*eb8dc403SDave Cobbley    basepath = os.path.abspath(os.path.dirname(__file__) + '/../..')
30*eb8dc403SDave Cobbley    bitbakepath = None
31*eb8dc403SDave Cobbley    if os.path.exists(basepath + '/bitbake/lib/bb'):
32*eb8dc403SDave Cobbley        bitbakepath = basepath + '/bitbake'
33*eb8dc403SDave Cobbley    else:
34*eb8dc403SDave Cobbley        # look for bitbake/bin dir in PATH
35*eb8dc403SDave Cobbley        for pth in os.environ['PATH'].split(':'):
36*eb8dc403SDave Cobbley            if os.path.exists(os.path.join(pth, '../lib/bb')):
37*eb8dc403SDave Cobbley                bitbakepath = os.path.abspath(os.path.join(pth, '..'))
38*eb8dc403SDave Cobbley                break
39*eb8dc403SDave Cobbley
40*eb8dc403SDave Cobbley    if bitbakepath:
41*eb8dc403SDave Cobbley        sys.path.insert(0, bitbakepath + '/lib')
42*eb8dc403SDave Cobbley    return bitbakepath
43