OSDN Git Service

Fixed a bug that obsolete or moved ports were not inspected. For this purpose, the...
[portsreinstall/current.git] / lib / libdatabase_build.sh
index a61672d..bef02a7 100644 (file)
@@ -45,6 +45,7 @@ database_build_convert_and_register_origin_if_obsolete ()
        if [ `wc -l < ${TMPDIR}/moved.info` -eq 0 ]
        then
                fileedit_add_a_line_if_new "$origin" "${DBDIR}/obsolete_ports"
+               fileedit_rm_a_line "$origin" "${DBDIR}/moved_ports"
                if [ -n "$recursedb_in" ]
                then
                        message_echo "${DEPTH_INDEX}  ===> Disappeared port (MOVED broken?)"
@@ -62,10 +63,13 @@ database_build_convert_and_register_origin_if_obsolete ()
                then
                        message_echo "${DEPTH_INDEX}  ===> Moved to $origin_new at $date_moved because \"$why_moved\""
                        fileedit_add_a_line_if_new "$origin" "${TMPDIR}/database_build_convert_and_register_origin_if_obsolete:origins_old"
+                       fileedit_add_a_line_if_new "$origin" "${DBDIR}/moved_ports"
+                       fileedit_rm_a_line "$origin" "${DBDIR}/obsolete_ports"
                        database_build_convert_and_register_origin_if_obsolete "$origin_new" "${TMPDIR}/MOVED.DB" || return 1
                else
                        message_echo "${DEPTH_INDEX}  ===> Deleted at $date_moved because \"$why_moved\""
                        fileedit_add_a_line_if_new "$origin" "${DBDIR}/obsolete_ports"
+                       fileedit_rm_a_line "$origin" "${DBDIR}/moved_ports"
                        return 1
                fi
        fi
@@ -124,7 +128,7 @@ database_build_setup_make_envs ()
        origin=$1
        dbdir=${DBDIR}/requires/$origin
        [ -d "$dbdir" ] || dbdir=${DBDIR}/conf/each_port/$origin
-       cat "$dbdir/MENV.conf" 2> /dev/null || :
+       cat "$dbdir/MENV.conf" 2> /dev/null | tr '\n' ' '
 }
 
 # ============= Execute make command for building the temporary database =============
@@ -296,6 +300,7 @@ database_build_is_port_already_inspected_in_required_level ()
        inspected_level=`database_build_get_inspected_level "$origin_actual" "$origin_dependent"`
        {
                cat "${DBDIR}/ports.inspected.${inspected_level}.list" || :
+               cat "${DBDIR}/moved_ports" || :
                cat "${DBDIR}/obsolete_ports" || :
        }  2> /dev/null | grep -q -Fx "$origin_actual" || return
        fileedit_rm_a_line "$origin" "${DBDIR}/stage.loop_list/ports_to_inspect.remain"
@@ -477,43 +482,62 @@ database_build_determine_flavored_origin ()
 database_build_escape_inspect_conflict ()
 {
        local origin dbpath
+       origin=$1
        dbpath=${DBDIR}/requires/$origin
        if [ -e "$dbpath/CONFLICT.conf" ]
        then
                message_echo "${DEPTH_INDEX}  ===> Escaping inspection conflict..."
-               pkgsys_eval_ports_glob `cat "$dbpath/CONFLICT.conf"` | while read origin_conflict
-               do
-                       pkg_conflict=`pkgsys_get_installed_pkg_from_origin "$origin_conflict"`
-                       [ -n "$pkg_conflict" ] || continue
-                       message_echo "${DEPTH_INDEX}  ===> Escaping $pkg_conflict..."
-                       pkgarc=`pkgsys_create_backup_pkg "$pkg_conflict" "${DBDIR}/backup_packages" 2> /dev/null` || \
-                               message_echo "${DEPTH_INDEX}  ===> (WARNING: Failed to back up)"
-                       pkg_delete_f "$pkg_conflict" > /dev/null 2>&1 || \
-                               message_echo "${DEPTH_INDEX}  ===> (WARNING: Failed to delete)"
-                       [ -n "$pkgarc" ] && printf '%s\t%s\n' "$pkg_conflict" "$pkgarc" >> $dbpath/CONFLICT_pkgarc.lst
-               done
+               pkgsys_eval_ports_glob `cat "$dbpath/CONFLICT.conf"` | database_build_escape "$dbpath/CONFLICT_pkgarc.lst"
        fi
 }
 
