Skip to content

Commit 2712b6c

Browse files
committed
Update build workflow and tests
1 parent 88a638b commit 2712b6c

File tree

7 files changed

+77
-66
lines changed

7 files changed

+77
-66
lines changed

.clippy.toml

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
doc-valid-idents = ["MessagePack"]

.github/workflows/release-rust.yaml

+3-2
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,11 @@ jobs:
103103
# Remove the "unreleased" section from our changelog
104104
perl -0777 -i -pe "s/(<\!-- next-header -->.*## \[Unreleased\].*?\n)(?=## |<\!--)//gms" CHANGELOG.md
105105
106-
./dist/create_install_makefile.sh
106+
# Create Makefile.dist for shipping with the package
107+
sh dist/create_install_makefile.sh
107108
108109
cp {README.md,LICENSE} "$staging/"
109-
cp Makefile.tmp "$staging/Makefile"
110+
cp Makefile.dist "$staging/Makefile"
110111
cp CHANGELOG.md "$staging/doc/"
111112
# Copy manpages
112113
cp "$cargo_outdir"/msgpack.1 "$staging/doc"

.github/workflows/validation-rust.yaml

+4-4
Original file line numberDiff line numberDiff line change
@@ -66,20 +66,20 @@ jobs:
6666
- name: Test make
6767
if: matrix.os != 'windows-latest'
6868
run: |
69-
./dist/create_install_makefile.sh
70-
cargo_outdir="$(find "${{ env.TARGET_DIR }}" -name zspell-stamp -print0 | xargs -0 ls -t | head -n1 | xargs dirname)"
69+
sh dist/create_install_makefile.sh
70+
cargo_outdir="$(find target -name zspell-stamp -print0 | xargs -0 ls -t | head -n1 | xargs dirname)"
7171
mkdir testdir
7272
mv Makefile.tmp testdir/Makefile
7373
mv target
7474
cd testdir
7575
make install
7676
test -f /usr/local/bin/msgpack
7777
test -f /usr/local/share/man/msgpack.1
78-
test -f /usr/share/bash-completion/completions
78+
test -f /usr/share/bash-completion/completions/msgpack.bash
7979
make uninstall
8080
test ! -f /usr/local/bin/msgpack
8181
test ! -f /usr/local/share/man/msgpack.1
82-
test ! -f /usr/share/bash-completion/completions
82+
test ! -f /usr/share/bash-completion/completions/msgpack.bash
8383
8484
miri:
8585
name: Miri

Makefile

+57-47
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,34 @@
11
# This makefile will build (via Cargo)
22

3+
MAKEFLAGS=--warn-undefined-variables
34
VERSION=0.1.0
5+
CARGO := $(shell command -v cargo 2> /dev/null)
6+
47

8+
# Install locations
59
DESTDIR=
10+
MANFILE=msgpack.1
611
PREFIX=/usr/local
712
AUTOPFX=/usr/share
13+
MANDEST=${DESTDIR}${PREFIX}/share/man/man1
14+
BINDEST=${DESTDIR}${PREFIX}/bin
15+
COMPDEST_BASH=${AUTOPFX}/bash-completion/completions
16+
COMPDEST_FISH=${AUTOPFX}/fish/vendor_completions.d
17+
COMPDEST_ZSH=${AUTOPFX}/zsh/vendor-completions
18+
19+
USE_RELEASED_INSTALL=0
20+
21+
ifeq ($(USE_RELEASED_INSTALL),1)
22+
BINSOURCE= .
23+
MANSOURCE = doc
24+
COMPLETESOURCE = completion
25+
else
26+
builddir=$(shell find target -name msgpack-stamp -print0 | xargs -0 ls -t | head -n1 | xargs dirname)
27+
BINSOURCE = target/release
28+
MANSOURCE = $(builddir)
29+
COMPLETESOURCE = $(builddir)
30+
endif
831

9-
MANDIR=${DESTDIR}/${PREFIX}/share/man
10-
BINDIR=${DESTDIR}/${PREFIX}/bin
11-
MANFILE=msgpack.1
12-
13-
BASHACDIR="${AUTOPFX}/bash-completion/completions
14-
FISHACDIR="${AUTOPFX}/fish/vendor_completions.d
15-
ZSHACDIR="${AUTOPFX}/zsh/vendor-completions
16-
17-
CARGO := $(shell command -v cargo 2> /dev/null)
1832

