1 /*
2 * Copyright (C) 2024 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #include "perfetto/base/logging.h"
18 #include "perfetto/base/status.h"
19 #include "src/trace_redaction/trace_redaction_framework.h"
20 #include "src/trace_redaction/trace_redactor.h"
21 #include "src/trace_redaction/verify_integrity.h"
22
23 namespace perfetto::trace_redaction {
24
25 // Builds and runs a trace redactor.
Main(std::string_view input,std::string_view output,std::string_view package_name)26 static base::Status Main(std::string_view input,
27 std::string_view output,
28 std::string_view package_name) {
29 TraceRedactor::Config config;
30 auto redactor = TraceRedactor::CreateInstance(config);
31
32 Context context;
33 context.package_name = package_name;
34
35 return redactor->Redact(input, output, &context);
36 }
37
38 } // namespace perfetto::trace_redaction
39
main(int argc,char ** argv)40 int main(int argc, char** argv) {
41 constexpr int kSuccess = 0;
42 constexpr int kFailure = 1;
43 constexpr int kInvalidArgs = 2;
44
45 if (argc != 4) {
46 PERFETTO_ELOG(
47 "Invalid arguments: %s <input file> <output file> <package name>",
48 argv[0]);
49 return kInvalidArgs;
50 }
51
52 auto result = perfetto::trace_redaction::Main(argv[1], argv[2], argv[3]);
53
54 if (result.ok()) {
55 return kSuccess;
56 }
57
58 PERFETTO_ELOG("Unexpected error: %s", result.c_message());
59 return kFailure;
60 }
61