Flutter Engine
 
Loading...
Searching...
No Matches
main.cc File Reference
#include <filesystem>
#include <fstream>
#include "flutter/tools/licenses_cpp/src/license_checker.h"
#include "third_party/abseil-cpp/absl/flags/flag.h"
#include "third_party/abseil-cpp/absl/flags/parse.h"
#include "third_party/abseil-cpp/absl/flags/usage.h"
#include "third_party/abseil-cpp/absl/log/globals.h"
#include "third_party/abseil-cpp/absl/log/initialize.h"
#include "third_party/abseil-cpp/absl/strings/str_cat.h"

Go to the source code of this file.

Functions

 ABSL_FLAG (std::optional< std::string >, working_dir, std::nullopt, "[REQUIRED] The directory to scan.")
 
 ABSL_FLAG (std::optional< std::string >, input, std::nullopt, "The file to scan.")
 
 ABSL_FLAG (std::optional< std::string >, data_dir, std::nullopt, "[REQUIRED] The directory with the licenses.")
 
 ABSL_FLAG (std::optional< std::string >, licenses_path, std::nullopt, "[REQUIRED] The path to write the licenses collection to.")
 
 ABSL_FLAG (std::optional< std::string >, include_filter, std::nullopt, "Regex that overrides the include filter.")
 
 ABSL_FLAG (int, v, 0, "Set the verbosity of logs.")
 
 ABSL_FLAG (bool, treat_unmatched_comments_as_errors, false, "Whether unmatched comments are considered errors.")
 
 ABSL_FLAG (std::optional< std::string >, root_package, std::nullopt, "Name of the root package.")
 
int main (int argc, char **argv)
 

Function Documentation

◆ ABSL_FLAG() [1/8]

ABSL_FLAG ( bool  ,
treat_unmatched_comments_as_errors  ,
false  ,
"Whether unmatched comments are considered errors."   
)

◆ ABSL_FLAG() [2/8]

ABSL_FLAG ( int  ,
,
,
"Set the verbosity of logs."   
)

◆ ABSL_FLAG() [3/8]

ABSL_FLAG ( std::optional< std::string >  ,
data_dir  ,
std::nullopt  ,
" The directory with the licenses."  [REQUIRED] 
)

◆ ABSL_FLAG() [4/8]

ABSL_FLAG ( std::optional< std::string >  ,
include_filter  ,
std::nullopt  ,
"Regex that overrides the include filter."   
)

◆ ABSL_FLAG() [5/8]

ABSL_FLAG ( std::optional< std::string >  ,
input  ,
std::nullopt  ,
"The file to scan."   
)

◆ ABSL_FLAG() [6/8]

ABSL_FLAG ( std::optional< std::string >  ,
licenses_path  ,
std::nullopt  ,
" The path to write the licenses collection to."  [REQUIRED] 
)

◆ ABSL_FLAG() [7/8]

ABSL_FLAG ( std::optional< std::string >  ,
root_package  ,
std::nullopt  ,
"Name of the root package."   
)

◆ ABSL_FLAG() [8/8]

ABSL_FLAG ( std::optional< std::string >  ,
working_dir  ,
std::nullopt  ,
" The directory to scan."  [REQUIRED] 
)

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 78 of file main.cc.

78 {
79 absl::SetProgramUsageMessage(
80 absl::StrCat("Sample usage:\n", argv[0],
81 " --working_dir=<directory> --data_dir=<directory>"));
82
83 std::vector<char*> args = absl::ParseCommandLine(argc, argv);
84 absl::SetGlobalVLogLevel(absl::GetFlag(FLAGS_v));
85 absl::InitializeLog();
86 absl::SetStderrThreshold(absl::LogSeverity::kInfo);
87
88 std::optional<std::string> working_dir = absl::GetFlag(FLAGS_working_dir);
89 std::optional<std::string> input = absl::GetFlag(FLAGS_input);
90 std::optional<std::string> data_dir = absl::GetFlag(FLAGS_data_dir);
91 std::optional<std::string> licenses_path = absl::GetFlag(FLAGS_licenses_path);
92 std::optional<std::string> include_filter =
93 absl::GetFlag(FLAGS_include_filter);
94 if (working_dir.has_value() && data_dir.has_value() &&
95 licenses_path.has_value()) {
96 std::ofstream licenses;
97 licenses.open(licenses_path.value());
98 if (licenses.bad()) {
99 std::cerr << "Unable to write to '" << licenses_path.value() << "'.";
100 return 1;
101 }
104 absl::GetFlag(FLAGS_treat_unmatched_comments_as_errors);
105 flags.root_package_name = absl::GetFlag(FLAGS_root_package);
106 if (input.has_value()) {
107 if (include_filter.has_value()) {
108 std::cerr << "`--input_filter` not supported with `--input`"
109 << std::endl;
110 }
111 fs::path full_path = fs::canonical(input.value());
112 return LicenseChecker::FileRun(working_dir.value(), full_path.string(),
113 licenses, data_dir.value(), flags);
114 } else {
115 if (include_filter.has_value()) {
116 return Run(working_dir.value(), licenses, data_dir.value(),
117 include_filter.value(), flags);
118 } else {
119 return LicenseChecker::Run(working_dir.value(), licenses,
120 data_dir.value(), flags);
121 }
122 }
123 }
124
125 if (!working_dir.has_value()) {
126 std::cerr << "Expected --working_dir flag." << std::endl;
127 }
128
129 if (!licenses_path.has_value()) {
130 std::cerr << "Expected --licenses_path flag." << std::endl;
131 }
132
133 if (!data_dir.has_value()) {
134 std::cerr << "Expected --data_dir flag." << std::endl;
135 }
136
137 return 1;
138}
static int FileRun(std::string_view working_dir, std::string_view full_path, std::ostream &licenses, std::string_view data_dir, const Flags &flags)
Run on a single file.
static std::vector< absl::Status > Run(std::string_view working_dir, std::ostream &licenses, const Data &data)
static int input(yyscan_t yyscanner)
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
char ** argv
Definition library.h:9
std::optional< std::string > root_package_name

References args, argv, LicenseChecker::FileRun(), input(), LicenseChecker::Flags::root_package_name, LicenseChecker::Run(), and LicenseChecker::Flags::treat_unmatched_comments_as_errors.