Skip to content

Commit

Permalink
Trim unneeded code in scripts.
Browse files Browse the repository at this point in the history
  • Loading branch information
SergioBenitez committed Feb 29, 2024
1 parent 8d3f1d6 commit 32c8199
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 51 deletions.
66 changes: 20 additions & 46 deletions scripts/config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,45 +37,19 @@ function future_date() {

# Root of workspace-like directories.
PROJECT_ROOT=$(relative "") || exit $?
CORE_ROOT=$(relative "core") || exit $?
CONTRIB_ROOT=$(relative "contrib") || exit $?
SITE_ROOT=$(relative "site") || exit $?
BENCHMARKS_ROOT=$(relative "benchmarks") || exit $?
FUZZ_ROOT=$(relative "core/lib/fuzz") || exit $?

# Root of project-like directories.
CORE_LIB_ROOT=$(relative "core/lib") || exit $?
CORE_CODEGEN_ROOT=$(relative "core/codegen") || exit $?
CORE_HTTP_ROOT=$(relative "core/http") || exit $?
GUIDE_TESTS_ROOT=$(relative "site/tests") || exit $?

# Root of infrastructure directories.
EXAMPLES_DIR=$(relative "examples") || exit $?
DOC_DIR=$(relative "target/doc") || exit $?

# Versioning information. These are changed as versions change.
VERSION=$(git grep -h "^version" "${CORE_LIB_ROOT}" | head -n 1 | cut -d '"' -f2)
MAJOR_VERSION=$(echo "${VERSION}" | cut -d'.' -f1-2)
GIT_BRANCH="$(git branch --show-current)"
GIT_BRANCH=${GIT_BRANCH:-$BRANCH}
IS_RELEASE_BRANCH=$( [[ $GIT_BRANCH == "v"* ]]; echo $? )

# A generated codename for this version. Use the git branch for pre-releases.
case $IS_RELEASE_BRANCH in
1)
CODENAME="${GIT_BRANCH}"
DOC_VERSION="${GIT_BRANCH}-$(future_date)"
;;
*)
CODENAME="${MAJOR_VERSION}"
DOC_VERSION="${VERSION}"
;;
esac

CORE_CRATE_ROOTS=(
"${CORE_HTTP_ROOT}"
"${CORE_CODEGEN_ROOT}"
"${CORE_LIB_ROOT}"
"${CORE_CODEGEN_ROOT}"
"${CORE_HTTP_ROOT}"
)

CONTRIB_SYNC_DB_POOLS_CRATE_ROOTS=(
Expand All @@ -88,38 +62,38 @@ CONTRIB_DB_POOLS_CRATE_ROOTS=(
"${CONTRIB_ROOT}/db_pools/codegen"
)

ALL_CRATE_ROOTS=(
"${CORE_HTTP_ROOT}"
"${CORE_CODEGEN_ROOT}"
"${CORE_LIB_ROOT}"
"${CONTRIB_ROOT}/sync_db_pools/codegen"
"${CONTRIB_ROOT}/sync_db_pools/lib"
"${CONTRIB_ROOT}/db_pools/codegen"
"${CONTRIB_ROOT}/db_pools/lib"
"${CONTRIB_ROOT}/dyn_templates"
"${CONTRIB_ROOT}/ws"
)
# Root of infrastructure directories.
EXAMPLES_DIR=$(relative "examples") || exit $?
DOC_DIR=$(relative "target/doc") || exit $?

# Versioning information.
VERSION=$(git grep -h "^version" "${CORE_LIB_ROOT}" | head -n 1 | cut -d '"' -f2)
GIT_BRANCH="$(git branch --show-current)"
GIT_BRANCH=${GIT_BRANCH:-$BRANCH}
IS_DEV_BRANCH=$( [[ $GIT_BRANCH == "v"* ]]; echo $? )

case $IS_DEV_BRANCH in
1) DOC_VERSION="${GIT_BRANCH}-$(future_date)" ;;
*) DOC_VERSION="${VERSION}" ;;
esac

