From f7dff29c6ce959968cb489fcbee2d3ebde0784d0 Mon Sep 17 00:00:00 2001 From: Zoltan Varga Date: Thu, 18 Apr 2019 16:41:47 -0400 Subject: [PATCH] [aot] Add a depfile= argument which causes the AOT compiler to write out a gcc style dep file listing the dependencies between the output file and all referenced assemblies. (#14124) * [aot] Add a depfile= argument which causes the AOT compiler to write out a gcc style dep file listing the dependencies between the output file and all referenced assemblies. * Add a manpage entry. * Update after comments. --- man/mono.1 | 3 +++ mono/mini/aot-compiler.c | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/man/mono.1 b/man/mono.1 index e783173c932..cf27efc72a9 100644 --- a/man/mono.1 +++ b/man/mono.1 @@ -267,6 +267,9 @@ Print the architecture the AOT in this copy of Mono targets and quit. Generates all required wrappers, so that it is possible to run --interpreter without any code generation at runtime. This option only makes sense with \fBmscorlib.dll\fR. Embedders can set +.TP +.I depfile=[filename] +Outputs a gcc -M style dependency file. .nf mono_jit_set_aot_mode (MONO_AOT_MODE_INTERP); diff --git a/mono/mini/aot-compiler.c b/mono/mini/aot-compiler.c index 886d715c30f..d03c43f2694 100644 --- a/mono/mini/aot-compiler.c +++ b/mono/mini/aot-compiler.c @@ -234,6 +234,7 @@ typedef struct MonoAotOptions { gboolean profile_only; gboolean no_opt; char *clangxx; + char *depfile; } MonoAotOptions; typedef enum { @@ -8029,6 +8030,8 @@ mono_aot_parse_options (const char *aot_options, MonoAotOptions *opts) opts->no_opt = TRUE; } else if (str_begins_with (arg, "clangxx=")) { opts->clangxx = g_strdup (arg + strlen ("clangxx=")); + } else if (str_begins_with (arg, "depfile=")) { + opts->depfile = g_strdup (arg + strlen ("depfile=")); } else if (str_begins_with (arg, "help") || str_begins_with (arg, "?")) { printf ("Supported options for --aot:\n"); printf (" asmonly\n"); @@ -8076,6 +8079,7 @@ mono_aot_parse_options (const char *aot_options, MonoAotOptions *opts) printf (" llvmopts=\n"); printf (" llvmllc=\n"); printf (" clangxx=\n"); + printf (" depfile=\n"); printf (" help/?\n"); exit (0); } else { @@ -13588,6 +13592,32 @@ print_stats (MonoAotCompile *acfg) mono_dedup_log_stats (acfg); } +static void +create_depfile (MonoAotCompile *acfg) +{ + FILE *depfile; + + // FIXME: Support other configurations + g_assert (acfg->aot_opts.llvm_only && acfg->aot_opts.asm_only && acfg->aot_opts.llvm_outfile); + + depfile = fopen (acfg->aot_opts.depfile, "w"); + g_assert (depfile); + + int ntargets = 1; + char **targets = g_new0 (char*, ntargets); + targets [0] = acfg->aot_opts.llvm_outfile; + for (int tindex = 0; tindex < ntargets; ++tindex) { + fprintf (depfile, "%s: ", targets [tindex]); + for (int i = 0; i < acfg->image_table->len; i++) { + MonoImage *image = (MonoImage*)g_ptr_array_index (acfg->image_table, i); + fprintf (depfile, " %s", image->filename); + } + fprintf (depfile, "\n"); + } + g_free (targets); + fclose (depfile); +} + static int emit_aot_image (MonoAotCompile *acfg) { @@ -13810,6 +13840,9 @@ emit_aot_image (MonoAotCompile *acfg) aot_printf (acfg, "JIT time: %d ms, Generation time: %d ms, Assembly+Link time: %d ms.\n", acfg->stats.jit_time / 1000, acfg->stats.gen_time / 1000, acfg->stats.link_time / 1000); + if (acfg->aot_opts.depfile) + create_depfile (acfg); + if (acfg->aot_opts.dump_json) aot_dump (acfg); -- 2.11.4.GIT