Flutter Engine
 
Loading...
Searching...
No Matches
LicenseChecker Class Reference

#include <license_checker.h>

Classes

struct  Flags
 

Static Public Member Functions

static std::vector< absl::Status > Run (std::string_view working_dir, std::ostream &licenses, const Data &data)
 
static std::vector< absl::Status > Run (std::string_view working_dir, std::ostream &licenses, const Data &data, const Flags &flags)
 
static int Run (std::string_view working_dir, std::ostream &licenses, std::string_view data_dir, const Flags &flags)
 
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 Public Attributes

static const char * kHeaderLicenseRegex = "(?i)(license|copyright)"
 

Detailed Description

Definition at line 14 of file license_checker.h.

Member Function Documentation

◆ FileRun()

int LicenseChecker::FileRun ( std::string_view  working_dir,
std::string_view  full_path,
std::ostream &  licenses,
std::string_view  data_dir,
const Flags flags 
)
static

Run on a single file.

Definition at line 627 of file license_checker.cc.

631 {
632 absl::StatusOr<Data> data = Data::Open(data_dir);
633 if (!data.ok()) {
634 std::cerr << "Can't load data at " << data_dir << ": " << data.status()
635 << std::endl;
636 return 1;
637 }
638
639 ProcessState state;
640 fs::path working_dir_path =
641 fs::absolute(fs::path(working_dir)).lexically_normal();
642 fs::path absolute_full_path = fs::absolute(fs::path(full_path));
643 absl::Status process_result =
644 ProcessFile(working_dir_path, licenses, data.value(), absolute_full_path,
645 flags, &state);
646
647 if (!process_result.ok()) {
648 std::cerr << process_result << std::endl;
649 return 1;
650 }
651
652 state.license_map.Write(licenses);
653 for (const absl::Status& status : state.errors) {
654 std::cerr << status << "\n";
655 }
656
657 if (!state.errors.empty()) {
658 std::cout << "Error count: " << state.errors.size();
659 }
660
661 return state.errors.empty() ? 0 : 1;
662}
static absl::StatusOr< Data > Open(std::string_view data_dir)
Definition data.cc:14
std::shared_ptr< const fml::Mapping > data

References data, and Data::Open().

Referenced by main().

◆ Run() [1/3]

std::vector< absl::Status > LicenseChecker::Run ( std::string_view  working_dir,
std::ostream &  licenses,
const Data data 
)
static

Definition at line 497 of file license_checker.cc.

499 {
500 Flags flags;
501 return Run(working_dir, licenses, data, flags);
502}
static std::vector< absl::Status > Run(std::string_view working_dir, std::ostream &licenses, const Data &data)
DlVertices::Builder::Flags Flags

References data.

Referenced by main(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), and TEST_F().

◆ Run() [2/3]

std::vector< absl::Status > LicenseChecker::Run ( std::string_view  working_dir,
std::ostream &  licenses,
const Data data,
const Flags flags 
)
static

Definition at line 504 of file license_checker.cc.

