decode_typed argument handling, README, output formats.
This commit is contained in:
parent
2b0ee72ceb
commit
b63b880959
1 changed files with 250 additions and 27 deletions
|
|
@ -3,13 +3,15 @@ set -e
|
|||
|
||||
REPO_DIR="$(cd $(dirname ${BASH_SOURCE[0]} )/..; pwd )"
|
||||
|
||||
TYPE_CRATE_DIR="${TYPE_CRATE_DIR-${REPO_DIR}/test_type}"
|
||||
TYPE_NAME="${TYPE_NAME-framed_test_type::Test}"
|
||||
DECODE_TYPE_CRATE_DIR="${DECODE_TYPE_CRATE_DIR?You must set this environment variable with the path to the crate containing your serialized type.
|
||||
E.g. \'framed-rs/test_type\'}"
|
||||
DECODE_TYPE_NAME="${DECODE_TYPE_NAME?You must set this environment variable with the full name of your serialized type including its module path.
|
||||
E.g. \'framed_test_type::Test\'}"
|
||||
|
||||
echo "TYPE_CRATE_DIR = '${TYPE_CRATE_DIR}'"
|
||||
echo "TYPE_NAME = '${TYPE_NAME}'"
|
||||
echo "DECODE_TYPE_CRATE_DIR = '${DECODE_TYPE_CRATE_DIR}'"
|
||||
echo "DECODE_TYPE_NAME = '${DECODE_TYPE_NAME}'"
|
||||
|
||||
TYPE_CRATE_NAME="$(cargo read-manifest --manifest-path "${TYPE_CRATE_DIR}/Cargo.toml" | jq '.name' -r)"
|
||||
TYPE_CRATE_NAME="$(cargo read-manifest --manifest-path "${DECODE_TYPE_CRATE_DIR}/Cargo.toml" | jq '.name' -r)"
|
||||
|
||||
TMP_DIR="${REPO_DIR}/target/decode_typed/tmp"
|
||||
|
||||
|
|
@ -17,33 +19,41 @@ mkdir -p "${TMP_DIR}";
|
|||
rm -f "${TMP_DIR}/"*;
|
||||
|
||||
# TODO: Move dynamic.rs to TMP_DIR, both here and in the include! in main.rs.
|
||||
export FRAMED_DECODE_DYNAMIC_RS="${TMP_DIR}/dynamic_${TYPE_NAME}.rs";
|
||||
export FRAMED_DECODE_DYNAMIC_RS="${TMP_DIR}/dynamic_${DECODE_TYPE_NAME}.rs";
|
||||
cat > "${FRAMED_DECODE_DYNAMIC_RS}" <<EOF
|
||||
// Generated by framed-rs/bin/decode_typed, your changes will be overwritten.
|
||||
extern crate ${TYPE_CRATE_NAME};
|
||||
use ${TYPE_NAME} as UserType;
|
||||
static USER_TYPE_NAME: &'static str = "${TYPE_NAME}";
|
||||
use ${DECODE_TYPE_NAME} as UserType;
|
||||
static USER_TYPE_NAME: &'static str = "${DECODE_TYPE_NAME}";
|
||||
EOF
|
||||
|
||||
|
||||
# Build user type crate.
|
||||
cargo rustc \
|
||||
--manifest-path "${TYPE_CRATE_DIR}/Cargo.toml" \
|
||||
--manifest-path "${DECODE_TYPE_CRATE_DIR}/Cargo.toml" \
|
||||
--lib \
|
||||
-v \
|
||||
${DECODE_TYPE_CARGO_FLAGS} \
|
||||
-- \
|
||||
-o "${TMP_DIR}/${TYPE_CRATE_NAME}.rlib" \
|
||||
${DECODE_TYPE_RUSTC_FLAGS} \
|
||||
< /dev/null;
|
||||
TYPE_CRATE_RLIB="$(ls "${TMP_DIR}"/lib${TYPE_CRATE_NAME}*.rlib)";
|
||||
|
||||
# Build decode bin.
|
||||
cargo rustc \
|
||||
--manifest-path "${REPO_DIR}/decode/Cargo.toml" \
|
||||
--bin framed_decode \
|
||||
-v \
|
||||
${DECODE_BIN_CARGO_FLAGS} \
|
||||
-- \
|
||||
-o "${TMP_DIR}/decode" \
|
||||
--extern ${TYPE_CRATE_NAME}="${TYPE_CRATE_RLIB}" \
|
||||
--emit obj \
|
||||
${DECODE_BIN_RUSTC_FLAGS} \
|
||||
< /dev/null;
|
||||
DECODE_PATH="$(find "${TMP_DIR}/decode"* -executable -type f)";
|
||||
|
||||
echo "";
|
||||
echo "";
|
||||
${DECODE_PATH};
|
||||
|
||||
# Run decode bin.
|
||||
${DECODE_PATH} "$@";
|
||||
|
|
|
|||
Loading…
Reference in a new issue