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

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 and fix documentation 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
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 patterns can be used.\n"
brettw 2016/03/07 21:57:30 "If there are multiple files, source patterns can
sdefresne 2016/03/08 14:33:31 Done.
260 " All the output path needs to be relative to {{bundle_root_dir}}.\n"
brettw 2016/03/07 21:57:30 This should either say "the output is treated as r
sdefresne 2016/03/08 14:33:30 Done.
261 "\n"
262 " This target can be used on all platforms though it is designed only to\n"
263 " generate iOS/OS X bundle. It is advised to put it behind \"is_ios\" or\n"
264 " \"is_mac\" tests.\n"
265 "\n"
266 " See \"gn help create_bundle\" for more information.\n"
267 "\n"
268 "Variables\n"
269 "\n"
270 " sources*, outputs*, deps, data_deps, public_deps, visibility\n"
271 " * = required\n"
272 "\n"
273 "Examples\n"
274 "\n"
275 " bundle_data(\"icudata\") {\n"
276 " sources = [ \"sources/data/in/icudtl.dat\" ]\n"
277 " outputs = [ \"{{bundle_resources_dir}}/{{source_file_part}}\" ]\n"
278 " }\n"
279 "\n"
280 " bundle_data(\"base_unittests_bundle_data]\") {\n"
281 " sources = [ \"test/data\" ]\n"
282 " outputs = [\n"
283 " \"{{bundle_resources_dir}}/{{source_root_relative_dir}}/\" +\n"
284 " \"{{source_file_part}}\"\n"
285 " ]\n"
286 " }\n"
287 "\n"
288 " bundle_data(\"material_typography_bundle_data\") {\n"
289 " sources = [\n"
290 " \"src/MaterialTypography.bundle/Roboto-Black.ttf\",\n"
291 " \"src/MaterialTypography.bundle/Roboto-BlackItalic.ttf\",\n"
brettw 2016/03/07 21:57:30 I think 2-4 ttf files should be enough for this ex
sdefresne 2016/03/08 14:33:31 Ack.
292 " \"src/MaterialTypography.bundle/Roboto-Bold.ttf\",\n"
293 " \"src/MaterialTypography.bundle/Roboto-BoldItalic.ttf\",\n"
294 " \"src/MaterialTypography.bundle/Roboto-Italic.ttf\",\n"
295 " \"src/MaterialTypography.bundle/Roboto-Light.ttf\",\n"
296 " \"src/MaterialTypography.bundle/Roboto-LightItalic.ttf\",\n"
297 " \"src/MaterialTypography.bundle/Roboto-Medium.ttf\",\n"
298 " \"src/MaterialTypography.bundle/Roboto-MediumItalic.ttf\",\n"
299 " \"src/MaterialTypography.bundle/Roboto-Regular.ttf\",\n"
300 " \"src/MaterialTypography.bundle/Roboto-Thin.ttf\",\n"
301 " \"src/MaterialTypography.bundle/Roboto-ThinItalic.ttf\",\n"
302 " ]\n"
303 " outputs = [\n"
304 " \"{{bundle_resources_dir}}/MaterialTypography.bundle/\"\n"
305 " \"{{source_file_part}}\"\n"
306 " ]\n"
307 " }\n";
257 308
258 Value RunBundleData(Scope* scope, 309 Value RunBundleData(Scope* scope,
259 const FunctionCallNode* function, 310 const FunctionCallNode* function,
260 const std::vector<Value>& args, 311 const std::vector<Value>& args,
261 BlockNode* block, 312 BlockNode* block,
262 Err* err) { 313 Err* err) {
263 return ExecuteGenericTarget(functions::kBundleData, scope, function, args, 314 return ExecuteGenericTarget(functions::kBundleData, scope, function, args,
264 block, err); 315 block, err);
265 } 316 }
266 317
318 // create_bundle ---------------------------------------------------------------
319
320 const char kCreateBundle[] = "create_bundle";
321 const char kCreateBundle_HelpShort[] =
322 "create_bundle: [iOS/OS X] Build an OS X / iOS bundle.";
323 const char kCreateBundle_Help[] =
324 "create_bundle: [iOS/OS X] Build an OS X / iOS bundle.\n"
325 "\n"
326 " This target generates an iOS/OS X bundle (which is a directory with a\n"
327 " well know structure). This target does not define any sources, instead\n"
brettw 2016/03/07 21:57:30 "well know" -> "well-known"
sdefresne 2016/03/08 14:33:30 Done.
328 " they are computed from all \"bundle_data\" target this one depends on\n"
329 " transitively (the recursion stops at each \"create_bundle\" targets).\n"
brettw 2016/03/07 21:57:30 Remove "each"
sdefresne 2016/03/08 14:33:31 Done.
330 "\n"
331 " This target needs to define the value used for the expansion of the\n"
brettw 2016/03/07 21:57:30 Can you express this a different way? I found this
sdefresne 2016/03/08 14:33:30 Is it better now?
332 " patterns used in \"bundle_data\" target via the property with the same\n"
333 " name, i.e. \"bundle_root_dir\" correspond to {{bundle_root_dir}}, etc.\n"
334 "\n"
335 " This target can be used on all platforms though it is designed only to\n"
336 " generate iOS/OS X bundle. It is advised to put it behind \"is_ios\" or\n"
brettw 2016/03/07 21:57:30 is_ios and is_mac aren't built-in variables (they'
sdefresne 2016/03/08 14:33:30 Done.
337 " \"is_mac\" tests.\n"
338 "\n"
339 "Variables\n"
340 "\n"
341 " bundle_root_dir*, bundle_resources_dir*, bundle_executable_dir*,\n"
342 " bundle_plugins_dir*, deps, data_deps, public_deps, visibility\n"
343 " * = required\n"
344 "\n"
345 "Example\n"
346 "\n"
347 " # Defines a template to create an application. On most platform, this\n"
348 " # is just an alias for an \"executable\" target, but on iOS/OS X, it\n"
349 " # builds an application bundle.\n"
350 " template(\"app\") {\n"
351 " if (!is_ios && !is_mac) {\n"
352 " executable(target_name) {\n"
353 " forward_variables_from(invoker, \"*\")\n"
354 " }\n"
355 " } else {\n"
356 " app_name = target_name\n"
357 " gen_path = target_gen_dir\n"
358 "\n"
359 " action(\"${app_name}_generate_info_plist\") {\n"
360 " script = [ \"//build/ios/ios_gen_plist.py\" ]\n"
361 " sources = [ \"templates/Info.plist\" ]\n"
362 " outputs = [ \"$gen_path/Info.plist\" ]\n"
363 " args = rebase_path(sources, root_build_dir) +\n"
364 " rebase_path(outputs, root_build_dir)\n"
365 " }\n"
366 "\n"
367 " bundle_data(\"${app_name}_bundle_info_plist\") {\n"
368 " deps = [ \":${app_name}_generate_info_plist\" ]\n"
369 " sources = [ \"$gen_path/Info.plist\" ]\n"
370 " outputs = [ \"{{bundle_root_dir}}/Info.plist\" ]\n"
371 " }\n"
372 "\n"
373 " executable(\"${app_name}_generate_executable\") {\n"
374 " forward_variables_from(invoker, \"*\", [\n"
375 " \"output_name\",\n"
376 " \"visibility\",\n"
377 " ])\n"
378 " output_name =\n"
379 " rebase_path(\"$gen_path/$app_name\", root_build_dir)\n"
380 " }\n"
381 "\n"
382 " bundle_data(\"${app_name}_bundle_executable\") {\n"
383 " deps = [ \":${app_name}_generate_executable\" ]\n"
384 " sources = [ \"$gen_path/$app_name\" ]\n"
385 " outputs = [ \"{{bundle_executable_dir}}/$app_name\" ]\n"
386 " }\n"
387 "\n"
388 " create_bundle(\"${app_name}.app\") {\n"
389 " deps = [\n"
390 " \":${app_name}_bundle_executable\",\n"
391 " \":${app_name}_bundle_info_plist\",\n"
392 " ]\n"
393 " if (is_ios) {\n"
394 " bundle_root_dir = \"${root_build_dir}/$target_name\"\n"
395 " bundle_resources_dir = bundle_root_dir\n"
396 " bundle_executable_dir = bundle_root_dir\n"
397 " bundle_plugins_dir = bundle_root_dir + \"/Plugins\"\n"
398 " } else {\n"
399 " bundle_root_dir = \"${root_build_dir}/target_name/Contents\"\n"
400 " bundle_resources_dir = bundle_root_dir + \"/Resources\"\n"
401 " bundle_executable_dir = bundle_root_dir + \"/MacOS\"\n"
402 " bundle_plugins_dir = bundle_root_dir + \"/Plugins\"\n"
403 " }\n"
404 " }\n"
405 "\n"
406 " group(target_name) {\n"
407 " forward_variables_from(invoker, [\"visibility\"])\n"
408 " deps = [ \":${app_name}.app\" ]\n"
409 " }\n"
410 " }\n"
411 " }\n"
412 "\n";
413
414 Value RunCreateBundle(Scope* scope,
415 const FunctionCallNode* function,
416 const std::vector<Value>& args,
417 BlockNode* block,
418 Err* err) {
419 return ExecuteGenericTarget(functions::kCreateBundle, scope, function, args,
420 block, err);
421 }
422
267 // copy ------------------------------------------------------------------------ 423 // copy ------------------------------------------------------------------------
268 424
269 const char kCopy[] = "copy"; 425 const char kCopy[] = "copy";
270 const char kCopy_HelpShort[] = 426 const char kCopy_HelpShort[] =
271 "copy: Declare a target that copies files."; 427 "copy: Declare a target that copies files.";
272 const char kCopy_Help[] = 428 const char kCopy_Help[] =
273 "copy: Declare a target that copies files.\n" 429 "copy: Declare a target that copies files.\n"
274 "\n" 430 "\n"
275 "File name handling\n" 431 "File name handling\n"
276 "\n" 432 "\n"
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after
578 const Template* templ = scope->GetTemplate(target_type); 734 const Template* templ = scope->GetTemplate(target_type);
579 if (templ) 735 if (templ)
580 return templ->Invoke(scope, function, sub_args, block, err); 736 return templ->Invoke(scope, function, sub_args, block, err);
581 737
582 // Otherwise, assume the target is a built-in target type. 738 // Otherwise, assume the target is a built-in target type.
583 return ExecuteGenericTarget(target_type.c_str(), scope, function, sub_args, 739 return ExecuteGenericTarget(target_type.c_str(), scope, function, sub_args,
584 block, err); 740 block, err);
585 } 741 }
586 742
587 } // namespace functions 743 } // namespace functions
OLDNEW
« tools/gn/function_toolchain.cc ('K') | « tools/gn/functions.cc ('k') | tools/gn/gn.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698