Home | History | Annotate | Download | only in win
      1 # Copyright 2015 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 assert(is_win, "This only runs on Windows.")
      6 
      7 # Runs mc.exe over a list of sources. The outputs (a header and rc file) are
      8 # placed in the target gen dir, and compiled.
      9 #
     10 # sources
     11 #   List of message files to process.
     12 #
     13 # user_mode_logging (optional bool)
     14 #   Generates user-mode logging code. Defaults to false (no logging code).
     15 #
     16 # compile_generated_code (optional, deafults = true)
     17 #   If unset or true, the generated code will be compiled and linked into
     18 #   targets that depend on it. If set to false, the .h and .rc files will only
     19 #   be generated.
     20 #
     21 # deps, public_deps, visibility
     22 #   Normal meaning.
     23 template("message_compiler") {
     24   if (defined(invoker.compile_generated_code) &&
     25       !invoker.compile_generated_code) {
     26     compile_generated_code = false
     27     action_name = target_name
     28   } else {
     29     compile_generated_code = true
     30     action_name = "${target_name}_mc"
     31     source_set_name = target_name
     32   }
     33 
     34   action_foreach(action_name) {
     35     if (compile_generated_code) {
     36       visibility = [ ":$source_set_name" ]
     37     } else {
     38       forward_variables_from(invoker, [ "visibility" ])
     39     }
     40 
     41     script = "//build/win/message_compiler.py"
     42 
     43     outputs = [
     44       "$target_gen_dir/{{source_name_part}}.h",
     45       "$target_gen_dir/{{source_name_part}}.rc",
     46     ]
     47 
     48     args = [
     49       # The first argument is the environment file saved to the build
     50       # directory. This is required because the Windows toolchain setup saves
     51       # the VC paths and such so that running "mc.exe" will work with the
     52       # configured toolchain. This file is in the root build dir.
     53       "environment.$current_cpu",
     54 
     55       # Where to put the header.
     56       "-h",
     57       rebase_path(target_gen_dir, root_build_dir),
     58 
     59       # Where to put the .rc file.
     60       "-r",
     61       rebase_path(target_gen_dir, root_build_dir),
     62 
     63       # Input is Unicode.
     64       "-u",
     65     ]
     66     if (defined(invoker.user_mode_logging) && invoker.user_mode_logging) {
     67       args += [ "-um" ]
     68     }
     69     args += [ "{{source}}" ]
     70 
     71     forward_variables_from(invoker,
     72                            [
     73                              "deps",
     74                              "public_deps",
     75                              "sources",
     76                            ])
     77   }
     78 
     79   if (compile_generated_code) {
     80     # Compile the generated rc file.
     81     source_set(source_set_name) {
     82       forward_variables_from(invoker, [ "visibility" ])
     83       sources = get_target_outputs(":$action_name")
     84       deps = [
     85         ":$action_name",
     86       ]
     87     }
     88   }
     89 }
     90