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

Switch crosstool-ng configure scripts to xtask. #877

Merged
merged 1 commit into from
Jun 29, 2022

Conversation

Alexhuszagh
Copy link
Contributor

Rewrite the bash build scripts to Rust, allowing a better CLI interface, easier maintenance, and better help messages via clap.

@Alexhuszagh Alexhuszagh added the meta issues/PRs related to the maintenance of the crate. label Jun 27, 2022
@Alexhuszagh Alexhuszagh requested a review from a team as a code owner June 27, 2022 15:46
@Alexhuszagh Alexhuszagh added the no changelog A valid PR without changelog (no-changelog) label Jun 27, 2022
@Alexhuszagh
Copy link
Contributor Author

This is related to the discussion here.

Ok(targets)
}

fn configure_target(
Copy link
Member

Choose a reason for hiding this comment

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

I feel like all the if statements here on major and minor can be combined into a match (minor, major) with either range patterns or if guards.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think that's somewhat difficult, since there's no fallthrough cases (the only time this is actually valuable):

if gcc_major > 4 || (gcc_major == 4 && gcc_major > 9) {
    ct_gcc.push_str("\nCT_GCC_later_than_4_9=y");
}
if gcc_major > 4 || (gcc_major == 4 && gcc_major >= 9) {
    ct_gcc.push_str("\nCT_GCC_4_9_or_later=y");
}
if gcc_major > 4 || (gcc_major == 4 && gcc_major > 8) {
    ct_gcc.push_str("\nCT_GCC_later_than_4_8=y");
}
if gcc_major > 4 || (gcc_major == 4 && gcc_major >= 8) {
    ct_gcc.push_str("\nCT_GCC_4_8_or_later=y");
}

Would become:

match (gcc_major, gcc_major) {
    (5.., _) | (4, 10..) => {
        ct_gcc.push_str("\nCT_GCC_later_than_4_9=y");
        ct_gcc.push_str("\nCT_GCC_4_9_or_later=y");
        ct_gcc.push_str("\nCT_GCC_later_than_4_8=y");
        ct_gcc.push_str("\nCT_GCC_4_8_or_later=y");
    },
    (4, 9) => {
        ct_gcc.push_str("\nCT_GCC_4_9_or_later=y");
        ct_gcc.push_str("\nCT_GCC_later_than_4_8=y");
        ct_gcc.push_str("\nCT_GCC_4_8_or_later=y");
    }
    (4, 8) => {
        ct_gcc.push_str("\nCT_GCC_4_8_or_later=y");
    }
    _ => (),
}

These aren't exclusive if statements, they each run sequentially. I guess we could have an external helper function?

let push_ge_49 = |output: &mut String| {
    ct_gcc.push_str("\nCT_GCC_4_9_or_later=y");
    ct_gcc.push_str("\nCT_GCC_later_than_4_8=y");
    ct_gcc.push_str("\nCT_GCC_4_8_or_later=y");
};

match (gcc_major, gcc_major) {
    (5.., _) | (4, 10..) => {
        ct_gcc.push_str("\nCT_GCC_later_than_4_9=y");
        push_ge_49(&mut ct_gcc);
    },
    (4, 9) => {
        push_ge_49(&mut ct_gcc);
    }
    (4, 8) => {
        ct_gcc.push_str("\nCT_GCC_4_8_or_later=y");
    }
    _ => (),
}

But I still don't think that's better.

Rewrite the bash build scripts to Rust, allowing a better CLI interface,
easier maintenance, and better help messages via clap.
Copy link
Member

@Emilgardis Emilgardis left a comment

Choose a reason for hiding this comment

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

I dislike the repetitive if blocks, but that just leaves more room for improvement, and if it works it works. LGTM!

bors r+

@bors
Copy link
Contributor

bors bot commented Jun 29, 2022

Build succeeded:

@bors bors bot merged commit 6c2226d into cross-rs:main Jun 29, 2022
@Alexhuszagh Alexhuszagh deleted the configure_ctng branch June 29, 2022 16:54
@Emilgardis Emilgardis added this to the v0.2.3 milestone Jul 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
meta issues/PRs related to the maintenance of the crate. no changelog A valid PR without changelog (no-changelog)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants