Skip to content

Commit

Permalink
Make code compatible with gcc 7 using std::experimental::filesystem
Browse files Browse the repository at this point in the history
  • Loading branch information
milianw committed Dec 8, 2021
1 parent fc45783 commit 1985687
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 9 deletions.
4 changes: 2 additions & 2 deletions clioptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ CliOptions parseCliOptions(int argc, char** argv)
{"skip-instant-events"});
args::Flag relativeTid(parser, "rtid", "subtract pid from tid so that main threads have tid = 0 (only works if vpid and vtid properties present in the context)",
{"rtid"});
args::Positional<std::filesystem::path> pathArg(
args::Positional<fs::path> pathArg(
parser, "path", "The path to an LTTng trace folder, will be searched recursively for trace data");
try {
parser.ParseCLI(argc, argv);
Expand All @@ -66,7 +66,7 @@ CliOptions parseCliOptions(int argc, char** argv)
}

const auto path = args::get(pathArg);
if (!std::filesystem::exists(path)) {
if (!fs::exists(path)) {
std::cerr << "path does not exist: " << path << std::endl;
exit(1);
}
Expand Down
5 changes: 3 additions & 2 deletions clioptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,15 @@

#pragma once

#include <filesystem>
#include "fs.h"

#include <string>
#include <vector>

struct CliOptions
{
std::string outputFile;
std::filesystem::path path;
fs::path path;
std::vector<std::string> exclude;
std::vector<int64_t> pidWhitelist;
std::vector<std::string> processWhitelist;
Expand Down
2 changes: 1 addition & 1 deletion cmake/modules/FindBabeltrace.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ find_path(Babeltrace_LIBRARY_DIR
NAMES libbabeltrace.so
NAMES libbabeltrace-ctf.so
PATHS ${Babeltrace_PATH_HINT}
PATH_SUFFIXES lib lib64
PATH_SUFFIXES lib lib64 lib/x86_64-linux-gnu
DOC "The Babeltrace libraries")

find_library(BABELTRACE NAMES babeltrace PATHS ${Babeltrace_LIBRARY_DIR})
Expand Down
8 changes: 4 additions & 4 deletions ctf2ctf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
#include <cstring>

#include <algorithm>
#include <filesystem>
#include <iomanip>
#include <iostream>
#include <limits>
Expand All @@ -50,6 +49,7 @@
#include <variant>
#include <vector>

#include "fs.h"
#include "clioptions.h"

#include "config.h"
Expand Down Expand Up @@ -168,10 +168,10 @@ std::string rwbsToString(uint64_t rwbs)
constexpr auto TIMESTAMP_PRECISION = std::numeric_limits<double>::max_digits10;

template<typename Callback>
void findMetadataFiles(const std::filesystem::path& path, Callback&& callback)
void findMetadataFiles(const fs::path& path, Callback&& callback)
{
for (const auto& entry : std::filesystem::recursive_directory_iterator(path)) {
if (entry.is_regular_file() && entry.path().filename() == "metadata")
for (const auto& entry : fs::recursive_directory_iterator(path)) {
if (fs::is_regular_file(entry.status()) && entry.path().filename() == "metadata")
callback(entry.path().parent_path().c_str());
}
}
Expand Down
36 changes: 36 additions & 0 deletions fs.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
fs.h
This file is part of ctf2ctf, a converter from LTTng/CTF to Chromium's Common Trace Format.
Copyright (C) 2021 Klarälvdalens Datakonsult AB, a KDAB Group company, [email protected]
Author: Milian Wolff <[email protected]>
Licensees holding valid commercial KDAB ctf2ctf licenses may use this file in
accordance with ctf2ctf Commercial License Agreement provided with the Software.
Contact [email protected] if any conditions of this licensing are not clear to you.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#pragma once

#if __has_include(<filesystem>)
#include <filesystem>
namespace fs = std::filesystem;
#else
#include <experimental/filesystem>
namespace fs = std::experimental::filesystem;
#endif

0 comments on commit 1985687

Please sign in to comment.