# HG changeset patch
# User Vincent Hatakeyama <vincent.hatakeyama@xcg-consulting.fr>
# Date 1596029903 -7200
#      Wed Jul 29 15:38:23 2020 +0200
# Node ID 812df2cd25ecf0a48e99e57153b6663f75e3033c
# Parent  e9dd36c971744abfe03e6ab297edd21f50add033
📝 fix autotodo in super project modules doc

diff --git a/NEWS.rst b/NEWS.rst
--- a/NEWS.rst
+++ b/NEWS.rst
@@ -7,6 +7,8 @@
 
 Shell scripts stop assuming that they are in a directory inside the superproject, but assume they are called from the superproject directory instead.
 
+Improve documentation generation.
+
 4.0
 ---
 
diff --git a/create_documentation b/create_documentation
--- a/create_documentation
+++ b/create_documentation
@@ -42,7 +42,7 @@
 for doc_dir in doc docs; do
     if [[ -d "$doc_dir" ]] ; then
         superproject_modules_doc=$project_home/$doc_dir/modules
-        mkdir $superproject_modules_doc
+        [[ -d $superproject_modules_doc ]] || mkdir $superproject_modules_doc
     fi
 done
 
@@ -50,6 +50,8 @@
 for module_path in $(eval echo $odoo_modules) ;
 do
     if [[ -d "$module_path" ]] ; then
+        echo ""
+        echo "${YELLOW}INFO${RESET}  - Documentation for ${BOLD_WHITE}$module_path${RESET}"
         pushd $module_path
         module=$(basename $module_path)
         has_doc=""
@@ -65,14 +67,14 @@
             if [[ -d $doc_dir && -e $doc_dir/Makefile ]]; then
                 echo "${YELLOW}INFO ${RESET} - Branch name: $branch"
                 has_doc=True
-                echo ${YELLOW}INFO ${RESET} - Makefile found in $dir/$module_path/$doc_dir
+                echo ${YELLOW}INFO ${RESET} - Makefile found in $module_path/$doc_dir
                 pushd $doc_dir
                 # TODO read languages value from Makefile (at least available ones)
                 for language in $languages ; do
                     make $format LANGUAGE=${language} BUILDDIR=_build
                     if [[ $? -eq 0 ]] ; then
                         dest_dir=$out_dir/$module/$language/$branch
-                        echo ${GREEN}OK${RESET}    - Documentation generation done for $dir/$module_path/$doc_dir, copy to $dest_dir
+                        echo ${GREEN}OK${RESET}    - Documentation generation done for $module_path/$doc_dir, copy to $dest_dir
                         mkdir -p $dest_dir
                         if [[ -d "_build/$format/$language" ]];
                         then
@@ -84,24 +86,33 @@
                             cp --archive --recursive "_build/$format/." "$dest_dir"
                         fi
                     else
-                        echo ${RED}ERROR${RESET} - Documentation generation failed for $dir/$module_path/$doc_dir
+                        echo ${RED}ERROR${RESET} - Documentation generation failed for $module_path/$doc_dir
                         ((module_error++))
                     fi
                 done
                 popd
                 # copy documentation in super project
-                rsync --recursive --copy-links --perms --times --group --owner --include="*.rst" $doc_dir/ "$superproject_modules_doc/$module"
+                rsync --recursive --copy-links --perms --times --group --owner $doc_dir/ "$superproject_modules_doc/$module"
+                # generate autotodo for each module (to update pathes)
+                if [[ -e $doc_dir/autotodo.py ]] ; then
+                    echo "${YELLOW}INFO ${RESET} - running autotodo again from different path $superproject_modules_doc/$module for ${project_home}/${module_path}"
+                    pushd "$superproject_modules_doc/$module"
+                    ./autotodo.py $(realpath --relative-to="." "${project_home}/${module_path}") .py TODO,FIXME,XXX
+                    popd
+                fi
                 # TODO translation will not work when copying like that.
             fi
         done
         if [[ -z "$has_doc" ]] ; then
-            echo ${RED}WARN${RESET}  - Missing documentation for $dir/$module_path
+            echo ${RED}WARN${RESET}  - Missing documentation for $module_path
         fi
         popd
     fi
 done
 
 # Generate super project documentation
+echo ""
+echo "${YELLOW}INFO ${RESET} - ${WHITE_BOLD}Super project${RESET} documentation generation"
 
 # determine branch name
 if [ -n "$DRONE_BRANCH" ]; then
@@ -120,14 +131,14 @@
     if [[ -d "$doc_dir" ]] ; then
         pushd $doc_dir
         for language in $languages ; do
-            make $format LANGUAGE=${language} BUILDDIR=_build
+            make $format LANGUAGE=${language} BUILDDIR=_build SPHINXOPTS="-w _build/warnings.out"
             if [[ $? -eq 0 ]] ; then
                 dest_dir=$out_dir/$project_name/$language/$branch
                 echo "${YELLOW}INFO ${RESET} - Documentation generation done for $doc_dir (superproject), copy to $dest_dir"
                 mkdir -p $dest_dir
                 cp --recursive --archive _build/$format/$language/. $dest_dir
             else
-                echo "${RED}ERROR${RESET} - Documentation generation failed for $doc_dir (superproject)"
+                echo "${RED}FATAL${RESET} - Documentation generation failed for $doc_dir (superproject)"
                 ((error++))
             fi
         done
@@ -137,4 +148,13 @@
 
 popd
 
+if [[ $module_error -gt 0 ]]; then
+    echo "${RED}ERROR${RESET} - $module_error module(s) with errors"
+fi
+# create a metrics file
+if [[ "$CI" = "true" ]]; then
+    echo -e "# HELP odoo_scripts_create_documentation_module_error Number of module in error.\n# TYPE odoo_scripts_create_documentation_module_error gauge\nodoo_scripts_create_documentation_module_error ${module_error}\n" > metrics
+    [[ -e doc*/_build/warnings.out ]] || echo -e "# HELP odoo_scripts_create_documentation_superproject_warnings Number of warnings in superproject.\n# TYPE odoo_scripts_create_documentation_superproject_warnings gauge\nodoo_scripts_create_documentation_superproject_warnings $(grep --count WARNING doc*/_build/warnings.out)\n" >> metrics
+fi
+
 exit $error