Will Salmon pushed to branch willsalmon/outOfSourecBuild at BuildStream / buildstream
Commits:
-
755e5b9f
by William Salmon at 2018-09-20T10:00:53Z
-
90e9fe7f
by William Salmon at 2018-09-20T10:00:53Z
-
6babbc3f
by William Salmon at 2018-09-20T14:58:46Z
25 changed files:
- buildstream/buildelement.py
- buildstream/source.py
- + doc/examples/cmake/elements/base.bst
- + doc/examples/cmake/elements/base/alpine.bst
- + doc/examples/cmake/elements/hello.bst
- + doc/examples/cmake/files/hello/CMakeLists.txt
- + doc/examples/cmake/files/hello/main.c
- + doc/examples/cmake/project.conf
- + doc/examples/out-of-source-autotool-in-source-tree/elements/base.bst
- + doc/examples/out-of-source-autotool-in-source-tree/elements/base/alpine.bst
- + doc/examples/out-of-source-autotool-in-source-tree/elements/hello.bst
- + doc/examples/out-of-source-autotool-in-source-tree/project.conf
- + doc/examples/out-of-source-build-helloworld/elements/base.bst
- + doc/examples/out-of-source-build-helloworld/elements/base/alpine.bst
- + doc/examples/out-of-source-build-helloworld/elements/hello.bst
- + doc/examples/out-of-source-build-helloworld/files/hello/Makefile.am
- + doc/examples/out-of-source-build-helloworld/files/hello/README
- + doc/examples/out-of-source-build-helloworld/files/hello/configure.ac
- + doc/examples/out-of-source-build-helloworld/files/hello/src/Makefile.am
- + doc/examples/out-of-source-build-helloworld/files/hello/src/hello.c
- + doc/examples/out-of-source-build-helloworld/files/hello/src/libhello.c
- + doc/examples/out-of-source-build-helloworld/files/hello/src/libhello.h
- + doc/examples/out-of-source-build-helloworld/project.conf
- + tests/examples/autotools-outofsource.py
- + tests/examples/cmake.py
Changes:
... | ... | @@ -23,6 +23,38 @@ BuildElement - Abstract class for build elements |
23 | 23 |
The BuildElement class is a convenience element one can derive from for
|
24 | 24 |
implementing the most common case of element.
|
25 | 25 |
|
26 |
+Built-in functionality
|
|
27 |
+----------------------
|
|
28 |
+ |
|
29 |
+The BuildElement base class provides built in functionality that could be overridden by the
|
|
30 |
+individual plugins.
|
|
31 |
+ |
|
32 |
+This section will give a brief summary of how some of the common features work, some of them or the variables they
|
|
33 |
+use will be further detailed in the following sections.
|
|
34 |
+ |
|
35 |
+* Location for running commands
|
|
36 |
+ |
|
37 |
+ The ``command-subdir`` variable sets where the build commands will be executed, if the directory dose not exist it
|
|
38 |
+ will be created, it is defined relative to the buildroot.
|
|
39 |
+ |
|
40 |
+* Location for configuring the project
|
|
41 |
+ |
|
42 |
+ The ``conf-root`` is defined by default as ``.`` and is the location that specific build element can use to look
|
|
43 |
+ for build configuration files, currently autotools and cmake use this.
|
|
44 |
+ |
|
45 |
+ The configuration commands are run in ``command-subdir`` and by default ``conf-root`` is ``.`` so if
|
|
46 |
+ ``conf-root`` is not set the configuration files in ``command-subdir`` will be used.
|
|
47 |
+ |
|
48 |
+ By setting ``conf-root`` to ``"%{build-root}/Source/conf_location"`` and your source elements ``directory`` variable
|
|
49 |
+ to ``Source`` then the configuration files in the directory ``conf_location`` with in your Source will be used.
|
|
50 |
+ However the location where your configuration command will be run will still be wherever you set your
|
|
51 |
+ ``command-subdir`` to be.
|
|
52 |
+ |
|
53 |
+* Install Location
|
|
54 |
+ |
|
55 |
+ You should not change the ``install-root`` variable as it is a special writeable location in the sandbox but it is
|
|
56 |
+ useful when writing custom install instructions as it may need to be supplied as the ``DESTDIR``, please see the
|
|
57 |
+ cmake build element for example.
|
|
26 | 58 |
|
27 | 59 |
Abstract method implementations
|
28 | 60 |
-------------------------------
|
... | ... | @@ -20,6 +20,19 @@ |
20 | 20 |
Source - Base source class
|
21 | 21 |
==========================
|
22 | 22 |
|
23 |
+Built-in functionality
|
|
24 |
+----------------------
|
|
25 |
+ |
|
26 |
+The Source base class provides built in functionality that could be overridden by the
|
|
27 |
+individual plugins.
|
|
28 |
+ |
|
29 |
+* Directory
|
|
30 |
+ |
|
31 |
+ The ``directory`` variable can be set for all sources of a type in project.conf
|
|
32 |
+ or per source within a element.
|
|
33 |
+ |
|
34 |
+ This sets the location with in the build root that the content of the source will be
|
|
35 |
+ loaded in to. If the location dose not exist it will be created.
|
|
23 | 36 |
|
24 | 37 |
.. _core_source_abstract_methods:
|
25 | 38 |
|
1 |
+kind: stack
|
|
2 |
+description: Base stack
|
|
3 |
+ |
|
4 |
+depends:
|
|
5 |
+- base/alpine.bst
|
1 |
+kind: import
|
|
2 |
+description: |
|
|
3 |
+ |
|
4 |
+ Alpine Linux base runtime
|
|
5 |
+ |
|
6 |
+sources:
|
|
7 |
+- kind: tar
|
|
8 |
+ |
|
9 |
+ # This is a post doctored, trimmed down system image
|
|
10 |
+ # of the Alpine linux distribution.
|
|
11 |
+ #
|
|
12 |
+ url: alpine:integration-tests-base.v1.x86_64.tar.xz
|
|
13 |
+ ref: 3eb559250ba82b64a68d86d0636a6b127aa5f6d25d3601a79f79214dc9703639
|
1 |
+depends:
|
|
2 |
+- base.bst
|
|
3 |
+description: |2
|
|
4 |
+ |
|
5 |
+ Hello world example from cmake
|
|
6 |
+kind: cmake
|
|
7 |
+sources:
|
|
8 |
+- kind: local
|
|
9 |
+ path: files/hello
|
|
10 |
+ directory: Source
|
|
11 |
+variables:
|
|
12 |
+ command-subdir: build
|
|
13 |
+ conf-root: "%{build-root}/Source"
|
|
14 |
+ |
1 |
+ |
|
2 |
+# Set the minimum version of CMake that can be used
|
|
3 |
+# To find the cmake version run
|
|
4 |
+# $ cmake --version
|
|
5 |
+cmake_minimum_required(VERSION 2.8)
|
|
6 |
+ |
|
7 |
+# Set the project name
|
|
8 |
+project (hello_buildstreams C)
|
|
9 |
+ |
|
10 |
+# Add an executable
|
|
11 |
+add_executable(hello_buildstream main.c)
|
|
12 |
+ |
|
13 |
+ |
|
14 |
+install(TARGETS hello_buildstream DESTINATION /bin)
|
1 |
+#include <stdio.h>
|
|
2 |
+int main()
|
|
3 |
+{
|
|
4 |
+ // printf() displays the string inside quotation
|
|
5 |
+ printf("Hello, World!\n");
|
|
6 |
+ return 0;
|
|
7 |
+}
|
1 |
+# Unique project name
|
|
2 |
+name: cmake-out-of-source-build
|
|
3 |
+ |
|
4 |
+# Required BuildStream format version
|
|
5 |
+format-version: 9
|
|
6 |
+ |
|
7 |
+# Subdirectory where elements are stored
|
|
8 |
+element-path: elements
|
|
9 |
+ |
|
10 |
+# Define some aliases for the tarballs we download
|
|
11 |
+aliases:
|
|
12 |
+ alpine: https://gnome7.codethink.co.uk/tarballs/
|
|
13 |
+ gnu: https://ftp.gnu.org/gnu/automake/
|
1 |
+kind: stack
|
|
2 |
+description: Base stack
|
|
3 |
+ |
|
4 |
+depends:
|
|
5 |
+- base/alpine.bst
|
1 |
+kind: import
|
|
2 |
+description: |
|
|
3 |
+ |
|
4 |
+ Alpine Linux base runtime
|
|
5 |
+ |
|
6 |
+sources:
|
|
7 |
+- kind: tar
|
|
8 |
+ |
|
9 |
+ # This is a post doctored, trimmed down system image
|
|
10 |
+ # of the Alpine linux distribution.
|
|
11 |
+ #
|
|
12 |
+ url: alpine:integration-tests-base.v1.x86_64.tar.xz
|
|
13 |
+ ref: 3eb559250ba82b64a68d86d0636a6b127aa5f6d25d3601a79f79214dc9703639
|
1 |
+depends:
|
|
2 |
+- base.bst
|
|
3 |
+description: |2
|
|
4 |
+ |
|
5 |
+ Hello world example from automake
|
|
6 |
+kind: autotools
|
|
7 |
+sources:
|
|
8 |
+- directory: SourB
|
|
9 |
+ kind: tar
|
|
10 |
+ ref: 80da43bb5665596ee389e6d8b64b4f122ea4b92a685b1dbd813cd1f0e0c2d83f
|
|
11 |
+ url: gnu:automake-1.16.tar.gz
|
|
12 |
+variables:
|
|
13 |
+ conf-root: "%{build-root}/SourB/doc/amhello"
|
|
14 |
+ command-subdir: build
|
|
15 |
+ |
1 |
+# Unique project name
|
|
2 |
+name: Out-of-Source-builds-in-autotool-in-Source-tree
|
|
3 |
+ |
|
4 |
+# Required BuildStream format version
|
|
5 |
+format-version: 9
|
|
6 |
+ |
|
7 |
+# Subdirectory where elements are stored
|
|
8 |
+element-path: elements
|
|
9 |
+ |
|
10 |
+# Define some aliases for the tarballs we download
|
|
11 |
+aliases:
|
|
12 |
+ alpine: https://gnome7.codethink.co.uk/tarballs/
|
|
13 |
+ gnu: https://ftp.gnu.org/gnu/automake/
|
1 |
+kind: stack
|
|
2 |
+description: Base stack
|
|
3 |
+ |
|
4 |
+depends:
|
|
5 |
+- base/alpine.bst
|
1 |
+kind: import
|
|
2 |
+description: |
|
|
3 |
+ |
|
4 |
+ Alpine Linux base runtime
|
|
5 |
+ |
|
6 |
+sources:
|
|
7 |
+- kind: tar
|
|
8 |
+ |
|
9 |
+ # This is a post doctored, trimmed down system image
|
|
10 |
+ # of the Alpine linux distribution.
|
|
11 |
+ #
|
|
12 |
+ url: alpine:integration-tests-base.v1.x86_64.tar.xz
|
|
13 |
+ ref: 3eb559250ba82b64a68d86d0636a6b127aa5f6d25d3601a79f79214dc9703639
|
1 |
+depends:
|
|
2 |
+- base.bst
|
|
3 |
+description: |2
|
|
4 |
+ |
|
5 |
+ Hello world example from automake
|
|
6 |
+kind: autotools
|
|
7 |
+sources:
|
|
8 |
+- directory: Source
|
|
9 |
+ kind: local
|
|
10 |
+ path: files/hello
|
|
11 |
+variables:
|
|
12 |
+ conf-root: "%{build-root}/Source"
|
|
13 |
+ command-subdir: build
|
|
14 |
+ |
1 |
+SUBDIRS = src
|
1 |
+AC_INIT([helloworld], [0.1], [will salmon codethink co uk])
|
|
2 |
+AM_INIT_AUTOMAKE([-Wall -Werror foreign])
|
|
3 |
+AC_PROG_CC
|
|
4 |
+AC_CONFIG_FILES([Makefile
|
|
5 |
+ src/Makefile])
|
|
6 |
+AC_OUTPUT
|
1 |
+bin_PROGRAMS = hello
|
|
2 |
+hello_SOURCES = hello.c libhello.c
|
1 |
+/*
|
|
2 |
+ * hello.c - Simple hello program
|
|
3 |
+ */
|
|
4 |
+#include <stdio.h>
|
|
5 |
+#include <libhello.h>
|
|
6 |
+ |
|
7 |
+int main(int argc, char *argv[])
|
|
8 |
+{
|
|
9 |
+ const char *person = NULL;
|
|
10 |
+ |
|
11 |
+ if (argc > 1)
|
|
12 |
+ person = argv[1];
|
|
13 |
+ |
|
14 |
+ if (person)
|
|
15 |
+ hello(person);
|
|
16 |
+ else
|
|
17 |
+ hello("stranger");
|
|
18 |
+ |
|
19 |
+ return 0;
|
|
20 |
+}
|
1 |
+/*
|
|
2 |
+ * libhello.c - The hello library
|
|
3 |
+ */
|
|
4 |
+#include <stdio.h>
|
|
5 |
+ |
|
6 |
+void hello(const char *person)
|
|
7 |
+{
|
|
8 |
+ printf("Hello %s\n", person);
|
|
9 |
+}
|
1 |
+/*
|
|
2 |
+ * libhello.h - The hello library
|
|
3 |
+ */
|
|
4 |
+ |
|
5 |
+/*
|
|
6 |
+ * A function to say hello to @person
|
|
7 |
+ */
|
|
8 |
+void hello(const char *person);
|
1 |
+# Unique project name
|
|
2 |
+name: our-of-source-build-helloworld
|
|
3 |
+ |
|
4 |
+# Required BuildStream format version
|
|
5 |
+format-version: 9
|
|
6 |
+ |
|
7 |
+# Subdirectory where elements are stored
|
|
8 |
+element-path: elements
|
|
9 |
+ |
|
10 |
+# Define some aliases for the tarballs we download
|
|
11 |
+aliases:
|
|
12 |
+ alpine: https://gnome7.codethink.co.uk/tarballs/
|
|
13 |
+ gnu: https://ftp.gnu.org/gnu/automake/
|
1 |
+import os
|
|
2 |
+import pytest
|
|
3 |
+ |
|
4 |
+from tests.testutils import cli_integration as cli
|
|
5 |
+from tests.testutils.integration import assert_contains
|
|
6 |
+from tests.testutils.site import IS_LINUX
|
|
7 |
+ |
|
8 |
+pytestmark = pytest.mark.integration
|
|
9 |
+ |
|
10 |
+DATA_DIR = os.path.join(
|
|
11 |
+ os.path.dirname(os.path.realpath(__file__)), '..', '..', 'doc', 'examples',
|
|
12 |
+ 'out-of-source-autotool-in-source-tree'
|
|
13 |
+)
|
|
14 |
+ |
|
15 |
+ |
|
16 |
+# Tests a build of the autotools amhello project on a alpine-linux base runtime
|
|
17 |
+@pytest.mark.skipif(not IS_LINUX, reason='Only available on linux')
|
|
18 |
+@pytest.mark.datafiles(DATA_DIR)
|
|
19 |
+def test_autotools_build(cli, tmpdir, datafiles):
|
|
20 |
+ project = os.path.join(datafiles.dirname, datafiles.basename)
|
|
21 |
+ checkout = os.path.join(cli.directory, 'checkout')
|
|
22 |
+ |
|
23 |
+ # Check that the project can be built correctly.
|
|
24 |
+ result = cli.run(project=project, args=['build', 'hello.bst'])
|
|
25 |
+ result.assert_success()
|
|
26 |
+ |
|
27 |
+ result = cli.run(project=project, args=['checkout', 'hello.bst', checkout])
|
|
28 |
+ result.assert_success()
|
|
29 |
+ |
|
30 |
+ assert_contains(checkout, ['/usr', '/usr/lib', '/usr/bin',
|
|
31 |
+ '/usr/share', '/usr/lib/debug',
|
|
32 |
+ '/usr/lib/debug/usr', '/usr/lib/debug/usr/bin',
|
|
33 |
+ '/usr/lib/debug/usr/bin/hello',
|
|
34 |
+ '/usr/bin/hello',
|
|
35 |
+ '/usr/share/doc', '/usr/share/doc/amhello',
|
|
36 |
+ '/usr/share/doc/amhello/README'])
|
|
37 |
+ |
|
38 |
+ |
|
39 |
+# Test running an executable built with autotools.
|
|
40 |
+@pytest.mark.skipif(not IS_LINUX, reason='Only available on linux')
|
|
41 |
+@pytest.mark.datafiles(DATA_DIR)
|
|
42 |
+def test_autotools_run(cli, tmpdir, datafiles):
|
|
43 |
+ project = os.path.join(datafiles.dirname, datafiles.basename)
|
|
44 |
+ |
|
45 |
+ result = cli.run(project=project, args=['build', 'hello.bst'])
|
|
46 |
+ result.assert_success()
|
|
47 |
+ |
|
48 |
+ result = cli.run(project=project, args=['shell', 'hello.bst', 'hello'])
|
|
49 |
+ result.assert_success()
|
|
50 |
+ assert result.output == 'Hello World!\nThis is amhello 1.0.\n'
|
1 |
+import os
|
|
2 |
+import pytest
|
|
3 |
+ |
|
4 |
+from tests.testutils import cli_integration as cli
|
|
5 |
+from tests.testutils.integration import assert_contains
|
|
6 |
+from tests.testutils.site import IS_LINUX
|
|
7 |
+ |
|
8 |
+pytestmark = pytest.mark.integration
|
|
9 |
+ |
|
10 |
+DATA_DIR = os.path.join(
|
|
11 |
+ os.path.dirname(os.path.realpath(__file__)), '..', '..', 'doc', 'examples', 'cmake'
|
|
12 |
+)
|
|
13 |
+ |
|
14 |
+ |
|
15 |
+# Tests a build using cmake with the C complier from alpine-linux base runtime
|
|
16 |
+@pytest.mark.skipif(not IS_LINUX, reason='Only available on linux')
|
|
17 |
+@pytest.mark.datafiles(DATA_DIR)
|
|
18 |
+def test_autotools_build(cli, tmpdir, datafiles):
|
|
19 |
+ project = os.path.join(datafiles.dirname, datafiles.basename)
|
|
20 |
+ checkout = os.path.join(cli.directory, 'checkout')
|
|
21 |
+ |
|
22 |
+ # Check that the project can be built correctly.
|
|
23 |
+ result = cli.run(project=project, args=['build', 'hello.bst'])
|
|
24 |
+ result.assert_success()
|
|
25 |
+ |
|
26 |
+ result = cli.run(project=project, args=['checkout', 'hello.bst', checkout])
|
|
27 |
+ result.assert_success()
|
|
28 |
+ |
|
29 |
+ assert_contains(checkout, ['/usr', '/usr/lib', '/usr/bin',
|
|
30 |
+ '/usr/share',
|
|
31 |
+ '/bin/hello_buildstream'])
|
|
32 |
+ |
|
33 |
+ |
|
34 |
+# Test running an executable built with cmake.
|
|
35 |
+@pytest.mark.skipif(not IS_LINUX, reason='Only available on linux')
|
|
36 |
+@pytest.mark.datafiles(DATA_DIR)
|
|
37 |
+def test_autotools_run(cli, tmpdir, datafiles):
|
|
38 |
+ project = os.path.join(datafiles.dirname, datafiles.basename)
|
|
39 |
+ |
|
40 |
+ result = cli.run(project=project, args=['build', 'hello.bst'])
|
|
41 |
+ result.assert_success()
|
|
42 |
+ |
|
43 |
+ result = cli.run(project=project, args=['shell', 'hello.bst', 'hello_buildstream'])
|
|
44 |
+ result.assert_success()
|
|
45 |
+ assert result.output == 'Hello, World!\n'
|