Skip to content

Commit

Permalink
use path::stem (#987)
Browse files Browse the repository at this point in the history
refactoring piece of my code a bit
  • Loading branch information
yaito3014 authored Sep 15, 2024
1 parent 1119bff commit 30acce3
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/BuildConfig.cc
Original file line number Diff line number Diff line change
Expand Up @@ -774,16 +774,16 @@ configureBuild(BuildConfig& config, const bool isDebug) {
}

// find main source file
const auto isMainSource = [](const std::string_view filename) {
return filename.substr(0, filename.find_last_of('.')) == "main";
const auto isMainSource = [](const fs::path& file) {
return file.filename().stem() == "main";
};
fs::path mainSource;
for (const auto& entry : fs::directory_iterator("src")) {
fs::path path = entry.path();
if (!SOURCE_FILE_EXTS.contains(path.extension())) {
continue;
}
if (!isMainSource(path.filename().string())) {
if (!isMainSource(path)) {
continue;
}
if (mainSource.empty()) {
Expand Down Expand Up @@ -814,8 +814,7 @@ configureBuild(BuildConfig& config, const bool isDebug) {
std::vector<fs::path> sourceFilePaths = listSourceFilePaths("src");
std::string srcs;
for (fs::path& sourceFilePath : sourceFilePaths) {
if (sourceFilePath != mainSource
&& isMainSource(sourceFilePath.filename().string())) {
if (sourceFilePath != mainSource && isMainSource(sourceFilePath)) {
logger::warn(fmt::format(
"source file `{}` is named `main` but is not located directly in the "
"`src/` directory. "
Expand Down

0 comments on commit 30acce3

Please sign in to comment.