aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/lib/recipetool/create_npm.py
blob: 888aa2b00a39707d7bf3e27d4009c02f0b1dd748 (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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
# Recipe creation tool - node.js NPM module support plugin
#
# Copyright (C) 2016 Intel Corporation
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

import os
import logging
import subprocess
import tempfile
import shutil
import json
from recipetool.create import RecipeHandler, split_pkg_licenses, handle_license_vars, check_npm

logger = logging.getLogger('recipetool')


tinfoil = None

def tinfoil_init(instance):
    global tinfoil
    tinfoil = instance


class NpmRecipeHandler(RecipeHandler):
    lockdownpath = None

    def _handle_license(self, data):
        '''
        Handle the license value from an npm package.json file
        '''
        license = None
        if 'license' in data:
            license = data['license']
            if isinstance(license, dict):
                license = license.get('type', None)
        return license

    def _shrinkwrap(self, srctree, localfilesdir, extravalues, lines_before):
        try:
            runenv = dict(os.environ, PATH=tinfoil.config_data.getVar('PATH'))
            bb.process.run('npm shrinkwrap', cwd=srctree, stderr=subprocess.STDOUT, env=runenv, shell=True)
        except bb.process.ExecutionError as e:
            logger.warn('npm shrinkwrap failed:\n%s' % e.stdout)
            return

        tmpfile = os.path.join(localfilesdir, 'npm-shrinkwrap.json')
        shutil.move(os.path.join(srctree, 'npm-shrinkwrap.json'), tmpfile)
        extravalues.setdefault('extrafiles', {})
        extravalues['extrafiles']['npm-shrinkwrap.json'] = tmpfile
        lines_before.append('NPM_SHRINKWRAP := "${THISDIR}/${PN}/npm-shrinkwrap.json"')

    def _lockdown(self, srctree, localfilesdir, extravalues, lines_before):
        runenv = dict(os.environ, PATH=tinfoil.config_data.getVar('PATH'))
        if not NpmRecipeHandler.lockdownpath:
            NpmRecipeHandler.lockdownpath = tempfile.mkdtemp('recipetool-npm-lockdown')
            bb.process.run('npm install lockdown --prefix %s' % NpmRecipeHandler.lockdownpath,
                           cwd=srctree, stderr=subprocess.STDOUT, env=runenv, shell=True)
        relockbin = os.path.join(NpmRecipeHandler.lockdownpath, 'node_modules', 'lockdown', 'relock.js')
        if not os.path.exists(relockbin):
            logger.warn('Could not find relock.js within lockdown directory; skipping lockdown')
            return
        try:
            bb.process.run('node %s' % relockbin, cwd=srctree, stderr=subprocess.STDOUT, env=runenv, shell=True)
        except bb.process.ExecutionError as e:
            logger.warn('lockdown-relock failed:\n%s' % e.stdout)
            return

        tmpfile = os.path.join(localfilesdir, 'lockdown.json')
        shutil.move(os.path.join(srctree, 'lockdown.json'), tmpfile)
        extravalues.setdefault('extrafiles', {})
        extravalues['extrafiles']['lockdown.json'] = tmpfile
        lines_before.append('NPM_LOCKDOWN := "${THISDIR}/${PN}/lockdown.json"')

    def _handle_dependencies(self, d, deps, lines_before, srctree):
        import scriptutils
        # If this isn't a single module we need to get the dependencies
        # and add them to SRC_URI
        def varfunc(varname, origvalue, op, newlines):
            if varname == 'SRC_URI':
                if not origvalue.startswith('npm://'):
                    src_uri = origvalue.split()
                    changed = False
                    for dep, depdata in deps.items():
                        version = self.get_node_version(dep, depdata, d)
                        if version:
                            url = 'npm://registry.npmjs.org;name=%s;version=%s;subdir=node_modules/%s' % (dep, version, dep)
                            scriptutils.fetch_uri(d, url, srctree)
                            src_uri.append(url)
                            changed = True
                    if changed:
                        return src_uri, None, -1, True
            return origvalue, None, 0, True
        updated, newlines = bb.utils.edit_metadata(lines_before, ['SRC_URI'], varfunc)
        if updated:
            del lines_before[:]
            for line in newlines:
                # Hack to avoid newlines that edit_metadata inserts
                if line.endswith('\n'):
                    line = line[:-1]
                lines_before.append(line)
        return updated

    def _replace_license_vars(self, srctree, lines_before, handled, extravalues, d):
        for item in handled:
            if isinstance(item, tuple):
                if item[0] == 'license':
                    del item
                    break

        calledvars = []
        def varfunc(varname, origvalue, op, newlines):
            if varname in ['LICENSE', 'LIC_FILES_CHKSUM']:
                for i, e in enumerate(reversed(newlines)):
                    if not e.startswith('#'):
                        stop = i
                        while stop > 0:
                            newlines.pop()
                            stop -= 1
                        break
                calledvars.append(varname)
                if len(calledvars) > 1:
                    # The second time around, put the new license text in
                    insertpos = len(newlines)
                    handle_license_vars(srctree, newlines, handled, extravalues, d)
                return None, None, 0, True
            return origvalue, None, 0, True
        updated, newlines = bb.utils.edit_metadata(lines_before, ['LICENSE', 'LIC_FILES_CHKSUM'], varfunc)
        if updated:
            del lines_before[:]
            lines_before.extend(newlines)
        else:
            raise Exception('Did not find license variables')

    def process(self, srctree, classes, lines_before, lines_after, handled, extravalues):
        import bb.utils
        import oe
        from collections import OrderedDict

        if 'buildsystem' in handled:
            return False

        def read_package_json(fn):
            with open(fn, 'r', errors='surrogateescape') as f:
                return json.loads(f.read())

        files = RecipeHandler.checkfiles(srctree, ['package.json'])
        if files:
            check_npm(tinfoil.config_data)

            data = read_package_json(files[0])
            if 'name' in data and 'version' in data:
                extravalues['PN'] = data['name']
                extravalues['PV'] = data['version']
                classes.append('npm')
                handled.append('buildsystem')
                if 'description' in data:
                    extravalues['SUMMARY'] = data['description']
                if 'homepage' in data:
                    extravalues['HOMEPAGE'] = data['homepage']

                deps = data.get('dependencies', {})
                updated = self._handle_dependencies(tinfoil.config_data, deps, lines_before, srctree)
                if updated:
                    # We need to redo the license stuff
                    self._replace_license_vars(srctree, lines_before, handled, extravalues, tinfoil.config_data)

                # Shrinkwrap
                localfilesdir = tempfile.mkdtemp(prefix='recipetool-npm')
                self._shrinkwrap(srctree, localfilesdir, extravalues, lines_before)

                # Lockdown
                self._lockdown(srctree, localfilesdir, extravalues, lines_before)

                # Split each npm module out to is own package
                npmpackages = oe.package.npm_split_package_dirs(srctree)
                for item in handled:
                    if isinstance(item, tuple):
                        if item[0] == 'license':
                            licvalues = item[1]
                            break
                if licvalues:
                    # Augment the license list with information we have in the packages
                    licenses = {}
                    license = self._handle_license(data)
                    if license:
                        licenses['${PN}'] = license
                    for pkgname, pkgitem in npmpackages.items():
                        _, pdata = pkgitem
                        license = self._handle_license(pdata)
                        if license:
                            licenses[pkgname] = license
                    # Now write out the package-specific license values
                    # We need to strip out the json data dicts for this since split_pkg_licenses
                    # isn't expecting it
                    packages = OrderedDict((x,y[0]) for x,y in npmpackages.items())
                    packages['${PN}'] = ''
                    pkglicenses = split_pkg_licenses(licvalues, packages, lines_after, licenses)
                    all_licenses = list(set([item for pkglicense in pkglicenses.values() for item in pkglicense]))
                    # Go back and update the LICENSE value since we have a bit more
                    # information than when that was written out (and we know all apply
                    # vs. there being a choice, so we can join them with &)
                    for i, line in enumerate(lines_before):
                        if line.startswith('LICENSE = '):
                            lines_before[i] = 'LICENSE = "%s"' % ' & '.join(all_licenses)
                            break

                # Need to move S setting after inherit npm
                for i, line in enumerate(lines_before):
                    if line.startswith('S ='):
                        lines_before.pop(i)
                        lines_after.insert(0, '# Must be set after inherit npm since that itself sets S')
                        lines_after.insert(1, line)
                        break

                return True

        return False

    # FIXME this is duplicated from lib/bb/fetch2/npm.py
    def _parse_view(self, output):
        '''
        Parse the output of npm view --json; the last JSON result
        is assumed to be the one that we're interested in.
        '''
        pdata = None
        outdeps = {}
        datalines = []
        bracelevel = 0
        for line in output.splitlines():
            if bracelevel:
                datalines.append(line)
            elif '{' in line:
                datalines = []
                datalines.append(line)
            bracelevel = bracelevel + line.count('{') - line.count('}')
        if datalines:
            pdata = json.loads('\n'.join(datalines))
        return pdata

    # FIXME this is effectively duplicated from lib/bb/fetch2/npm.py
    # (split out from _getdependencies())
    def get_node_version(self, pkg, version, d):
        import bb.fetch2
        pkgfullname = pkg
        if version != '*' and not '/' in version:
            pkgfullname += "@'%s'" % version
        logger.debug(2, "Calling getdeps on %s" % pkg)
        runenv = dict(os.environ, PATH=d.getVar('PATH'))
        fetchcmd = "npm view %s --json" % pkgfullname
        output, _ = bb.process.run(fetchcmd, stderr=subprocess.STDOUT, env=runenv, shell=True)
        data = self._parse_view(output)
        return data.get('version', None)

def register_recipe_handlers(handlers):
    handlers.append((NpmRecipeHandler(), 60))
headless system: <literallayout class='monospaced'> $ sudo zypper install &OPENSUSE_HOST_PACKAGES_ESSENTIAL; </literallayout></para></listitem> <listitem><para><emphasis>Graphical and Eclipse Plug-In Extras:</emphasis> Packages recommended if the host system has graphics support or if you are going to use the Eclipse IDE: <literallayout class='monospaced'> $ sudo zypper install libSDL-devel xterm </literallayout></para></listitem> <listitem><para><emphasis>Documentation:</emphasis> Packages needed if you are going to build out the Yocto Project documentation manuals: <literallayout class='monospaced'> $ sudo zypper install make fop xsltproc dblatex xmlto </literallayout></para></listitem> <listitem><para><emphasis>OpenEmbedded Self-Test (<filename>oe-selftest</filename>):</emphasis> Packages needed if you are going to run <filename>oe-selftest</filename>: <literallayout class='monospaced'> $ sudo zypper install python-GitPython </literallayout></para></listitem> </itemizedlist> </para> </section> <section id='centos-packages'> <title>CentOS Packages</title> <para> The following list shows the required packages by function given a supported CentOS Linux distribution: <note> For CentOS 6.x, some of the versions of the components provided by the distribution are too old (e.g. Git, Python, and tar). It is recommended that you install the buildtools in order to provide versions that will work with the OpenEmbedded build system. For information on how to install the buildtools tarball, see the "<link linkend='required-git-tar-and-python-versions'>Required Git, Tar, and Python Versions</link>" section. </note> <itemizedlist> <listitem><para><emphasis>Essentials:</emphasis> Packages needed to build an image for a headless system: <literallayout class='monospaced'> $ sudo yum install &CENTOS_HOST_PACKAGES_ESSENTIAL; SDL-devel xterm </literallayout> <note><title>Notes</title> <itemizedlist> <listitem><para> Extra Packages for Enterprise Linux (i.e. <filename>epel-release</filename>) is a collection of packages from Fedora built on RHEL/CentOS for easy installation of packages not included in enterprise Linux by default. You need to install these packages separately. </para></listitem> <listitem><para> The <filename>makecache</filename> command consumes additional Metadata from <filename>epel-release</filename>. </para></listitem> </itemizedlist> </note> </para></listitem> <listitem><para><emphasis>Graphical and Eclipse Plug-In Extras:</emphasis> Packages recommended if the host system has graphics support or if you are going to use the Eclipse IDE: <literallayout class='monospaced'> $ sudo yum install SDL-devel xterm </literallayout></para></listitem> <listitem><para><emphasis>Documentation:</emphasis> Packages needed if you are going to build out the Yocto Project documentation manuals: <literallayout class='monospaced'> $ sudo yum install make docbook-style-dsssl docbook-style-xsl \ docbook-dtds docbook-utils fop libxslt dblatex xmlto xsltproc </literallayout></para></listitem> <listitem><para><emphasis>OpenEmbedded Self-Test (<filename>oe-selftest</filename>):</emphasis> Packages needed if you are going to run <filename>oe-selftest</filename>: <literallayout class='monospaced'> $ sudo yum install GitPython </literallayout> </para></listitem> </itemizedlist> </para> </section> </section> <section id='required-git-tar-and-python-versions'> <title>Required Git, tar, and Python Versions</title> <para> In order to use the build system, your host development system must meet the following version requirements for Git, tar, and Python: <itemizedlist> <listitem><para>Git 1.8.3.1 or greater</para></listitem> <listitem><para>tar 1.24 or greater</para></listitem> <listitem><para>Python 3.4.0 or greater</para></listitem> </itemizedlist> </para> <para> If your host development system does not meet all these requirements, you can resolve this by installing a <filename>buildtools</filename> tarball that contains these tools. You can get the tarball one of two ways: download a pre-built tarball or use BitBake to build the tarball. </para> <section id='downloading-a-pre-built-buildtools-tarball'> <title>Downloading a Pre-Built <filename>buildtools</filename> Tarball</title> <para> Downloading and running a pre-built buildtools installer is the easiest of the two methods by which you can get these tools: <orderedlist> <listitem><para> Locate and download the <filename>*.sh</filename> at <ulink url='&YOCTO_DL_URL;/releases/yocto/yocto-&DISTRO;/buildtools/'></ulink>. </para></listitem> <listitem><para> Execute the installation script. Here is an example: <literallayout class='monospaced'> $ sh poky-glibc-x86_64-buildtools-tarball-x86_64-buildtools-nativesdk-standalone-&DISTRO;.sh </literallayout> During execution, a prompt appears that allows you to choose the installation directory. For example, you could choose the following: <literallayout class='monospaced'> /home/<replaceable>your-username</replaceable>/buildtools </literallayout> </para></listitem> <listitem><para> Source the tools environment setup script by using a command like the following: <literallayout class='monospaced'> $ source /home/<replaceable>your_username</replaceable>/buildtools/environment-setup-i586-poky-linux </literallayout> Of course, you need to supply your installation directory and be sure to use the right file (i.e. i585 or x86-64). </para> <para> After you have sourced the setup script, the tools are added to <filename>PATH</filename> and any other environment variables required to run the tools are initialized. The results are working versions versions of Git, tar, Python and <filename>chrpath</filename>. </para></listitem> </orderedlist> </para> </section> <section id='building-your-own-buildtools-tarball'> <title>Building Your Own <filename>buildtools</filename> Tarball</title> <para> Building and running your own buildtools installer applies only when you have a build host that can already run BitBake. In this case, you use that machine to build the <filename>.sh</filename> file and then take steps to transfer and run it on a machine that does not meet the minimal Git, tar, and Python requirements. </para> <para> Here are the steps to take to build and run your own buildtools installer: <orderedlist> <listitem><para> On the machine that is able to run BitBake, be sure you have set up your build environment with the setup script (<link linkend='structure-core-script'><filename>&OE_INIT_FILE;</filename></link> or <link linkend='structure-memres-core-script'><filename>oe-init-build-env-memres</filename></link>). </para></listitem> <listitem><para> Run the BitBake command to build the tarball: <literallayout class='monospaced'> $ bitbake buildtools-tarball </literallayout> <note> The <link linkend='var-SDKMACHINE'><filename>SDKMACHINE</filename></link> variable in your <filename>local.conf</filename> file determines whether you build tools for a 32-bit or 64-bit system. </note> Once the build completes, you can find the <filename>.sh</filename> file that installs the tools in the <filename>tmp/deploy/sdk</filename> subdirectory of the <link linkend='build-directory'>Build Directory</link>. The installer file has the string "buildtools" in the name. </para></listitem> <listitem><para> Transfer the <filename>.sh</filename> file from the build host to the machine that does not meet the Git, tar, or Python requirements. </para></listitem> <listitem><para> On the machine that does not meet the requirements, run the <filename>.sh</filename> file to install the tools. Here is an example: <literallayout class='monospaced'> $ sh poky-glibc-x86_64-buildtools-tarball-x86_64-buildtools-nativesdk-standalone-&DISTRO;.sh </literallayout> During execution, a prompt appears that allows you to choose the installation directory. For example, you could choose the following: <literallayout class='monospaced'> /home/<replaceable>your_username</replaceable>/buildtools </literallayout> </para></listitem> <listitem><para> Source the tools environment setup script by using a command like the following: <literallayout class='monospaced'> $ source /home/<replaceable>your_username</replaceable>/buildtools/environment-setup-i586-poky-linux </literallayout> Of course, you need to supply your installation directory and be sure to use the right file (i.e. i585 or x86-64). </para> <para> After you have sourced the setup script, the tools are added to <filename>PATH</filename> and any other environment variables required to run the tools are initialized. The results are working versions versions of Git, tar, Python and <filename>chrpath</filename>. </para></listitem> </orderedlist> </para> </section> </section> </section> <section id='intro-getit'> <title>Obtaining the Yocto Project</title> <para> The Yocto Project development team makes the Yocto Project available through a number of methods: <itemizedlist> <listitem><para><emphasis>Source Repositories:</emphasis> Working from a copy of the upstream <filename>poky</filename> repository is the preferred method for obtaining and using a Yocto Project release. You can view the Yocto Project Source Repositories at <ulink url='&YOCTO_GIT_URL;/cgit.cgi'></ulink>. In particular, you can find the <filename>poky</filename> repository at <ulink url='http://git.yoctoproject.org/cgit/cgit.cgi/poky/'></ulink>. </para></listitem> <listitem><para><emphasis>Releases:</emphasis> Stable, tested releases are available as tarballs through <ulink url='&YOCTO_DL_URL;/releases/yocto/'/>.</para></listitem> <listitem><para><emphasis>Nightly Builds:</emphasis> These tarball releases are available at <ulink url='&YOCTO_AB_NIGHTLY_URL;'/>. These builds include Yocto Project releases, SDK installation scripts, and experimental builds. </para></listitem> <listitem><para><emphasis>Yocto Project Website:</emphasis> You can find tarball releases of the Yocto Project and supported BSPs at the <ulink url='&YOCTO_HOME_URL;'>Yocto Project website</ulink>. Along with these downloads, you can find lots of other information at this site. </para></listitem> </itemizedlist> </para> </section> <section id='intro-getit-dev'> <title>Development Checkouts</title> <para> Development using the Yocto Project requires a local <ulink url='&YOCTO_DOCS_DEV_URL;#source-directory'>Source Directory</ulink>. You can set up the Source Directory by cloning a copy of the upstream <ulink url='&YOCTO_DOCS_DEV_URL;#poky'>poky</ulink> Git repository. For information on how to do this, see the "<ulink url='&YOCTO_DOCS_DEV_URL;#getting-setup'>Getting Set Up</ulink>" section in the Yocto Project Development Manual. </para> </section> <section id='yocto-project-terms'> <title>Yocto Project Terms</title> <para> Following is a list of terms and definitions users new to the Yocto Project development environment might find helpful. While some of these terms are universal, the list includes them just in case: <itemizedlist> <listitem><para> <emphasis>Append Files:</emphasis> Files that append build information to a recipe file. Append files are known as BitBake append files and <filename>.bbappend</filename> files. The OpenEmbedded build system expects every append file to have a corresponding recipe (<filename>.bb</filename>) file. Furthermore, the append file and corresponding recipe file must use the same root filename. The filenames can differ only in the file type suffix used (e.g. <filename>formfactor_0.0.bb</filename> and <filename>formfactor_0.0.bbappend</filename>).</para> <para>Information in append files extends or overrides the information in the similarly-named recipe file. For an example of an append file in use, see the "<ulink url='&YOCTO_DOCS_DEV_URL;#using-bbappend-files'>Using .bbappend Files</ulink>" section in the Yocto Project Development Manual. <note> Append files can also use wildcard patterns in their version numbers so they can be applied to more than one version of the underlying recipe file. </note> </para></listitem> <listitem><para id='bitbake-term'> <emphasis>BitBake:</emphasis> The task executor and scheduler used by the OpenEmbedded build system to build images. For more information on BitBake, see the <ulink url='&YOCTO_DOCS_BB_URL;'>BitBake User Manual</ulink>. </para></listitem> <listitem> <para id='build-directory'> <emphasis>Build Directory:</emphasis> This term refers to the area used by the OpenEmbedded build system for builds. The area is created when you <filename>source</filename> the setup environment script that is found in the Source Directory (i.e. <link linkend='structure-core-script'><filename>&OE_INIT_FILE;</filename></link> or <link linkend='structure-memres-core-script'><filename>oe-init-build-env-memres</filename></link>). The <link linkend='var-TOPDIR'><filename>TOPDIR</filename></link> variable points to the Build Directory.</para> <para>You have a lot of flexibility when creating the Build Directory. Following are some examples that show how to create the directory. The examples assume your <link linkend='source-directory'>Source Directory</link> is named <filename>poky</filename>: <itemizedlist> <listitem><para>Create the Build Directory inside your Source Directory and let the name of the Build Directory default to <filename>build</filename>: <literallayout class='monospaced'> $ cd $HOME/poky $ source &OE_INIT_FILE; </literallayout> </para></listitem> <listitem><para>Create the Build Directory inside your home directory and specifically name it <filename>test-builds</filename>: <literallayout class='monospaced'> $ cd $HOME $ source poky/&OE_INIT_FILE; test-builds </literallayout> </para></listitem> <listitem><para> Provide a directory path and specifically name the Build Directory. Any intermediate folders in the pathname must exist. This next example creates a Build Directory named <filename>YP-&POKYVERSION;</filename> in your home directory within the existing directory <filename>mybuilds</filename>: <literallayout class='monospaced'> $cd $HOME $ source $HOME/poky/&OE_INIT_FILE; $HOME/mybuilds/YP-&POKYVERSION; </literallayout> </para></listitem> </itemizedlist> <note> By default, the Build Directory contains <link linkend='var-TMPDIR'><filename>TMPDIR</filename></link>, which is a temporary directory the build system uses for its work. <filename>TMPDIR</filename> cannot be under NFS. Thus, by default, the Build Directory cannot be under NFS. However, if you need the Build Directory to be under NFS, you can set this up by setting <filename>TMPDIR</filename> in your <filename>local.conf</filename> file to use a local drive. Doing so effectively separates <filename>TMPDIR</filename> from <filename>TOPDIR</filename>, which is the Build Directory. </note> </para></listitem> <listitem><para> <emphasis>Classes:</emphasis> Files that provide for logic encapsulation and inheritance so that commonly used patterns can be defined once and then easily used in multiple recipes. For reference information on the Yocto Project classes, see the "<link linkend='ref-classes'>Classes</link>" chapter. Class files end with the <filename>.bbclass</filename> filename extension. </para></listitem> <listitem><para> <emphasis>Configuration File:</emphasis> Configuration information in various <filename>.conf</filename> files provides global definitions of variables. The <filename>conf/local.conf</filename> configuration file in the <link linkend='build-directory'>Build Directory</link> contains user-defined variables that affect every build. The <filename>meta-poky/conf/distro/poky.conf</filename> configuration file defines Yocto "distro" configuration variables used only when building with this policy. Machine configuration files, which are located throughout the <link linkend='source-directory'>Source Directory</link>, define variables for specific hardware and are only used when building for that target (e.g. the <filename>machine/beaglebone.conf</filename> configuration file defines variables for the Texas Instruments ARM Cortex-A8 development board). Configuration files end with a <filename>.conf</filename> filename extension. </para></listitem> <listitem><para id='cross-development-toolchain'> <emphasis>Cross-Development Toolchain:</emphasis> In general, a cross-development toolchain is a collection of software development tools and utilities that run on one architecture and allow you to develop software for a different, or targeted, architecture. These toolchains contain cross-compilers, linkers, and debuggers that are specific to the target architecture.</para> <para>The Yocto Project supports two different cross-development toolchains: <itemizedlist> <listitem><para> A toolchain only used by and within BitBake when building an image for a target architecture. </para></listitem> <listitem><para>A relocatable toolchain used outside of BitBake by developers when developing applications that will run on a targeted device. </para></listitem> </itemizedlist></para> <para>Creation of these toolchains is simple and automated. For information on toolchain concepts as they apply to the Yocto Project, see the "<link linkend='cross-development-toolchain-generation'>Cross-Development Toolchain Generation</link>" section. You can also find more information on using the relocatable toolchain in the <ulink url='&YOCTO_DOCS_SDK_URL;'>Yocto Project Software Development Kit (SDK) Developer's Guide</ulink>. </para></listitem> <listitem><para> <emphasis>Image:</emphasis> An image is an artifact of the BitBake build process given a collection of recipes and related Metadata. Images are the binary output that run on specific hardware or QEMU and are used for specific use-cases. For a list of the supported image types that the Yocto Project provides, see the "<link linkend='ref-images'>Images</link>" chapter. </para></listitem> <listitem><para> <emphasis>Layer:</emphasis> A collection of recipes representing the core, a BSP, or an application stack. For a discussion specifically on BSP Layers, see the "<ulink url='&YOCTO_DOCS_BSP_URL;#bsp-layers'>BSP Layers</ulink>" section in the Yocto Project Board Support Packages (BSP) Developer's Guide. </para></listitem> <listitem><para id='metadata'> <emphasis>Metadata:</emphasis> The files that BitBake parses when building an image. In general, Metadata includes recipes, classes, and configuration files. In the context of the kernel ("kernel Metadata"), it refers to Metadata in the <filename>meta</filename> branches of the kernel source Git repositories. </para></listitem> <listitem><para id='oe-core'> <emphasis>OE-Core:</emphasis> A core set of Metadata originating with OpenEmbedded (OE) that is shared between OE and the Yocto Project. This Metadata is found in the <filename>meta</filename> directory of the <link linkend='source-directory'>Source Directory</link>. </para></listitem> <listitem><para id='build-system-term'> <emphasis>OpenEmbedded Build System:</emphasis> The build system specific to the Yocto Project. The OpenEmbedded build system is based on another project known as "Poky", which uses <link linkend='bitbake-term'>BitBake</link> as the task executor. Throughout the Yocto Project documentation set, the OpenEmbedded build system is sometimes referred to simply as "the build system". If other build systems, such as a host or target build system are referenced, the documentation clearly states the difference. <note> For some historical information about Poky, see the <link linkend='poky'>Poky</link> term. </note> </para></listitem> <listitem><para> <emphasis>Package:</emphasis> In the context of the Yocto Project, this term refers to a recipe's packaged output produced by BitBake (i.e. a "baked recipe"). A package is generally the compiled binaries produced from the recipe's sources. You "bake" something by running it through BitBake.</para> <para>It is worth noting that the term "package" can, in general, have subtle meanings. For example, the packages referred to in the "<ulink url='&YOCTO_DOCS_QS_URL;#packages'>The Build Host Packages</ulink>" section in the Yocto Project Quick Start are compiled binaries that, when installed, add functionality to your Linux distribution.</para> <para>Another point worth noting is that historically within the Yocto Project, recipes were referred to as packages - thus, the existence of several BitBake variables that are seemingly mis-named, (e.g. <link linkend='var-PR'><filename>PR</filename></link>, <link linkend='var-PV'><filename>PV</filename></link>, and <link linkend='var-PE'><filename>PE</filename></link>). </para></listitem> <listitem><para> <emphasis>Package Groups:</emphasis> Arbitrary groups of software Recipes. You use package groups to hold recipes that, when built, usually accomplish a single task. For example, a package group could contain the recipes for a company’s proprietary or value-add software. Or, the package group could contain the recipes that enable graphics. A package group is really just another recipe. Because package group files are recipes, they end with the <filename>.bb</filename> filename extension. </para></listitem> <listitem><para id='poky'> <emphasis>Poky:</emphasis> The term "poky", which is pronounced <emphasis>Pah</emphasis>-kee, can mean several things: <itemizedlist> <listitem><para> In its most general sense, poky is an open-source project that was initially developed by OpenedHand. OpenedHand developed poky off of the existing OpenEmbedded build system to create a commercially supportable build system for embedded Linux. After Intel Corporation acquired OpenedHand, the poky project became the basis for the Yocto Project's build system. </para></listitem> <listitem><para> Within the Yocto Project <ulink url='&YOCTO_GIT_URL;'>Source Repositories</ulink>, "poky" exists as a separate Git repository from which you can clone to yield a local Git repository that is a copy on your host system. Thus, "poky" can refer to the upstream or local copy of the files used for development within the Yocto Project. </para></listitem> <listitem><para> Finally, "poky" can refer to the default <link linkend='var-DISTRO'><filename>DISTRO</filename></link> (i.e. distribution) created when you use the Yocto Project in conjunction with the <filename>poky</filename> repository to build an image. </para></listitem> </itemizedlist> </para></listitem> <listitem><para> <emphasis>Recipe:</emphasis> A set of instructions for building packages. A recipe describes where you get source code, which patches to apply, how to configure the source, how to compile it and so on. Recipes also describe dependencies for libraries or for other recipes. Recipes represent the logical unit of execution, the software to build, the images to build, and use the <filename>.bb</filename> file extension. </para></listitem> <listitem> <para id='source-directory'> <emphasis>Source Directory:</emphasis> This term refers to the directory structure created as a result of creating a local copy of the <filename>poky</filename> Git repository <filename>git://git.yoctoproject.org/poky</filename> or expanding a released <filename>poky</filename> tarball. <note> Creating a local copy of the <filename>poky</filename> Git repository is the recommended method for setting up your Source Directory. </note> Sometimes you might hear the term "poky directory" used to refer to this directory structure. <note> The OpenEmbedded build system does not support file or directory names that contain spaces. Be sure that the Source Directory you use does not contain these types of names. </note></para> <para>The Source Directory contains BitBake, Documentation, Metadata and other files that all support the Yocto Project. Consequently, you must have the Source Directory in place on your development system in order to do any development using the Yocto Project.</para> <para>When you create a local copy of the Git repository, you can name the repository anything you like. Throughout much of the documentation, "poky" is used as the name of the top-level folder of the local copy of the poky Git repository. So, for example, cloning the <filename>poky</filename> Git repository results in a local Git repository whose top-level folder is also named "poky".</para> <para>While it is not recommended that you use tarball expansion to set up the Source Directory, if you do, the top-level directory name of the Source Directory is derived from the Yocto Project release tarball. For example, downloading and unpacking <filename>&YOCTO_POKY_TARBALL;</filename> results in a Source Directory whose root folder is named <filename>&YOCTO_POKY;</filename>.</para> <para>It is important to understand the differences between the Source Directory created by unpacking a released tarball as compared to cloning <filename>git://git.yoctoproject.org/poky</filename>. When you unpack a tarball, you have an exact copy of the files based on the time of release - a fixed release point. Any changes you make to your local files in the Source Directory are on top of the release and will remain local only. On the other hand, when you clone the <filename>poky</filename> Git repository, you have an active development repository with access to the upstream repository's branches and tags. In this case, any local changes you make to the local Source Directory can be later applied to active development branches of the upstream <filename>poky</filename> Git repository.</para> <para>For more information on concepts related to Git repositories, branches, and tags, see the "<link linkend='repositories-tags-and-branches'>Repositories, Tags, and Branches</link>" section. </para></listitem> <listitem><para><emphasis>Task:</emphasis> A unit of execution for BitBake (e.g. <link linkend='ref-tasks-compile'><filename>do_compile</filename></link>, <link linkend='ref-tasks-fetch'><filename>do_fetch</filename></link>, <link linkend='ref-tasks-patch'><filename>do_patch</filename></link>, and so forth). </para></listitem> <listitem><para> <emphasis>Upstream:</emphasis> A reference to source code or repositories that are not local to the development system but located in a master area that is controlled by the maintainer of the source code. For example, in order for a developer to work on a particular piece of code, they need to first get a copy of it from an "upstream" source. </para></listitem> </itemizedlist> </para> </section> </chapter> <!-- vim: expandtab tw=80 ts=4 -->