From b7e75ee75df228e15e903fa81bd09dfbe364ecd1 Mon Sep 17 00:00:00 2001 From: Calvin Walton Date: Wed, 22 Dec 2021 13:06:22 -0500 Subject: [PATCH 1/5] Add meson build system --- docs/index.py | 5 +++++ docs/meson.build | 46 +++++++++++++++++++++++++++++++++++++++ lib/meson.build | 30 ++++++++++++++++++++++++++ lib/version.cc.in | 1 + meson.build | 33 ++++++++++++++++++++++++++++ meson_options.txt | 4 ++++ scripts/beesd.in | 2 +- scripts/meson.build | 25 ++++++++++++++++++++++ src/bees-usage.py | 9 ++++++++ src/bees-version.c.in | 1 + src/meson.build | 50 +++++++++++++++++++++++++++++++++++++++++++ test/meson.build | 23 ++++++++++++++++++++ 12 files changed, 228 insertions(+), 1 deletion(-) create mode 100644 docs/index.py create mode 100644 docs/meson.build create mode 100644 lib/meson.build create mode 100644 lib/version.cc.in create mode 100644 meson.build create mode 100644 meson_options.txt create mode 100644 scripts/meson.build create mode 100644 src/bees-usage.py create mode 100644 src/bees-version.c.in create mode 100644 src/meson.build create mode 100644 test/meson.build diff --git a/docs/index.py b/docs/index.py new file mode 100644 index 00000000..f720eb36 --- /dev/null +++ b/docs/index.py @@ -0,0 +1,5 @@ +import sys + +# Rewrite relative links in index file to remove 'docs/' prefix +with open(sys.argv[1]) as file: + sys.stdout.write(file.read().replace('docs/', '')) diff --git a/docs/meson.build b/docs/meson.build new file mode 100644 index 00000000..dcf6f44d --- /dev/null +++ b/docs/meson.build @@ -0,0 +1,46 @@ +markdown_bin = find_program( + 'cmark-gfm', 'redcarpet', 'markdown2', 'markdown', 'markdown_py', + disabler: true, + required: get_option('docs') +) + +if markdown_bin.found() and markdown_bin.full_path().endswith('cmark-gfm') + markdown_args = [ '-e', 'table' ] +else + if markdown_bin.found() + warning('The preferred markdown tool cmark-gfm was not found, you will not get Github-style tables.') + endif + markdown_args = [] +endif + +index_md = custom_target( + input: [ 'index.py', '../README.md' ], + output: 'index.md', + command: [ python, '@INPUT@' ], + capture: true, +) + +docs_md = [ + 'btrfs-kernel.md', + 'btrfs-other.md', + 'config.md', + 'event-counters.md', + 'gotchas.md', + 'how-it-works.md', + 'install.md', + 'missing.md', + 'options.md', + 'running.md', + 'wrong.md', + index_md, +] + +foreach doc_md: docs_md + custom_target( + build_by_default: true, + capture: true, + command: [ markdown_bin ] + markdown_args + '@INPUT@', + input: doc_md, + output: '@BASENAME@.html', + ) +endforeach diff --git a/lib/meson.build b/lib/meson.build new file mode 100644 index 00000000..0fae16ae --- /dev/null +++ b/lib/meson.build @@ -0,0 +1,30 @@ +crucible_version_cc = vcs_tag( + input: 'version.cc.in', + output: 'version.cc', + replace_string: '@VERSION@', +) + +crucible_lib = static_library( + 'crucible', + [ + 'bytevector.cc', + 'chatter.cc', + 'city.cc', + 'cleanup.cc', + 'crc64.cc', + 'error.cc', + 'extentwalker.cc', + 'fd.cc', + 'fs.cc', + 'ntoa.cc', + 'path.cc', + 'process.cc', + 'string.cc', + 'task.cc', + 'time.cc', + 'uname.cc', + crucible_version_cc, + ], + dependencies: [ thread_dep ], + include_directories: [ inc ], +) diff --git a/lib/version.cc.in b/lib/version.cc.in new file mode 100644 index 00000000..670fd0fb --- /dev/null +++ b/lib/version.cc.in @@ -0,0 +1 @@ +namespace crucible { const char *VERSION = "@VERSION@"; } diff --git a/meson.build b/meson.build new file mode 100644 index 00000000..fe06ee8d --- /dev/null +++ b/meson.build @@ -0,0 +1,33 @@ +project( + 'bees', + [ 'c', 'cpp', ], + default_options : [ + 'warning_level=3', + 'c_std=c99', + 'cpp_std=c++11', + ], + license: 'GPL-3.0-or-later', + version : '0.7', +) + +# Helper scripts for source generation are written in python. +# Use the same python as meson was run with. +pymod = import('python') +python = pymod.find_installation() + +systemd_dep = dependency('systemd', disabler: true, required: get_option('systemd')) +systemdsystemunitdir = systemd_dep.get_variable('systemdsystemunitdir') + +# This is meson automagic to figure out how to enable pthreads +thread_dep = dependency('threads') + +inc = include_directories('include') + +beesconfdir = get_option('sysconfdir') / 'bees' +beeslibdir = get_option('libdir') / 'bees' + +subdir('lib') +subdir('src') +subdir('test') +subdir('docs') +subdir('scripts') diff --git a/meson_options.txt b/meson_options.txt new file mode 100644 index 00000000..de51ab09 --- /dev/null +++ b/meson_options.txt @@ -0,0 +1,4 @@ +option('docs', type: 'feature', value: 'auto', + description: 'Build HTML documentation from Markdown source') +option('systemd', type: 'feature', value: 'auto', + description: 'Install systemd unit files') diff --git a/scripts/beesd.in b/scripts/beesd.in index 0e0bdb6e..b1f03887 100755 --- a/scripts/beesd.in +++ b/scripts/beesd.in @@ -31,7 +31,7 @@ help(){ exec "$bees_bin" --help } -for i in $(/usr/lib/bees/bees --help 2>&1 | grep "\-\-" | sed -e "s/^[^-]*-/-/" -e "s/,[^-]*--/ --/" -e "s/ [^-]*$//") +for i in $("$bees_bin" --help 2>&1 | grep "\-\-" | sed -e "s/^[^-]*-/-/" -e "s/,[^-]*--/ --/" -e "s/ [^-]*$//") do TMP_ARGS="$TMP_ARGS $i" done diff --git a/scripts/meson.build b/scripts/meson.build new file mode 100644 index 00000000..77f7c55f --- /dev/null +++ b/scripts/meson.build @@ -0,0 +1,25 @@ +scripts_config = configuration_data({ + 'PREFIX': get_option('prefix'), + 'ETC_PREFIX': get_option('prefix') / get_option('sysconfdir'), + 'LIBEXEC_PREFIX': get_option('prefix') / beeslibdir, +}) + +configure_file( + configuration: scripts_config, + input: 'beesd.in', + install: true, + install_dir: get_option('sbindir'), + install_mode: 'rwxr-xr-x', + output: 'beesd', +) + +configure_file( + configuration: scripts_config, + input: 'beesd@.service.in', + install: true, + install_dir: systemdsystemunitdir, + install_mode: 'rw-r--r--', + output: 'beesd@.service', +) + +install_data('beesd.conf.sample', install_dir: beesconfdir, install_mode: 'rw-r--r--') diff --git a/src/bees-usage.py b/src/bees-usage.py new file mode 100644 index 00000000..f6038bdf --- /dev/null +++ b/src/bees-usage.py @@ -0,0 +1,9 @@ +import sys + +c_str_escape = str.maketrans({'\n': '\\n', '"': '\\"', '\\': '\\\\'}) + +print("const char *BEES_USAGE = ") +with open(sys.argv[1]) as file: + for line in file: + print('"{}"'.format(line.translate(c_str_escape))) +print(";") diff --git a/src/bees-version.c.in b/src/bees-version.c.in new file mode 100644 index 00000000..7ea8f6d8 --- /dev/null +++ b/src/bees-version.c.in @@ -0,0 +1 @@ +const char *BEES_VERSION = "@VERSION@"; diff --git a/src/meson.build b/src/meson.build new file mode 100644 index 00000000..a98c4ad6 --- /dev/null +++ b/src/meson.build @@ -0,0 +1,50 @@ +bees_version_c = vcs_tag( + input: 'bees-version.c.in', + output: 'bees-version.c', + replace_string: '@VERSION@', +) + +bees_usage_c = custom_target( + input: [ 'bees-usage.py', 'bees-usage.txt' ], + output: 'bees-usage.c', + command: [ python, '@INPUT@' ], + capture: true, +) + +executable( + 'bees', + [ + 'bees.cc', + 'bees-context.cc', + 'bees-hash.cc', + 'bees-resolve.cc', + 'bees-roots.cc', + 'bees-thread.cc', + 'bees-trace.cc', + 'bees-types.cc', + bees_version_c, + bees_usage_c, + ], + dependencies: [ thread_dep ], + include_directories: [ inc ], + install: true, + install_dir: beeslibdir, + link_with: [ crucible_lib ], +) + +executable( + 'fiemap', + [ 'fiemap.cc' ], + include_directories: [ inc ], + install: true, + link_with: [ crucible_lib ], +) + +executable( + 'fiewalk', + [ 'fiewalk.cc' ], + include_directories: [ inc ], + install: true, + install_dir: get_option('sbindir'), + link_with: [ crucible_lib ], +) diff --git a/test/meson.build b/test/meson.build new file mode 100644 index 00000000..54e0aa0f --- /dev/null +++ b/test/meson.build @@ -0,0 +1,23 @@ +tests = [ + 'chatter', + 'crc64', + 'fd', + 'limits', + 'namedptr', + 'path', + 'process', + 'progress', + 'task' +] + +test_workdir = meson.current_source_dir() + +foreach test_name: tests + exe = executable( + test_name, + [ '@0@.cc'.format(test_name) ], + include_directories: [ inc ], + link_with: [ crucible_lib ], + ) + test(test_name, exe, workdir: test_workdir) +endforeach From ab429b35aa54cd6deac2fa59a44f4f9233f17647 Mon Sep 17 00:00:00 2001 From: Calvin Walton Date: Wed, 22 Dec 2021 13:47:29 -0500 Subject: [PATCH 2/5] Update install docs for meson build system --- docs/install.md | 48 +++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 41 insertions(+), 7 deletions(-) diff --git a/docs/install.md b/docs/install.md index 5ff53ba0..9f2f0159 100644 --- a/docs/install.md +++ b/docs/install.md @@ -60,8 +60,43 @@ If you want to start hacking on bees and contribute changes, just emerge the live version which automatically pulls in all required development packages. -Build from source ------------------ +Build from source with meson +----------------------------- + +The quick steps to build and test: + +```sh +$ cd /path/to/source/bees +$ meson builddir && cd builddir +$ meson compile +$ meson test +``` + +The build produces `src/bees` in the `builddir`. + +It will also generate `scripts/beesd@.service` for systemd users. This +service makes use of a helper script `scripts/beesd` to boot the service. +Both of the latter use the filesystem UUID to mount the root subvolume +within a temporary runtime directory. + +You can install these files to the configured prefix using `meson install` +or manually copy them as you like. + +Depending on your Linux distribution, you may need to install some +dependencies first: + +### Ubuntu 16.04 - 17.04: +```sh +$ apt -y install build-essential btrfs-tools markdown meson +``` + +### Ubuntu 18.10: +```sh +$ apt -y install build-essential btrfs-progs markdown meson +``` + +Build from source with make +--------------------------- Build with `make`. The build produces `bin/bees` which must be copied to somewhere in `$PATH` on the target system respectively. @@ -80,12 +115,11 @@ within a temporary runtime directory. Packaging --------- -See 'Dependencies' below. Package maintainers can pick ideas for building and +See 'Dependencies' above. Package maintainers can pick ideas for building and configuring the source package from the Gentoo ebuild: -You can configure some build options by creating a file `localconf` and -adjust settings for your distribution environment there. - -Please also review the Makefile for additional hints. +When using the `make` build system, you can configure some build options by +creating a file `localconf` and adjust settings for your distribution +environment there. Please also review the Makefile for additional hints. From eb0236e44d5470f0ff6cd5401a65965272e5ce18 Mon Sep 17 00:00:00 2001 From: Calvin Walton Date: Wed, 22 Dec 2021 14:04:46 -0500 Subject: [PATCH 3/5] meson: Don't install fiemap, fiewalk by default --- meson_options.txt | 2 ++ src/meson.build | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/meson_options.txt b/meson_options.txt index de51ab09..073b1b9f 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -2,3 +2,5 @@ option('docs', type: 'feature', value: 'auto', description: 'Build HTML documentation from Markdown source') option('systemd', type: 'feature', value: 'auto', description: 'Install systemd unit files') +option('tools', type: 'boolean', value: false, + description: 'Install fiemap and fiewalk helper tools') diff --git a/src/meson.build b/src/meson.build index a98c4ad6..b76a8526 100644 --- a/src/meson.build +++ b/src/meson.build @@ -36,7 +36,7 @@ executable( 'fiemap', [ 'fiemap.cc' ], include_directories: [ inc ], - install: true, + install: get_option('tools'), link_with: [ crucible_lib ], ) @@ -44,7 +44,7 @@ executable( 'fiewalk', [ 'fiewalk.cc' ], include_directories: [ inc ], - install: true, + install: get_option('tools'), install_dir: get_option('sbindir'), link_with: [ crucible_lib ], ) From 82e8d79e0c262fbaabf106e1070806c4bdf1147d Mon Sep 17 00:00:00 2001 From: Calvin Walton Date: Wed, 22 Dec 2021 14:38:53 -0500 Subject: [PATCH 4/5] meson: Ensure "implicit_include_directories" is disabled Having the implicit directories present causes some rebuilds to fail due to name collisions. --- lib/meson.build | 1 + src/meson.build | 3 +++ test/meson.build | 1 + 3 files changed, 5 insertions(+) diff --git a/lib/meson.build b/lib/meson.build index 0fae16ae..95f206cf 100644 --- a/lib/meson.build +++ b/lib/meson.build @@ -26,5 +26,6 @@ crucible_lib = static_library( crucible_version_cc, ], dependencies: [ thread_dep ], + implicit_include_directories: false, include_directories: [ inc ], ) diff --git a/src/meson.build b/src/meson.build index b76a8526..0d1bbd61 100644 --- a/src/meson.build +++ b/src/meson.build @@ -26,6 +26,7 @@ executable( bees_usage_c, ], dependencies: [ thread_dep ], + implicit_include_directories: false, include_directories: [ inc ], install: true, install_dir: beeslibdir, @@ -35,6 +36,7 @@ executable( executable( 'fiemap', [ 'fiemap.cc' ], + implicit_include_directories: false, include_directories: [ inc ], install: get_option('tools'), link_with: [ crucible_lib ], @@ -43,6 +45,7 @@ executable( executable( 'fiewalk', [ 'fiewalk.cc' ], + implicit_include_directories: false, include_directories: [ inc ], install: get_option('tools'), install_dir: get_option('sbindir'), diff --git a/test/meson.build b/test/meson.build index 54e0aa0f..ca63674a 100644 --- a/test/meson.build +++ b/test/meson.build @@ -16,6 +16,7 @@ foreach test_name: tests exe = executable( test_name, [ '@0@.cc'.format(test_name) ], + implicit_include_directories: false, include_directories: [ inc ], link_with: [ crucible_lib ], ) From 6eb633b50400793e9f41a20e14bea4efc48c3c71 Mon Sep 17 00:00:00 2001 From: Calvin Walton Date: Thu, 23 Dec 2021 00:24:02 -0500 Subject: [PATCH 5/5] meson: Better handling of python scripts for source generation * Use the find_program function to find python rather than load the whole python module. * Adjust python scripts to write directly to an output file rather than requiring the meson wrapper for capture. * Move the python scripts to the custom_target command array rather than input files. Changes thanks to review by Eli Schwartz. --- docs/index.py | 4 ++-- docs/meson.build | 5 ++--- meson.build | 4 +--- src/bees-usage.py | 10 +++++----- src/meson.build | 5 ++--- 5 files changed, 12 insertions(+), 16 deletions(-) diff --git a/docs/index.py b/docs/index.py index f720eb36..3eb4cc60 100644 --- a/docs/index.py +++ b/docs/index.py @@ -1,5 +1,5 @@ import sys # Rewrite relative links in index file to remove 'docs/' prefix -with open(sys.argv[1]) as file: - sys.stdout.write(file.read().replace('docs/', '')) +with open(sys.argv[1]) as input, open(sys.argv[2], 'w') as output: + output.write(input.read().replace('docs/', '')) diff --git a/docs/meson.build b/docs/meson.build index dcf6f44d..65ed9cc3 100644 --- a/docs/meson.build +++ b/docs/meson.build @@ -14,10 +14,9 @@ else endif index_md = custom_target( - input: [ 'index.py', '../README.md' ], + input: '../README.md', output: 'index.md', - command: [ python, '@INPUT@' ], - capture: true, + command: [ python, files('index.py'), '@INPUT@', '@OUTPUT@' ], ) docs_md = [ diff --git a/meson.build b/meson.build index fe06ee8d..14888880 100644 --- a/meson.build +++ b/meson.build @@ -11,9 +11,7 @@ project( ) # Helper scripts for source generation are written in python. -# Use the same python as meson was run with. -pymod = import('python') -python = pymod.find_installation() +python = find_program('python3') systemd_dep = dependency('systemd', disabler: true, required: get_option('systemd')) systemdsystemunitdir = systemd_dep.get_variable('systemdsystemunitdir') diff --git a/src/bees-usage.py b/src/bees-usage.py index f6038bdf..9703519e 100644 --- a/src/bees-usage.py +++ b/src/bees-usage.py @@ -2,8 +2,8 @@ c_str_escape = str.maketrans({'\n': '\\n', '"': '\\"', '\\': '\\\\'}) -print("const char *BEES_USAGE = ") -with open(sys.argv[1]) as file: - for line in file: - print('"{}"'.format(line.translate(c_str_escape))) -print(";") +with open(sys.argv[1]) as input, open(sys.argv[2], 'w') as output: + output.write('const char *BEES_USAGE = \n') + for line in input: + output.write('"{}"\n'.format(line.translate(c_str_escape))) + output.write(';\n') diff --git a/src/meson.build b/src/meson.build index 0d1bbd61..b8f544d4 100644 --- a/src/meson.build +++ b/src/meson.build @@ -5,10 +5,9 @@ bees_version_c = vcs_tag( ) bees_usage_c = custom_target( - input: [ 'bees-usage.py', 'bees-usage.txt' ], + input: 'bees-usage.txt', output: 'bees-usage.c', - command: [ python, '@INPUT@' ], - capture: true, + command: [ python, files('bees-usage.py'), '@INPUT@', '@OUTPUT@' ], ) executable(