Skip to content

Prevent users from misusing CMake #5782

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

Merged

Conversation

hannes-steffenhagen-diffblue
Copy link
Contributor

When CMake is invoked from the source directory it will overwrite files
in there. In general CMake expects to be used for out-of-source builds.
Previously it was still possible to get this wrong by accident, this
just adds a check to prevent this from happening and tells people what
to do instead.

  • Each commit message has a non-empty body, explaining why the change was made.
  • Methods or procedures I have added are documented, following the guidelines provided in CODING_STANDARD.md.
  • The feature or user visible behaviour I have added or modified has been documented in the User Guide in doc/cprover-manual/
  • Regression or unit tests are included, or existing tests cover the modified code (in this case I have detailed which ones those are in the commit message).
  • My commit message includes data points confirming performance improvements (if claimed).
  • My PR is restricted to a single feature or bugfix.
  • White-space or formatting changes outside the feature-related changed lines are in commits of their own.

@codecov
Copy link

codecov bot commented Jan 25, 2021

Codecov Report

Merging #5782 (e832c07) into develop (5efb6ad) will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff            @@
##           develop    #5782   +/-   ##
========================================
  Coverage    69.64%   69.64%           
========================================
  Files         1248     1248           
  Lines       100920   100920           
========================================
  Hits         70290    70290           
  Misses       30630    30630           
Flag Coverage Δ
cproversmt2 43.36% <ø> (ø)
regression 66.62% <ø> (ø)
unit 32.19% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.


Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5efb6ad...e832c07. Read the comment docs.

Copy link
Collaborator

@tautschnig tautschnig left a comment

Choose a reason for hiding this comment

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

Thank you for adding those changes (and @TGWDB thank you for raising this topic!) The wording could do with some tweaking as indicated by my comments below.

CMakeLists.txt Outdated
if("${CMAKE_BINARY_DIR}" STREQUAL "${CMAKE_SOURCE_DIR}")
message(FATAL_ERROR
"Do not generate CMake files inside of the cbmc source directory."
" Please either create a separate build directory and invoke cbmc from there, or specify a build directory with -B."
Copy link
Collaborator

Choose a reason for hiding this comment

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

s/cbmc/cmake/ ?

CMakeLists.txt Outdated
@@ -8,6 +16,7 @@ if (NOT EXISTS ${CMAKE_BINARY_DIR}/CMakeCache.txt)
endif()
endif()


Copy link
Collaborator

Choose a reason for hiding this comment

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

Necessary change?

CMakeLists.txt Outdated
@@ -1,5 +1,13 @@
cmake_minimum_required(VERSION 3.2)

# If cbmc generates files inside of the cbmc source directory this can lead to important files being overwritten, so we prevent that here
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why does "cbmc" generate anything (at build time!)?

CMakeLists.txt Outdated
# If cbmc generates files inside of the cbmc source directory this can lead to important files being overwritten, so we prevent that here
if("${CMAKE_BINARY_DIR}" STREQUAL "${CMAKE_SOURCE_DIR}")
message(FATAL_ERROR
"Do not generate CMake files inside of the cbmc source directory."
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not sure about the wording here: you are talking to the user here, who just invoked cmake - they didn't actually (intend to) create any files at all, and might thus be confused by this error message.

When CMake is invoked from the source directory it will overwrite files
in there. In general CMake expects to be used for out-of-source builds.
Previously it was still possible to get this wrong by accident, this
just adds a check to prevent this from happening and tells people what
to do instead.
@hannes-steffenhagen-diffblue
Copy link
Contributor Author

@tautschnig I updated the wording

@tautschnig
Copy link
Collaborator

@tautschnig I updated the wording

That's great, thank you very much!

" specifying a build directory. Since this can lead to cmake overwriting"
" files in the source tree, this is prohibited. Please perform an"
" out-of-source build by either creating a separate build directory and"
" invoking cmake from there, or specifying a build directory with -B.\n"
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe add 'flag' or 'option' after -B?

..., or specifying a build directory using -B option.

@TGWDB
Copy link
Contributor

TGWDB commented Jan 26, 2021

Looks fine for checking the single top level directory, do we care about mistakes related to subdirectories as well?
tgw@DB0907:~/github/hannes/cbmc$ cmake . -Bsrc
will continue fine and only over-write a couple of files.

@hannes-steffenhagen-diffblue
Copy link
Contributor Author

@TGWDB I'm trying to prevent accidental misuse, it seems unlikely to me that someone would do that by accident?

@TGWDB
Copy link
Contributor

TGWDB commented Jan 26, 2021

@hannes-steffenhagen-diffblue Probably not a concern then, there is always a limit to how much safety/checking we can do.

Copy link
Contributor

@NlightNFotis NlightNFotis left a comment

Choose a reason for hiding this comment

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

LGTM, only one question, why are there 2 spaces in some lines (for example line 10)?

@tautschnig
Copy link
Collaborator

@hannes-steffenhagen-diffblue Probably not a concern then, there is always a limit to how much safety/checking we can do.

But perhaps that's still easy to add by replacing the STREQUAL by a prefix check?

@TGWDB
Copy link
Contributor

TGWDB commented Jan 26, 2021

@hannes-steffenhagen-diffblue Probably not a concern then, there is always a limit to how much safety/checking we can do.

But perhaps that's still easy to add by replacing the STREQUAL by a prefix check?

@tautschnig Except that this then prevents building in a subdirectory called "build" since the prefix will match.

@tautschnig
Copy link
Collaborator

@hannes-steffenhagen-diffblue Probably not a concern then, there is always a limit to how much safety/checking we can do.

But perhaps that's still easy to add by replacing the STREQUAL by a prefix check?

@tautschnig Except that this then prevents building in a subdirectory called "build" since the prefix will match.

Err, of course true. Let's stick with the current approach for now.

@tautschnig tautschnig merged commit f2fafac into diffblue:develop Jan 26, 2021
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.

5 participants