+# ============= Escape of conflicts =============
+# A list of conflict package origins are given by stdin.
+database_build_escape ()
+{
+       local backup_list origin_conflict pkg_conflict pkgarc
+       backup_list=$1
+       while read origin_conflict
+       do
+               pkg_conflict=`pkgsys_get_installed_pkg_from_origin "$origin_conflict"`
+               [ -n "$pkg_conflict" ] || continue
+               message_echo "${DEPTH_INDEX}  ===> Escaping $pkg_conflict..."
+               pkgarc=`pkgsys_create_backup_pkg "$pkg_conflict" "${DBDIR}/backup_packages" 2> /dev/null` || \
+                       message_echo "${DEPTH_INDEX}  ===> (WARNING: Failed to back up)"
+               pkg_delete_f "$pkg_conflict" > /dev/null 2>&1 || \
+                       message_echo "${DEPTH_INDEX}  ===> (WARNING: Failed to delete)"
+               [ -n "$pkgarc" ] && printf '%s\t%s\n' "$pkg_conflict" "$pkgarc" >> $backup_list
+       done
+}
+
 # ============= Restoration of escaped inspection conflict =============
 database_build_restore_inspect_conflict ()
 {
        local origin dbpath
+       origin=$1
        dbpath=${DBDIR}/requires/$origin
        if [ -e "$dbpath/CONFLICT.conf" ]
        then
                message_echo "${DEPTH_INDEX}  ===> Restoring inspection conflict..."
-               cat "$dbpath/CONFLICT_pkgarc.lst" 2> /dev/null | while read pkg_conflict pkgarc
-               do
-                       pkg_info_e "$pkg_conflict" && continue
-                       message_echo "${DEPTH_INDEX}  ===> Restoring $pkg_conflict..."
-                       pkg_add_f "$pkgarc" > /dev/null 2>&1 || \
-                               message_echo "${DEPTH_INDEX}  ===> (WARNING: Failed to restore $pkg_conflict)"
-               done
+               cat "$dbpath/CONFLICT_pkgarc.lst" 2> /dev/null | database_build_restore
                rm -f "$dbpath/CONFLICT_pkgarc.lst"
        fi
 }
 
