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

Findthrust.cmake: Fix the bug in regular replacement. #408

Merged
merged 1 commit into from
Mar 13, 2024

Conversation

HWZen
Copy link
Contributor

@HWZen HWZen commented Mar 13, 2024

Fix bug #407: The original regular replacement does not consider the possibility that THRUST_VERSION may be followed by comments.

Fix bug stotko#407: The original regular replacement does not consider the possibility that THRUST_VERSION may be followed by comments.
@stotko stotko added the bug label Mar 13, 2024
Copy link

codecov bot commented Mar 13, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 97.33%. Comparing base (71a5aef) to head (f0febd7).

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #408   +/-   ##
=======================================
  Coverage   97.33%   97.33%           
=======================================
  Files          31       31           
  Lines        2512     2512           
=======================================
  Hits         2445     2445           
  Misses         67       67           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@stotko stotko added this to the 2.0.0 milestone Mar 13, 2024
@stotko stotko linked an issue Mar 13, 2024 that may be closed by this pull request
@stotko stotko self-requested a review March 13, 2024 07:46
Copy link
Owner

@stotko stotko left a comment

Choose a reason for hiding this comment

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

Thanks for the fix!

@stotko stotko merged commit 1f0b2d5 into stotko:master Mar 13, 2024
61 checks passed
@dengchenlong
Copy link

Why does REGEX "#define THRUST_VERSION[ \t]+([0-9x]+)") match the comments that follow?

@HWZen
Copy link
Contributor Author

HWZen commented Jun 6, 2024

Why does REGEX "#define THRUST_VERSION[ \t]+([0-9x]+)") match the comments that follow?

This regex statement does not match comments, but does match the current version numbers.

@dengchenlong
Copy link

Why does REGEX "#define THRUST_VERSION[ \t]+([0-9x]+)") match the comments that follow?

This regex statement does not match comments, but does match the current version numbers.

The original code was like this before being modified:

    # Findthrust.cmake
    ...
    file(STRINGS "${THRUST_INCLUDE_DIR}/thrust/version.h"
         THRUST_VERSION_STRING
         REGEX "#define THRUST_VERSION[ \t]+([0-9x]+)")

    string(REGEX REPLACE "#define THRUST_VERSION[ \t]+" "" THRUST_VERSION_STRING ${THRUST_VERSION_STRING})
    ...
// thrust/version.h
...
#define THRUST_VERSION 200400 // macro expansion with ## requires this to be a single value
...

Why is THRUST_VERSION_STRING equal to "#define THRUST_VERSION 200400 // macro expansion with ## requires this to be a single value" instead of "#define THRUST_VERSION 200400" before string(REGEX REPLACE ...)?

@HWZen
Copy link
Contributor Author

HWZen commented Jun 6, 2024

Why does REGEX "#define THRUST_VERSION[ \t]+([0-9x]+)") match the comments that follow?

This regex statement does not match comments, but does match the current version numbers.

The original code was like this before being modified:

    # Findthrust.cmake
    ...
    file(STRINGS "${THRUST_INCLUDE_DIR}/thrust/version.h"
         THRUST_VERSION_STRING
         REGEX "#define THRUST_VERSION[ \t]+([0-9x]+)")

    string(REGEX REPLACE "#define THRUST_VERSION[ \t]+" "" THRUST_VERSION_STRING ${THRUST_VERSION_STRING})
    ...
// thrust/version.h
...
#define THRUST_VERSION 200400 // macro expansion with ## requires this to be a single value
...

Why is THRUST_VERSION_STRING equal to "#define THRUST_VERSION 200400 // macro expansion with ## requires this to be a single value" instead of "#define THRUST_VERSION 200400" before string(REGEX REPLACE ...)?

Because CMake regular matching uses one line as the minimum judgment unit. When the content in this line matches the regular expression, this line will be insert into THRUST_VERSION_STRING

You can do the following experiment

# CMakeLists.txt
file(STRINGS "./temp.txt"
        TEST_STRING
        REGEX "e"
)

message(STATUS "TEST_STRING: ${TEST_STRING}")
temp.txt
#define THRUST_VERSION 200400
Hello world

You will see the output
-- TEST_STRING: #define THRUST_VERSION 200400;Hello world

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Findthrust.cmake parse error
3 participants