function print_environment() {
echo " VERSION: ${VERSION}"
echo " MAJOR_VERSION: ${MAJOR_VERSION}"
echo " GIT_BRANCH: ${GIT_BRANCH}"
echo " IS_RELEASE_BRANCH: ${IS_RELEASE_BRANCH}"
echo " CODENAME: ${CODENAME}"
echo " IS_DEV_BRANCH: ${IS_DEV_BRANCH}"
echo " DOC_VERSION: ${DOC_VERSION}"
echo " SCRIPT_DIR: ${SCRIPT_DIR}"
echo " PROJECT_ROOT: ${PROJECT_ROOT}"
echo " CORE_ROOT: ${CORE_ROOT}"
echo " CONTRIB_ROOT: ${CONTRIB_ROOT}"
echo " SITE_ROOT: ${SITE_ROOT}"
echo " FUZZ_ROOT: ${FUZZ_ROOT}"
echo " BENCHMARKS_ROOT: ${BENCHMARKS_ROOT}"
echo " CORE_LIB_ROOT: ${CORE_LIB_ROOT}"
echo " CORE_CODEGEN_ROOT: ${CORE_CODEGEN_ROOT}"
echo " CORE_HTTP_ROOT: ${CORE_HTTP_ROOT}"
echo " GUIDE_TESTS_ROOT: ${GUIDE_TESTS_ROOT}"
echo " CONTRIB_SYNC_DB_POOLS_CRATE_ROOTS: ${CONTRIB_SYNC_DB_POOLS_CRATE_ROOTS[*]}"
echo " CONTRIB_DB_POOLS_CRATE_ROOTS: ${CONTRIB_DB_POOLS_CRATE_ROOTS[*]}"
echo " EXAMPLES_DIR: ${EXAMPLES_DIR}"
echo " DOC_DIR: ${DOC_DIR}"
echo " ALL_CRATE_ROOTS: ${ALL_CRATE_ROOTS[*]}"
echo " date(): $(future_date)"
}

Expand Down
9 changes: 5 additions & 4 deletions scripts/mk-docs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ echo ":::: Generating docs (${DOC_VERSION})..."
pushd "${PROJECT_ROOT}" > /dev/null 2>&1
# Set the crate version and fill in missing doc URLs with docs.rs links.
RUSTDOCFLAGS="-Z unstable-options \
--extern-html-root-url rocket=https://api.rocket.rs/${GIT_BRANCH}/rocket/ \
--crate-version ${DOC_VERSION} \
--enable-index-page \
--generate-link-to-definition" \
cargo doc -Zrustdoc-map --no-deps --all-features \
-p rocket \
Expand All @@ -31,17 +33,16 @@ pushd "${PROJECT_ROOT}" > /dev/null 2>&1
-p rocket_ws
popd > /dev/null 2>&1

# Generating redirection list: from to.
echo ":::: Generating redirects..."
REDIRECTS="
/ /v0.5/rocket/ 302!
/rocket/ /v0.5/rocket/ 302!
/:v /:v/rocket/
/:v/* https://:v--rocket-docs.netlify.app/:splat 200
"

# Generating redirection list: from to.
if [ "${GIT_BRANCH}" = "master" ]; then
echo ":::: Generating redirects..."
echo "${REDIRECTS}" | tee "${DOC_DIR}/_redirects"
else
echo "-> '${GIT_BRANCH}' branch does not require redirects"
echo ":: Skipping redirects for branch '${GIT_BRANCH}'"
fi
2 changes: 1 addition & 1 deletion scripts/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ echo ":: Ensuring contrib sync_db_pools versions match..."
check_versions_match "${CONTRIB_SYNC_DB_POOLS_CRATE_ROOTS[@]}"

echo ":: Ensuring contrib db_pools versions match..."
check_versions_match "${CONTRIB_SYNC_DB_POOLS_CRATE_ROOTS[@]}"
check_versions_match "${CONTRIB_DB_POOLS_CRATE_ROOTS[@]}"

echo ":: Ensuring minimum style requirements are met..."
check_style
Expand Down

0 comments on commit 32c8199

Please sign in to comment.