summaryrefslogtreecommitdiffstats
path: root/scripts/bitbake
blob: 79a81eaf0faaf580ad40e7dfa36b1920c791e6b0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
#!/bin/sh

# This is the bitbake wrapper script that ensures everything is set up
# correctly in the environment, builds pseudo separately if it hasn't
# already been built, and then runs bitbake within pseudo.

export BBFETCH2=True
export BB_ENV_EXTRAWHITE="PSEUDO_BUILD PSEUDO_DISABLED $BB_ENV_EXTRAWHITE"

# For certain operations (i.e. that won't be actually running any tasks)
# we don't need pseudo
NO_BUILD_OPTS="--version -h --help -p --parse-only -s --show-versions -e --environment -g --graphviz"

# Some options are useful to pass through to the initial pseudo build if
# that needs to be run (for debugging)
PASSTHROUGH_OPTS="-D -DD -DDD -DDDD -v"

needpseudo="1"
for opt in $@; do
for key in $NO_BUILD_OPTS; do
    if [ $opt = $key ]
    then
        needpseudo="0"
        break
    fi
done
[ $needpseudo = "0" ] && break
done

# Make sure we're not using python v3.x. This check can't go into
# sanity.bbclass because bitbake's source code doesn't even pass
# parsing stage when used with python v3, so we catch it here so we
# can offer a meaningful error message.
py_v3_check=`/usr/bin/env python --version 2>&1 | grep "Python 3"`
if [ "$py_v3_check" != "" ]; then
	echo "Bitbake is not compatible with python v3"
	echo "Please set up python v2 as your default python interpreter"
	exit 1
fi

# Similarly, we now have code that doesn't parse correctly with older
# versions of Python, and rather than fixing that and being eternally
# vigilant for any other new feature use, just check the version here.
py_v26_check=`python -c 'import sys; print sys.version_info >= (2,6,0)'`
if [ "$py_v26_check" != "True" ]; then
	echo "BitBake requires Python 2.6 or later"
	exit 1
fi

if [ ! -e conf/bblayers.conf ] ; then
    BDPRINT=""
    [ -n "$BUILDDIR" ] && BDPRINT=": $BUILDDIR"
    echo "Unable to find conf/bblayers.conf"
    echo "BitBake must be run from within your build directory$BDPRINT"
    exit 1
elif [ -z "$BUILDDIR" ] ; then
    BUILDDIR="`pwd`"
fi

needtar="1"
needgit="1"
TARVERSION=`tar --version | head -n 1 | cut -d ' ' -f 4`
GITVERSION=`git --version | cut -d ' ' -f 3`
float_test() {
     echo | awk 'END { exit ( !( '"$1"')); }'
}
version_compare() {
    python -c "from distutils.version import LooseVersion; import sys; sys.exit(not (LooseVersion('$1') $2 LooseVersion('$3')))"
}

# Tar version 1.24 and onwards handle overwriting symlinks correctly
# but earlier versions do not; this needs to work properly for sstate
float_test "$TARVERSION > 1.23" && needtar="0"

# Need git >= 1.7.5 for git-remote --mirror=xxx syntax
version_compare $GITVERSION ">=" 1.7.5 && needgit="0"


buildpseudo="1"
if [ $needpseudo = "1" ]; then
    if [ -e "$BUILDDIR/pseudodone" ]; then
        PSEUDOBINDIR=`cat $BUILDDIR/pseudodone`
    else
        PSEUDOBINDIR=`bitbake -e | grep STAGING_BINDIR_NATIVE=\" | cut -d '=' -f2 | cut -d '"' -f2`
    fi
    if [ -e "$PSEUDOBINDIR/pseudo" ]; then
        buildpseudo="0"
    fi

    # Verify that the pseudo recipes are older then the pseudodone file
    PSEUDO_RECIPE="`dirname $0`/../meta/recipes-devtools/pseudo"
    if [ $buildpseudo -eq 0 ] && [ ! -d "$PSEUDO_RECIPE" ]; then
        echo "Unable to verify if pseudo-native is up to date..." >&2
    elif [ $buildpseudo -eq 0 ]; then
	PSEUDO_NEWER=`find $PSEUDO_RECIPE -type f -newer $BUILDDIR/pseudodone`
	if [ -n "$PSEUDO_NEWER" ]; then
            buildpseudo="2"
	fi
    fi
    if [ $buildpseudo = "0" -a ! -e "$BUILDDIR/pseudodone" ] ; then
        echo $PSEUDOBINDIR > $BUILDDIR/pseudodone
    fi
fi

# If tar is already built, we don't want to do it again...
if [ -e "$PSEUDOBINDIR/tar" -a "$needtar" = "1" ]; then
    needtar="0"
fi
# If git is already built, we don't want to do it again...
if [ -e "$PSEUDOBINDIR/git" -a "$needgit" = "1" ]; then
    needgit="0"
fi

if [ $needpseudo = "0" ]; then
    buildpseudo="0"
fi

# If pseudo-native is an argument, assume the user wants to build pseudo-native!
if [ $needpseudo != "0" -a $buildpseudo -eq 0 ]; then
    for opt in $@; do
        if [ "$opt" = "pseudo-native" ]; then
            buildpseudo="3"
            break
        fi
    done
fi

OLDPATH=$PATH
export PATH=`echo $PATH | sed s#[^:]*/scripts:##`
if [ $buildpseudo -gt 0 ]; then
    [ $buildpseudo -eq 1 ] && echo "Pseudo is not present but is required, building this first before the main build"
    [ $buildpseudo -eq 2 ] && echo "Pseudo may be out of date, rebuilding pseudo before the main build"
    [ $buildpseudo -eq 3 ] && echo "Building pseudo-native before main build"
    export PSEUDO_BUILD=1
    TARTARGET="tar-replacement-native"
    if [ $needtar = "0" ]; then
        TARTARGET=""
    fi
    GITTARGET="git-replacement-native"
    if [ $needgit = "0" ]; then
        GITTARGET=""
    fi

    # Pass through debug options
    additionalopts=""
    for opt in $@; do
        for key in $PASSTHROUGH_OPTS; do
            if [ $opt = $key ]
            then
                additionalopts="$additionalopts $opt"
                break
            fi
        done
    done

    if [ $needtar = "1" ]; then
	bitbake $TARTARGET -c populate_sysroot
    fi

    bitbake pseudo-native $GITTARGET $additionalopts -c populate_sysroot
    ret=$?
    if [ "$ret" != "0" ]; then
        exit 1
    fi
    PSEUDOBINDIR=`bitbake -e | grep STAGING_BINDIR_NATIVE=\" | cut -d '=' -f2 | cut -d '"' -f2`
    ret=$?
    if [ "$ret" != "0" ]; then
        exit 1
    fi
    echo $PSEUDOBINDIR > $BUILDDIR/pseudodone
    # This needs to exist in case pseudo has to log somewhere
    mkdir -p $PSEUDOBINDIR/../../var/pseudo
fi
BITBAKE=`which bitbake`
export PATH=$OLDPATH
if [ $needpseudo = "1" ]; then
    export PSEUDO_BUILD=2
    PSEUDO_BINDIR=$PSEUDOBINDIR PSEUDO_LIBDIR=$PSEUDOBINDIR/../lib/pseudo/lib PSEUDO_PREFIX=$PSEUDOBINDIR/../../ PSEUDO_DISABLED=1 $PSEUDOBINDIR/pseudo $BITBAKE $@
else
    export PSEUDO_BUILD=0
    $BITBAKE $@
fi
ret=$?
exit $ret
OpenPOWER on IntegriCloud