Skip to content

Commit

Permalink
inline-source: inline also if $srcdir contains spaces
Browse files Browse the repository at this point in the history
Add new syntax for source inline:

  # set '$inline_source_dir' to `dirname "$0"/`
  inline_source_dir=`echo "$0" |${SED-sed} 's|[^/]*$||'`
  . "$inline_source_dir"/sourced-file

This version avoids "`"sth"`" like commands (nested quotes), while
we are now able to use inline-source script within directory
which pathname contains spaces.  As a side effect, we save some
fork() calls because the directory is constructed only once.

Related to github issue #6.

* build-aux/inline-source: Move ourself to the new syntax,
document new syntax.
(func_include): Parse the new syntax, quote $progpath properly.
* build-aux/bootstrap.in: Use new syntax.
* bootstrap: Sync with new sources.
  • Loading branch information
praiskup committed Oct 21, 2016
1 parent 0d95666 commit 83e6857
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 15 deletions.
5 changes: 3 additions & 2 deletions bootstrap
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#! /bin/sh
## DO NOT EDIT - This file generated from build-aux/bootstrap.in
## by inline-source v2016-02-21.11
## by inline-source v2016-10-21.11

# Bootstrap an Autotooled package from checked-out sources.
# Written by Gary V. Vaughan, 2010
Expand Down Expand Up @@ -222,6 +222,7 @@ vc_ignore=
## External Libraries. ##
## ------------------- ##


# Source required external libraries:
# Set a version string for this script.
scriptversion=2016-02-28.16; # UTC
Expand Down Expand Up @@ -2822,7 +2823,7 @@ test extract-trace = "$progname" && func_main "$@"
# End:

# Set a version string for *this* script.
scriptversion=2016-02-28.16; # UTC
scriptversion=2016-10-21.11; # UTC


## ------------------- ##
Expand Down
10 changes: 6 additions & 4 deletions build-aux/bootstrap.in
Original file line number Diff line number Diff line change
Expand Up @@ -220,13 +220,15 @@ vc_ignore=
## External Libraries. ##
## ------------------- ##

inline_source_dir=`echo "$0" |${SED-sed} 's|[^/]*$||'`

# Source required external libraries:
. `echo "$0" |${SED-sed} 's|[^/]*$||'`"funclib.sh"
. `echo "$0" |${SED-sed} 's|[^/]*$||'`"options-parser"
. `echo "$0" |${SED-sed} 's|[^/]*$||'`"extract-trace"
. "$inline_source_dir"funclib.sh
. "$inline_source_dir"options-parser
. "$inline_source_dir"extract-trace

# Set a version string for *this* script.
scriptversion=2016-02-28.16; # UTC
scriptversion=2016-10-21.11; # UTC


## ------------------- ##
Expand Down
39 changes: 30 additions & 9 deletions build-aux/inline-source
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@
# Please report bugs or propose patches to:
# <https://github.com/gnulib-modules/bootstrap/issues>

inline_source_dir=`echo "$0" |${SED-sed} 's|[^/]*$||'`

# Source required external libraries:
. `echo "$0" |${SED-sed} 's|[^/]*$||'`"funclib.sh"
. `echo "$0" |${SED-sed} 's|[^/]*$||'`"options-parser"
. "$inline_source_dir"funclib.sh
. "$inline_source_dir"options-parser

# Set a version string for *this* script.
scriptversion=2016-02-21.11; # UTC
scriptversion=2016-10-21.11; # UTC


## ------ ##
Expand All @@ -35,9 +37,14 @@ scriptversion=2016-02-21.11; # UTC

# Recursively scan through a FILE passed on the command line, replacing
# either of the following:
# . "relative/file"
# . `echo "$0" |edit`"relative/file"
# with the contents of the referenced files.
#
# a) . "relative/file"
# b) . `echo "$0" |edit`"relative/file"
# c) . "$inline_source_dir"/relative/file
#
# with the contents of the referenced files. When the c) option is used,
# '$inline_source_dir' must be explicitly set to script's source directory
# within the source file. See the example few lines above.


## ---------------- ##
Expand Down Expand Up @@ -118,6 +125,11 @@ func_include ()
_G_scriptdir=`echo "$1" |$SED 's|[^/]*$||'`
test -n "$_G_scriptdir" || _G_scriptdir="./"

func_quote_arg unquoted "$progpath"
prog=$func_quote_arg_unquoted_result

export inline_source_dir=$_G_scriptdir

$AWK '
BEGIN { magic = '${_RECURSE_MAGIC-0}'; }
Expand All @@ -129,16 +141,25 @@ func_include ()
next;
}
/^inline_source_dir=.*/ {
next;
}
/^\. "\$inline_source_dir.*/ {
system (sprintf ("env _RECURSE_MAGIC=%d \"'"$prog"'\" %s", magic, $2));
next;
}
/^\. ['\''"].*['\''"]$/ {
file = substr ($2, 2, length ($2) -2);
system (sprintf ("env _RECURSE_MAGIC=%d '$progpath' %s", magic, file));
system (sprintf ("env _RECURSE_MAGIC=%d \"'"$prog"'\" %s", magic, file));
next;
}
/^\. `echo [^`]*`['\''"][^'\''"]*['\''"]$/ {
tail = substr ($0, match ($0, /`['\''"]/));
file = substr (tail, 3, length (tail) -3);
system (sprintf ("env _RECURSE_MAGIC=%d '$progpath' '"$_G_scriptdir"'%s", magic, file));
file = substr (tail, 3, length (tail) -3);
system (sprintf ("env _RECURSE_MAGIC=%d \"'"$prog"'\" '"$_G_scriptdir"'%s", magic, file));
next;
}
Expand Down

0 comments on commit 83e6857

Please sign in to comment.