scons icon indicating copy to clipboard operation
scons copied to clipboard

Add analogue to _concat for writable directories

Open mwichmann opened this issue 2 years ago • 2 comments

The regular _concat function, when processing a list of strings, adds a prefix+suffix to each, possibly after expanding the list through a call to a function. The function is often RDirs, which can add additional paths (repositories, usually). This is used for things like path-to-include dir, so we get "-Iinclude" without storing the compiler-specific syntax.

When used for a directory which we tell the compiler to write to, as opposed to just search, this can give the wrong result. For example, for $FORTRANMODIR, which describes where to put generated module files, we only want to write to the target directory (and in fact, for gfortran, it's an error to specify the module-write-dir more than once), but we might want to still search the backing directories - any repository, and in case of non-duplicating variantdir, the directory of the original source - in case there were already module files there that can be used.

This new function wraps the first string from the expanded list in the prefix/suffix, and any remaining strings in the extra_prefix and extra_suffix arguments, for example to produce "-Jtargetmoddir -Isourcemoddir -Irepository" instead of "-Jtargetmoddir -Jsourcemoddir -Jrepository". The latter would abort the Fortran compiler with an error, and the equivalent for the D compilers would ignore the first (correct) directory and select the last one for use. In any case, we're not allowed to write to the repository, so the previous behavior using _concat was definitely wrong.

Contributor Checklist:

  • [X] I have created a new test or updated the unit tests to cover the new/changed functionality.
  • [X] I have updated CHANGES.txt (and read the README.rst)
  • [X] I have updated the appropriate documentation

mwichmann avatar Jul 19 '23 16:07 mwichmann

While this solution works, I'm not sure if specifying a list of directories of which only the first one is handled differently is the best solution?

If there's includepaths, and write to paths, shouldn't those be separate envvars?

bdbaddog avatar Jul 21 '23 16:07 bdbaddog

Those two languages have cvars already for include paths, those are for ones the developer actually knows about - plus any possible backing copies in repositories. This is for the problem when SCons silently adds directories. The other alternative is to throw those extras away, perhaps by not calling RDirs - but you suggested earlier that wasn't a good idea, might want to search for already built modules in a repository.

mwichmann avatar Jul 21 '23 18:07 mwichmann

I'll revisit this someday, no need to have it hanging around here for now.

mwichmann avatar Jun 29 '24 17:06 mwichmann