cc-rs icon indicating copy to clipboard operation
cc-rs copied to clipboard

Map source absolute paths to OUT_DIR as relative.

Open dot-asm opened this issue 3 years ago • 6 comments

If a source file was specified by absolute path, then the corresponding object file was placed into OUT_DIR. This posed a problem if multiple files with the same base name were specified by absolute paths.

Fixes #683.

dot-asm avatar Jun 01 '22 15:06 dot-asm

This method can still cause multiple distinct paths to be mapped to the same object file.

For example, all these source files will be mapped to the same object file:

foo/bar.c          -> OUT_DIR/foo/bar.o
/home/me/foo/bar.c -> OUT_DIR/foo/bar.o
/home/foo/bar.c    -> OUT_DIR/foo/bar.o

A different option could be to include a hash of the source path in the object name. That avoids clashes without producing very long file paths.

de-vri-es avatar Jul 21 '22 19:07 de-vri-es

Well, arguably suggested scenario is unlikely to be a common case, but I've added unique prefix based on absolute path for maintainers to consider :-)

dot-asm avatar Jul 22 '22 20:07 dot-asm

I'd remove the path grafting entirely now. I'd even consider doing the same for relative paths and dump all object files in one directory. Although I guess it's nice to mimic the directory structure for relative paths.

de-vri-es avatar Jul 25 '22 11:07 de-vri-es

I'd remove the path grafting entirely now.

Even for relative paths? The original idea was to be as conservative as possible. I mean not changing the way it currently works in the most common case of relative paths. As for absolute paths, yeah, I've thought of "flattening" and reckoned that keeping traces of the directory structure could be helpful for trouble-shooting purposes. But sure, it's definitely a viable option. For both relative and absolute paths. Nobody traverses the object files' destination directories anyway...

dot-asm avatar Jul 25 '22 13:07 dot-asm

I've thought of "flattening" and reckoned that keeping traces of the directory structure could be helpful for trouble-shooting purposes.

On the other hand, one can totally say that "flattening" would actually be more a conservative approach, because that's how the absolute paths are treated now. Fair enough, I'll remove the grafting for absolute paths and let maintainers choose [or express their preferences]...

dot-asm avatar Jul 25 '22 13:07 dot-asm

Note for maintainers. There are three suggestions to consider, one per commit. First one attempts to graft subdirectories of absolute source files' paths to output directory. The second one prefixes object files with source directories' hashes. And the third one removes grafting. There is also suggestion to use hashes as prefixes even with relative paths.

dot-asm avatar Jul 26 '22 19:07 dot-asm

This seems fine -- I prefer this approach to flattening.

Could you clarify the course of further actions for me here. I mean should I remove all commits but the fist here, or do you simply cherry-pick it yourself?

dot-asm avatar Nov 03 '22 11:11 dot-asm

Sorry, that wasn't about the commit structure. I just forgot to merge

thomcc avatar Nov 24 '22 02:11 thomcc