blob: 586da42fbe749f4549363f06932080280c90ba48 [file] [log] [blame]
Yun Peng09dd8c02017-07-21 15:57:05 +02001// Copyright 2017 The Bazel Authors. All rights reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#ifndef BAZEL_SRC_TOOLS_LAUNCHER_UTIL_DATA_PARSER_H_
16#define BAZEL_SRC_TOOLS_LAUNCHER_UTIL_DATA_PARSER_H_
17
18#include <fstream>
19#include <memory>
20#include <string>
21#include <unordered_map>
22
23namespace bazel {
24namespace launcher {
25
26class LaunchDataParser {
27 public:
Yun Peng40f5a772018-06-25 05:35:50 -070028 typedef std::unordered_map<std::string, std::wstring> LaunchInfo;
Yun Peng09dd8c02017-07-21 15:57:05 +020029 LaunchDataParser() = delete;
30 ~LaunchDataParser() = delete;
Yun Peng40f5a772018-06-25 05:35:50 -070031 static bool GetLaunchInfo(const std::wstring& binary_path,
Yun Peng09dd8c02017-07-21 15:57:05 +020032 LaunchInfo* launch_info);
33
34 private:
35 // Read the last 64 bit from the given binary to get the data size
36 static int64_t ReadDataSize(std::ifstream* binary);
37
38 // Read launch data at the end of the given binary into a buffer
39 static void ReadLaunchData(std::ifstream* binary, char* launch_data,
40 int64_t data_size);
41
42 // Parse the launch data into a map
43 static bool ParseLaunchData(LaunchInfo* launch_info, const char* launch_data,
44 int64_t data_size);
45};
46
47} // namespace launcher
48} // namespace bazel
49
50#endif // BAZEL_SRC_TOOLS_LAUNCHER_UTIL_DATA_PARSER_H_