Search code examples
google-chromechromiumbuild-toolsgn

How to override variable value for GN target/template?


I've added shared_library GN target in my Chromium build. It has an extension according to defined in toolchain.gnirules:

# Extension for shared library files (including leading dot).
if (is_mac || is_ios) {
  shlib_extension = ".dylib"
} else if (is_android && is_component_build) {
  # By appending .cr, we prevent name collisions with libraries already
  # loaded by the Android zygote.
  shlib_extension = ".cr.so"
} else if (is_posix) {
  shlib_extension = ".so"
} else if (is_win) {
  shlib_extension = ".dll"
} else {
  assert(false, "Platform not supported")
}

# Prefix for shared library files.
if (is_posix) {
  shlib_prefix = "lib"
} else {
  shlib_prefix = ""
}

I want to change an extension so i need to override shlib_extension variable but only for my shared_library target. If i modify toolchain.gni it will affects all targets that use shlib_extension variable.

I'd like not to use output_name shared_library attribute as i can see using out_name="lib${target_name}.cr" makes the following v8.ninja:

...
output_extension = .so
output_dir = .
solibs = ./libv8_libbase.cr.so

but if having shlib_ext=".cr.so" makes the following v8.ninja:

...
output_extension = .cr.so
output_dir = .
solibs = ./libicui18n.cr.so ./libicuuc.cr.so ./libv8_libbase.cr.so

(it means output_name changes file name, not extension)

As logical continuation of the question is it possible to override variables like is_debug or is_component_build not in .gn file but for target/template only?

Let's say i want to build V8 just like is_component_build=true (and do it in v8.gni in templaets) but the rest code taking default or user-defined variable value.


Solution

  • In my case adding output_extension worked for me:

    shared_library(target_name) {
      output_extension = "cr.so"
      ...
    }
    

    Not sure about general case of overriding variables.