update doc-build.sh to allow multiple depth of dir 23/4323/3
authorRyota MIBU <r-mibu@cq.jp.nec.com>
Fri, 11 Dec 2015 09:37:51 +0000 (18:37 +0900)
committerRyota MIBU <r-mibu@cq.jp.nec.com>
Wed, 16 Dec 2015 12:52:35 +0000 (21:52 +0900)
In our new documentation guideline, we suggest to create
documentation directory just in one depth from top 'docs' directory.
This rule can make sure there is no name collision.

However, some projects are already using multiple depth of
documentation directories. So, let's allow them to create their
documents without any namespace collision by creating unique names
from directory path.

Change-Id: I7806abd00be56b0a4811b3d17216495e11bca825
Signed-off-by: Ryota MIBU <r-mibu@cq.jp.nec.com>
utils/docs-build.sh

index 5ac8b2b..fc607fa 100755 (executable)
@@ -84,6 +84,34 @@ function add_config() {
     fi
 }
 
+function is_top_dir() {
+    [[ "$1" == "$SRC_DIR" ]]
+}
+
+function generate_name_for_top_dir() {
+    for suffix in '' '.top' '.all' '.master' '_' '__' '___'
+    do
+        _name="$(basename $SRC_DIR)$suffix"
+        [[ -e "$SRC_DIR/$_name" ]] && continue
+        echo "$_name"
+        return
+    done
+
+    echo "Error: cannot find name for top directory [$SRC_DIR]"
+    exit 1
+}
+
+function generate_name() {
+    _dir=$1
+
+    if is_top_dir "$_dir" ; then
+        _name=$(generate_name_for_top_dir $SRC_DIR)
+    else
+        _name="${_dir#$SRC_DIR/}"
+    fi
+    # Replace '/' by '_'
+    echo "${_name////_}"
+}
 
 check_rst_doc $SRC_DIR
 
@@ -94,7 +122,7 @@ fi
 
 find $SRC_DIR -name $INDEX_RST -printf '%h\n' | while read dir
 do
-    name="${dir##*/}"
+    name=$(generate_name $dir)
     src="$BUILD_DIR/src/$name"
     build="$BUILD_DIR/$name"
     output="$OUTPUT_DIR/$name"
@@ -143,4 +171,9 @@ do
         [[ -n "$GERRIT_COMMENT" ]] && echo "$msg" >> "$GERRIT_COMMENT"
     }
 
+    if is_top_dir "$dir" ; then
+        mv "$output"/* "$OUTPUT_DIR"/
+        rm -rf "$output"
+    fi
+
 done