I'm using gyp to generate Visual Studio projects, make files, and Xcode projects.
I would like to have a pre-build step that calls a command line tool which generates some code that I later compile in, is this possible?
Incidentally, in cmake I do it using a post build step on a project that I depend on as a kind of workaround for there being no pre build there, so a post build step would also be fine.
I can see that I can call arbitrary commands at generation time using <!()
syntax but I'd really prefer to generate the projects once and then on compile have the code generation step occur.
I got somewhere using actions...
I have this little application:
main.c
#include <stdio.h>
int main() {
#include "some_output"
return 0;
}
And this input file
some_input
printf("Hello World!\n");
And so I can fake up some, albeit Windows specific, code generation in my .gyp file like so (i.e. printing the file to standard out and redirecting back into a file, yes, silly but it illustrates the point hopefully):
gypping.gyp
{
'targets': [
{
'target_name': 'gypping',
'type': 'executable',
'sources': [
'main.c',
'<(INTERMEDIATE_DIR)/some_output',
],
'actions': [{
'action_name': 'create_something_generated',
'inputs': [
'some_input'
],
'outputs': [
'<(INTERMEDIATE_DIR)/some_output',
],
'action': ['type', '<@(_inputs)', '>', '<@(_outputs)'],
},
],
},
],
}
This seems to nearly work in so much as when I build in Visual Studio (having run gyp --depth=.
) I get the following error:
1>------ Build started: Project: gypping, Configuration: Default Win32 ------
1> create_something_generated
1> '"C:\dev\code\Sandpit\gypping\.\setup_env.bat"' is not recognized as an internal or external command,
1> operable program or batch file.
1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.CppCommon.targets(171,5): error MSB6006: "cmd.exe" exited with code 1.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
I can't find setup_env.bat
in my path.
I created an empty setup_env.bat file and I simplified the action by removing the >
(I guess the escaping goes wrong with this). Now I get this:
'bash' is not recognized as an internal or external command,
I do not have bash as I'm on Windows.
I think Gyp is finished for me then, I guess I'll stick to cmake.