mirror of https://gitlab.com/cppit/jucipp
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
122 lines
3.2 KiB
122 lines
3.2 KiB
|
3 weeks ago
|
#pragma once
|
||
|
|
|
||
|
|
#include <string>
|
||
|
|
#include <vector>
|
||
|
|
|
||
|
|
#include <boost/filesystem.hpp>
|
||
|
|
#include <boost/optional.hpp>
|
||
|
|
|
||
|
|
#include "nlohmann/json_fwd.hpp"
|
||
|
|
|
||
|
|
namespace SARIF {
|
||
|
|
|
||
|
|
struct Message {
|
||
|
|
std::string text;
|
||
|
|
std::vector<std::string> arguments;
|
||
|
|
|
||
|
|
std::string to_string() const;
|
||
|
|
};
|
||
|
|
void from_json(const nlohmann::json &json, Message &message);
|
||
|
|
|
||
|
|
struct Region {
|
||
|
|
std::size_t start_line;
|
||
|
|
std::size_t end_line;
|
||
|
|
std::size_t start_column;
|
||
|
|
std::size_t end_column;
|
||
|
|
std::string snippet;
|
||
|
|
|
||
|
|
bool operator<(const Region &other) const noexcept;
|
||
|
|
};
|
||
|
|
void from_json(const nlohmann::json &json, Region ®ion);
|
||
|
|
|
||
|
|
struct Location {
|
||
|
|
Message message;
|
||
|
|
boost::filesystem::path artifact_location;
|
||
|
|
Region region;
|
||
|
|
boost::optional<Region> context_region;
|
||
|
|
};
|
||
|
|
void from_json(const nlohmann::json &json, Location &location);
|
||
|
|
|
||
|
|
struct ThreadFlowLocation {
|
||
|
|
enum class Importance {
|
||
|
|
important,
|
||
|
|
essential,
|
||
|
|
unimportant,
|
||
|
|
};
|
||
|
|
|
||
|
|
Importance importance;
|
||
|
|
Location location;
|
||
|
|
};
|
||
|
|
void from_json(const nlohmann::json &json, ThreadFlowLocation &location);
|
||
|
|
|
||
|
|
struct ThreadFlow {
|
||
|
|
std::vector<ThreadFlowLocation> locations;
|
||
|
|
};
|
||
|
|
void from_json(const nlohmann::json &json, ThreadFlow &flow);
|
||
|
|
|
||
|
|
struct CodeFlow {
|
||
|
|
std::vector<ThreadFlow> thread_flows;
|
||
|
|
};
|
||
|
|
void from_json(const nlohmann::json &json, CodeFlow &flow);
|
||
|
|
|
||
|
|
struct Result {
|
||
|
|
enum class Level {
|
||
|
|
none,
|
||
|
|
note,
|
||
|
|
warning,
|
||
|
|
error,
|
||
|
|
};
|
||
|
|
|
||
|
|
Level level;
|
||
|
|
Message message;
|
||
|
|
std::vector<Location> locations;
|
||
|
|
std::vector<CodeFlow> code_flows;
|
||
|
|
std::string rule_id;
|
||
|
|
// Custom field
|
||
|
|
std::string help_uri;
|
||
|
|
|
||
|
|
std::string get_message(const Location &location, bool markdown = false) const;
|
||
|
|
};
|
||
|
|
std::string to_string(Result::Level level);
|
||
|
|
void from_json(const nlohmann::json &json, Result &result);
|
||
|
|
|
||
|
|
struct ReportingDescriptor {
|
||
|
|
std::string id;
|
||
|
|
std::string name;
|
||
|
|
std::string help_uri;
|
||
|
|
};
|
||
|
|
void from_json(const nlohmann::json &json, ReportingDescriptor &descriptor);
|
||
|
|
|
||
|
|
struct ToolComponent {
|
||
|
|
std::vector<ReportingDescriptor> rules;
|
||
|
|
};
|
||
|
|
void from_json(const nlohmann::json &json, ToolComponent &component);
|
||
|
|
|
||
|
|
struct Tool {
|
||
|
|
ToolComponent driver;
|
||
|
|
};
|
||
|
|
void from_json(const nlohmann::json &json, Tool &tool);
|
||
|
|
|
||
|
|
struct Run {
|
||
|
|
std::vector<Result> results;
|
||
|
|
Tool tool;
|
||
|
|
};
|
||
|
|
void from_json(const nlohmann::json &json, Run &run);
|
||
|
|
|
||
|
|
// According to Static Analysis Results Interchange Format (SARIF) specification version 2.1,
|
||
|
|
// see https://docs.oasis-open.org/sarif/sarif/v2.1.0/sarif-v2.1.0.html
|
||
|
|
struct Log {
|
||
|
|
std::vector<Run> runs;
|
||
|
|
};
|
||
|
|
void from_json(const nlohmann::json &json, Log &log);
|
||
|
|
|
||
|
|
/// Merges the results of all input files.
|
||
|
|
/// Removes duplicate entries (e.g. findings in headers included in multiple files).
|
||
|
|
/// Adds a context region for each location where possible.
|
||
|
|
/// Returns the list of merged results.
|
||
|
|
std::vector<Result> merge_files(const boost::filesystem::path &output_file, std::vector<boost::filesystem::path> &input_files);
|
||
|
|
|
||
|
|
/// Returns the list of results for the given file.
|
||
|
|
std::vector<Result> results_for_file(const boost::filesystem::path &results_file, const boost::filesystem::path &source_file);
|
||
|
|
} // namespace SARIF
|