xref: /openbmc/openbmc/poky/scripts/oe-run-native (revision d1e89497)
1#!/bin/bash
2#
3# Copyright (c) 2016,  Intel Corporation.
4#
5# SPDX-License-Identifier: GPL-2.0-or-later
6#
7
8#
9# This script is for running tools from native oe sysroot
10#
11
12if [ $# -lt 1 -o "$1" = '--help' -o "$1" = '-h' ] ; then
13    echo 'oe-run-native: the following arguments are required: <native recipe> <native tool>'
14    echo 'Usage: oe-run-native native-recipe tool [parameters]'
15    echo ''
16    echo 'OpenEmbedded run-native - runs native tools'
17    echo ''
18    echo 'arguments:'
19    echo '  native-recipe       The recipe which provides tool'
20    echo '  tool                Native tool to run'
21    echo ''
22    exit 2
23fi
24
25native_recipe="$1"
26tool="$2"
27
28if [ "${native_recipe%-native}" = "$native_recipe" ]; then
29    echo Error: $native_recipe is not a native recipe
30    echo Error: Use \"oe-run-native -h\" for help
31    exit 1
32fi
33
34shift
35
36SYSROOT_SETUP_SCRIPT=`which oe-find-native-sysroot 2> /dev/null`
37if [ -z "$SYSROOT_SETUP_SCRIPT" ]; then
38        echo "Error: Unable to find oe-find-native-sysroot script"
39        exit 1
40fi
41. $SYSROOT_SETUP_SCRIPT $native_recipe
42
43OLD_PATH=$PATH
44
45# look for a tool only in native sysroot
46PATH=$OECORE_NATIVE_SYSROOT/usr/bin:$OECORE_NATIVE_SYSROOT/bin:$OECORE_NATIVE_SYSROOT/usr/sbin:$OECORE_NATIVE_SYSROOT/sbin$(find $OECORE_NATIVE_SYSROOT/usr/bin -maxdepth 1 -name "*-native" -type d -printf ":%p")
47tool_find=`/usr/bin/which $tool 2>/dev/null`
48
49if [ -n "$tool_find" ] ; then
50    # add old path to allow usage of host tools
51    PATH=$PATH:$OLD_PATH "$@"
52else
53    echo "Error: Unable to find '$tool' in $PATH"
54    echo "Error: Have you run 'bitbake $native_recipe -caddto_recipe_sysroot'?"
55    exit 1
56fi
57