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

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

Issue 2006923004: Add support for user defined "pool" to GN. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 4 years, 6 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
« no previous file with comments | « tools/gn/functions.h ('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 <stddef.h> 7 #include <stddef.h>
8 #include <iostream> 8 #include <iostream>
9 #include <utility> 9 #include <utility>
10 10
11 #include "base/environment.h" 11 #include "base/environment.h"
12 #include "base/strings/string_util.h" 12 #include "base/strings/string_util.h"
13 #include "tools/gn/config.h" 13 #include "tools/gn/config.h"
14 #include "tools/gn/config_values_generator.h" 14 #include "tools/gn/config_values_generator.h"
15 #include "tools/gn/err.h" 15 #include "tools/gn/err.h"
16 #include "tools/gn/input_file.h" 16 #include "tools/gn/input_file.h"
17 #include "tools/gn/parse_tree.h" 17 #include "tools/gn/parse_tree.h"
18 #include "tools/gn/pool.h"
18 #include "tools/gn/scheduler.h" 19 #include "tools/gn/scheduler.h"
19 #include "tools/gn/scope.h" 20 #include "tools/gn/scope.h"
20 #include "tools/gn/settings.h" 21 #include "tools/gn/settings.h"
21 #include "tools/gn/template.h" 22 #include "tools/gn/template.h"
22 #include "tools/gn/token.h" 23 #include "tools/gn/token.h"
23 #include "tools/gn/value.h" 24 #include "tools/gn/value.h"
24 #include "tools/gn/value_extractors.h" 25 #include "tools/gn/value_extractors.h"
25 #include "tools/gn/variables.h" 26 #include "tools/gn/variables.h"
26 27
27 namespace { 28 namespace {
(...skipping 643 matching lines...) Expand 10 before | Expand all | Expand 10 after
671 *err = Err(function, "set_sources_assignment_filter takes one argument."); 672 *err = Err(function, "set_sources_assignment_filter takes one argument.");
672 } else { 673 } else {
673 std::unique_ptr<PatternList> f(new PatternList); 674 std::unique_ptr<PatternList> f(new PatternList);
674 f->SetFromValue(args[0], err); 675 f->SetFromValue(args[0], err);
675 if (!err->has_error()) 676 if (!err->has_error())
676 scope->set_sources_assignment_filter(std::move(f)); 677 scope->set_sources_assignment_filter(std::move(f));
677 } 678 }
678 return Value(); 679 return Value();
679 } 680 }
680 681
682 // pool ------------------------------------------------------------------------
683
684 const char kPool[] = "pool";
685 const char kPool_HelpShort[] =
686 "pool: Defines a pool object.";
687 const char kPool_Help[] =
688 "pool: Defines a pool object.\n"
689 "\n"
690 " Pool objects can be applied to a tool to limit the parallelism of the\n"
691 " build. This object has a single property \"depth\" corresponding to\n"
692 " the number of tasks that may run simultaneously.\n"
693 "\n"
694 " As the file containing the pool definition may be executed in the\n"
695 " of more than one toolchain it is recommended to specify an explicit\n"
Dirk Pranke 2016/06/06 23:32:18 nit: "in the context of"
696 " toolchain when definining and referencing a pool.\n"
Dirk Pranke 2016/06/06 23:32:18 nit: "defining"
697 "\n"
698 " A pool is referenced by its label just like a target.\n"
699 "\n"
700 "Variables\n"
701 "\n"
702 " depth*\n"
703 " * = required\n"
704 "\n"
705 "Example\n"
706 "\n"
707 " if (current_toolchain == default_toolchain) {\n"
708 " pool(\"link_pool\") {\n"
709 " depth = 1\n"
710 " }\n"
711 " }\n"
712 "\n"
713 " toolchain(\"toolchain\") {\n"
714 " tool(\"link\") {\n"
715 " command = \"...\"\n"
716 " pool = \":link_pool($default_toolchain)\")\n"
717 " }\n"
718 " }\n";
719
720 const char kDepth[] = "depth";
721
722 Value RunPool(const FunctionCallNode* function,
723 const std::vector<Value>& args,
724 Scope* scope,
725 Err* err) {
726 NonNestableBlock non_nestable(scope, function, "pool");
727 if (!non_nestable.Enter(err))
728 return Value();
729
730 if (!EnsureSingleStringArg(function, args, err) ||
731 !EnsureNotProcessingImport(function, scope, err))
732 return Value();
733
734 Label label(MakeLabelForScope(scope, function, args[0].string_value()));
735
736 if (g_scheduler->verbose_logging())
737 g_scheduler->Log("Defining pool", label.GetUserVisibleName(true));
738
739 // Get the pool depth. It is an error to define a pool without a depth,
740 // so check first for the presence of the value.
741 const Value* depth = scope->GetValue(kDepth, true);
742 if (!depth) {
743 *err = Err(function, "Can't define a pool without depth.");
744 return Value();
745 }
746
747 if (!depth->VerifyTypeIs(Value::INTEGER, err))
748 return Value();
749
750 if (depth->int_value() < 0) {
751 *err = Err(function, "depth must be positive or nul.");
752 return Value();
753 }
754
755 // Create the new pool.
756 std::unique_ptr<Pool> pool(new Pool(scope->settings(), label));
757 pool->set_depth(depth->int_value());
758
759 // Save the generated item.
760 Scope::ItemVector* collector = scope->GetItemCollector();
761 if (!collector) {
762 *err = Err(function, "Can't define a pool in this context.");
763 return Value();
764 }
765 collector->push_back(pool.release());
766
767 return Value();
768 }
769
681 // print ----------------------------------------------------------------------- 770 // print -----------------------------------------------------------------------
682 771
683 const char kPrint[] = "print"; 772 const char kPrint[] = "print";
684 const char kPrint_HelpShort[] = 773 const char kPrint_HelpShort[] =
685 "print: Prints to the console."; 774 "print: Prints to the console.";
686 const char kPrint_Help[] = 775 const char kPrint_Help[] =
687 "print: Prints to the console.\n" 776 "print: Prints to the console.\n"
688 "\n" 777 "\n"
689 " Prints all arguments to the console separated by spaces. A newline is\n" 778 " Prints all arguments to the console separated by spaces. A newline is\n"
690 " automatically appended to the end.\n" 779 " automatically appended to the end.\n"
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
819 INSERT_FUNCTION(DeclareArgs, false) 908 INSERT_FUNCTION(DeclareArgs, false)
820 INSERT_FUNCTION(Defined, false) 909 INSERT_FUNCTION(Defined, false)
821 INSERT_FUNCTION(ExecScript, false) 910 INSERT_FUNCTION(ExecScript, false)
822 INSERT_FUNCTION(ForEach, false) 911 INSERT_FUNCTION(ForEach, false)
823 INSERT_FUNCTION(ForwardVariablesFrom, false) 912 INSERT_FUNCTION(ForwardVariablesFrom, false)
824 INSERT_FUNCTION(GetEnv, false) 913 INSERT_FUNCTION(GetEnv, false)
825 INSERT_FUNCTION(GetLabelInfo, false) 914 INSERT_FUNCTION(GetLabelInfo, false)
826 INSERT_FUNCTION(GetPathInfo, false) 915 INSERT_FUNCTION(GetPathInfo, false)
827 INSERT_FUNCTION(GetTargetOutputs, false) 916 INSERT_FUNCTION(GetTargetOutputs, false)
828 INSERT_FUNCTION(Import, false) 917 INSERT_FUNCTION(Import, false)
918 INSERT_FUNCTION(Pool, false)
829 INSERT_FUNCTION(Print, false) 919 INSERT_FUNCTION(Print, false)
830 INSERT_FUNCTION(ProcessFileTemplate, false) 920 INSERT_FUNCTION(ProcessFileTemplate, false)
831 INSERT_FUNCTION(ReadFile, false) 921 INSERT_FUNCTION(ReadFile, false)
832 INSERT_FUNCTION(RebasePath, false) 922 INSERT_FUNCTION(RebasePath, false)
833 INSERT_FUNCTION(SetDefaults, false) 923 INSERT_FUNCTION(SetDefaults, false)
834 INSERT_FUNCTION(SetDefaultToolchain, false) 924 INSERT_FUNCTION(SetDefaultToolchain, false)
835 INSERT_FUNCTION(SetSourcesAssignmentFilter, false) 925 INSERT_FUNCTION(SetSourcesAssignmentFilter, false)
836 INSERT_FUNCTION(Template, false) 926 INSERT_FUNCTION(Template, false)
837 INSERT_FUNCTION(Tool, false) 927 INSERT_FUNCTION(Tool, false)
838 INSERT_FUNCTION(Toolchain, false) 928 INSERT_FUNCTION(Toolchain, false)
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
921 } 1011 }
922 1012
923 // Otherwise it's a no-block function. 1013 // Otherwise it's a no-block function.
924 if (!VerifyNoBlockForFunctionCall(function, block, err)) 1014 if (!VerifyNoBlockForFunctionCall(function, block, err))
925 return Value(); 1015 return Value();
926 return found_function->second.no_block_runner(scope, function, 1016 return found_function->second.no_block_runner(scope, function,
927 args.list_value(), err); 1017 args.list_value(), err);
928 } 1018 }
929 1019
930 } // namespace functions 1020 } // namespace functions
OLDNEW
« no previous file with comments | « tools/gn/functions.h ('k') | tools/gn/gn.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698