Thread overview
[Issue 12116] dmd -op -od broken
Jul 31, 2014
Richard Cattermole
Jan 08, 2017
Timothee Cour
Jan 08, 2017
Timothee Cour
Jan 08, 2017
kinke@gmx.net
Jan 08, 2017
Timothee Cour
Nov 19, 2017
Mike
Apr 03, 2018
Mike Franklin
Dec 17, 2022
Iain Buclaw
July 31, 2014
https://issues.dlang.org/show_bug.cgi?id=12116

Richard Cattermole <alphaglosined@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |alphaglosined@gmail.com

--- Comment #2 from Richard Cattermole <alphaglosined@gmail.com> ---
Similar again to https://issues.dlang.org/show_bug.cgi?id=13206 but for generated interface files.

--
January 08, 2017
https://issues.dlang.org/show_bug.cgi?id=12116

Timothee Cour <timothee.cour2@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |timothee.cour2@gmail.com

--- Comment #3 from Timothee Cour <timothee.cour2@gmail.com> ---
still completely broken:

dmd --version
DMD64 D Compiler v2.073.0-devel-a2b772f
rdmd | grep build
rdmd build 20170107

fun.d:
void main(){}

# with absolute path_to_file.d:
dmd -op -od/tmp/d01 /path/bug_12116/fun.d
creates ./fun and /path/bug_12116/fun.o (BUG: /tmp/d01 is ignored)

dmd -c -op -od/tmp/d01 /path/bug_12116/fun.d
creates /path/bug_12116/fun.o (BUG: /tmp/d01 is ignored)

rdmd -c -op -od/tmp/d01 /path/bug_12116/fun.d
creates /tmp/d01/fun.o (BUG: inconsistent with dmd)

# with .. in path_to_file.d:
mkdir temp && cd temp
dmd -op -od/tmp/d01 ../bug_12116/fun.d
creates ./fun and /tmp/bug_12116/fun.o (BUG: expected: something under
/tmp/d01)

