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 cf8a7b1
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 11 deletions.
1 change: 1 addition & 0 deletions bootstrap
Original file line number Diff line number Diff line change
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
8 changes: 5 additions & 3 deletions build-aux/bootstrap.in
Original file line number Diff line number Diff line change
Expand Up @@ -220,10 +220,12 @@ 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
Expand Down
37 changes: 29 additions & 8 deletions build-aux/inline-source
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@
# 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
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 \"'"$progpath"'\" '"$_G_scriptdir"'%s", magic, file));
next;
}
Expand Down

0 comments on commit cf8a7b1

Please sign in to comment.