Skip to content

Commit

Permalink
Inline smoke test (#35)
Browse files Browse the repository at this point in the history
* Integrate the examples into cargo-raze

* Add the remote examples as well

* Add a README doc for remote examples

* Fix the build after adding remote README

* Remove examples for PR

* Enable -f on `rm` so no error if dirs don't exist

* Explicitly reset working directory back to original

* Rename examples/README.md

* Move the command exists check to a function

* Make sure `command_exists` actually checks for existence

* DIR -> REPO_ROOT
  • Loading branch information
bspeice authored and acmcarther committed Mar 27, 2018
1 parent 2f65244 commit f453818
Show file tree
Hide file tree
Showing 30 changed files with 1,966 additions and 6 deletions.
5 changes: 5 additions & 0 deletions examples/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
bazel-bin
bazel-examples
bazel-genfiles
bazel-out
bazel-testlogs
9 changes: 9 additions & 0 deletions examples/DO_NOT_EDIT_HERE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Cargo Raze Examples

The examples directory contains some example usages of Cargo Raze to set up projects for Bazel building.

# Contributing

This directory is used in the testing process of Cargo Raze to make sure that practical examples work
during the test process for all contributions. Please do not commit new code here, as it will be destroyed
by the testing process. Instead, new examples should be added to the `smoke_test` directory.
84 changes: 78 additions & 6 deletions smoke-test.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,79 @@
#! /usr/bin/env bash
set -e
#!/usr/bin/env bash

mkdir /tmp/cargo_raze_scratch && cd /tmp/cargo_raze_scratch
git clone https://github.com/acmcarther/cargo-raze-examples
cd cargo-raze-examples
(cd ./internal && ./evaluate-local-raze.sh)
set -eu

function command_exists {
command -v "$1" >/dev/null 2>&1 || ( echo "Command \`$1\` isn't available. Please install before continuing."; exit 1 )
}

PWD="$(pwd)"

REPO_ROOT="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
cd "$REPO_ROOT"

EXAMPLES_DIR="$REPO_ROOT/examples"
TEST_DIR="$REPO_ROOT/smoke_test"

command_exists "cargo"
command_exists "cargo-vendor"
command_exists "bazel"

# Clean the `examples` directory
rm -rf "$EXAMPLES_DIR/remote" "$EXAMPLES_DIR/vendored"
cp -r "$TEST_DIR/remote" "$TEST_DIR/vendored" "$EXAMPLES_DIR"

# Set up the new WORKSPACE file
cat > "$EXAMPLES_DIR/WORKSPACE" << EOF
workspace(name = "io_bazel_rules_rust")
git_repository(
name = "io_bazel_rules_rust",
commit = "ee61ddff0b97cfc36278902e5210d1929ba5b119",
remote = "https://github.com/bazelbuild/rules_rust.git",
)
load("@io_bazel_rules_rust//rust:repositories.bzl", "rust_repositories")
rust_repositories()
EOF

for ex in $(find $TEST_DIR/remote -maxdepth 1 -type d | tail -n+2); do
name="$(basename "$ex")"
cat >> "$EXAMPLES_DIR/WORKSPACE" << EOF
load("//remote/${name}/cargo:crates.bzl", "${name}_fetch_remote_crates")
${name}_fetch_remote_crates()
EOF
done

# Run Cargo Vendor over the appropriate projects
for ex in $(find $EXAMPLES_DIR/vendored -maxdepth 1 -type d | tail -n+2); do
echo "Running Cargo Vendor for $(basename "$ex")"
cd "$ex/cargo"
cargo vendor -xq
done

# Ensure Cargo Raze build is up-to-date
cd "$REPO_ROOT"
echo "Building local Cargo Raze"
cargo build --quiet
RAZE="$REPO_ROOT/target/debug/cargo-raze raze"
for ex in $(find $EXAMPLES_DIR -mindepth 2 -maxdepth 2 -type d); do
echo "Running Cargo Raze for $(basename $ex)"
cd "$ex/cargo"
eval "$RAZE"
done

# Run the Bazel build for all targets
cd "$EXAMPLES_DIR"
for ex in $(find $EXAMPLES_DIR -mindepth 2 -maxdepth 2 -type d); do
ex_name="$(basename "$ex")"
ex_type="$(basename $(dirname "$ex"))"
bazel_path="//$ex_type/$ex_name:all"
bazel_cargo_path="//$ex_type/$ex_name/cargo:all"

echo "Running Bazel build for $bazel_path, $bazel_cargo_path"
bazel build "$bazel_path" && bazel build "$bazel_cargo_path"
done

cd "$PWD"
5 changes: 5 additions & 0 deletions smoke_test/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Cargo Raze Smoke Test

The smoke test for Cargo raze consists of some basic examples that are tested to make sure Bazel
functionality hasn't broken for new code. New examples should be created here, but `cargo-vendor`
and `cargo-raze` should *NOT* be run.
13 changes: 13 additions & 0 deletions smoke_test/remote/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Adding new remote examples

The smoke test script generates a WORKSPACE file that looks up the `crates.bzl` functions
and assumes that the function name is `<folder>_fetch_remote_crates`.

In order to make sure that this assertion holds, please make sure set up **Cargo.toml** as such:

**Cargo.toml**
```toml

[raze]
gen_workspace_prefix = "<folder>"
```
10 changes: 10 additions & 0 deletions smoke_test/remote/complicated_cargo_library/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
load("@io_bazel_rules_rust//rust:rust.bzl", "rust_binary")

rust_binary(
name = "complicated_cargo_library",
srcs = ["src/main.rs"],
deps = [
"//remote/complicated_cargo_library/cargo:regex",
"//remote/complicated_cargo_library/cargo:specs",
],
)
3 changes: 3 additions & 0 deletions smoke_test/remote/complicated_cargo_library/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# complicated_cargo_library_remote

This is a "no vendor" version of the complicated_cargo_library.
Loading

0 comments on commit f453818

Please sign in to comment.