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

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: 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
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 tool to limit the parallelism of the\n"
Dirk Pranke 2016/05/25 02:04:52 Nit: "applied to a tool".
sdefresne 2016/05/26 15:38:37 Done.
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 " A pool is referenced by its label just like a target.\n"
brettw 2016/05/24 22:03:31 The file containing the pool definition could theo
sdefresne 2016/05/26 15:38:37 Good point. Done.
695 "\n"
696 "Variables\n"
697 "\n"
698 " depth*\n"
699 " * = required\n"
700 "\n"
701 "Example\n"
702 "\n"
703 " pool(\"link_pool\") {\n"
704 " depth = 1\n"
705 " }\n"
706 "\n"
707 " toolchain(\"toolchain\") {\n"
708 " tool(\"link\") {\n"
709 " command = \"...\"\n"
710 " pool = \":link_pool\")\n"
711 " }\n"
712 " }\n";
713
714 const char kDepth[] = "depth";
715
716 Value RunPool(const FunctionCallNode* function,
717 const std::vector<Value>& args,
718 Scope* scope,
719 Err* err) {
720 NonNestableBlock non_nestable(scope, function, "pool");
721 if (!non_nestable.Enter(err))
722 return Value();
723
724 if (!EnsureSingleStringArg(function, args, err) ||
725 !EnsureNotProcessingImport(function, scope, err))
726 return Value();
727
728 Label label(MakeLabelForScope(scope, function, args[0].string_value()));
729
730 if (g_scheduler->verbose_logging())
731 g_scheduler->Log("Defining pool", label.GetUserVisibleName(true));
732
733 // Get the pool depth. It is an error to define a pool without a depth,
734 // so check first for the presence of the value.
735 const Value* depth = scope->GetValue(kDepth, true);
736 if (!depth) {
737 *err = Err(function, "Can't define a pool without depth.");
738 return Value();
739 }
740
741 if (!depth->VerifyTypeIs(Value::INTEGER, err))
742 return Value();
743
744 if (depth->int_value() < 0) {
745 *err = Err(function, "depth must be positive or nul.");
746 return Value();
747 }
748
749 // Create the new pool.
750 std::unique_ptr<Pool> pool(new Pool(scope->settings(), label));
751 pool->set_depth(depth->int_value());
752
753 // Save the generated item.
754 Scope::ItemVector* collector = scope->GetItemCollector();
755 if (!collector) {
756 *err = Err(function, "Can't define a pool in this context.");
757 return Value();
758 }
759 collector->push_back(pool.release());
760
761 return Value();
762 }
763
681 // print ----------------------------------------------------------------------- 764 // print -----------------------------------------------------------------------
682 765
683 const char kPrint[] = "print"; 766 const char kPrint[] = "print";
684 const char kPrint_HelpShort[] = 767 const char kPrint_HelpShort[] =
685 "print: Prints to the console."; 768 "print: Prints to the console.";
686 const char kPrint_Help[] = 769 const char kPrint_Help[] =
687 "print: Prints to the console.\n" 770 "print: Prints to the console.\n"
688 "\n" 771 "\n"
689 " Prints all arguments to the console separated by spaces. A newline is\n" 772 " Prints all arguments to the console separated by spaces. A newline is\n"
690 " automatically appended to the end.\n" 773 " automatically appended to the end.\n"
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
819 INSERT_FUNCTION(DeclareArgs, false) 902 INSERT_FUNCTION(DeclareArgs, false)
820 INSERT_FUNCTION(Defined, false) 903 INSERT_FUNCTION(Defined, false)
821 INSERT_FUNCTION(ExecScript, false) 904 INSERT_FUNCTION(ExecScript, false)
822 INSERT_FUNCTION(ForEach, false) 905 INSERT_FUNCTION(ForEach, false)
823 INSERT_FUNCTION(ForwardVariablesFrom, false) 906 INSERT_FUNCTION(ForwardVariablesFrom, false)
824 INSERT_FUNCTION(GetEnv, false) 907 INSERT_FUNCTION(GetEnv, false)
825 INSERT_FUNCTION(GetLabelInfo, false) 908 INSERT_FUNCTION(GetLabelInfo, false)
826 INSERT_FUNCTION(GetPathInfo, false) 909 INSERT_FUNCTION(GetPathInfo, false)
827 INSERT_FUNCTION(GetTargetOutputs, false) 910 INSERT_FUNCTION(GetTargetOutputs, false)
828 INSERT_FUNCTION(Import, false) 911 INSERT_FUNCTION(Import, false)
912 INSERT_FUNCTION(Pool, false)
829 INSERT_FUNCTION(Print, false) 913 INSERT_FUNCTION(Print, false)
830 INSERT_FUNCTION(ProcessFileTemplate, false) 914 INSERT_FUNCTION(ProcessFileTemplate, false)
831 INSERT_FUNCTION(ReadFile, false) 915 INSERT_FUNCTION(ReadFile, false)
832 INSERT_FUNCTION(RebasePath, false) 916 INSERT_FUNCTION(RebasePath, false)
833 INSERT_FUNCTION(SetDefaults, false) 917 INSERT_FUNCTION(SetDefaults, false)
834 INSERT_FUNCTION(SetDefaultToolchain, false) 918 INSERT_FUNCTION(SetDefaultToolchain, false)
835 INSERT_FUNCTION(SetSourcesAssignmentFilter, false) 919 INSERT_FUNCTION(SetSourcesAssignmentFilter, false)
836 INSERT_FUNCTION(Template, false) 920 INSERT_FUNCTION(Template, false)
837 INSERT_FUNCTION(Tool, false) 921 INSERT_FUNCTION(Tool, false)
838 INSERT_FUNCTION(Toolchain, false) 922 INSERT_FUNCTION(Toolchain, false)
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
921 } 1005 }
922 1006
923 // Otherwise it's a no-block function. 1007 // Otherwise it's a no-block function.
924 if (!VerifyNoBlockForFunctionCall(function, block, err)) 1008 if (!VerifyNoBlockForFunctionCall(function, block, err))
925 return Value(); 1009 return Value();
926 return found_function->second.no_block_runner(scope, function, 1010 return found_function->second.no_block_runner(scope, function,
927 args.list_value(), err); 1011 args.list_value(), err);
928 } 1012 }
929 1013
930 } // namespace functions 1014 } // namespace functions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698