508 {
509 fs::path working_dir_path =
510 fs::absolute(fs::path(working_dir)).lexically_normal();
511 std::vector<fs::path> git_repos = GetGitRepos(working_dir_path.string());
512
513 size_t count = 0;
514 ProcessState state;
515
516 // Not every dependency is a git repository, so it won't be considered with
517 // the crawl that happens below of git repositories. For those dependencies
518 // we just crawl the whole directory.
519 fs::path deps_path = FindFileInParentDirectories(working_dir_path, "DEPS");
520 if (!deps_path.empty()) {
521 absl::StatusOr<MMapFile> deps_file = MMapFile::Make(deps_path.string());
522 if (deps_file.ok()) {
523 DepsParser deps_parser;
524 std::vector<std::string> deps = deps_parser.Parse(
525 std::string_view(deps_file->GetData(), deps_file->GetSize()));
526 for (const std::string& dep : deps) {
527 fs::path dep_path = deps_path.parent_path() / dep;
528 if (fs::is_directory(dep_path)) {
529 // We don't want to process deps that are outside the working
530 // directory.
531 if (dep_path.string().find(working_dir_path.string()) != 0) {
532 continue;
533 }
534
535 for (const auto& entry : fs::recursive_directory_iterator(dep_path)) {
536 if (entry.is_regular_file()) {
537 absl::Status process_result =
538 ProcessFile(working_dir_path, licenses, data, entry.path(),
539 flags, &state);
540 if (!process_result.ok()) {
541 return state.errors;
542 }
543 }
544 }
545 }
546 }
547 }
548 }
549
550 for (const fs::path& git_repo : git_repos) {
551 if (!VLOG_IS_ON(1) && IsStdoutTerminal()) {
552 PrintProgress(count++, git_repos.size());
553 }
554
555 absl::StatusOr<std::vector<std::string>> git_files = GitLsFiles(git_repo);
556 if (!git_files.ok()) {
557 state.errors.push_back(git_files.status());
558 return state.errors;
559 }
560 for (const std::string& git_file : git_files.value()) {
561 fs::path full_path = git_repo / git_file;
562 absl::Status process_result = ProcessFile(working_dir_path, licenses,
563 data, full_path, flags, &state);
564 if (!process_result.ok()) {
565 return state.errors;
566 }
567 }
568 }
569
570 if (!data.secondary_dir.empty()) {
571 for (const auto& entry :
572 fs::recursive_directory_iterator(data.secondary_dir)) {
573 if (!fs::is_directory(entry)) {
574 fs::path relative_path = fs::relative(entry, data.secondary_dir);
575 if (!fs::exists(working_dir / relative_path.parent_path())) {
576 state.errors.push_back(absl::InvalidArgumentError(absl::StrCat(
577 "secondary license path mixmatch at ", relative_path.string())));
578 } else {
579 fs::path full_path = data.secondary_dir / entry;
580 Package package =
581 GetPackage(data, working_dir_path, relative_path, flags);
582 absl::StatusOr<MMapFile> file = MMapFile::Make(full_path.string());
583 if (file.ok()) {
584 state.license_map.Add(
585 package.name,
586 std::string_view(file->GetData(), file->GetSize()));
587 } else {
588 state.errors.push_back(file.status());
589 }
590 }
591 }
592 }
593 }
594
595 state.license_map.Write(licenses);
596 if (!VLOG_IS_ON(1) && IsStdoutTerminal()) {
597 PrintProgress(count++, git_repos.size());
598 std::cout << std::endl;
599 }
600
601 return state.errors;
602}
std::vector< std::string > Parse(std::string_view input)
static absl::StatusOr< MMapFile > Make(std::string_view path)
Definition mmap_file.cc:13
int32_t value

References data, MMapFile::Make(), and DepsParser::Parse().

◆ Run() [3/3]

int LicenseChecker::Run ( std::string_view  working_dir,
std::ostream &  licenses,
std::string_view  data_dir,
const Flags flags 
)
static

Definition at line 604 of file license_checker.cc.

607 {
608 absl::StatusOr<Data> data = Data::Open(data_dir);
609 if (!data.ok()) {
610 std::cerr << "Can't load data at " << data_dir << ": " << data.status()
611 << std::endl;
612 return 1;
613 }
614 std::vector<absl::Status> errors =
615 Run(working_dir, licenses, data.value(), flags);
616 for (const absl::Status& status : errors) {
617 std::cerr << status << "\n";
618 }
619
620 if (!errors.empty()) {
621 std::cout << "Error count: " << errors.size();
622 }
623
624 return errors.empty() ? 0 : 1;
625}

References data, and Data::Open().

Member Data Documentation

◆ kHeaderLicenseRegex

const char * LicenseChecker::kHeaderLicenseRegex = "(?i)(license|copyright)"
static

Definition at line 21 of file license_checker.h.


The documentation for this class was generated from the following files: