[PATCH] D110019: [gn build] improve write_cmake_config to be truthy and exception friendly

yaozhongxiao via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 20 21:40:47 PDT 2021


zhongxiao.yzx added a comment.

In D110019#3009928 <https://reviews.llvm.org/D110019#3009928>, @thakis wrote:

> Can you explain the motivation behind this?
>
>> Besides, in order to substiute #cmakedefine var with value,
>> it needs to access "values[key]" which will raises a "KeyError"
>> exception if searching for a key that does not exist.
>
> That part is intentional, to make sure the list of keys passed to the script matches exactly the list of keys needed in the cmake file.

It’s more convenient to make an appointment in advance:

Taking the following example, the project needs to define the "header.h.in" with the following contents

- header.h.in *

  #cmakedefine Key-1
  #cmakedefine Key-2
  ...
  #cmakedefine Key-i
  ...
  #cmakedefine Key-j
  ...
  #cmakedefine Key-n

- write_cmake_config_key represents "the list of keys passed to the script", it's the KYE=VALUE should be provided while invoking write_cmake_config.py

  write_cmake_config.py  -o  header.h  header.h.in  ${write_cmake_config_key}

- header_key represents "the list of keys needed in the header file." which corresponds to " the list of keys needed in the cmake file"

My intents to replace "values[keys]" with "values.get()" are as follows:

1. facilitate write_cmake_config.py invoking with default values for optional keys.
-----------------------------------------------------------------------------------

There are many keys in "header.h.in",  in order to generate the "header.h",  we may only 
want to provide the values for keys those we want to overwrite the default values
rather than provide all the keys defined in "header.h.in" even if most of them are
duplicated with default values
we can invoke write_cmake_config.py  only define the Value-i, Value-j leaving other keys with default values

  write_cmake_config.py  -o  header.h  header.h.in  Key-i=Value-i  Key-j=Value-j

Yes, of course, we can provide all the values for keys defined in "header.h.in"

2.  keep compatible with  config_file in CMakeLists.txt
-------------------------------------------------------

The behaviours of config_file in the CMake build system is the same as described above.
Furthermore, with the help of "unused_values checking",  It is also guaranteed that the list
of keys passed to the script matches exactly the sub-list of keys needed in the "header.h.in"

3.  keep friendly to be integrated
----------------------------------

"write_cmake_config.py" works integrated into gn build system, the KeyError exception is
not friendly enough to be caught in gn system.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D110019/new/

https://reviews.llvm.org/D110019



More information about the llvm-commits mailing list