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

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

Issue 1752033002: Add "create_bundle" target in order to support bundle with gn. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@gn-bundle-data
Patch Set: Add unit tests, address comments, update docs and format with clang-format Created 4 years, 9 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.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 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 BlockNode* block, 240 BlockNode* block,
241 Err* err) { 241 Err* err) {
242 return ExecuteGenericTarget(functions::kActionForEach, scope, function, args, 242 return ExecuteGenericTarget(functions::kActionForEach, scope, function, args,
243 block, err); 243 block, err);
244 } 244 }
245 245
246 // bundle_data ----------------------------------------------------------------- 246 // bundle_data -----------------------------------------------------------------
247 247
248 const char kBundleData[] = "bundle_data"; 248 const char kBundleData[] = "bundle_data";
249 const char kBundleData_HelpShort[] = 249 const char kBundleData_HelpShort[] =
250 "bundle_data: Declare a target without output."; 250 "bundle_data: [iOS/OS X] Declare a target without output.";
251 const char kBundleData_Help[] = 251 const char kBundleData_Help[] =
252 "bundle_data: Declare a target without output.\n" 252 "bundle_data: [iOS/OS X] Declare a target without output.\n"
253 "\n" 253 "\n"
254 " This target type allows to declare data that is required at runtime.\n" 254 " This target type allows to declare data that is required at runtime.\n"
255 " It is used to inform \"create_bundle\" targets of the files to copy\n" 255 " It is used to inform \"create_bundle\" targets of the files to copy\n"
256 " into generated bundle, see \"gn help create_bundle\" for help.\n"; 256 " into generated bundle, see \"gn help create_bundle\" for help.\n"
257 "\n"
258 " The target must define a list of files as \"sources\" and a single\n"
259 " \"outputs\". If there are multiple files, source expansions must be\n"
260 " used to express the output. The output must reference a file inside\n"
261 " of {{bundle_root_dir}}.\n"
262 "\n"
263 " This target can be used on all platforms though it is designed only to\n"
264 " generate iOS/OS X bundle. In cross-platform projects, it is advised to\n"
265 " put it behind iOS/Mac conditionals.\n"
266 "\n"
267 " See \"gn help create_bundle\" for more information.\n"
268 "\n"
269 "Variables\n"
270 "\n"
271 " sources*, outputs*, deps, data_deps, public_deps, visibility\n"
272 " * = required\n"
273 "\n"
274 "Examples\n"
275 "\n"
276 " bundle_data(\"icudata\") {\n"
277 " sources = [ \"sources/data/in/icudtl.dat\" ]\n"
278 " outputs = [ \"{{bundle_resources_dir}}/{{source_file_part}}\" ]\n"
279 " }\n"
280 "\n"
281 " bundle_data(\"base_unittests_bundle_data]\") {\n"
282 " sources = [ \"test/data\" ]\n"
283 " outputs = [\n"
284 " \"{{bundle_resources_dir}}/{{source_root_relative_dir}}/\" +\n"
285 " \"{{source_file_part}}\"\n"
286 " ]\n"
287 " }\n"
288 "\n"
289 " bundle_data(\"material_typography_bundle_data\") {\n"
290 " sources = [\n"
291 " \"src/MaterialTypography.bundle/Roboto-Bold.ttf\",\n"
292 " \"src/MaterialTypography.bundle/Roboto-Italic.ttf\",\n"
293 " \"src/MaterialTypography.bundle/Roboto-Regular.ttf\",\n"
294 " \"src/MaterialTypography.bundle/Roboto-Thin.ttf\",\n"
295 " ]\n"
296 " outputs = [\n"
297 " \"{{bundle_resources_dir}}/MaterialTypography.bundle/\"\n"
298 " \"{{source_file_part}}\"\n"
299 " ]\n"
300 " }\n";
257 301
258 Value RunBundleData(Scope* scope, 302 Value RunBundleData(Scope* scope,
259 const FunctionCallNode* function, 303 const FunctionCallNode* function,
260 const std::vector<Value>& args, 304 const std::vector<Value>& args,
261 BlockNode* block, 305 BlockNode* block,
262 Err* err) { 306 Err* err) {
263 return ExecuteGenericTarget(functions::kBundleData, scope, function, args, 307 return ExecuteGenericTarget(functions::kBundleData, scope, function, args,
264 block, err); 308 block, err);
265 } 309 }
266 310
311 // create_bundle ---------------------------------------------------------------
312
313 const char kCreateBundle[] = "create_bundle";
314 const char kCreateBundle_HelpShort[] =
315 "create_bundle: [iOS/OS X] Build an OS X / iOS bundle.";
316 const char kCreateBundle_Help[] =
317 "create_bundle: [iOS/OS X] Build an OS X / iOS bundle.\n"
318 "\n"
319 " This target generates an iOS/OS X bundle (which is a directory with a\n"
320 " well-know structure). This target does not define any sources, instead\n"
321 " they are computed from all \"bundle_data\" target this one depends on\n"
322 " transitively (the recursion stops at \"create_bundle\" targets).\n"
323 "\n"
324 " The \"bundle_*_dir\" properties must be defined. They will be used for\n"
325 " the expansion of {{bundle_*_dir}} rules in \"bundle_data\" outputs.\n"
326 "\n"
327 " This target can be used on all platforms though it is designed only to\n"
328 " generate iOS/OS X bundle. In cross-platform projects, it is advised to\n"
329 " put it behind iOS/Mac conditionals.\n"
330 "\n"
331 "Variables\n"
332 "\n"
333 " bundle_root_dir*, bundle_resources_dir*, bundle_executable_dir*,\n"
334 " bundle_plugins_dir*, deps, data_deps, public_deps, visibility\n"
335 " * = required\n"
336 "\n"
337 "Example\n"
338 "\n"
339 " # Defines a template to create an application. On most platform, this\n"
340 " # is just an alias for an \"executable\" target, but on iOS/OS X, it\n"
341 " # builds an application bundle.\n"
342 " template(\"app\") {\n"
343 " if (!is_ios && !is_mac) {\n"
344 " executable(target_name) {\n"
345 " forward_variables_from(invoker, \"*\")\n"
346 " }\n"
347 " } else {\n"
348 " app_name = target_name\n"
349 " gen_path = target_gen_dir\n"
350 "\n"
351 " action(\"${app_name}_generate_info_plist\") {\n"
352 " script = [ \"//build/ios/ios_gen_plist.py\" ]\n"
353 " sources = [ \"templates/Info.plist\" ]\n"
354 " outputs = [ \"$gen_path/Info.plist\" ]\n"
355 " args = rebase_path(sources, root_build_dir) +\n"
356 " rebase_path(outputs, root_build_dir)\n"
357 " }\n"
358 "\n"
359 " bundle_data(\"${app_name}_bundle_info_plist\") {\n"
360 " deps = [ \":${app_name}_generate_info_plist\" ]\n"
361 " sources = [ \"$gen_path/Info.plist\" ]\n"
362 " outputs = [ \"{{bundle_root_dir}}/Info.plist\" ]\n"
363 " }\n"
364 "\n"
365 " executable(\"${app_name}_generate_executable\") {\n"
366 " forward_variables_from(invoker, \"*\", [\n"
367 " \"output_name\",\n"
368 " \"visibility\",\n"
369 " ])\n"
370 " output_name =\n"
371 " rebase_path(\"$gen_path/$app_name\", root_build_dir)\n"
372 " }\n"
373 "\n"
374 " bundle_data(\"${app_name}_bundle_executable\") {\n"
375 " deps = [ \":${app_name}_generate_executable\" ]\n"
376 " sources = [ \"$gen_path/$app_name\" ]\n"
377 " outputs = [ \"{{bundle_executable_dir}}/$app_name\" ]\n"
378 " }\n"
379 "\n"
380 " create_bundle(\"${app_name}.app\") {\n"
381 " deps = [\n"
382 " \":${app_name}_bundle_executable\",\n"
383 " \":${app_name}_bundle_info_plist\",\n"
384 " ]\n"
385 " if (is_ios) {\n"
386 " bundle_root_dir = \"${root_build_dir}/$target_name\"\n"
387 " bundle_resources_dir = bundle_root_dir\n"
388 " bundle_executable_dir = bundle_root_dir\n"
389 " bundle_plugins_dir = bundle_root_dir + \"/Plugins\"\n"
390 " } else {\n"
391 " bundle_root_dir = \"${root_build_dir}/target_name/Contents\"\n"
392 " bundle_resources_dir = bundle_root_dir + \"/Resources\"\n"
393 " bundle_executable_dir = bundle_root_dir + \"/MacOS\"\n"
394 " bundle_plugins_dir = bundle_root_dir + \"/Plugins\"\n"
395 " }\n"
396 " }\n"
397 "\n"
398 " group(target_name) {\n"
399 " forward_variables_from(invoker, [\"visibility\"])\n"
400 " deps = [ \":${app_name}.app\" ]\n"
401 " }\n"
402 " }\n"
403 " }\n";
404
405 Value RunCreateBundle(Scope* scope,
406 const FunctionCallNode* function,
407 const std::vector<Value>& args,
408 BlockNode* block,
409 Err* err) {
410 return ExecuteGenericTarget(functions::kCreateBundle, scope, function, args,
411 block, err);
412 }
413
267 // copy ------------------------------------------------------------------------ 414 // copy ------------------------------------------------------------------------
268 415
269 const char kCopy[] = "copy"; 416 const char kCopy[] = "copy";
270 const char kCopy_HelpShort[] = 417 const char kCopy_HelpShort[] =
271 "copy: Declare a target that copies files."; 418 "copy: Declare a target that copies files.";
272 const char kCopy_Help[] = 419 const char kCopy_Help[] =
273 "copy: Declare a target that copies files.\n" 420 "copy: Declare a target that copies files.\n"
274 "\n" 421 "\n"
275 "File name handling\n" 422 "File name handling\n"
276 "\n" 423 "\n"
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after
578 const Template* templ = scope->GetTemplate(target_type); 725 const Template* templ = scope->GetTemplate(target_type);
579 if (templ) 726 if (templ)
580 return templ->Invoke(scope, function, sub_args, block, err); 727 return templ->Invoke(scope, function, sub_args, block, err);
581 728
582 // Otherwise, assume the target is a built-in target type. 729 // Otherwise, assume the target is a built-in target type.
583 return ExecuteGenericTarget(target_type.c_str(), scope, function, sub_args, 730 return ExecuteGenericTarget(target_type.c_str(), scope, function, sub_args,
584 block, err); 731 block, err);
585 } 732 }
586 733
587 } // namespace functions 734 } // 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