Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(335)

Side by Side Diff: tools/gn/commands.cc

Issue 165823003: GN: Change gen command syntax, support relative dirs. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Change in build file writing Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 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 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/commands.h" 5 #include "tools/gn/commands.h"
6 #include "tools/gn/filesystem_utils.h"
6 #include "tools/gn/item.h" 7 #include "tools/gn/item.h"
7 #include "tools/gn/label.h" 8 #include "tools/gn/label.h"
8 #include "tools/gn/setup.h" 9 #include "tools/gn/setup.h"
9 #include "tools/gn/standard_out.h" 10 #include "tools/gn/standard_out.h"
10 #include "tools/gn/target.h" 11 #include "tools/gn/target.h"
11 12
12 namespace commands { 13 namespace commands {
13 14
14 CommandInfo::CommandInfo() 15 CommandInfo::CommandInfo()
15 : help_short(NULL), 16 : help_short(NULL),
(...skipping 25 matching lines...) Expand all
41 INSERT_COMMAND(Refs) 42 INSERT_COMMAND(Refs)
42 43
43 #undef INSERT_COMMAND 44 #undef INSERT_COMMAND
44 } 45 }
45 return info_map; 46 return info_map;
46 } 47 }
47 48
48 const Target* GetTargetForDesc(const std::vector<std::string>& args) { 49 const Target* GetTargetForDesc(const std::vector<std::string>& args) {
49 // Deliberately leaked to avoid expensive process teardown. 50 // Deliberately leaked to avoid expensive process teardown.
50 Setup* setup = new Setup; 51 Setup* setup = new Setup;
51 if (!setup->DoSetup()) 52 // TODO(brettw) bug 343726: Use a temporary directory instead of this
53 // default one to avoid messing up any build that's in there.
54 if (!setup->DoSetup("//out/Default/"))
52 return NULL; 55 return NULL;
53 56
54 // TODO(brettw): set the output dir to be a sandbox one to avoid polluting
55 // the real output dir with files written by the build scripts.
56
57 // Do the actual load. This will also write out the target ninja files. 57 // Do the actual load. This will also write out the target ninja files.
58 if (!setup->Run()) 58 if (!setup->Run())
59 return NULL; 59 return NULL;
60 60
61 // Need to resolve the label after we know the default toolchain. 61 // Need to resolve the label after we know the default toolchain.
62 // TODO(brettw) find the current directory and resolve the input label
63 // relative to that.
64 Label default_toolchain = setup->loader()->default_toolchain_label(); 62 Label default_toolchain = setup->loader()->default_toolchain_label();
65 Value arg_value(NULL, args[0]); 63 Value arg_value(NULL, args[0]);
66 Err err; 64 Err err;
67 Label label = 65 Label label = Label::Resolve(SourceDirForCurrentDirectory(
68 Label::Resolve(SourceDir("//"), default_toolchain, arg_value, &err); 66 setup->build_settings().root_path()),
67 default_toolchain, arg_value, &err);
69 if (err.has_error()) { 68 if (err.has_error()) {
70 err.PrintToStdout(); 69 err.PrintToStdout();
71 return NULL; 70 return NULL;
72 } 71 }
73 72
74 const Item* item = setup->builder()->GetItem(label); 73 const Item* item = setup->builder()->GetItem(label);
75 if (!item) { 74 if (!item) {
76 Err(Location(), "Label not found.", 75 Err(Location(), "Label not found.",
77 label.GetUserVisibleName(false) + " not found.").PrintToStdout(); 76 label.GetUserVisibleName(false) + " not found.").PrintToStdout();
78 return NULL; 77 return NULL;
79 } 78 }
80 79
81 const Target* target = item->AsTarget(); 80 const Target* target = item->AsTarget();
82 if (!target) { 81 if (!target) {
83 Err(Location(), "Not a target.", 82 Err(Location(), "Not a target.",
84 "The \"" + label.GetUserVisibleName(false) + "\" thing\n" 83 "The \"" + label.GetUserVisibleName(false) + "\" thing\n"
85 "is not a target. Somebody should probably implement this command for " 84 "is not a target. Somebody should probably implement this command for "
86 "other\nitem types."); 85 "other\nitem types.");
87 return NULL; 86 return NULL;
88 } 87 }
89 88
90 return target; 89 return target;
91 } 90 }
92 91
93 } // namespace commands 92 } // namespace commands
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698