Skip to content

Commit

Permalink
added automatic space_id detection
Browse files Browse the repository at this point in the history
  • Loading branch information
oxarbitrage committed Sep 27, 2018
1 parent aa87cd2 commit 64505a8
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
24 changes: 24 additions & 0 deletions libraries/plugins/make_new_plugin.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
#!/bin/bash

# Find next available space id by checking all current plugins
next_space_id () {
SPACE_IDS=()
for i in * ; do
if [ -d "$i" ] && [ "$i" != "CMakeFiles" ]; then
cd "$i/include/graphene/$i"
result=$(grep -rnw '.' -e '#define [[:alnum:]]*_SPACE_ID')
B=$(echo $result | cut -d ' ' -f 3)
if [[ $B =~ [[:digit:]] ]]; then
SPACE_IDS+=($B)
fi
cd "../../../.."
fi
done
max=$( printf "%d\n" "${SPACE_IDS[@]}" | sort -n | tail -1 )
next=$(($max + 1))
return $next
}

## create new plugin
if [ $# -ne 1 ]; then
echo Usage: $0 my_new_plugin
echo ... where my_new_plugin is the name of the plugin you want to create
Expand All @@ -16,6 +36,10 @@ mv $pluginName/include/graphene/template_plugin $pluginName/include/graphene/$pl
for file in `find $pluginName -type f -name '*template_plugin*'`; do mv $file `sed s/template_plugin/$pluginName/g <<< $file`; done;
echo Renaming in files...
find $pluginName -type f -exec sed -i "s/template_plugin/$pluginName/g" {} \;
echo Assigning next available SPACE_ID...
next_space_id
find $pluginName -type f -exec sed -i "s/0000/$?/g" {} \;
echo "Done! $pluginName is ready."
echo "Next steps:"
echo "1- Add 'add_subdirectory( $pluginName )' to CmakeLists.txt in this directory."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,21 @@
namespace graphene { namespace template_plugin {
using namespace chain;

//
// Plugins should #define their SPACE_ID's so plugins with
// conflicting SPACE_ID assignments can be compiled into the
// same binary (by simply re-assigning some of the conflicting #defined
// SPACE_ID's in a build script).
//
// Assignment of SPACE_ID's cannot be done at run-time because
// various template automagic depends on them being known at compile
// time.
//
#ifndef template_plugin_SPACE_ID
#define template_plugin_SPACE_ID 0000
#endif


namespace detail
{
class template_plugin_impl;
Expand Down

0 comments on commit 64505a8

Please sign in to comment.