OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "tools/gn/xcode_writer.h" | 5 #include "tools/gn/xcode_writer.h" |
6 | 6 |
7 #include <iomanip> | 7 #include <iomanip> |
8 #include <map> | 8 #include <map> |
9 #include <memory> | 9 #include <memory> |
10 #include <sstream> | 10 #include <sstream> |
(...skipping 18 matching lines...) Expand all Loading... |
29 #include "tools/gn/variables.h" | 29 #include "tools/gn/variables.h" |
30 #include "tools/gn/xcode_object.h" | 30 #include "tools/gn/xcode_object.h" |
31 | 31 |
32 namespace { | 32 namespace { |
33 | 33 |
34 struct SafeEnvironmentVariableInfo { | 34 struct SafeEnvironmentVariableInfo { |
35 const char* name; | 35 const char* name; |
36 bool capture_at_generation; | 36 bool capture_at_generation; |
37 }; | 37 }; |
38 | 38 |
| 39 // clang-format off |
39 SafeEnvironmentVariableInfo kSafeEnvironmentVariables[] = { | 40 SafeEnvironmentVariableInfo kSafeEnvironmentVariables[] = { |
40 {"HOME", true}, {"LANG", true}, {"PATH", true}, | 41 {"HOME", true}, |
41 {"USER", true}, {"TMPDIR", false}, | 42 {"LANG", true}, |
| 43 {"PATH", true}, |
| 44 {"USER", true}, |
| 45 {"TMPDIR", false}, |
42 }; | 46 }; |
| 47 // clang-format on |
43 | 48 |
44 XcodeWriter::TargetOsType GetTargetOs(const Args& args) { | 49 XcodeWriter::TargetOsType GetTargetOs(const Args& args) { |
45 const Value* target_os_value = args.GetArgOverride(variables::kTargetOs); | 50 const Value* target_os_value = args.GetArgOverride(variables::kTargetOs); |
46 if (target_os_value) { | 51 if (target_os_value) { |
47 if (target_os_value->type() == Value::STRING) { | 52 if (target_os_value->type() == Value::STRING) { |
48 if (target_os_value->string_value() == "ios") | 53 if (target_os_value->string_value() == "ios") |
49 return XcodeWriter::WRITER_TARGET_OS_IOS; | 54 return XcodeWriter::WRITER_TARGET_OS_IOS; |
50 } | 55 } |
51 } | 56 } |
52 return XcodeWriter::WRITER_TARGET_OS_MACOS; | 57 return XcodeWriter::WRITER_TARGET_OS_MACOS; |
53 } | 58 } |
54 | 59 |
55 std::string GetBuildScript(const std::string& target_name, | 60 std::string GetBuildScript(const std::string& target_name, |
56 const std::string& ninja_extra_args, | 61 const std::string& ninja_extra_args, |
57 base::Environment* environment) { | 62 base::Environment* environment) { |
58 std::stringstream script; | 63 std::stringstream script; |
59 script << "echo note: \"Compile and copy " << target_name << " via ninja\"\n" | 64 script << "echo note: \"Compile and copy " << target_name << " via ninja\"\n" |
60 << "exec "; | 65 << "exec "; |
61 | 66 |
62 // Launch ninja with a sanitized environment (Xcode sets many environment | 67 // Launch ninja with a sanitized environment (Xcode sets many environment |
63 // variable overridding settings, including the SDK, thus breaking hermetic | 68 // variable overridding settings, including the SDK, thus breaking hermetic |
64 // build). | 69 // build). |
65 script << "env -i "; | 70 script << "env -i "; |
66 for (size_t i = 0; i < arraysize(kSafeEnvironmentVariables); ++i) { | 71 for (const auto& variable : kSafeEnvironmentVariables) { |
67 const auto& variable = kSafeEnvironmentVariables[i]; | |
68 script << variable.name << "=\""; | 72 script << variable.name << "=\""; |
69 | 73 |
70 std::string value; | 74 std::string value; |
71 if (variable.capture_at_generation) | 75 if (variable.capture_at_generation) |
72 environment->GetVar(variable.name, &value); | 76 environment->GetVar(variable.name, &value); |
73 | 77 |
74 if (!value.empty()) | 78 if (!value.empty()) |
75 script << value; | 79 script << value; |
76 else | 80 else |
77 script << "$" << variable.name; | 81 script << "$" << variable.name; |
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
428 for (auto* object : pair.second) { | 432 for (auto* object : pair.second) { |
429 object->Print(out, 2); | 433 object->Print(out, 2); |
430 } | 434 } |
431 out << "/* End " << ToString(pair.first) << " section */\n"; | 435 out << "/* End " << ToString(pair.first) << " section */\n"; |
432 } | 436 } |
433 | 437 |
434 out << "\t};\n" | 438 out << "\t};\n" |
435 << "\trootObject = " << project->Reference() << ";\n" | 439 << "\trootObject = " << project->Reference() << ";\n" |
436 << "}\n"; | 440 << "}\n"; |
437 } | 441 } |
OLD | NEW |