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

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

Issue 2926013002: Support explicit pools in actions (Closed)
Patch Set: Update reference Created 3 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
(...skipping 715 matching lines...) Expand 10 before | Expand all | Expand 10 after
726 R"*(pool: Defines a pool object. 726 R"*(pool: Defines a pool object.
727 727
728 Pool objects can be applied to a tool to limit the parallelism of the 728 Pool objects can be applied to a tool to limit the parallelism of the
729 build. This object has a single property "depth" corresponding to 729 build. This object has a single property "depth" corresponding to
730 the number of tasks that may run simultaneously. 730 the number of tasks that may run simultaneously.
731 731
732 As the file containing the pool definition may be executed in the 732 As the file containing the pool definition may be executed in the
733 context of more than one toolchain it is recommended to specify an 733 context of more than one toolchain it is recommended to specify an
734 explicit toolchain when defining and referencing a pool. 734 explicit toolchain when defining and referencing a pool.
735 735
736 A pool marked "console = true" will use the built-in ninja "console"
737 pool and cannot specify "depth" which is always 1.
738
736 A pool is referenced by its label just like a target. 739 A pool is referenced by its label just like a target.
737 740
738 Variables 741 Variables
739 742
740 depth* 743 console, depth*
741 * = required 744 * = required
742 745
743 Example 746 Example
744 747
745 if (current_toolchain == default_toolchain) { 748 if (current_toolchain == default_toolchain) {
746 pool("link_pool") { 749 pool("link_pool") {
747 depth = 1 750 depth = 1
748 } 751 }
749 } 752 }
750 753
(...skipping 17 matching lines...) Expand all
768 771
769 if (!EnsureSingleStringArg(function, args, err) || 772 if (!EnsureSingleStringArg(function, args, err) ||
770 !EnsureNotProcessingImport(function, scope, err)) 773 !EnsureNotProcessingImport(function, scope, err))
771 return Value(); 774 return Value();
772 775
773 Label label(MakeLabelForScope(scope, function, args[0].string_value())); 776 Label label(MakeLabelForScope(scope, function, args[0].string_value()));
774 777
775 if (g_scheduler->verbose_logging()) 778 if (g_scheduler->verbose_logging())
776 g_scheduler->Log("Defining pool", label.GetUserVisibleName(true)); 779 g_scheduler->Log("Defining pool", label.GetUserVisibleName(true));
777 780
778 // Get the pool depth. It is an error to define a pool without a depth, 781 // Create the new pool.
779 // so check first for the presence of the value. 782 std::unique_ptr<Pool> pool(new Pool(scope->settings(), label));
780 const Value* depth = scope->GetValue(kDepth, true); 783
781 if (!depth) { 784 // Check the value of console.
782 *err = Err(function, "Can't define a pool without depth."); 785 const Value* console = scope->GetValue(variables::kConsole, true);
783 return Value(); 786 if (console) {
787 if (!console->VerifyTypeIs(Value::BOOLEAN, err))
788 return Value();
784 } 789 }
785 790
786 if (!depth->VerifyTypeIs(Value::INTEGER, err)) 791 // Get the pool depth. Pool must hae a depth or be a console pool.
787 return Value(); 792 const Value* depth = scope->GetValue(kDepth, true);
793 if (console && console->boolean_value()) {
794 if (depth) {
795 *err = Err(function, "Can't define a console pool with depth.");
796 return Value();
797 }
788 798
789 if (depth->int_value() < 0) { 799 pool->set_console(console->boolean_value());
790 *err = Err(function, "depth must be positive or nul."); 800 } else {
791 return Value(); 801 if (!depth) {
802 *err = Err(function, "Can't define a pool without depth.");
803 return Value();
804 }
805
806 if (!depth->VerifyTypeIs(Value::INTEGER, err))
807 return Value();
808
809 if (depth->int_value() < 0) {
810 *err = Err(function, "depth must be positive or nul.");
811 return Value();
812 }
813
814 pool->set_depth(depth->int_value());
792 } 815 }
793 816
794 // Create the new pool.
795 std::unique_ptr<Pool> pool(new Pool(scope->settings(), label));
796 pool->set_depth(depth->int_value());
797
798 // Save the generated item. 817 // Save the generated item.
799 Scope::ItemVector* collector = scope->GetItemCollector(); 818 Scope::ItemVector* collector = scope->GetItemCollector();
800 if (!collector) { 819 if (!collector) {
801 *err = Err(function, "Can't define a pool in this context."); 820 *err = Err(function, "Can't define a pool in this context.");
802 return Value(); 821 return Value();
803 } 822 }
804 collector->push_back(pool.release()); 823 collector->push_back(pool.release());
805 824
806 return Value(); 825 return Value();
807 } 826 }
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after
1137 } 1156 }
1138 1157
1139 // Otherwise it's a no-block function. 1158 // Otherwise it's a no-block function.
1140 if (!VerifyNoBlockForFunctionCall(function, block, err)) 1159 if (!VerifyNoBlockForFunctionCall(function, block, err))
1141 return Value(); 1160 return Value();
1142 return found_function->second.no_block_runner(scope, function, 1161 return found_function->second.no_block_runner(scope, function,
1143 args.list_value(), err); 1162 args.list_value(), err);
1144 } 1163 }
1145 1164
1146 } // namespace functions 1165 } // namespace functions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698