Files
mercury/scripts/mercury_cleanup_install
Zoltan Somogyi 6b0fb566ce Move the mdbcomp library to its own directory.
Estimated hours taken: 12
Branches: main

Move the mdbcomp library to its own directory. To make this change less painful
to test, improve the way we handle installs.

browser/mdbcomp.m:
browser/mer_mdbcomp.m:
browser/prim_data.m:
browser/program_representation.m:
browser/trace_counts.m:
	Move these files to the mdbcomp directory.

browser/Mmakefile:
browser/Mercury.options:
mdbcomp/Mmakefile:
mdbcomp/Mercury.options:
	Split the contents of the old Mmakefile and Mercury.options file
	in the browser directory between these files as appropriate.
	Simplify away the stuff not needed now that there is only one library
	per directory. Make the browser directory see the relevant files
	from the mdbcomp directory.

Mmake.common.in:
	Separate out the prefixes allowed in the browser and the mdbcomp
	directories.

Mmake.workspace:
	Set up a make variable to refer to the mdbcomp directory.

	Adjust references to the mdbcomp library to point to its new location.

Mmakefile:
	Make invocations visit the mdbcomp library as necessary.

	Improve the way we install grades. Making temporary backups of the
	directories modified by the install process is unsatisfactory for two
	reasons. First, if the install fails, the cleanup script, which is
	necessary for user friendliness, destroys any evidence of the cause.
	Second, the restore of the backup wasn't perfect, e.g. it left the
	.d files modified to depend on .mih files, which don't exist in
	LLDS grades, and also left altered timestamps.

	This diff changes the install process to make a single tmp_dir
	subdirectory of the workspace, with all the work of install_grade
	being done inside tmp_dir. The original directories aren't touched
	at all.

*/Mmakefile:
	Adjust references to the browser directory to refer to the mdbcomp
	directory instead or as well.

scripts/Mmake.rules:
*/Mmakefile:
	Make it easier to debug Mmakefiles. Previously, creating a
	Mmake.makefile with mmake -s and invoking "make -d" ignored the
	most fundamental rules of mmake, because Mmake.rules was treating
	an unset MMAKE_USE_MMC_MAKE as if it were set to "yes", simply because
	it was different from "no". This diff changes it to treat an unset
	MMAKE_USE_MMC_MAKE as if it were set to "no", which is a more
	sensible default.

scripts/prepare_tmp_dir_fixed_part.in:
scripts/scripts/prepare_tmp_dir_grade_part:
	Two new scripts that each do half the work of preparing tmp_dir for
	the real work of the install_grade make target. The fixed_part script
	prepares the parts of tmp_dir that are grade-independent, while the
	grade_part scripts prepares the parts that are grade-dependent.

configure.in:
	Test C files in the mdbcomp directory to see whether they need to
	be recompiled after reconfiguration.

	Create prepare_tmp_dir_fixed_part from prepare_tmp_dir_fixed_part.in.

compiler/*.m:
runtime/mercury_wrapper.c:
	Update the references to the moved files.

compiler/notes/overall_design.html:
	Mention the new directory.
2005-01-28 07:12:05 +00:00

104 lines
3.8 KiB
Bash
Executable File

#! /bin/sh
#---------------------------------------------------------------------------#
# Copyright (C) 1999 Monash University.
# Copyright (C) 2000-2002, 2005 The University of Melbourne.
# This file may only be copied under the terms of the GNU General
# Public License - see the file COPYING in the Mercury distribution.
#---------------------------------------------------------------------------#
#
# mercury_cleanup_install
#
# Author: Warwick Harvey <wharvey@cs.monash.edu.au>
#
# Checks for failed/aborted installation attempts, and tries to clean up
# after them, since simply re-starting the install may do the wrong thing.
#
# The main problem with restarting an install is when the install is
# interrupted during the building of alternative grades of the library,
# runtime, etc. When the alternative grades are being built, the versions
# of the compiled files needed for the compiler itself (as opposed to
# installed libraries) are moved into a `tmp_dir' subdirectory, with the
# alternative versions being built in the old location. This means that if
# the process is interrupted and then re-started, the build process will
# attempt to re-build the compiler using some files with the wrong grade.
#
# This script checks for the presence of subdirectories named `tmp_dir',
# and if it finds them, assumes that an install process has failed and
# needs to be cleaned up. Cleaning up the failed install consists simply
# of moving all the files in each `tmp_dir' back to where they came
# from, overwriting any alternative grade versions that may be there,
# and deleting the temporary directories.
#
# If there is an error while doing the clean-up, a more aggressive approach
# is used. An "mmake clean" is run on the directory in question, and then
# the `tmp_dir' is deleted completely. Note that for some directories (e.g.
# `library', `browser'), this deletes some C files, which require a
# working version of Mercury to rebuild. However, if the installation got
# as far as building the different grades of the library, then the compiler
# (plus its default grade) has already been installed. The build scripts
# are smart enough to find and use this installed version even if it's not
# in the user's path, so the "mmake clean" is safe even if there is no
# existing Mercury installation (e.g. if the user is building it from
# release sources).
cleanup_failed_dirs=
for tmp in `find . -name tmp_dir -print` ; do
dir=`dirname $tmp`
echo "Cleaning up from apparent failed install in \`$dir'..."
if (
cd $dir && (
if [ -d Mercury/dirs ] ; then
dirs_subdir=Mercury/dirs/
else
dirs_subdir=
fi
# For every saved `.dir' directory, delete any existing one so
# it can be moved back (one can't just clobber directories).
(
cd tmp_dir &&
for dir in *.dir ; do
if [ "$dir" != "*.dir" ] ; then
rm -rf ../$dirs_subdir$dir
fi
done
)
[ -d Mercury/dirs ] && mv tmp_dir/*.dir $dirs_subdir
[ -d Mercury/cs ] && mv -f tmp_dir/*.c Mercury/cs
[ -d Mercury/os ] && mv -f tmp_dir/*.o tmp_dir/*.pic_o Mercury/os
[ -d Mercury/deps ] && mv -f tmp_dir/*.dep Mercury/deps
[ -d Mercury/c_dates ] && mv -f tmp_dir/*.c_date Mercury/c_dates
[ -d Mercury/mihs ] && mv -f tmp_dir/*.mih Mercury/mihs
[ -d Mercury/useds ] && mv -f tmp_dir/*.used Mercury/useds
mv -f tmp_dir/* .
rmdir tmp_dir
)
) ; then
echo "Done."
else
echo "Failed. Trying a more aggressive approach..."
if ( cd $dir && mmake clean && rm -rf tmp_dir ) ; then
echo "Succeeded."
else
echo "Failed again. :-("
cleanup_failed_dirs="$cleanup_failed_dirs $dir"
fi
fi
done
if [ -n "$cleanup_failed_dirs" ] ; then
cat <<END
Clean-up failed in the following directories:
$cleanup_failed_dirs
Either fix these directories by hand, or start over from scratch.
END
exit 1
fi
exit 0