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

cmake: Copy tests to the build tree instead of linking them #309

Closed
wants to merge 1 commit into from

Conversation

hebasto
Copy link
Owner

@hebasto hebasto commented Aug 6, 2024

This PR enables in-source builds, which currently fail on the staging branch.

As discussed offline, we won't restrict the user, even though CMake discourages in-source builds.

Other features of this approach:
PROS:

  1. Less of code. Simpler code.
  2. The same code for both POSIX and Windows platforms.
  3. It prevents the source tree from being polluted with Python bytecode caches for the test framework when running functional tests. For reference, test: Do not write Python bytecode to source directory bitcoin/bitcoin#30533 aims for the same goal for unit tests.

CONS:

  1. Approximately 4MB larger build directory. Note that it is smaller than its size just after configuring on the staging branch.

Resolves #306.

@hebasto hebasto added bug Something isn't working tests Tests, benchmarks, fuzzing, CI etc labels Aug 6, 2024
@hebasto
Copy link
Owner Author

hebasto commented Aug 6, 2024

cc:

@m3dwards
Copy link

m3dwards commented Aug 6, 2024

ACK af3b042

Tested on Arm Mac and x86 Linux. Can replicate problems without and can configue/build/test with PR.

Copy link

@maflcko maflcko left a comment

Choose a reason for hiding this comment

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

review-only ACK lgtm.

I presume there is another small difference, in that editing the symlink in the build dir will no longer modify the file in the source dir, but instead the copy of the file in the build dir. (Not sure if this is a PRO or CON, just wanted to mention it)

file(CREATE_LINK ${CMAKE_CURRENT_SOURCE_DIR}/${script} ${CMAKE_CURRENT_BINARY_DIR}/${script} COPY_ON_ERROR ${symlink})
endforeach()
unset(functional_tests)
file(COPY functional util/rpcauth-test.py DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
Copy link

Choose a reason for hiding this comment

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

q: Creating a copy here, removes bitcoin#30463 again as a cmake requirement?

Just a question, not saying it should be reverted. It seems clearer and harmless either way, in case someone wants to use symbolic links, or otherwise symbolic links are use by cmake in the future again.

Copy link
Owner Author

Choose a reason for hiding this comment

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

q: Creating a copy here, removes bitcoin#30463 again as a cmake requirement?

Correct.

@hebasto
Copy link
Owner Author

hebasto commented Aug 7, 2024

I presume there is another small difference, in that editing the symlink in the build dir will no longer modify the file in the source dir, but instead the copy of the file in the build dir. (Not sure if this is a PRO or CON, just wanted to mention it)

That's true. I forgot to mention it. Thanks for bringing this up.

@maflcko
Copy link

maflcko commented Aug 8, 2024

Actually, can you add exact steps to test this?

How is someone supposed to make clean or make distclean with this pull request. IIRC, cmake doesn't have the equivalent and it should be rm -r ./build_dir. However, if the source dir is the build dir, it requires the user to know what they are doing. For example, they could be using a git-worktree.

If this is true, wouldn't it be better to hide this feature behind a flag to avoid anyone running into this by accident? There are too many support requests about stale/broken make builds (due to a missing call to make (dist)clean), so I fear unlocking this for cmake may encourage more support requests of the same build issue to happen?

@fanquake
Copy link

fanquake commented Aug 8, 2024

~0. Not sure. After a year of deciding we'll do things the "CMake way", at the last minute we're going to start allowing the thing CMake actively discourages, because of an unintuitive error message? Can't we just provide a more useful error?

The PROs listed here are all pretty weak, and don't point to anything that's actually useful for a developer, doing development. It'd be good to get some example usecases of why someone might want to build in tree, that doesn't (or for some reason can't?) work with out-of-tree builds. As opposed to allowing this just because someone might "want to", and opening us up to also maintaining that can of worms (especially if it's not something we are going to actually use or test).

Copy link

@TheCharlatan TheCharlatan left a comment

Choose a reason for hiding this comment

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

I tend towards NACK here for the downsides brought up already. I also think adding a flag for changing this behaviour and allowing in-tree builds is not a good alternative - especially absent a clear use-case. I also remember reviewing the script linking behaviour and thinking this was a good improvement.

@hebasto
Copy link
Owner Author

hebasto commented Aug 8, 2024

I tend towards NACK here for the downsides brought up already. I also think adding a flag for changing this behaviour and allowing in-tree builds is not a good alternative - especially absent a clear use-case. I also remember reviewing the script linking behaviour and thinking this was a good improvement.

Please consider an alternative in #314.

@achow101
Copy link

achow101 commented Aug 8, 2024

Is it possible to allow in source builds while preserving the symlink behavior for out of tree builds? If I do an out of tree build with this PR, changes I make to the functional tests require an additional cmake invocation for those changes to appear in the build. When working on test changes, that's really annoying.

@hebasto
Copy link
Owner Author

hebasto commented Aug 8, 2024

Is it possible to allow in source builds while preserving the symlink behavior for out of tree builds?

Yes, it is.

If I do an out of tree build with this PR, changes I make to the functional tests require an additional cmake invocation for those changes to appear in the build. When working on test changes, that's really annoying.

That's true.

Copy tests to the build tree instead of linking them.
@hebasto
Copy link
Owner Author

hebasto commented Aug 10, 2024

Rebased.

Copy link

@maflcko maflcko left a comment

Choose a reason for hiding this comment

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

symlinks should be kept for out-of-tree builds, otherwise it seems like a breaking change to dev experience when editing files

@hebasto
Copy link
Owner Author

hebasto commented Aug 11, 2024

symlinks should be kept for out-of-tree builds, otherwise it seems like a breaking change to dev experience when editing files

I agree with this point.

However, instead of adjusting this PR, I'm going to close in favour of #314.

The main reason is that in-source builds with CMake are incompatible with Autotools because the Makefile files are being overwritten.

We can reconsider this idea after completing the migration to CMake.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working tests Tests, benchmarks, fuzzing, CI etc
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Give more useful error when build dir wasn't specified
6 participants