+# ============= Restoration of escaped conflicts =============
+# The backup list is given by stdin.
+database_build_restore ()
+{
+       local pkg_conflict pkgarc
+       while read pkg_conflict pkgarc
+       do
+               pkg_info_e "$pkg_conflict" && continue
+               message_echo "${DEPTH_INDEX}  ===> Restoring $pkg_conflict..."
+               pkg_add_f "$pkgarc" > /dev/null 2>&1 || \
+                       message_echo "${DEPTH_INDEX}  ===> (WARNING: Failed to restore $pkg_conflict)"
+       done
+}
+
 # ============= Recursively inspect dependencies of a port and build a node database of the information =============
 database_build_inspect_dependencies ()
 {
@@ -528,9 +552,8 @@ database_build_inspect_dependencies ()
                message_echo "${DEPTH_INDEX} $origin_orig"
                database_build_convert_and_register_origin_if_obsolete__reset_origins_old
                origin_id=`echo "$origin_orig" | tr / :`
-               database_build_setup_initial_node "$origin_orig"
                # Replacement specified by the configuration file, knobs and port options
-               tmp_config=${TMPDIR}/database_build_inspect_dependencies:confi
+               tmp_config=${TMPDIR}/database_build_inspect_dependencies:config
                database_build_setup_replace_node "$origin_orig" "$tmp_config.before" "$tmp_config.after"
                if [ -e "${DBDIR}/replace/$origin_orig/origin" ]
                then
@@ -556,6 +579,7 @@ database_build_inspect_dependencies ()
                        if ! grep -qFx "$origin" "${DBDIR}/done_required_ports_to_inspect" 2> /dev/null
                        then
                                fileedit_rm_a_line "$origin" "${DBDIR}/obsolete_ports"
+                               fileedit_rm_a_line "$origin" "${DBDIR}/moved_ports"
                                dbpath=${DBDIR}/requires/$origin
                                dbpath_prev=${DBDIR}/prevset/requires/$origin
                                if [ ! -e "$dbpath/complete_as_node" ] || \
@@ -868,8 +892,8 @@ database_build_get_complete_recursive_dependency ()
                                message_echo "WARNING: The following loop was found for requirements.${tag}${suffix}:" >&2
                        fi
                        message_echo "  $origin" >&2
-                       sed -n $(($loophead+1)),\$p "$tmppath.parents" > $tmppath.ports_in_loop.tmp
-                       sed 's/^/  -->/' "$tmppath.ports_in_loop.tmp" | message_cat >&2
+                       ports_in_loop=`sed -n $(($loophead+1)),\$p "$tmppath.parents"`
+                       echo "$ports_in_loop" | sed 's/^/  -->/' | message_cat >&2
                        message_echo "  -->$origin" >&2
                        if [ "x$opt_disallow_force_continuation_for_looped_dependency" = xyes ]
                        then
@@ -880,7 +904,7 @@ database_build_get_complete_recursive_dependency ()
                        else
                                message_echo 'Exploring a node port to terminate the loop by evaluating only build-and-run-time dependencies as essential ones.' >&2
                                echo "$origin" > $tmppath.ports_in_loop
-                               cat "$tmppath.ports_in_loop.tmp" >> $tmppath.ports_in_loop
+                               echo "$ports_in_loop" >> $tmppath.ports_in_loop
                                echo "$origin" >> $tmppath.ports_in_loop
                                index_loop=1
                                loop_len=`wc -l < $tmppath.ports_in_loop`
@@ -919,19 +943,21 @@ database_build_get_complete_recursive_dependency ()
                mkdir -p "$tmpdstpath"
                database_build_filter_ignored_requirements "$origin" < $srcfile | while read origin_requirement
                do
-                       database_build_get_complete_recursive_dependency "$tag" "$origin_requirement" "$suffix" \
-                               > $tmppath.recursive_dependency
+                       # The least requirements of build are the direct build-time requirements and the full run-time requirements of the direct build-time requirements.
+                       tag_dep=$tag
+                       [ "x$tag" = xbuild ] && tag_dep=run
+                       recursive_dependency=`database_build_get_complete_recursive_dependency "$tag_dep" "$origin_requirement" "$suffix"`
                        [ -e "$dbpath/ignored_requirements.filter" ] && \
                                echo "$origin_requirement" | grep -Fxq -f "$dbpath/ignored_requirements.filter" 2> /dev/null && \
                                continue
                        echo "$origin_requirement"
-                       cat "$tmppath.recursive_dependency"
+                       echo "$recursive_dependency"
                done > $dstfile_tmp
                sed -n ${num_parents}p "$tmppath.parents" > $tmppath.parents.tmp
                mv "$tmppath.parents.tmp" "$tmppath.parents"
                if [ ! -e "$dstfile" ]
                then
-                       sort -u "$dstfile_tmp" > $dstfile
+                       sort -u "$dstfile_tmp" | grep -v '^$' > $dstfile || :
                        rm "$dstfile_tmp"
                fi
        fi
@@ -1081,6 +1107,7 @@ _database_build_reset_a_port_confdb ()
                fileedit_rm_a_line "$origin" "${DBDIR}/ports.inspected.${level}.list"
        done
        fileedit_rm_a_line "$origin" "${DBDIR}/obsolete_ports"
+       fileedit_rm_a_line "$origin" "${DBDIR}/moved_ports"
        fileedit_rm_a_line "$origin" "${DBDIR}/ports.inspected.list"
        cat "${DBDIR}/replace/$origin/origin" 2> /dev/null || :
 }
@@ -1121,6 +1148,13 @@ database_build_patch_reconf ()
        database_build_clear_db_dirs "$origin"
 }
 
+# ============= Post-processes after finishing to inspect initial dependencies =============
+database_build_post_inspect_initial_dependencies ()
+{
+       find "${DBDIR}/initial" -depth 2 -type d \
+               | sed -E 's|.*/([^/]+/[^/]+)$|\1|' > ${DBDIR}/inspected_ports.initial
+}
+
 # ============= Post-processes after finishing to inspect dependencies =============
 database_build_post_inspect_dependencies ()
 {
@@ -1129,8 +1163,6 @@ database_build_post_inspect_dependencies ()
        touch "${DBDIR}/obsolete_ports" "${DBDIR}/inspected_ports.update"
        find "${DBDIR}/requires" -depth 2 -type d \
                | sed -E 's|.*/([^/]+/[^/]+)$|\1|' > ${DBDIR}/inspected_ports
-       find "${DBDIR}/initial" -depth 2 -type d \
-               | sed -E 's|.*/([^/]+/[^/]+)$|\1|' > ${DBDIR}/inspected_ports.initial
        sort -u "${DBDIR}/inspected_ports" "${DBDIR}/inspected_ports.initial" > ${DBDIR}/inspected_ports.all
        {
                cat "${DBDIR}/conf/HOLD:PORTS.parsed" || :