From: Andrew Boyarshin Subject: [PATCH] widl: Add an option to specify wpp temporary files folder Message-Id: <20210208150218.21-1-andrew.boyarshin@gmail.com> Date: Mon, 8 Feb 2021 22:02:18 +0700 All 3 usages of mkstemps now respect a new option that enables customizing temporary files root. This is useful in build systems, where it can simplify running widl using relative paths without polluting source directories. The behavior when a new option is not specified is identical to the one before the patch. Also added a way to identify failing mkstemps by using specialized log messages for each call to mkstemps. Signed-off-by: Andrew Boyarshin --- tools/widl/parser.l | 33 +++++++++++++++++++++++++++++---- tools/widl/widl.c | 25 ++++++++++++++++++++++--- tools/widl/widl.h | 1 + 3 files changed, 52 insertions(+), 7 deletions(-) diff --git a/tools/widl/parser.l b/tools/widl/parser.l index 7e20d30e7f08..2b8389dbd4a7 100644 --- a/tools/widl/parser.l +++ b/tools/widl/parser.l @@ -531,6 +531,7 @@ int do_import(char *fname) struct imports *import; int ptr = import_stack_ptr; int ret, fd; + char* base_fname = dup_basename(fname, ".idl"); import = first_import; while (import && strcmp(import->name, fname)) @@ -559,9 +560,22 @@ int do_import(char *fname) input_name = path; line_number = 1; - name = xstrdup( "widl.XXXXXX" ); + name = xmalloc( (temp_dir_name ? strlen(temp_dir_name) : 0) + strlen(base_fname) + 15); + + if (temp_dir_name) + { + strcpy( name, temp_dir_name ); + strcat( name, base_fname ); + } + else + { + strcpy( name, base_fname ); + } + + strcat( name, "_import.XXXXXX" ); + if((fd = mkstemps( name, 0 )) == -1) - error("Could not generate a temp name from %s\n", name); + error("Could not generate an import temp name from %s\n", name); temp_name = name; if (!(f = fdopen(fd, "wt"))) @@ -600,9 +614,20 @@ static void switch_to_acf(void) acf_name = NULL; line_number = 1; - name = xstrdup( "widl.XXXXXX" ); + name = xmalloc( (temp_dir_name ? strlen(temp_dir_name) : 0) + 16 ); + + if (temp_dir_name) + { + strcpy( name, temp_dir_name ); + strcat( name, "widl_acf.XXXXXX" ); + } + else + { + strcpy( name, "widl_acf.XXXXXX" ); + } + if((fd = mkstemps( name, 0 )) == -1) - error("Could not generate a temp name from %s\n", name); + error("Could not generate an ACF temp name from %s\n", name); temp_name = name; if (!(f = fdopen(fd, "wt"))) diff --git a/tools/widl/widl.c b/tools/widl/widl.c index 333351bc11bc..ebc55e1864df 100644 --- a/tools/widl/widl.c +++ b/tools/widl/widl.c @@ -74,6 +74,7 @@ static const char usage[] = " --sysroot=DIR Prefix include paths with DIR\n" " -s Generate server stub\n" " -t Generate typelib\n" +" --tmp=dir Path to the directory for WPP temporary files\n" " -u Generate interface identifiers file\n" " -V Print version and exit\n" " -W Enable pedantic warnings\n" @@ -151,6 +152,7 @@ char *temp_name; const char *prefix_client = ""; const char *prefix_server = ""; static const char *includedir; +char *temp_dir_name; int line_number = 1; @@ -176,6 +178,7 @@ enum { RT_OPTION, ROBUST_OPTION, SYSROOT_OPTION, + TMP_WPP_OPTION, WIN32_OPTION, WIN64_OPTION, WIN32_ALIGN_OPTION, @@ -201,6 +204,7 @@ static const struct option long_options[] = { { "robust", 0, NULL, ROBUST_OPTION }, { "sysroot", 1, NULL, SYSROOT_OPTION }, { "target", 0, NULL, 'b' }, + { "tmp", 1, NULL, TMP_WPP_OPTION }, { "winrt", 0, NULL, RT_OPTION }, { "win32", 0, NULL, WIN32_OPTION }, { "win64", 0, NULL, WIN64_OPTION }, @@ -647,6 +651,9 @@ int main(int argc,char *argv[]) case SYSROOT_OPTION: sysroot = xstrdup(optarg); break; + case TMP_WPP_OPTION: + temp_dir_name = xstrdup(optarg); + break; case WIN32_OPTION: pointer_size = 4; break; @@ -928,13 +935,25 @@ int main(int argc,char *argv[]) { FILE *output; int fd; - char *name = xmalloc( strlen(header_name) + 8 ); + char* base_input_name = dup_basename(input_name, ".idl"); + char *name = xmalloc( (temp_dir_name ? strlen(temp_dir_name) : 0) + strlen(base_input_name) + 8 ); + + if (temp_dir_name) + { + strcpy( name, temp_dir_name ); + strcat( name, base_input_name ); + } + else + { + strcpy( name, base_input_name ); + } - strcpy( name, header_name ); strcat( name, ".XXXXXX" ); + free(base_input_name); + if ((fd = mkstemps( name, 0 )) == -1) - error("Could not generate a temp name from %s\n", name); + error("Could not generate a root temp name from %s\n", name); temp_name = name; if (!(output = fdopen(fd, "wt"))) diff --git a/tools/widl/widl.h b/tools/widl/widl.h index 4f4252e3ea3a..f35c54210c6c 100644 --- a/tools/widl/widl.h +++ b/tools/widl/widl.h @@ -66,6 +66,7 @@ extern char *server_name; extern char *server_token; extern char *regscript_name; extern char *regscript_token; +extern char *temp_dir_name; extern const char *prefix_client; extern const char *prefix_server; extern unsigned int pointer_size; -- 2.30.0.windows.1