Skip to content

Commit 69d4d5f

Browse files
committed
Auto merge of #145809 - he32:installer-perf-fix-1, r=Mark-Simulacrum
rust-installer/install-template.sh: improve efficiency, step 1. This round replaces repetitive pattern matching in the inner loop of this script using grep (which causes a `fork()` for each test) with built-in pattern matching in the Bourne shell using the `case` / `esac` construct. This in reference to #80684 and is a separated-out request from rust-lang/rust-installer#111 which apparently never got any review. The forthcoming planned "step 2" change builds on top of this change, and replaces the inner-loops needless uses of `sed` (which again causes a `fork()` for each instance) with the suffix removal constructs from the Bourne shell. Since this change touches lots of the same lines this change does, that pull request cannot be submitted before this one is accepted. Hopefully this first step is less controversial than the latter change.
2 parents 518b428 + 9248435 commit 69d4d5f

File tree

1 file changed

+44
-53
lines changed

1 file changed

+44
-53
lines changed

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

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

603596
# Make sure there's a directory for it
604597
make_dir_recursive "$(dirname "$_file_install_path")"
@@ -617,13 +610,11 @@ install_components() {
617610

618611
maybe_backup_path "$_file_install_path"
619612

620-
if echo "$_file" | grep "^bin/" > /dev/null || test -x "$_src_dir/$_component/$_file"
621-
then
622613
run cp "$_src_dir/$_component/$_file" "$_file_install_path"
623-
run chmod 755 "$_file_install_path"
614+
if $_is_bin || test -x "$_src_dir/$_component/$_file"; then
615+
run chmod 755 "$_file_install_path"
624616
else
625-
run cp "$_src_dir/$_component/$_file" "$_file_install_path"
626-
run chmod 644 "$_file_install_path"
617+
run chmod 644 "$_file_install_path"
627618
fi
628619
critical_need_ok "file creation failed"
629620

0 commit comments

Comments
 (0)