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

allow BENCHMARK_VERSION to be undefined #1769

Merged
merged 1 commit into from
Mar 21, 2024

Conversation

PhilipDeegan
Copy link
Contributor

closes #1768

motivation is to allow simpler override at compilation time
shouldn't impact anyone using the official build tools as it's all internal in that case

I haven't tested the bazel build output for the function benchmark::GetBenchmarkVersion() but I'm guessing it's without the extra quote from "stringification" given the modifications

I have tested the cmake build output for the funciton, and the string is without quotes with the proposed changes

PRed on my fork for testing here
I can't explain the sanitizer failures so I'm figuring they are existing

@LebedevRI
Copy link
Collaborator

I feel this is a roundabout way to achieve the the end result.
How about we just explicitly do

std::string GetBenchmarkVersion() {
#ifdef BENCHMARK_VERSION
return {BENCHMARK_VERSION};
#else
return {""};
#endif
}

?

@LebedevRI
Copy link
Collaborator

Hm, and if BENCHMARK_VERSION is not defined, GetBenchmarkVersion() now returns "BENCHMARK_VERSION":
https://godbolt.org/z/d9xKEbc7o
Is that the expected outcome?

@PhilipDeegan
Copy link
Contributor Author

Hm, and if BENCHMARK_VERSION is not defined, GetBenchmarkVersion() now returns "BENCHMARK_VERSION": https://godbolt.org/z/d9xKEbc7o Is that the expected outcome?

I'm kinda surprised it even compiles if it's not defined, but perhaps BENCHMARK_VERSION is more informative than an empty string

@PhilipDeegan
Copy link
Contributor Author

How about we just explicitly do ...

I can do this, but I still think the escapes can be avoided via stringification as @dmah42 suggested

@LebedevRI
Copy link
Collaborator

LebedevRI commented Mar 20, 2024

Hm, and if BENCHMARK_VERSION is not defined, GetBenchmarkVersion() now returns "BENCHMARK_VERSION": https://godbolt.org/z/d9xKEbc7o Is that the expected outcome?

I'm kinda surprised it even compiles if it's not defined, but perhaps BENCHMARK_VERSION is more informative than an empty string

That's because it's passed into the stringification macro. Normally it indeed fails: https://godbolt.org/z/j5x4a4sWG
Which is why i would've preferred to not change anything in benchmark,
and let the external buildsystems deal wit this, because if we do this workaround,
they may not even realize they need to deal with this.

@PhilipDeegan
Copy link
Contributor Author

updated to just

std::string GetBenchmarkVersion() {
#ifdef BENCHMARK_VERSION
  return {BENCHMARK_VERSION};
#else
  return {""};
#endif
}

@PhilipDeegan PhilipDeegan changed the title stringify BENCHMARK_VERSION on usage allow BENCHMARK_VERSION to be undefined Mar 20, 2024
@LebedevRI LebedevRI requested a review from dmah42 March 20, 2024 17:58
@dmah42
Copy link
Member

dmah42 commented Mar 21, 2024

oh, that's a shame. i quite liked the reduced complexity in the bazel config. i was thinking we'd land somewhere in between where be both stringify it if it's set but return a safe value if it's not. anyway, this also looks fine.

@LebedevRI LebedevRI merged commit d5c55e8 into google:main Mar 21, 2024
79 of 80 checks passed
@LebedevRI
Copy link
Collaborator

@PhilipDeegan thank you!

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.

[FR] BENCHMARK_VERSION is not set by default
3 participants