From 037ad0360056ec38eda1b3b8a74cd3ae4371630f Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Sat, 21 Jul 2018 14:47:30 +0200 Subject: Add binding support executable stub for manifest parsing --- libbutl/.gitignore | 1 + libbutl/buildfile | 12 ++++++-- libbutl/manifest-parser.bash.in | 7 +---- libbutl/manifest-serializer.bash.in | 3 ++ libbutl/manifest.cxx | 59 +++++++++++++++++++++++++++++++++++++ libbutl/utility.bash.in | 12 ++++++++ 6 files changed, 86 insertions(+), 8 deletions(-) create mode 100644 libbutl/.gitignore create mode 100644 libbutl/manifest.cxx (limited to 'libbutl') diff --git a/libbutl/.gitignore b/libbutl/.gitignore new file mode 100644 index 0000000..6b2eb75 --- /dev/null +++ b/libbutl/.gitignore @@ -0,0 +1 @@ +manifest diff --git a/libbutl/buildfile b/libbutl/buildfile index 1255424..03dd084 100644 --- a/libbutl/buildfile +++ b/libbutl/buildfile @@ -2,8 +2,16 @@ # copyright : Copyright (c) 2014-2018 Code Synthesis Ltd # license : MIT; see accompanying LICENSE file +import libs = libbutl%lib{butl} + ./: bash{$path.base($path.base(*.bash.in))} bash{utility}: in{utility} -bash{manifest-parser}: in{manifest-parser} bash{utility} -bash{manifest-serializer}: in{manifest-serializer} bash{utility} +bash{manifest-parser}: in{manifest-parser} bash{utility} exe{manifest} +bash{manifest-serializer}: in{manifest-serializer} bash{utility} exe{manifest} + +exe{manifest}: cxx{manifest} $libs + +# Install our binding support executables next to the modules. +# +exe{*}: install = bin/libbutl/ diff --git a/libbutl/manifest-parser.bash.in b/libbutl/manifest-parser.bash.in index 3ac2fc7..4af565a 100644 --- a/libbutl/manifest-parser.bash.in +++ b/libbutl/manifest-parser.bash.in @@ -22,12 +22,7 @@ fi # function butl_parse_manifest () { - printf ":1\0" - printf "name:foo\0" - printf "version:1.2.3\0" - printf "description:foo\nexecutable\0" - printf "depends:libfoo\0" - printf "depends:libbar\0" + "$(butl_path)/manifest" parse } # Start the manifest parsing co-process setting the following "return" diff --git a/libbutl/manifest-serializer.bash.in b/libbutl/manifest-serializer.bash.in index c180a4b..24eac65 100644 --- a/libbutl/manifest-serializer.bash.in +++ b/libbutl/manifest-serializer.bash.in @@ -17,6 +17,9 @@ fi # function butl_serialize_manifest () { + # @@ TODO + #"$(butl_path)/manifest" serialize + local n v while IFS=: read -r -d '' n v; do printf "$n: $v\n" diff --git a/libbutl/manifest.cxx b/libbutl/manifest.cxx new file mode 100644 index 0000000..9319b71 --- /dev/null +++ b/libbutl/manifest.cxx @@ -0,0 +1,59 @@ +// file : libbutl/manifest.cxx +// copyright : Copyright (c) 2014-2018 Code Synthesis Ltd +// license : MIT; see accompanying LICENSE file + +#include +#include + +#include +#include +#include + +using namespace std; +using namespace butl; + +static int +cmd_parse () +{ + //@@ TODO + + const char m[] = + ":1\0" + "name:foo\0" + "version:1.2.3\0" + "description:foo\nexecutable\0" + "depends:libfoo\0" + "depends:libbar"; // Last \0 will be added. + + cout.write (m, sizeof (m)); + + return 0; +} + +static int +cmd_serialize () +{ + //@@ TODO + + return 0; +} + +int +main (int argc, char* argv[]) +{ + // We should switch to CLI if we need anything more elaborate. + // + if (argc < 2) + { + cerr << "error: missing command" << endl; + return 1; + } + + string c (argv[1]); + + if (c == "parse") return cmd_parse (); + if (c == "serialize") return cmd_serialize (); + + cerr << "error: unknown command '" << c << "'" << endl; + return 1; +} diff --git a/libbutl/utility.bash.in b/libbutl/utility.bash.in index e284c55..1face1a 100644 --- a/libbutl/utility.bash.in +++ b/libbutl/utility.bash.in @@ -12,3 +12,15 @@ if (( BASH_VERSINFO[0] < 4 || BASH_VERSINFO[0] == 4 && BASH_VERSINFO[1] < 3 )); echo 'error: bash 4.3 or later is required' 2>&1 exit 1 fi + +# Return the libbutl/ module directory. +# +# This is used to run the binding support executables. +# +function butl_path () +{ + # BASH_SOURCE[0] contains the source path of the function being executed + # (that is, us). + # + dirname "${BASH_SOURCE[0]}" +} -- cgit v1.1