1933
all: msgpack
2034

@@ -31,42 +45,38 @@ ifeq ($(OS),Windows_NT)
3145
$(error install does not yet work on Windows)
3246
exit 1
3347
endif
34-
$(info installing binary, manpages, and shell complete)
35-
36-
BUILDDIR="$(find target -name msgpack-stamp -print0 | xargs -0 ls -t | head -n1 | xargs dirname)"
3748

38-
# We override these in our release script
39-
BUILT_MANDIR=${BUILDDIR}
40-
BUILT_COMPLETEDIR=${BUILDDIR}
41-
42-
install -d ${MANDIR}/man1
43-
install target/release/msgpack ${DESTDIR}/msgpack; \
44-
install -m 644 ${BUILT_MANDIR}/${MANFILE} ${MANDIR}/man1/${MANFILE}
45-
46-
INSTALLEDAC=0
47-
48-
if [ -d "${BASHACDIR}" ]; then \
49-
install ${BUILDDIR}/msgpack.bash ${BASHACDIR}/msgpack.bash; \
50-
$(info installed bash autocomplete); \
51-
INSTALLEDAC=1
52-
fi
53-
54-
if [ -d "${FISHACDIR}" ]; then \
55-
install ${BUILDDIR}/msgpack.fish ${FISHACDIR}/msgpack.fish; \
56-
$(info installed fish autocomplete); \
57-
INSTALLEDAC=1
49+
$(info installing binary, manpages, and shell completion scripts)
50+
$(info binary source: ${BINSOURCE})
51+
$(info manpage source: ${MANSOURCE})
52+
$(info completion source: ${COMPLETESOURCE})
53+
54+
install -d ${BINDEST}
55+
install -d ${MANDEST}
56+
install ${BINSOURCE}/msgpack ${BINDEST}/msgpack
57+
install -m 644 ${MANSOURCE}/${MANFILE} ${MANDEST}/${MANFILE}
58+
59+
INSTALLEDAC=0; \
60+
if [ -d "${COMPDEST_BASH}" ]; then \
61+
install "${COMPLETESOURCE}/msgpack.bash" "${COMPDEST_BASH}/msgpack.bash"; \
62+
echo installed bash autocomplete; \
63+
INSTALLEDAC=1; \
64+
fi; \
65+
if [ -d "${COMPDEST_FISH}" ]; then \
66+
install "${COMPLETESOURCE}/msgpack.fish" "${COMPDEST_FISH}/msgpack.fish"; \
67+
echo installed fish autocomplete; \
68+
INSTALLEDAC=1; \
69+
fi; \
70+
if [ -d "${COMPDEST_ZSH}" ]; then \
71+
install "${COMPLETESOURCE}/_msgpack" "${COMPDEST_ZSH}/_msgpack"; \
72+
echo installed zsh autocomplete; \
73+
INSTALLEDAC=1; \
74+
fi; \
75+
if [ "$${INSTALLEDAC}" = "0" ]; then \
76+
echo did not find any directorys to install autocompletion scripts; \
5877
fi
5978

60-
if [ -d "${ZSHACDIR}" ]; then \
61-
install ${BUILDDIR}/_msgpack ${ZSHACDIR}/_msgpack; \
62-
$(info installed zsh autocomplete); \
63-
INSTALLEDAC=1
64-
fi
65-
66-
ifeq (${INSTALLEDAC},0)
67-
$(info did not find any directorys to install autocompletion scripts)
68-
endif
69-
79+
$(info install completed successfully)
7080

7181
clean:
7282
ifndef CARGO
@@ -78,8 +88,8 @@ endif
7888

7989
uninstall:
8090
$(info cleaning install directory)
81-
rm -f ${DESTDIR}/msgpack
82-
rm -f ${MANDIR}/man1/${MAN}
83-
rm -f ${BASHACDIR}/msgpack.bash
84-
rm -f ${FISHACDIR}/msgpack.fish
85-
rm -f ${ZSHACDIR}/_msgpack
91+
rm -f ${BINDEST}/msgpack
92+
rm -f ${MANDEST}/man1/${MANFILE}
93+
rm -f ${COMPDEST_BASH}/msgpack.bash
94+
rm -f ${COMPDEST_FISH}/msgpack.fish
95+
rm -f ${COMPDEST_ZSH}/_msgpack

