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 3# found in the LICENSE file. 4 5# Instantiate grit. This will produce a script target to run grit, and a 6# static library that compiles the .cc files. 7# 8# Example: 9# grit("my_resources") { 10# source = "myfile.grd" # source is required. 11# grit_flags = [ "-E", "foo=bar" ] # Optional extra flags. 12# # You can also put deps here if the grit source depends on generated 13# # files. 14# } 15template("grit") { 16 assert(defined(source), 17 "\"source\" must be defined for the grit template $target_name") 18 assert(!defined(sources) && !defined(outputs), 19 "Neither \"sources\" nor \"outputs\" can be defined for the grit " + 20 "template $target_name") 21 22 grit_info_script = "//tools/grit/grit_info.py" 23 24 # These are all passed as arguments to the script so have to be relative to 25 # the build directory. 26 resource_ids = 27 rebase_path("//tools/gritsettings/resource_ids", ".", root_build_dir) 28 output_dir = rebase_path(target_gen_dir, ".", root_build_dir) 29 source_path = rebase_path(source, ".", root_build_dir) 30 31 if (!defined(grit_flags)) { 32 grit_flags = [] # These are optional so default to empty list. 33 } 34 35 grit_inputs_build_rel = exec_script(grit_info_script, 36 [ "--inputs", source_path, "-f", resource_ids] + grit_flags, "list lines") 37 # The inputs are relative to the current (build) directory, rebase to 38 # the current one. 39 grit_inputs = rebase_path(grit_inputs_build_rel, root_build_dir, ".") 40 41 grit_outputs_build_rel = exec_script(grit_info_script, 42 [ "--outputs", "$output_dir", source_path, "-f", resource_ids ] + 43 grit_flags, 44 "list lines") 45 # The inputs are relative to the current (build) directory, rebase to 46 # the current one. 47 grit_outputs = rebase_path(grit_outputs_build_rel, root_build_dir, ".") 48 49 # The current grit setup makes an file in $target_gen_dir/grit/foo.h that 50 # the source code expects to include via "grit/foo.h". It would be nice to 51 # change this to including absolute paths relative to the root gen directory 52 # (like "mycomponent/foo.h"). This config sets up the include path. 53 grit_config = target_name + "_grit_config" 54 config(grit_config) { 55 include_dirs = [ target_gen_dir ] 56 } 57 58 grit_custom_target = target_name + "_grit" 59 custom(grit_custom_target) { 60 script = "//tools/grit/grit.py" 61 source_prereqs = grit_inputs 62 outputs = grit_outputs 63 64 # TODO(brettw) grit_defines. 65 args = [ 66 "-i", source_path, "build", 67 "-f", resource_ids, 68 "-o", output_dir, 69 ] + grit_flags 70 71 # Inherit deps from template invocation if any. 72 } 73 74 # This is the thing that people actually link with, it must be named the 75 # same as the argument the template was invoked with. 76 static_library(target_name) { 77 # Since we generate a file, we need to be run before the targets that 78 # depend on us. 79 hard_dep = true 80 sources = grit_outputs 81 82 # Deps set on the template invocation will go on the grit script running 83 # target rather than this library. 84 deps = [] 85 deps = [ ":$grit_custom_target" ] 86 direct_dependent_configs = [ ":$grit_config" ] 87 } 88} 89