GN Reference about inputs for actions:
For action and action_foreach targets, inputs should be the inputs to script that don't vary. These should be all .py files that the script uses via imports (the main script itself will be an implicit dependency of the action so need not be listed).
For action targets, inputs and sources are treated the same, but from a style perspective, it's recommended to follow the same rule as action_foreach and put helper files in the inputs, and the data used by the script (if any) in sources.
Note that another way to declare input dependencies from an action is to have the action write a depfile (see "gn help depfile"). This allows the script to dynamically write input dependencies, that might not be known until actually executing the script. This is more efficient than doing processing while running GN to determine the inputs, and is easier to keep in-sync than hardcoding the list.
In my case one of inputs is optional, so I want to add it to the list only if it exists. I don't see a way to test for this in GN itself. I can use depfiles, but is this the only option?