rdmd -op -od/tmp/d01 ../bug_12116/fun.d
creates /tmp/d01/fun (BUG: inconsistent with dmd) and the .o under
*/.rdmd-501/* (OK)


# with -c:
dmd -c -op -od/tmp/d01 ../bug_12116/fun.d
/tmp/bug_12116/fun.o (BUG)

rdmd -c -op -od/tmp/d01 ../bug_12116/fun.d
creates /tmp/d01/fun.o (BUG: inconsistent with dmd)


# with no absolute path and not .. in file.d:
dmd -c -op -od/tmp/d01 bug_12116/fun.d
creates /tmp/d01/bug_12116/fun.o (OK)

rdmd -c -op -od/tmp/d01 bug_12116/fun.d
creates /tmp/d01/fun.o (BUG:inconsistent with dmd)

Other argument why -op is much less useful compared to -oq:
* forces you be at the root of module import paths
* if you have multiple module roots, it can't work:

dmd -c -op -od/tmp/d01/ -Iroot1/import -Ipath2/root2/import/ root1/import/std/path.d path2/root2/import/core/stdio.d

=> will create:
/tmp/d01/root1/import/std/path.o
/tmp/d01/path2/root2/import/core/stdio.o

with -oq semantics are a lots easier, predictable, no weird edge cases, and
easy to implement:
/tmp/d01/std.path.o
/tmp/d01/core.stdio.o

--
January 08, 2017
https://issues.dlang.org/show_bug.cgi?id=12116

Andrei Alexandrescu <andrei@erdani.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |andrei@erdani.com

--- Comment #4 from Andrei Alexandrescu <andrei@erdani.com> ---
(In reply to Timothee Cour from comment #3)
> still completely broken:
> 
> dmd --version
> DMD64 D Compiler v2.073.0-devel-a2b772f
> rdmd | grep build
> rdmd build 20170107
> 
> fun.d:
> void main(){}
> 
> # with absolute path_to_file.d:
> dmd -op -od/tmp/d01 /path/bug_12116/fun.d
> creates ./fun and /path/bug_12116/fun.o (BUG: /tmp/d01 is ignored)
> 
> dmd -c -op -od/tmp/d01 /path/bug_12116/fun.d
> creates /path/bug_12116/fun.o (BUG: /tmp/d01 is ignored)
> 
> rdmd -c -op -od/tmp/d01 /path/bug_12116/fun.d
> creates /tmp/d01/fun.o (BUG: inconsistent with dmd)
> 
> # with .. in path_to_file.d:
> mkdir temp && cd temp
> dmd -op -od/tmp/d01 ../bug_12116/fun.d
> creates ./fun and /tmp/bug_12116/fun.o (BUG: expected: something under
> /tmp/d01)
> 
> rdmd -op -od/tmp/d01 ../bug_12116/fun.d
> creates /tmp/d01/fun (BUG: inconsistent with dmd) and the .o under
> */.rdmd-501/* (OK)
> 
> 
> # with -c:
> dmd -c -op -od/tmp/d01 ../bug_12116/fun.d
> /tmp/bug_12116/fun.o (BUG)
> 
> rdmd -c -op -od/tmp/d01 ../bug_12116/fun.d
> creates /tmp/d01/fun.o (BUG: inconsistent with dmd)
> 
> 
> # with no absolute path and not .. in file.d:
> dmd -c -op -od/tmp/d01 bug_12116/fun.d
> creates /tmp/d01/bug_12116/fun.o (OK)
> 
> rdmd -c -op -od/tmp/d01 bug_12116/fun.d
> creates /tmp/d01/fun.o (BUG:inconsistent with dmd)
> 
> Other argument why -op is much less useful compared to -oq:
> * forces you be at the root of module import paths
> * if you have multiple module roots, it can't work:
> 
> dmd -c -op -od/tmp/d01/ -Iroot1/import -Ipath2/root2/import/ root1/import/std/path.d path2/root2/import/core/stdio.d
> 
> => will create:
> /tmp/d01/root1/import/std/path.o
> /tmp/d01/path2/root2/import/core/stdio.o
> 
> with -oq semantics are a lots easier, predictable, no weird edge cases, and
> easy to implement:
> /tmp/d01/std.path.o
> /tmp/d01/core.stdio.o

Could you please paste this entire post along with what _should_ be the behavior? Thanks.

--
January 08, 2017
https://issues.dlang.org/show_bug.cgi?id=12116

--- Comment #5 from Timothee Cour <timothee.cour2@gmail.com> ---
Expected behavior:

* dmd -h | grep '\-od' should be accurate (currently: "write object & library files to directory" is not true when source path is absolute or contains ..; but would be under my proposed points below)

* `rdmd -c ` should place .o/.a files in same place as `dmd -c` (not the case
currently)

* dmd -op (path with ..)/fun.d should be an error: it's dangerous and unexpected to have something writing BELOW dir when user gives '-od=mydir'. But this won't restrict any use case, see below.

* `dmd` should be equivalent to `dmd -od=.`

* dmd -od=mydir -op /absolute_path/fun.d should write to: mydir/absolute_path/fun.o (eg: -od=/tmp/ => /tmp/absolute_path/fun.o)

this behavior is useful when users don't want to pollute a source repository with .o files, or when they want to keep multiple cached versions of object files (eg for different compilation options): the current behavior (/absolute_path/fun.o) won't allow that.

* Also introduce an optional value for -op=dir (multiple are possible, eg:
-op=mydir1 -op=mydir2) to make paths be relative to the first (if any)
directory where the absolute path is found:

dmd -c -od=/tmp/ -op=/absolute_path/ -op=import/ /absolute_path/std/fun.d
import/core/bar.d source/core/bar.d
/tmp/std/fun.o (thanks to -op=/absolute_path/)
/tmp/core/bar.o (thanks to -op=import/)
/tmp/source/core/bar.o (no match inside -op=)

There is a value to both -oq and -op (with the above fixes):
-op: allows compiling multiple source files with same module name (eg:
core.bar), which can be useful
-oq: should be used most of the time (when we don't expect such module name
clashes), because all builds are simply under 1 directory, simpler to reason
about.

--
January 08, 2017
https://issues.dlang.org/show_bug.cgi?id=12116

--- Comment #6 from kinke@gmx.net ---
(In reply to Timothee Cour from comment #5)
> * dmd -od=mydir -op /absolute_path/fun.d should write to: mydir/absolute_path/fun.o (eg: -od=/tmp/ => /tmp/absolute_path/fun.o)
> 
> this behavior is useful when users don't want to pollute a source repository with .o files, or when they want to keep multiple cached versions of object files (eg for different compilation options): the current behavior (/absolute_path/fun.o) won't allow that.

Please do not forget about Windows - how would you propose handling `dmd -c -od=mydir -op C:\bla.d D:\bla.d` then? ;)

--
January 08, 2017
https://issues.dlang.org/show_bug.cgi?id=12116

--- Comment #7 from Timothee Cour <timothee.cour2@gmail.com> ---
For windows:

 > Please do not forget about Windows - how would you propose handling `dmd -c
-od=mydir -op C:\bla.d D:\bla.d` then? ;)

=> creates:
mydir/C/bla.o
mydir/D/bla.o

but again, as in the proposal user can also write:

dmd -c -od=mydir -op=C:\ C:\bla.d D:\bla.d
=> creates:
mydir/bla.o
mydir/D/bla.o

it's nice and consistent. Another possiblity is to disallow the combo(windows+op+absolute files), but that doesn't seem necessary.

But whatever is decided on windows, hopefully we can at least do what's proposed here on mac/linux.

--
November 19, 2017
https://issues.dlang.org/show_bug.cgi?id=12116

Mike <slavo5150@yahoo.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |slavo5150@yahoo.com
           See Also|                            |https://issues.dlang.org/sh
                   |                            |ow_bug.cgi?id=3541

--
April 03, 2018
https://issues.dlang.org/show_bug.cgi?id=12116

Mike Franklin <slavo5150@yahoo.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           See Also|                            |https://issues.dlang.org/sh
                   |                            |ow_bug.cgi?id=18710

--
December 17, 2022
https://issues.dlang.org/show_bug.cgi?id=12116

Iain Buclaw <ibuclaw@gdcproject.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P2                          |P1

--