Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add experimental --bisect option #170

Merged
merged 1 commit into from
Jan 6, 2022
Merged

Conversation

smoelius
Copy link
Collaborator

@smoelius smoelius commented Jan 1, 2022

No description provided.

@smoelius smoelius force-pushed the bisect branch 3 times, most recently from 62ccace to edbd3de Compare January 3, 2022 12:04
Comment on lines +11 to +53
const SCRIPT: &str = r#"#! /bin/bash

set -euo pipefail

CHANNEL="$(echo "$RUSTUP_TOOLCHAIN" | sed -n 's/^bisector-\(nightly-[0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\}\)-.*$/\1/;T;p')"

unset RUSTUP_TOOLCHAIN

if [[ -z "$CHANNEL" ]]; then
if [[ ! -f first_commit_seen ]]; then
touch first_commit_seen
exit 1
else
exit 0
fi
fi

# smoelius: The rust-toolchain file should reflect the most recent successful build. So if the
# current build fails, restore the rust-toolchain file's previous contents.
TMP="$(mktemp -p . -t rust-toolchain.XXXXXXXXXX)"
cp rust-toolchain "$TMP"
trap '
STATUS="$?"
if [[ "$STATUS" -eq 0 ]]; then
rm "$TMP"
else
mv "$TMP" rust-toolchain
fi
exit "$STATUS"
' EXIT

sed -i "s/^channel = \"[^\"]*\"$/channel = \"$CHANNEL\"/" rust-toolchain

if [[ ! -f first_channel_seen ]]; then
cargo build --tests || (touch first_channel_seen && false)
elif [[ ! -f successful_build_seen ]]; then
# smoelius: Pretend the build succeeds (even if it doesn't) and proceed backwards until we find
# one that actually succeeds.
(cargo build --tests && touch successful_build_seen) || true
else
cargo build --tests
fi
"#;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An easy way to make this cross-platform like this is something like https://github.com/matklad/xshell/, which has mostly the same syntax as shell, but uses Command::new under the hood and doesn't depend on a specific shell.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I just saw you're passing the path to the script as an argument to some tool - maybe you could do that with xshell by adding a second binary and passing its path? something like src/bin/bisect.rs and then cargo install would install it alongside cargo-dylint.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I like this idea.

However, given that the script mostly works and I have other priorities (cough), I will likely merge this as-is and make implementing your suggestion a TODO item.

Thanks, BTW.

@smoelius smoelius merged commit 86f116d into trailofbits:master Jan 6, 2022
@smoelius smoelius deleted the bisect branch January 6, 2022 11:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants