Skip to content

Commit c0d34aa

Browse files
authored
Call realpath before comparing coverage paths (#60088)
This commit fixes an issue where `--code-coverage=@path` does not work if `path` has any symlinks in it (which happens e.g. when testing `Pkg` in tree - ref #60058). The issue is that we call `realpath` on the cli argument, but do not currently call realpath when inserting the instrumentation. One fix would be to stop calling realpath on the cli argument, but that has the potential to break users who rely on this behavior. The other fix (implemented here) is to also call realpath when doing the comparison. However, this is a bit aweful, because, as currently structured, this requires us to do a file system query for every line table entry. Most of those line table entries will probably have the same file, so that's a lot of redundant (and depending on filesystem, potentially expensive work). That said, I think this is the best solution for the time being. At some point in the near future we need to completely overhaul all and move the filtering to the writer side (rather than during codegen), as well as making coverage cacheable and work in the interpreter. Until then, this at least helps with addressing the test failure.
1 parent 3747300 commit c0d34aa

File tree

3 files changed

+17
-11
lines changed

3 files changed

+17
-11
lines changed

src/codegen.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8898,7 +8898,12 @@ static jl_llvm_functions_t
88988898
!jl_is_submodule(mod, jl_core_module));
88998899
};
89008900
auto in_tracked_path = [] (StringRef file) { // falls within an explicitly set file or directory
8901-
return jl_options.tracked_path != NULL && file.starts_with(jl_options.tracked_path);
8901+
if (jl_options.tracked_path == NULL)
8902+
return false;
8903+
char *absfile = jl_absrealpath(file.data(), 0);
8904+
bool match = StringRef(absfile).starts_with(jl_options.tracked_path);
8905+
free(absfile);
8906+
return match;
89028907
};
89038908
bool mod_is_user_mod = in_user_mod(ctx.module);
89048909
bool mod_is_tracked = in_tracked_path(ctx.file);

src/jlapi.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1170,7 +1170,7 @@ static const char *absformat(const char *in)
11701170
return out;
11711171
}
11721172

1173-
static char *absrealpath(const char *in, int nprefix)
1173+
JL_DLLEXPORT char *jl_absrealpath(const char *in, int nprefix)
11741174
{ // compute an absolute realpath location, so that chdir doesn't change the file reference
11751175
// ignores (copies directly over) nprefix characters at the start of abspath
11761176
char *out;
@@ -1245,7 +1245,7 @@ static void jl_resolve_sysimg_location(JL_IMAGE_SEARCH rel, const char* julia_bi
12451245
jl_options.julia_bindir = julia_bindir;
12461246
}
12471247
if (jl_options.julia_bindir)
1248-
jl_options.julia_bindir = absrealpath(jl_options.julia_bindir, 0);
1248+
jl_options.julia_bindir = jl_absrealpath(jl_options.julia_bindir, 0);
12491249
free(free_path);
12501250
free_path = NULL;
12511251
if (jl_options.image_file) {
@@ -1260,33 +1260,33 @@ static void jl_resolve_sysimg_location(JL_IMAGE_SEARCH rel, const char* julia_bi
12601260
jl_options.image_file = free_path;
12611261
}
12621262
if (jl_options.image_file)
1263-
jl_options.image_file = absrealpath(jl_options.image_file, 0);
1263+
jl_options.image_file = jl_absrealpath(jl_options.image_file, 0);
12641264
if (free_path) {
12651265
free(free_path);
12661266
free_path = NULL;
12671267
}
12681268
}
12691269
if (jl_options.outputo)
1270-
jl_options.outputo = absrealpath(jl_options.outputo, 0);
1270+
jl_options.outputo = jl_absrealpath(jl_options.outputo, 0);
12711271
if (jl_options.outputji)
1272-
jl_options.outputji = absrealpath(jl_options.outputji, 0);
1272+
jl_options.outputji = jl_absrealpath(jl_options.outputji, 0);
12731273
if (jl_options.outputbc)
1274-
jl_options.outputbc = absrealpath(jl_options.outputbc, 0);
1274+
jl_options.outputbc = jl_absrealpath(jl_options.outputbc, 0);
12751275
if (jl_options.outputasm)
1276-
jl_options.outputasm = absrealpath(jl_options.outputasm, 0);
1276+
jl_options.outputasm = jl_absrealpath(jl_options.outputasm, 0);
12771277
if (jl_options.machine_file)
1278-
jl_options.machine_file = absrealpath(jl_options.machine_file, 0);
1278+
jl_options.machine_file = jl_absrealpath(jl_options.machine_file, 0);
12791279
if (jl_options.output_code_coverage)
12801280
jl_options.output_code_coverage = absformat(jl_options.output_code_coverage);
12811281
if (jl_options.tracked_path)
1282-
jl_options.tracked_path = absrealpath(jl_options.tracked_path, 0);
1282+
jl_options.tracked_path = jl_absrealpath(jl_options.tracked_path, 0);
12831283

12841284
const char **cmdp = jl_options.cmds;
12851285
if (cmdp) {
12861286
for (; *cmdp; cmdp++) {
12871287
const char *cmd = *cmdp;
12881288
if (cmd[0] == 'L') {
1289-
*cmdp = absrealpath(cmd, 1);
1289+
*cmdp = jl_absrealpath(cmd, 1);
12901290
}
12911291
}
12921292
}

src/julia_internal.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1909,6 +1909,7 @@ void jl_log(int level, jl_value_t *module, jl_value_t *group, jl_value_t *id,
19091909
jl_value_t *msg);
19101910

19111911
JL_DLLEXPORT int jl_isabspath(const char *in) JL_NOTSAFEPOINT;
1912+
JL_DLLEXPORT char *jl_absrealpath(const char *in, int nprefix) JL_NOTSAFEPOINT;
19121913

19131914
// Commonly used symbols (jl_sym_t* values)
19141915
#define JL_COMMON_SYMBOLS(XX) \

0 commit comments

Comments
 (0)