[libblockdev 2/4] Add an SConstruct file largely equivalent to existing Makefile.

mulhern amulhern at redhat.com
Wed Jul 9 16:16:14 UTC 2014


---
 SConstruct | 162 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 162 insertions(+)
 create mode 100644 SConstruct

diff --git a/SConstruct b/SConstruct
new file mode 100644
index 0000000..3e4aa31
--- /dev/null
+++ b/SConstruct
@@ -0,0 +1,162 @@
+import glob
+import os
+import string
+
+PLUGIN_NAMES = [
+  "btrfs",
+  "crypto",
+  "dm",
+  "loop",
+  "lvm",
+  "mpath",
+  "swap"
+]
+
+UTILS_SOURCES = ['src/utils/exec.c', 'src/utils/sizes.c']
+
+# stub functions for plugins
+PLUGIN_HEADER_FILES = [os.path.join("src/lib/plugin_apis", name + ".h") for name in PLUGIN_NAMES]
+PLUGIN_SOURCE_FILES = [os.path.join("src/lib/plugin_apis", name + ".c") for name in PLUGIN_NAMES]
+
+# implemented plugins
+PLUGIN_SOURCES = [os.path.join("src/plugins", name + '.c') for name in PLUGIN_NAMES]
+PLUGIN_LIBS = [os.path.join("src/plugins", "libbd_" + name + ".so") for name in PLUGIN_NAMES]
+
+# plugin tests
+PLUGIN_TEST_SOURCES = glob.glob("src/plugins/test_*.c")
+PLUGIN_TEST_EXECUTABLES = [os.path.splitext(s)[0] for s in PLUGIN_TEST_SOURCES]
+PLUGIN_TESTS = [string.replace(os.path.split(e)[1], '_', '-') for e in PLUGIN_TEST_EXECUTABLES]
+
+# plugin management
+LIBRARY_FILES = [
+  "src/lib/blockdev.c",
+  "src/lib/blockdev.h",
+  "src/lib/plugins.h"
+]
+
+# PLUGIN STUBS
+
+# environment for plugin stubs
+boilerplate_env = Environment()
+builders = {
+  "Boilerplate": Builder(action="./boilerplate_generator.py $SOURCE > $TARGET")
+}
+boilerplate_env.Append(BUILDERS=builders)
+
+# plugin stub sources
+for h,s in zip(PLUGIN_HEADER_FILES, PLUGIN_SOURCE_FILES):
+    b = boilerplate_env.Boilerplate(target=s, source=h)
+    Depends(b, 'boilerplate_generator.py')
+
+# BASIC ENVIRONMENT
+basic_env = Environment()
+# for devicelibs command line utilities, e.g., mkswap
+basic_env.AppendENVPath('PATH', '/usr/sbin')
+
+# PLUGINS
+plugin_env = basic_env.Clone()
+plugin_env.ParseConfig('pkg-config --cflags --libs glib-2.0 libcryptsetup')
+plugin_env.Append(CPPPATH='src/utils')
+plugin_env.Append(LIBS="m")
+plugin_env.Append(CCFLAGS="-Wall -Werror -Wextra")
+
+# plugin tests
+plugin_tests = []
+for s,e,t in zip(PLUGIN_TEST_SOURCES, PLUGIN_TEST_EXECUTABLES, PLUGIN_TESTS):
+    plugin_env.Program(e, UTILS_SOURCES + [s])
+    plugin_tests.append(plugin_env.Command(target=t, source=e, action="./%s" % e))
+Alias("plugin-tests", plugin_tests)
+
+# individual plugin libraries
+for s,l in zip(PLUGIN_SOURCES, PLUGIN_LIBS):
+    plugin_env.SharedLibrary(target=l, source=s)
+
+# UTILS
+utils_env = Environment()
+utils_env.ParseConfig('pkg-config --cflags --libs glib-2.0')
+utils_env.Append(LIBS="m")
+utils_env.Append(CCFLAGS="-Wall -Werror -Wextra")
+
+# sizes test
+utils_env.Program('src/utils/test_sizes', ['src/utils/test_sizes.c'])
+utils_env.Command(
+  target='test-sizes',
+  source='src/utils/test_sizes',
+  action='./src/utils/test_sizes'
+)
+
+# utils library
+utils_env.SharedLibrary(
+  "src/utils/libbd_utils.so",
+  ["src/utils/exec.c", "src/utils/sizes.c"]
+)
+
+# LIBRARY
+library_env = Environment()
+library_env.ParseConfig('pkg-config --cflags --libs glib-2.0 gobject-2.0')
+library_env.Append(LIBS="dl")
+# no -Wall, because library includes a lot of stub functions
+library_env.Append(CCFLAGS="-Werror -Wextra")
+
+library_env.SharedLibrary("src/lib/libblockdev.so", ["src/lib/blockdev.c"])
+
+# library test
+test_library = library_env.Program('src/lib/test_library', ['src/lib/test_blockdev.c'])
+Depends(test_library, PLUGIN_LIBS)
+library_env.Command(
+  target='test-library',
+  source='src/lib/test_library',
+  action='LD_LIBRARY_PATH=src/plugins ./src/lib/test_library'
+)
+
+# DRIVER
+blockdev_gir = Command(
+  target="BlockDev-1.0.gir",
+  source=None,
+  action="LD_LIBRARY_PATH=src/lib/:src/utils/ g-ir-scanner `pkg-config --cflags --libs glib-2.0 gobject-2.0 libcryptsetup` --library=blockdev -I src/lib/ -L src/utils -lbd_utils -lm -L src/lib/ --identifier-prefix=BD --symbol-prefix=bd --namespace BlockDev --nsversion=1.0 -o $TARGET --warn-all %s %s" % (' '.join(LIBRARY_FILES), ' '.join(PLUGIN_HEADER_FILES))
+)
+Depends(blockdev_gir, ["src/lib/libblockdev.so", "src/utils/libbd_utils.so"])
+
+blockdev_typelib = Command(
+  target="BlockDev-1.0.typelib",
+  source="BlockDev-1.0.gir",
+  action="g-ir-compiler -o $TARGET $SOURCE"
+)
+
+# TESTING
+test_from_python = Command(
+  target="test-from-python",
+  source=None,
+  action="GI_TYPELIB_PATH=. LD_LIBRARY_PATH=src/plugins/:src/lib/:src/utils python -c 'from gi.repository import BlockDev; BlockDev.init(None); print BlockDev.lvm_get_max_lv_size()'"
+)
+Depends(test_from_python, PLUGIN_LIBS + ["BlockDev-1.0.typelib"])
+
+run_ipython = Command(
+  target="run-ipython",
+  source=None,
+  action="GI_TYPELIB_PATH=. LD_LIBRARY_PATH=src/plugins/:src/lib/:src/utils/ ipython"
+)
+Depends(run_ipython, PLUGIN_LIBS + ["BlockDev-1.0.typelib"])
+
+run_root_ipython = Command(
+  target="run_root_ipython",
+  source=None,
+  action="sudo GI_TYPELIB_PATH=. LD_LIBRARY_PATH=src/plugins/:src/lib/:src/utils/ ipython"
+)
+Depends(run_root_ipython, PLUGIN_LIBS + ["BlockDev-1.0.typelib"])
+
+test = Command(
+  target="test",
+  source=None,
+  action="sudo GI_TYPELIB_PATH=. LD_LIBRARY_PATH=src/plugins/:src/lib/:src/utils/ PYTHONPATH=.:tests/ python -m unittest discover -v -s tests/ -p '*_test.py'"
+)
+Depends(test, PLUGIN_LIBS + ["BlockDev-1.0.typelib"])
+
+fast_test = Command(
+  target="fast-test",
+  source=None,
+  action="sudo SKIP_SLOW= GI_TYPELIB_PATH=. LD_LIBRARY_PATH=src/plugins/:src/lib/:src/utils/ PYTHONPATH=.:tests/ python -m unittest discover -v -s tests/ -p '*_test.py'"
+)
+Depends(fast_test, PLUGIN_LIBS + ["BlockDev-1.0.typelib"])
+
+Default("BlockDev-1.0.typelib")
-- 
1.9.3



More information about the anaconda-patches mailing list