Experimental package creation tool for MinGW.org
修订版 | 28704533138e4016bb9748de883015c2eb1d08c1 (tree) |
---|---|
时间 | 2022-03-12 08:32:28 |
作者 | Keith Marshall <keith@user...> |
Commiter | Keith Marshall |
Add mkspec "--edit" and "--force-overwrite" options.
* src/modules/options.sh (--edit, --force-overwrite): Define them.
* src/modules/mkspec.sh (--edit, --force-overwrite): Implement them.
* src/modules/help.sh (--edit, --force-overwrite): Document them.
@@ -109,6 +109,15 @@ | ||
109 | 109 | output, rather than creating or overwriting the |
110 | 110 | default package specification file. |
111 | 111 | |
112 | + -e, --edit When specified in association with "mkspec" open | |
113 | + the package specification file for editing, using | |
114 | + the editor specified by the EDITOR variable. | |
115 | + | |
116 | + -f, --force-overwrite | |
117 | + Allow the "mkspec" action to overwrite an existing | |
118 | + package specification file; normally, this would be | |
119 | + blocked, to prevent accidental overwrite. | |
120 | + | |
112 | 121 | --xtool Enable cross-compiler build mode; do not pass any |
113 | 122 | "--build" or "--host" options to configure, so that |
114 | 123 | configuration relates to native compilation of the |
@@ -32,32 +32,53 @@ | ||
32 | 32 | # |
33 | 33 | # ----------------------------------------------------------------------------- |
34 | 34 | # |
35 | - local SPECSFILE SPECSFILE_DIR | |
36 | - SPECSFILE_DIR=${PACKAGE_SRCDIR-"."}/arch/${ARCH-"mingw32"} | |
37 | - SPECSFILE=$PACKAGE-$VERSION${ARCH+"-$ARCH"}.pkgspec | |
35 | +# Unless streaming the specification file content to stdout, determine an | |
36 | +# appropriate output file path name, and take precautions to avoid writing | |
37 | +# over an existing file. | |
38 | +# | |
38 | 39 | ${write_stdout=false} || { |
40 | + local SPECSFILE SPECSFILE_DIR | |
41 | + SPECSFILE_DIR=${PACKAGE_SRCDIR-"."}/arch/${ARCH-"mingw32"} | |
42 | + SPECSFILE=$PACKAGE-$VERSION${ARCH+"-$ARCH"}.pkgspec | |
39 | 43 | test -e "$SPECSFILE_DIR/$SPECSFILE" && { |
40 | - error "file '$SPECSFILE' already exists"; exit 1 | |
44 | + ${force_overwrite-false} || { | |
45 | + ${edit_mode-false} || { | |
46 | + error "file '$SPECSFILE' already exists"; exit 1 | |
47 | + } | |
48 | + local newfile=false | |
49 | + } | |
41 | 50 | } |
42 | 51 | } |
52 | +# Once we've verified intent to write a new specification data stream, we | |
53 | +# must ensure that designated output directory exists, if required, after | |
54 | +# which we arrange to stream to the designated location, via stdout. | |
55 | +# | |
56 | + ${newfile-true} && ( | |
57 | + $write_stdout || { | |
58 | + mkdir -p "$SPECSFILE_DIR" | |
59 | + exec > "$SPECSFILE_DIR/$SPECSFILE" | |
60 | + } | |
61 | + | |
62 | +# Set up template substitutions for download URIs... | |
43 | 63 | # |
44 | -( $write_stdout || { | |
45 | - mkdir -p "$SPECSFILE_DIR" | |
46 | - exec > "$SPECSFILE_DIR/$SPECSFILE" | |
47 | - } | |
64 | + test "${PACKAGE_HOME_URI+set}" = set && PKGHOME_SET="" || PKGHOME_SET="# " | |
48 | 65 | |
66 | +# ...for the optional "pkgrelease" specification... | |
67 | +# | |
49 | 68 | test "${RELEASE+"set"}" = set && RELEASE_PREFIX="" || RELEASE_PREFIX="# " |
50 | 69 | |
70 | +# ...and for archive compression choices... | |
71 | +# | |
51 | 72 | case $COMPRESS_CMD in |
52 | 73 | gzip) COMPRESSION_TYPE=.gz ;; |
53 | 74 | bzip2) COMPRESSION_TYPE=.bz2 ;; |
54 | 75 | lzma) COMPRESSION_TYPE=.lzma ;; |
55 | 76 | xz) COMPRESSION_TYPE=.xz ;; |
56 | 77 | esac |
57 | - | |
58 | - test "${PACKAGE_HOME_URI+set}" = set && PKGHOME_SET="" || PKGHOME_SET="# " | |
59 | 78 | PACKAGE_TYPE_SUFFIX=${ARCHIVE_CMD-"tar"}${COMPRESSION_TYPE-".gz"} |
60 | 79 | |
80 | +# ...before emitting the specification data stream. | |
81 | +# | |
61 | 82 | cat <<ETX |
62 | 83 | # $PACKAGE-$VERSION${RELEASE+"-$RELEASE"}${ARCH+"-$ARCH"}.pkgspec |
63 | 84 | # |
@@ -219,4 +240,21 @@ affiliate "MinGW Contributed Applications" | ||
219 | 240 | # $PACKAGE-$VERSION${RELEASE+"-$RELEASE"}${ARCH+"-$ARCH"}.pkgspec: end of file |
220 | 241 | ETX |
221 | 242 | ) |
243 | +# Regardless of whether we've just created it, or not, if the "--edit" | |
244 | +# option has been specified, then we should immediately open the package | |
245 | +# specification file in our preferred editor; however, we cannot do this, | |
246 | +# if the specification file content was streamed to stdout, or if the | |
247 | +# $EDITOR shell variable has not been specified. | |
248 | +# | |
249 | + if ${edit_mode-false} | |
250 | + then ${write_stdout-false} && { | |
251 | + error "cannot edit the standard output data stream" | |
252 | + } || { | |
253 | + test "${EDITOR+set}" = set && $EDITOR "$SPECSFILE_DIR/$SPECSFILE" || { | |
254 | + error 'editing requested but $EDITOR is not defined' | |
255 | + } | |
256 | + } | |
257 | + fi | |
258 | +# | |
259 | +# ----------------------------------------------------------------------------- | |
222 | 260 | # $RCSfile$: end of file |
@@ -49,6 +49,12 @@ | ||
49 | 49 | optdefine c stdout |
50 | 50 | opteval_stdout() { write_stdout=true; } |
51 | 51 | |
52 | + optdefine e edit | |
53 | + opteval_edit() { edit_mode=true; } | |
54 | + | |
55 | + optdefine f force-overwrite | |
56 | + opteval_force_overwrite() { force_overwrite=true; } | |
57 | + | |
52 | 58 | optdefine option requires_argument |
53 | 59 | opteval_option() { option $optarg; } |
54 | 60 |
@@ -56,7 +62,7 @@ | ||
56 | 62 | opteval_arch() { ARCH="$optarg"; } |
57 | 63 | |
58 | 64 | optdefine identity requires_argument |
59 | - opteval_identity() { PORTSPEC="$optarg"; } | |
65 | + opteval_identity() { PORTSPEC="$optarg" SRCDIR=${SRCDIR-"./$optarg"}; } | |
60 | 66 | |
61 | 67 | optdefine port |
62 | 68 | opteval_port() { MINGW_PORT_DISTRIBUTION=true SRCTAG=port; } |