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

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

Issue 26267003: Add the concept of a source set to GN. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 2 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
« no previous file with comments | « tools/gn/functions.cc ('k') | tools/gn/gn.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/functions.h" 5 #include "tools/gn/functions.h"
6 6
7 #include "tools/gn/config_values_generator.h" 7 #include "tools/gn/config_values_generator.h"
8 #include "tools/gn/err.h" 8 #include "tools/gn/err.h"
9 #include "tools/gn/parse_tree.h" 9 #include "tools/gn/parse_tree.h"
10 #include "tools/gn/scope.h" 10 #include "tools/gn/scope.h"
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 } 51 }
52 52
53 } // namespace 53 } // namespace
54 54
55 // component ------------------------------------------------------------------- 55 // component -------------------------------------------------------------------
56 56
57 const char kComponent[] = "component"; 57 const char kComponent[] = "component";
58 const char kComponent_Help[] = 58 const char kComponent_Help[] =
59 "component: Declare a component target.\n" 59 "component: Declare a component target.\n"
60 "\n" 60 "\n"
61 " A component is either a shared library or a static library depending\n" 61 " A component is a shared library, static library, or source set\n"
62 " on the component mode. This allows a project to separate out a build\n" 62 " depending on the component mode. This allows a project to separate\n"
63 " into shared libraries for faster devlopment (link time is reduced)\n" 63 " out a build into shared libraries for faster devlopment (link time is\n"
64 " but to switch to a static build for releases (for better performance).\n" 64 " reduced) but to switch to a static build for releases (for better\n"
65 " performance).\n"
65 "\n" 66 "\n"
66 " To use this function you must set the value of the \"component_mode\n" 67 " To use this function you must set the value of the \"component_mode\n"
67 " variable to the string \"shared_library\" or \"static_library\". It is\n" 68 " variable to one of the following strings:\n"
68 " an error to call \"component\" without defining the mode (typically\n" 69 " - \"shared_library\"\n"
69 " this is done in the master build configuration file).\n" 70 " - \"static_library\"\n"
70 "\n" 71 " - \"source_set\"\n"
71 " See \"gn help shared_library\" and \"gn help static_library\" for\n" 72 " It is an error to call \"component\" without defining the mode\n"
72 " more details.\n"; 73 " (typically this is done in the master build configuration file).\n";
73 74
74 Value RunComponent(Scope* scope, 75 Value RunComponent(Scope* scope,
75 const FunctionCallNode* function, 76 const FunctionCallNode* function,
76 const std::vector<Value>& args, 77 const std::vector<Value>& args,
77 BlockNode* block, 78 BlockNode* block,
78 Err* err) { 79 Err* err) {
79 // A component is either a shared or static library, depending on the value 80 // A component is either a shared or static library, depending on the value
80 // of |component_mode|. 81 // of |component_mode|.
81 const Value* component_mode_value = 82 const Value* component_mode_value =
82 scope->GetValue(variables::kComponentMode); 83 scope->GetValue(variables::kComponentMode);
83 84
84 static const char helptext[] = 85 static const char helptext[] =
85 "You're declaring a component here but have not defined " 86 "You're declaring a component here but have not defined "
86 "\"component_mode\" to\neither \"shared_library\" or \"static_library\"."; 87 "\"component_mode\" to\neither \"shared_library\" or \"static_library\".";
87 if (!component_mode_value) { 88 if (!component_mode_value) {
88 *err = Err(function->function(), "No component mode set.", helptext); 89 *err = Err(function->function(), "No component mode set.", helptext);
89 return Value(); 90 return Value();
90 } 91 }
91 if (component_mode_value->type() != Value::STRING || 92 if (component_mode_value->type() != Value::STRING ||
92 (component_mode_value->string_value() != functions::kSharedLibrary && 93 (component_mode_value->string_value() != functions::kSharedLibrary &&
93 component_mode_value->string_value() != functions::kStaticLibrary)) { 94 component_mode_value->string_value() != functions::kStaticLibrary &&
95 component_mode_value->string_value() != functions::kSourceSet)) {
94 *err = Err(function->function(), "Invalid component mode set.", helptext); 96 *err = Err(function->function(), "Invalid component mode set.", helptext);
95 return Value(); 97 return Value();
96 } 98 }
97 const std::string& component_mode = component_mode_value->string_value(); 99 const std::string& component_mode = component_mode_value->string_value();
98 100
99 if (!EnsureNotProcessingImport(function, scope, err)) 101 if (!EnsureNotProcessingImport(function, scope, err))
100 return Value(); 102 return Value();
101 Scope block_scope(scope); 103 Scope block_scope(scope);
102 if (!FillTargetBlockScope(scope, function, component_mode.c_str(), block, 104 if (!FillTargetBlockScope(scope, function, component_mode.c_str(), block,
103 args, &block_scope, err)) 105 args, &block_scope, err))
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
332 334
333 Value RunSharedLibrary(Scope* scope, 335 Value RunSharedLibrary(Scope* scope,
334 const FunctionCallNode* function, 336 const FunctionCallNode* function,
335 const std::vector<Value>& args, 337 const std::vector<Value>& args,
336 BlockNode* block, 338 BlockNode* block,
337 Err* err) { 339 Err* err) {
338 return ExecuteGenericTarget(functions::kSharedLibrary, scope, function, args, 340 return ExecuteGenericTarget(functions::kSharedLibrary, scope, function, args,
339 block, err); 341 block, err);
340 } 342 }
341 343
344 // source_set ------------------------------------------------------------------
345
346 extern const char kSourceSet[] = "source_set";
347 extern const char kSourceSet_Help[] =
348 "source_set: Declare a source set target.\n"
349 "\n"
350 " A source set is a collection of sources that get compiled, but are not\n"
351 " linked to produce any kind of library. Instead, the resulting object\n"
352 " files are implicitly added to the linker line of all targets that\n"
353 " depend on the source set.\n"
354 "\n"
355 " In most cases, a source set will behave like a static library, except\n"
356 " no actual library file will be produced. This will make the build go\n"
357 " a little faster by skipping creation of a large static library, while\n"
358 " maintaining the organizational benefits of focused build targets.\n"
359 "\n"
360 " The main difference between a source set and a static library is\n"
361 " around handling of exported symbols. Most linkers assume declaring\n"
362 " a function exported means exported from the static library. The linker\n"
363 " can then do dead code elimination to delete code not reachable from\n"
364 " exported functions.\n"
365 "\n"
366 " A source set will not do this code elimination since there is no link\n"
367 " step. This allows you to link many sources sets into a shared library\n"
368 " and have the \"exported symbol\" notation indicate \"export from the\n"
369 " final shared library and not from the intermediate targets.\" There is\n"
370 " no way to express this concept when linking multiple static libraries\n"
371 " into a shared library.\n"
372 "\n"
373 "Variables\n"
374 "\n"
375 CONFIG_VALUES_VARS_HELP
376 DEPS_VARS
377 DEPENDENT_CONFIG_VARS
378 GENERAL_TARGET_VARS;
379
380 Value RunSourceSet(Scope* scope,
381 const FunctionCallNode* function,
382 const std::vector<Value>& args,
383 BlockNode* block,
384 Err* err) {
385 return ExecuteGenericTarget(functions::kSourceSet, scope, function, args,
386 block, err);
387 }
388
342 // static_library -------------------------------------------------------------- 389 // static_library --------------------------------------------------------------
343 390
344 const char kStaticLibrary[] = "static_library"; 391 const char kStaticLibrary[] = "static_library";
345 const char kStaticLibrary_Help[] = 392 const char kStaticLibrary_Help[] =
346 "static_library: Declare a static library target.\n" 393 "static_library: Declare a static library target.\n"
347 "\n" 394 "\n"
395 " Make a \".a\" / \".lib\" file.\n"
396 "\n"
397 " If you only need the static library for intermediate results in the\n"
398 " build, you should consider a source_set instead since it will skip\n"
399 " the (potentially slow) step of creating the intermediate library file.\n"
400 "\n"
348 "Variables\n" 401 "Variables\n"
349 "\n" 402 "\n"
350 CONFIG_VALUES_VARS_HELP 403 CONFIG_VALUES_VARS_HELP
351 DEPS_VARS 404 DEPS_VARS
352 DEPENDENT_CONFIG_VARS 405 DEPENDENT_CONFIG_VARS
353 GENERAL_TARGET_VARS; 406 GENERAL_TARGET_VARS;
354 407
355 Value RunStaticLibrary(Scope* scope, 408 Value RunStaticLibrary(Scope* scope,
356 const FunctionCallNode* function, 409 const FunctionCallNode* function,
357 const std::vector<Value>& args, 410 const std::vector<Value>& args,
(...skipping 19 matching lines...) Expand all
377 Value RunTest(Scope* scope, 430 Value RunTest(Scope* scope,
378 const FunctionCallNode* function, 431 const FunctionCallNode* function,
379 const std::vector<Value>& args, 432 const std::vector<Value>& args,
380 BlockNode* block, 433 BlockNode* block,
381 Err* err) { 434 Err* err) {
382 return ExecuteGenericTarget(functions::kExecutable, scope, function, args, 435 return ExecuteGenericTarget(functions::kExecutable, scope, function, args,
383 block, err); 436 block, err);
384 } 437 }
385 438
386 } // namespace functions 439 } // namespace functions
OLDNEW
« no previous file with comments | « tools/gn/functions.cc ('k') | tools/gn/gn.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698