build.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ fn main() -> Result<(), std::io::Error> {
5959
let make_dist = std::env::var("MAKE_DIST").map_or(false, |v| v == "1");
6060

6161
// Don't generate outputs if we're in debug mode
62-
if make_dist || profile.as_str() != "debug" {
62+
if make_dist || profile.as_str() != "debug" {
6363
// Create a dummy file to help find the latest output
6464
let stamp_path = Path::new(&outdir).join("msgpack-stamp");
6565
if let Err(err) = File::create(&stamp_path) {

dist/create_install_makefile.sh

+5-5
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
# Generate a makefile suitable for prebuilt binaries
33

44
# Remove all targets except install & uninstall
5-
perl -0777 -pe 's/^(?!install|uninstall)\w+:.*?(?=^\w+:|\Z)//gms' Makefile > Makefile.tmp
5+
perl -0777 -pe 's/^(?!install|uninstall)\w+:.*?(?=^\w+:|\Z)//gms' Makefile > Makefile.dist
66

77
# Strip target prerequisites
8-
perl -0777 -i -pe 's/^((?:install|uninstall):)(.+)$/$1/gm' Makefile.tmp
8+
perl -0777 -i -pe 's/^((?:install|uninstall):)(.+)$/$1/gm' Makefile.dist
99

1010
# Remove BUILDDIR, update man & complete locations
11-
perl -0777 -i -pe 's/^\s+BUILDDIR=.*$//gm' Makefile.tmp
12-
perl -0777 -i -pe 's/^(\s+BUILT_MANDIR=).*$/$1\/doc/gm' Makefile.tmp
13-
perl -0777 -i -pe 's/^(\s+BUILT_COMPLETEDIR=).*$/$1\/completion/gm' Makefile.tmp
11+
perl -0777 -i -pe 's/^\s+builddir=.*$//gm' Makefile.dist
12+
perl -0777 -i -pe 's/^(\s+BUILT_MANDIR=).*$/$1\/doc/gm' Makefile.dist
13+
perl -0777 -i -pe 's/^(\s+USE_RELEASED_INSTALL=).*$/$1 1/gm' Makefile.dist

src/main.rs

+6-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! MessagePack command line interface
22
//!
33
//! Install with `cargo install msgpack-cli` or get a prebuilt binary on the
4-
//! releases page: https://github.com/pluots/msgpack-cli/releases
4+
//! releases page: <https://github.com/pluots/msgpack-cli/releases>
55
66
#![warn(clippy::pedantic)]
77
#![warn(clippy::cargo)]
@@ -139,7 +139,7 @@ impl fmt::Display for Error {
139139
),
140140
Self::NoDirection => write!(
141141
f,
142-
"Could not determine conversion direction. Specify '--to-json' or '--to-msgpack'."
142+
"Could not determine conversion direction. Specify '--to-json' or '--to-msgpack' ('-j'/'-m')."
143143
),
144144
Self::MessagePak(e) => write!(f, "Unable to parse MessagePack input, {e}"),
145145
Self::Json(e) => write!(f, "Unable to parse JSON input, {e}"),
@@ -269,16 +269,15 @@ where
269269
};
270270

271271
let mut deserializer = rmp_serde::Deserializer::new(deser_buf);
272-
let out_writer;
273-
274-
if pretty {
272+
// Run serializer, get our output writer back
273+
let out_writer = if pretty {
275274
let mut serializer = serde_json::Serializer::pretty(output);
276275
serde_transcode::transcode(&mut deserializer, &mut serializer)?;
277-
out_writer = serializer.into_inner();
276+
serializer.into_inner()
278277
} else {
279278
let mut serializer = serde_json::Serializer::new(output);
280279
serde_transcode::transcode(&mut deserializer, &mut serializer)?;
281-
out_writer = serializer.into_inner();
280+
serializer.into_inner()
282281
};
283282

284283
// Return ownership of the output

0 commit comments

Comments
 (0)