| 1 |
.. |
| 2 |
Licensed under the Apache License, Version 2.0 (the "License"); |
| 3 |
you may not use this file except in compliance with the License. |
| 4 |
You may obtain a copy of the License at |
| 5 |
|
| 6 |
http://www.apache.org/licenses/LICENSE-2.0 |
| 7 |
|
| 8 |
Unless required by applicable law or agreed to in writing, software |
| 9 |
distributed under the License is distributed on an "AS IS" BASIS, |
| 10 |
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 11 |
See the License for the specific language governing permissions and |
| 12 |
limitations under the License. |
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
.. _tutorial_first_project: |
| 17 |
|
| 18 |
Your first project |
| 19 |
================== |
| 20 |
To get a feel for the basics, we'll start with the most basic BuildStream project we |
| 21 |
could think of. |
| 22 |
|
| 23 |
.. note:: |
| 24 |
|
| 25 |
This example is distributed with BuildStream |
| 26 |
in the `doc/examples/first-project |
| 27 |
<https://github.com/apache/buildstream/tree/master/doc/examples/first-project>`_ |
| 28 |
subdirectory. |
| 29 |
|
| 30 |
|
| 31 |
Creating the project |
| 32 |
-------------------- |
| 33 |
First, lets create the project itself using the convenience :ref:`bst init <invoking_init>` |
| 34 |
command to create a little project structure: |
| 35 |
|
| 36 |
.. raw:: html |
| 37 |
:file: ../sessions/first-project-init.html |
| 38 |
|
| 39 |
|
| 40 |
This will give you a :ref:`project.conf <projectconf>` which will look like this: |
| 41 |
|
| 42 |
``project.conf`` |
| 43 |
~~~~~~~~~~~~~~~~ |
| 44 |
|
| 45 |
.. literalinclude:: ../../examples/first-project/project.conf |
| 46 |
:language: yaml |
| 47 |
|
| 48 |
The :ref:`project.conf <projectconf>` is a central point of configuration |
| 49 |
for your BuildStream project. |
| 50 |
|
| 51 |
|
| 52 |
Add some content |
| 53 |
---------------- |
| 54 |
BuildStream processes directory trees as input and output, |
| 55 |
so let's just create a ``hello.world`` file for the project |
| 56 |
to have. |
| 57 |
|
| 58 |
.. raw:: html |
| 59 |
:file: ../sessions/first-project-touch.html |
| 60 |
|
| 61 |
|
| 62 |
Declare the element |
| 63 |
------------------- |
| 64 |
Here we're going to declare a simple :mod:`import <elements.import>` element |
| 65 |
which will import the ``hello.world`` file we've created in the previous step. |
| 66 |
|
| 67 |
Create ``elements/hello.bst`` with the following content: |
| 68 |
|
| 69 |
|
| 70 |
``elements/hello.bst`` |
| 71 |
~~~~~~~~~~~~~~~~~~~~~~ |
| 72 |
|
| 73 |
.. literalinclude:: ../../examples/first-project/elements/hello.bst |
| 74 |
:language: yaml |
| 75 |
|
| 76 |
|
| 77 |
The source |
| 78 |
~~~~~~~~~~ |
| 79 |
The :mod:`local <sources.local>` source used by the ``hello.bst`` element, |
| 80 |
can be used to access files or directories which are stored in the same repository |
| 81 |
as your BuildStream project. The ``hello.bst`` element uses the :mod:`local <sources.local>` |
| 82 |
source to stage our local ``hello.world`` file. |
| 83 |
|
| 84 |
|
| 85 |
The element |
| 86 |
~~~~~~~~~~~ |
| 87 |
The :mod:`import <elements.import>` element can be used to simply add content |
| 88 |
directly to the output artifacts. In this case, it simply takes the ``hello.world`` file |
| 89 |
provided by its source and stages it directly to the artifact output root. |
| 90 |
|
| 91 |
.. tip:: |
| 92 |
|
| 93 |
In this example so far we've used two plugins, the :mod:`local <sources.local>` |
| 94 |
source and the :mod:`import <elements.import>` element. |
| 95 |
|
| 96 |
You can always browse the documentation for all plugins in |
| 97 |
the :ref:`plugins section <plugins>` of the manual. |
| 98 |
|
| 99 |
|
| 100 |
Build the element |
| 101 |
----------------- |
| 102 |
In order to carry out the activities of the :mod:`import <elements.import>` element |
| 103 |
we've declared, we're going to have to ask BuildStream to *build*. |
| 104 |
|
| 105 |
This process will collect all of the sources required for the specified ``hello.bst`` |
| 106 |
and get the backing :mod:`import <elements.import>` element to generate an *artifact* |
| 107 |
for us. |
| 108 |
|
| 109 |
.. raw:: html |
| 110 |
:file: ../sessions/first-project-build.html |
| 111 |
|
| 112 |
Now the artifact is ready. |
| 113 |
|
| 114 |
Using :ref:`bst show <invoking_show>`, we can observe that the artifact's state, which was reported |
| 115 |
as ``buildable`` in the :ref:`bst build <invoking_build>` command above, has now changed to ``cached``: |
| 116 |
|
| 117 |
.. raw:: html |
| 118 |
:file: ../sessions/first-project-show.html |
| 119 |
|
| 120 |
|
| 121 |
Observe the output |
| 122 |
------------------ |
| 123 |
Now that we've finished building, we can checkout the output of the |
| 124 |
artifact we've created using :ref:`bst artifact checkout <invoking_artifact_checkout>` |
| 125 |
|
| 126 |
.. raw:: html |
| 127 |
:file: ../sessions/first-project-checkout.html |
| 128 |
|
| 129 |
And observe that the file we expect is there: |
| 130 |
|
| 131 |
.. raw:: html |
| 132 |
:file: ../sessions/first-project-ls.html |
| 133 |
|
| 134 |
|
| 135 |
Summary |
| 136 |
------- |
| 137 |
In this section we've created our first BuildStream project from |
| 138 |
scratch, but it doesnt do much. |
| 139 |
|
| 140 |
We've observed the general structure of a BuildStream project, |
| 141 |
and we've run our first build. |