| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2013 The Chromium 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 "tools/gn/gyp_target_writer.h" | |
| 6 | |
| 7 #include <iostream> | |
| 8 | |
| 9 #include "base/file_util.h" | |
| 10 #include "base/files/file_path.h" | |
| 11 #include "tools/gn/build_settings.h" | |
| 12 #include "tools/gn/builder_record.h" | |
| 13 #include "tools/gn/filesystem_utils.h" | |
| 14 #include "tools/gn/gyp_action_target_writer.h" | |
| 15 #include "tools/gn/gyp_binary_target_writer.h" | |
| 16 #include "tools/gn/scheduler.h" | |
| 17 #include "tools/gn/settings.h" | |
| 18 #include "tools/gn/target.h" | |
| 19 #include "tools/gn/toolchain.h" | |
| 20 | |
| 21 GypTargetWriter::TargetGroup::TargetGroup() | |
| 22 : debug(NULL), | |
| 23 release(NULL), | |
| 24 host_debug(NULL), | |
| 25 host_release(NULL), | |
| 26 debug64(NULL), | |
| 27 release64(NULL), | |
| 28 xcode_debug(NULL), | |
| 29 xcode_release(NULL), | |
| 30 xcode_host_debug(NULL), | |
| 31 xcode_host_release(NULL) { | |
| 32 } | |
| 33 | |
| 34 GypTargetWriter::GypTargetWriter(const Target* target, | |
| 35 const Toolchain* toolchain, | |
| 36 const SourceDir& gyp_dir, | |
| 37 std::ostream& out) | |
| 38 : settings_(target->settings()), | |
| 39 target_(target), | |
| 40 toolchain_(toolchain), | |
| 41 gyp_dir_(gyp_dir), | |
| 42 out_(out), | |
| 43 // All GYP paths are relative to GYP file. | |
| 44 path_output_(gyp_dir, ESCAPE_JSON, false) { | |
| 45 } | |
| 46 | |
| 47 GypTargetWriter::~GypTargetWriter() { | |
| 48 } | |
| 49 | |
| 50 // static | |
| 51 void GypTargetWriter::WriteFile(const SourceFile& gyp_file, | |
| 52 const std::vector<TargetGroup>& targets, | |
| 53 const Toolchain* debug_toolchain, | |
| 54 Err* err) { | |
| 55 if (targets.empty()) | |
| 56 return; | |
| 57 const Settings* debug_settings = | |
| 58 targets[0].debug->item()->AsTarget()->settings(); | |
| 59 const BuildSettings* debug_build_settings = debug_settings->build_settings(); | |
| 60 | |
| 61 base::FilePath gyp_file_path = debug_build_settings->GetFullPath(gyp_file); | |
| 62 base::CreateDirectory(gyp_file_path.DirName()); | |
| 63 | |
| 64 std::stringstream file; | |
| 65 file << "# Generated by GN. Do not edit.\n\n"; | |
| 66 file << "{\n"; | |
| 67 | |
| 68 // Optional GYP header specified in the default debug toolchain. | |
| 69 if (!debug_toolchain->gyp_header().empty()) | |
| 70 file << debug_toolchain->gyp_header() << std::endl; | |
| 71 | |
| 72 file << " 'skip_includes': 1,\n"; | |
| 73 file << " 'targets': [\n"; | |
| 74 | |
| 75 for (size_t i = 0; i < targets.size(); i++) { | |
| 76 const Target* cur = targets[i].debug->item()->AsTarget(); | |
| 77 switch (cur->output_type()) { | |
| 78 case Target::COPY_FILES: | |
| 79 break; // TODO(brettw) | |
| 80 case Target::ACTION: | |
| 81 case Target::ACTION_FOREACH: { | |
| 82 GypActionTargetWriter writer(targets[i], debug_toolchain, | |
| 83 gyp_file.GetDir(), file); | |
| 84 writer.Run(); | |
| 85 break; | |
| 86 } | |
| 87 case Target::GROUP: | |
| 88 break; // TODO(brettw) | |
| 89 case Target::EXECUTABLE: | |
| 90 case Target::STATIC_LIBRARY: | |
| 91 case Target::SHARED_LIBRARY: | |
| 92 case Target::SOURCE_SET: { | |
| 93 GypBinaryTargetWriter writer(targets[i], debug_toolchain, | |
| 94 gyp_file.GetDir(), file); | |
| 95 writer.Run(); | |
| 96 break; | |
| 97 } | |
| 98 default: | |
| 99 CHECK(0); | |
| 100 } | |
| 101 } | |
| 102 | |
| 103 file << " ],\n}\n"; | |
| 104 | |
| 105 std::string contents = file.str(); | |
| 106 base::WriteFile(gyp_file_path, contents.c_str(), | |
| 107 static_cast<int>(contents.size())); | |
| 108 } | |
| 109 | |
| 110 std::ostream& GypTargetWriter::Indent(int spaces) { | |
| 111 return Indent(out_, spaces); | |
| 112 } | |
| 113 | |
| 114 // static | |
| 115 std::ostream& GypTargetWriter::Indent(std::ostream& out, int spaces) { | |
| 116 const char kSpaces[81] = | |
| 117 " " | |
| 118 " "; | |
| 119 CHECK(static_cast<size_t>(spaces) <= arraysize(kSpaces) - 1); | |
| 120 out.write(kSpaces, spaces); | |
| 121 return out; | |
| 122 } | |
| OLD | NEW |