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

[rustbuild] Implement testing and refactor configuration #48521

Closed

Conversation

Mark-Simulacrum
Copy link
Member

The important commits for review are marked with [VIC]. Each commit is intended to be relatively small, even though the overall patch is quite large. I would recommend reviewing by-commit for review purposes. I'm happy to split this PR up into smaller ones if that makes things easier -- the last commit (which implements the actual tests) is fairly small, though it builds on the refactoring done in the rest of the commits quite heavily.

Configuration refactor

This PR refactors the configuration to utilize Default impls for the structs and to directly include toml-deserialized structs in the final Config struct. This avoids quite a bit of boilerplate code, and, in my opinion, makes it considerably easier to understand what the default value for a given option is. It's intended that nothing has actually changed, but it's possible that I've accidentally forgotten some option -- I've tried to check manually and found nothing relevant.

Testing design (also included in relevant commit)

In order to run tests, various parts of rustbuild are cfg'd out,
generally speaking, these are filesystem-related operations and running
commands. Then, rustbuild is run "as normal" and the various steps that
where run are retrieved from the cache and checked against the expected
results.

Note that this means that the current implementation primarily tests
"what" we build, but doesn't actually test that what we build will
build. In other words, it doesn't do any form of dependency verification
for any crate. This is possible to implement, but is considered future
work.

This implementation strives to cfg out as little code as possible; it
also does not currently test anywhere near all of rustbuild. The current
tests are also not checked for "correctness," rather, they simply
represent what we do as of this commit, which may be wrong.

A fake fs module is also added to src/bootstrap/lib.rs and used
throughout rustbuild to make it so that most of the code doesn't have to
cfg out create_dir_all and remove_dir_all, etc.

Test cases are drawn from the old implementation of rustbuild, though
the expected results may vary.

r? @alexcrichton

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Feb 25, 2018
@bors
Copy link
Contributor

bors commented Feb 25, 2018

☔ The latest upstream changes (presumably #48520) made this pull request unmergeable. Please resolve the merge conflicts.

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Feb 25, 2018
@bors
Copy link
Contributor

bors commented Feb 25, 2018

☔ The latest upstream changes (presumably #48531) made this pull request unmergeable. Please resolve the merge conflicts.

All cases where it is used can be replaced by substituing run.host for
run.builder.build.build; that is its only effect. As such, it is
removable.
All uses are replaced with not accessing run.target/run.host, and
instead directly using run.builder.build.build.
Previously it was set to true when we didn't run HOSTS steps.
These arguments are passed to the relevant x.py invocation in all cases
anyway. As such, there is no need to separately configure them. x.py
will ignore the configuration when they are passed on the command line
anyway.
This isn't entirely possible, since we don't run only-hosts steps if
just --target is passed, but it is a good approximation.
Since rustdoc uses proc macros both the host and the target need a
full set of libraries. Also, ensure that build scripts have a std to
link against.
Previously each call to Builder::cargo would have to check on its own
the various stamp files and clear out it's target directory. Now, this
is done automatically in Builder::cargo.
Moves these calls into one central location instead of spread throughout
various cargo invocations.
Simplifies invocations of cargo to usually be builder.cargo(...).run()
unless we need to pass a manifest path (tools) or do something
non-standard with the environment.
This allows specifying the dependencies of the tool (and what stampfile
changes will require it) directly. It also means that all tools are no
longer built in the same stageN-tools directory. Previously, this could
cause unnecessary rebuilds as we'd wipe out the directory while building
rustc even though the tools already built only depended on std.
We need these for proc macros to work properly.
In order to run tests, various parts of rustbuild are cfg'd out,
generally speaking, these are filesystem-related operations and running
commands. Then, rustbuild is run "as normal" and the various steps that
where run are retrieved from the cache and checked against the expected
results.

Note that this means that the current implementation primarily tests
"what" we build, but doesn't actually test that what we build *will*
build. In other words, it doesn't do any form of dependency verification
for any crate. This is possible to implement, but is considered future
work.

This implementation strives to cfg out as little code as possible; it
also does not currently test anywhere near all of rustbuild. The current
tests are also not checked for "correctness," rather, they simply
represent what we do as of this commit, which may be wrong.

A fake fs module is also added to src/bootstrap/lib.rs and used
throughout rustbuild to make it so that most of the code doesn't have to
cfg out create_dir_all and remove_dir_all, etc.

Test cases are drawn from the old implementation of rustbuild, though
the expected results may vary.
Avoids breaking on File::open/File::create during testing when the
relevant directory hasn't been created.
Serde denies the field as unknown with serde(skip), so instead utilizing
a custom deserializer to avoid that problem.
@Mark-Simulacrum Mark-Simulacrum added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Feb 27, 2018
@alexcrichton
Copy link
Member

This is looking pretty nice, thanks for this @Mark-Simulacrum! I think I'm gonna have a pretty difficult time reviewing this, though. Would it be possible to split this apart in to separate PRs? At a high level I'm not sure that refactoring the configuration or testing would amount to 7k changes, so it seems like there's a lot more going on here as well?

In general I've found modifying rustc's build system to be extremely difficult on a large scale in the sense that there's always a regression lurking around the corner, so at least for me it's easiest to sit down with smaller chunks at a time and try to reason that through.

@petrochenkov
Copy link
Contributor

I'm not sure that refactoring the configuration or testing would amount to 7k changes, so it seems like there's a lot more going on here as well?

There's a "rustfmt everything" commit hiding somewhere in the middle which is responsible for half of the diff 😄
(A good candidate for splitting.)

@Mark-Simulacrum
Copy link
Member Author

#48599 and #48600 are now open. I'm going to close this for now -- I'll reopen once we've merged more of the parts, and work on trimming down the individual parts into separate PRs and open as I go.

@alexcrichton
Copy link
Member

Ok thanks @Mark-Simulacrum!

@Mark-Simulacrum Mark-Simulacrum deleted the rustbuild-updates branch June 8, 2019 13:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants