digitalmars.D - -op can be quite strange
- Jonathan Marler (46/46) Sep 01 2018 The -od (output directory) and -op (perserve source paths) work
- Nicholas Wilson (3/6) Sep 01 2018 LDC has this already as -oq, FWIW.
- Jonathan Marler (4/10) Sep 01 2018 I knew those LDC folks were smart :) Has there been any attempt
The -od (output directory) and -op (perserve source paths) work great when you're compiling multiple modules in a single invocation. For example, say we have the following: /foolib/src/foo/bar.d /myapp/src/main.d Current Directory: /myapp ``` dmd -I=../foolib/src -I=src -od=obj -op -c src/main.d ../foolib/src/foo/bar.d ``` This example shows a weird unexpected result. Because I've specified "../foolib/src/foo/bar.d" on the command line, the compiler will put the object file here: obj/../foolib/src/foo/bar.o which means it will go here: /myapp/foolib/src/foo/bar.o This is very strange. Because it has a ".." in the name, it doesn't even get put in the "obj" folder specified by "-od". What makes it worse is if you ad used "-i" instead of giving it on the command line: ``` dmd -I=../foolib/src -I=src -od=obj -op -c src/main.d -i ``` then it would be in: obj/foo/bar.o I thought about this for a bit an realized that maybe there's a better way. Instead of telling the compiler to append the "relative path" of the source file from CWD to the output directory like this: `<relative_path>/<basename>.d` -> `<output-dir>/<relative_path>/<basename>.o` `../foolib/src/foo/bar.d` -> `obj/../foolib/src/foo/bar.o` we could tell the compiler to use the path relative of the source file from the package root. Let's call it the "package path": `<some_path>/<package_path>/<basename>.d` -> `<output-dir>/<package_path>/<basename>.o` `../foolib/src/foo/bar.d` -> `obj/foo/bar.o` This would mean modules would go to the same place whether they were explicitly given on the command line or whether they were a "compiled import" via "-i". It also handles conflicts because each fully-qualified module name (and by extension each "package path" / "module name" combo) must be unique in a compiler invocation. Note that we would want this to be a new option so as not to break anyone depending on "-op" semantics. Maybe "-om" for "output path based on 'Module' name"?
Sep 01 2018
On Saturday, 1 September 2018 at 14:48:55 UTC, Jonathan Marler wrote:Note that we would want this to be a new option so as not to break anyone depending on "-op" semantics. Maybe "-om" for "output path based on 'Module' name"?LDC has this already as -oq, FWIW.
Sep 01 2018
On Saturday, 1 September 2018 at 23:29:01 UTC, Nicholas Wilson wrote:On Saturday, 1 September 2018 at 14:48:55 UTC, Jonathan Marler wrote:I knew those LDC folks were smart :) Has there been any attempt to add -oq to dmd?Note that we would want this to be a new option so as not to break anyone depending on "-op" semantics. Maybe "-om" for "output path based on 'Module' name"?LDC has this already as -oq, FWIW.
Sep 01 2018