Flutter Engine
 
Loading...
Searching...
No Matches
license_file_compare.cc
Go to the documentation of this file.
1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include <iostream>
6
7#include "flutter/third_party/re2/re2/re2.h"
9#include "third_party/abseil-cpp/absl/container/flat_hash_set.h"
10#include "third_party/abseil-cpp/absl/log/check.h"
11#include "third_party/abseil-cpp/absl/log/globals.h"
12#include "third_party/abseil-cpp/absl/log/initialize.h"
13#include "third_party/abseil-cpp/absl/log/log.h"
14
15namespace {
16re2::RE2 copyright_regex = R"regex((?i)copyright(.*\d\d\d\d.*))regex";
17
18absl::flat_hash_set<std::string_view> GetCopyrights(const MMapFile& filemap) {
19 std::string_view string_view(filemap.GetData(), filemap.GetSize());
20 absl::flat_hash_set<std::string_view> copyrights;
21 std::string_view clause;
22 while (RE2::FindAndConsume(&string_view, copyright_regex, &clause)) {
23 while (!clause.empty() && (clause.back() == '*' || clause.back() == ' ')) {
24 clause = std::string_view(clause.data(), clause.size() - 1);
25 }
26 copyrights.insert(clause);
27 }
28 return copyrights;
29}
30} // namespace
31
32int main(int argc, const char* argv[]) {
33 if (argc != 3) {
34 std::cerr << "usage: " << argv[0] << " <path> <path>" << std::endl;
35 return 1;
36 }
37
38 absl::InitializeLog();
39 absl::SetStderrThreshold(absl::LogSeverity::kInfo);
40
41 absl::StatusOr<MMapFile> first = MMapFile::Make(argv[1]);
42 CHECK(first.ok());
43 absl::StatusOr<MMapFile> second = MMapFile::Make(argv[2]);
44 CHECK(second.ok());
45
46 absl::flat_hash_set<std::string_view> first_copyrights =
47 GetCopyrights(*first);
48 absl::flat_hash_set<std::string_view> second_copyrights =
49 GetCopyrights(*second);
50
51 LOG(INFO) << "first size: " << first_copyrights.size();
52 LOG(INFO) << "second size: " << second_copyrights.size();
53
54 for (std::string_view entry : first_copyrights) {
55 if (second_copyrights.find(entry) == second_copyrights.end()) {
56 LOG(INFO) << "second missing: " << entry;
57 }
58 }
59 for (std::string_view entry : second_copyrights) {
60 if (first_copyrights.find(entry) == first_copyrights.end()) {
61 LOG(INFO) << "first missing: " << entry;
62 }
63 }
64
65 return 0;
66}
A memory mapped file.
Definition mmap_file.h:12
size_t GetSize() const
Definition mmap_file.h:25
static absl::StatusOr< MMapFile > Make(std::string_view path)
Definition mmap_file.cc:13
const char * GetData() const
Definition mmap_file.h:23
char ** argv
Definition library.h:9
int main(int argc, const char *argv[])