Skip to content

Commit 76ab1d0

Browse files
Auto merge of #145809 - he32:installer-perf-fix-1, r=<try>
rust-installer/install-template.sh: improve efficiency, step 1.
2 parents 41a79f1 + 29e205f commit 76ab1d0

File tree

1 file changed

+52
-54
lines changed

1 file changed

+52
-54
lines changed

src/tools/rust-installer/install-template.sh

Lines changed: 52 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -551,54 +551,45 @@ install_components() {
551551
# Decide the destination of the file
552552
local _file_install_path="$_dest_prefix/$_file"
553553

554-
if echo "$_file" | grep "^etc/" > /dev/null
555-
then
556-
local _f="$(echo "$_file" | sed 's/^etc\///')"
557-
_file_install_path="$CFG_SYSCONFDIR/$_f"
558-
fi
559-
560-
if echo "$_file" | grep "^bin/" > /dev/null
561-
then
562-
local _f="$(echo "$_file" | sed 's/^bin\///')"
563-
_file_install_path="$CFG_BINDIR/$_f"
564-
fi
565-
566-
if echo "$_file" | grep "^lib/" > /dev/null
567-
then
568-
local _f="$(echo "$_file" | sed 's/^lib\///')"
569-
_file_install_path="$CFG_LIBDIR/$_f"
570-
fi
571-
572-
if echo "$_file" | grep "^share" > /dev/null
573-
then
574-
local _f="$(echo "$_file" | sed 's/^share\///')"
575-
_file_install_path="$CFG_DATADIR/$_f"
576-
fi
577-
578-
if echo "$_file" | grep "^share/man/" > /dev/null
579-
then
580-
local _f="$(echo "$_file" | sed 's/^share\/man\///')"
581-
_file_install_path="$CFG_MANDIR/$_f"
582-
fi
583-
584-
# HACK: Try to support overriding --docdir. Paths with the form
585-
# "share/doc/$product/" can be redirected to a single --docdir
586-
# path. If the following detects that --docdir has been specified
587-
# then it will replace everything preceding the "$product" path
588-
# component. The problem here is that the combined rust installer
589-
# contains two "products": rust and cargo; so the contents of those
590-
# directories will both be dumped into the same directory; and the
591-
# contents of those directories are _not_ disjoint. Since this feature
592-
# is almost entirely to support 'make install' anyway I don't expect
593-
# this problem to be a big deal in practice.
594-
if [ "$CFG_DOCDIR" != "<default>" ]
595-
then
596-
if echo "$_file" | grep "^share/doc/" > /dev/null
597-
then
598-
local _f="$(echo "$_file" | sed 's/^share\/doc\/[^/]*\///')"
599-
_file_install_path="$CFG_DOCDIR/$_f"
600-
fi
601-
fi
554+
case "$_file" in
555+
etc/*)
556+
local _f="$(echo "$_file" | sed 's/^etc\///')"
557+
_file_install_path="$CFG_SYSCONFDIR/$_f"
558+
;;
559+
bin/*)
560+
local _f="$(echo "$_file" | sed 's/^bin\///')"
561+
_file_install_path="$CFG_BINDIR/$_f"
562+
;;
563+
lib/*)
564+
local _f="$(echo "$_file" | sed 's/^lib\///')"
565+
_file_install_path="$CFG_LIBDIR/$_f"
566+
;;
567+
share/man/*)
568+
local _f="$(echo "$_file" | sed 's/^share\/man\///')"
569+
_file_install_path="$CFG_MANDIR/$_f"
570+
;;
571+
share/doc/*)
572+
# HACK: Try to support overriding --docdir. Paths with the form
573+
# "share/doc/$product/" can be redirected to a single --docdir
574+
# path. If the following detects that --docdir has been specified
575+
# then it will replace everything preceding the "$product" path
576+
# component. The problem here is that the combined rust installer
577+
# contains two "products": rust and cargo; so the contents of those
578+
# directories will both be dumped into the same directory; and the
579+
# contents of those directories are _not_ disjoint. Since this feature
580+
# is almost entirely to support 'make install' anyway I don't expect
581+
# this problem to be a big deal in practice.
582+
if [ "$CFG_DOCDIR" != "<default>" ]
583+
then
584+
local _f="$(echo "$_file" | sed 's/^share\/doc\/[^/]*\///')"
585+
_file_install_path="$CFG_DOCDIR/$_f"
586+
fi
587+
;;
588+
share/*)
589+
local _f="$(echo "$_file" | sed 's/^share\///')"
590+
_file_install_path="$CFG_DATADIR/$_f"
591+
;;
592+
esac
602593

603594
# Make sure there's a directory for it
604595
make_dir_recursive "$(dirname "$_file_install_path")"
@@ -617,13 +608,20 @@ install_components() {
617608

618609
maybe_backup_path "$_file_install_path"
619610

620-
if echo "$_file" | grep "^bin/" > /dev/null || test -x "$_src_dir/$_component/$_file"
621-
then
622-
run cp "$_src_dir/$_component/$_file" "$_file_install_path"
623-
run chmod 755 "$_file_install_path"
611+
if test -x "$_src_dir/$_component/$_file"; then
612+
run cp "$_src_dir/$_component/$_file" "$_file_install_path"
613+
run chmod 755 "$_file_install_path"
624614
else
625-
run cp "$_src_dir/$_component/$_file" "$_file_install_path"
626-
run chmod 644 "$_file_install_path"
615+
case "$_file" in
616+
bin/*)
617+
run cp "$_src_dir/$_component/$_file" "$_file_install_path"
618+
run chmod 755 "$_file_install_path"
619+
;;
620+
*)
621+
run cp "$_src_dir/$_component/$_file" "$_file_install_path"
622+
run chmod 644 "$_file_install_path"
623+
;;
624+
esac
627625
fi
628626
critical_need_ok "file creation failed"
629627

0 commit comments

Comments
 (0)