blob: eec2b890ccfcdf83829033c0b4245ef34caa9e7b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
// Copyright (c) 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "tools/gn/gyp_target_writer.h"
#include <iostream>
#include "base/file_util.h"
#include "base/files/file_path.h"
#include "tools/gn/build_settings.h"
#include "tools/gn/filesystem_utils.h"
#include "tools/gn/gyp_binary_target_writer.h"
#include "tools/gn/scheduler.h"
#include "tools/gn/settings.h"
#include "tools/gn/target.h"
GypTargetWriter::GypTargetWriter(const Target* target, std::ostream& out)
: settings_(target->settings()),
target_(target),
out_(out) {
}
GypTargetWriter::~GypTargetWriter() {
}
// static
void GypTargetWriter::WriteFile(const SourceFile& gyp_file,
const std::vector<TargetPair>& targets,
Err* err) {
if (targets.empty())
return;
const BuildSettings* debug_build_settings =
targets[0].debug->settings()->build_settings();
std::stringstream file;
file << "# Generated by GN. Do not edit.\n\n";
file << "{\n";
file << " 'skip_includes': 1,\n";
file << " 'targets': [\n";
for (size_t i = 0; i < targets.size(); i++) {
switch (targets[i].debug->output_type()) {
case Target::COPY_FILES:
case Target::CUSTOM:
case Target::GROUP:
break; // TODO(brettw)
case Target::EXECUTABLE:
case Target::STATIC_LIBRARY:
case Target::SHARED_LIBRARY:
case Target::SOURCE_SET: {
GypBinaryTargetWriter writer(targets[i].debug, targets[i].release,
file);
writer.Run();
break;
}
default:
CHECK(0);
}
}
file << " ],\n}\n";
base::FilePath gyp_file_path = debug_build_settings->GetFullPath(gyp_file);
std::string contents = file.str();
file_util::WriteFile(gyp_file_path, contents.c_str(),
static_cast<int>(contents.size()));
}
|