bin/decode_typed can run decode with a type and crate passed via environment variables.
Issue #9.
This commit is contained in:
parent
bee76d3668
commit
2b0ee72ceb
6 changed files with 60 additions and 8 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -75,7 +75,6 @@ dependencies = [
|
||||||
"clap 2.29.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"clap 2.29.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"derive-error 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
"derive-error 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"framed 0.1.4",
|
"framed 0.1.4",
|
||||||
"framed_test_type 0.1.0",
|
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|
49
bin/decode_typed
Executable file
49
bin/decode_typed
Executable file
|
@ -0,0 +1,49 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
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}"
|
||||||
|
|
||||||
|
echo "TYPE_CRATE_DIR = '${TYPE_CRATE_DIR}'"
|
||||||
|
echo "TYPE_NAME = '${TYPE_NAME}'"
|
||||||
|
|
||||||
|
TYPE_CRATE_NAME="$(cargo read-manifest --manifest-path "${TYPE_CRATE_DIR}/Cargo.toml" | jq '.name' -r)"
|
||||||
|
|
||||||
|
TMP_DIR="${REPO_DIR}/target/decode_typed/tmp"
|
||||||
|
|
||||||
|
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";
|
||||||
|
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}";
|
||||||
|
EOF
|
||||||
|
|
||||||
|
|
||||||
|
cargo rustc \
|
||||||
|
--manifest-path "${TYPE_CRATE_DIR}/Cargo.toml" \
|
||||||
|
--lib \
|
||||||
|
-v \
|
||||||
|
-- \
|
||||||
|
-o "${TMP_DIR}/${TYPE_CRATE_NAME}.rlib" \
|
||||||
|
< /dev/null;
|
||||||
|
TYPE_CRATE_RLIB="$(ls "${TMP_DIR}"/lib${TYPE_CRATE_NAME}*.rlib)";
|
||||||
|
cargo rustc \
|
||||||
|
--manifest-path "${REPO_DIR}/decode/Cargo.toml" \
|
||||||
|
--bin framed_decode \
|
||||||
|
-v \
|
||||||
|
-- \
|
||||||
|
-o "${TMP_DIR}/decode" \
|
||||||
|
--extern ${TYPE_CRATE_NAME}="${TYPE_CRATE_RLIB}" \
|
||||||
|
--emit obj \
|
||||||
|
< /dev/null;
|
||||||
|
DECODE_PATH="$(find "${TMP_DIR}/decode"* -executable -type f)";
|
||||||
|
echo "";
|
||||||
|
echo "";
|
||||||
|
${DECODE_PATH};
|
|
@ -20,7 +20,6 @@ branch = "master"
|
||||||
clap = "^2.29.0"
|
clap = "^2.29.0"
|
||||||
derive-error = "^0.0.4"
|
derive-error = "^0.0.4"
|
||||||
framed = { path = "../framed" }
|
framed = { path = "../framed" }
|
||||||
framed_test_type = { path = "../test_type" }
|
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = ["typed"]
|
default = ["typed"]
|
||||||
|
|
10
decode/README.md
Normal file
10
decode/README.md
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
# `framed_decode`
|
||||||
|
|
||||||
|
TODO.
|
||||||
|
|
||||||
|
## framed-rs/bin/decode_typed
|
||||||
|
|
||||||
|
TODO.
|
||||||
|
|
||||||
|
Note: you must install [`jq`][jq] and have it on your path.
|
||||||
|
[jq]: https://stedolan.github.io/jq/
|
|
@ -1,5 +0,0 @@
|
||||||
// TODO: Generate this.
|
|
||||||
|
|
||||||
extern crate framed_test_type;
|
|
||||||
use framed_test_type::Test as UserType;
|
|
||||||
static USER_TYPE_NAME: &'static str = "framed_test_type::Test";
|
|
|
@ -6,7 +6,7 @@ extern crate clap;
|
||||||
extern crate derive_error;
|
extern crate derive_error;
|
||||||
extern crate framed;
|
extern crate framed;
|
||||||
|
|
||||||
include!("dynamic.rs");
|
include!(env!("FRAMED_DECODE_DYNAMIC_RS"));
|
||||||
|
|
||||||
mod error;
|
mod error;
|
||||||
use error::{Error, Result};
|
use error::{Error, Result};
|
||||||
|
|
Loading…
Reference in a new issue