Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

glslc writes bad dependency file if -o - #327

Closed
versalinyaa opened this issue Mar 22, 2017 · 3 comments
Closed

glslc writes bad dependency file if -o - #327

versalinyaa opened this issue Mar 22, 2017 · 3 comments

Comments

@versalinyaa
Copy link

If glslc is given option '-o -' and one of the -M* dependency
options, then it wrote an incorrect dependency file. For example:

$ glslc -MD -S -o - a.glsl | sed ...
$ ls
-.d a.glsl
$ cat ./-.d
-: a.glsl

It doesn't make sense to write a dependency file when the compilation
output is stdout. So glslc should catch this error when parsing the command line flags.j

versalinyaa added a commit to versalinyaa/shaderc that referenced this issue Mar 22, 2017
If glslc is given option '-o -' and one of the -M* dependency
options, then it wrote an incorrect dependency file. For example:

    $ glslc -MD -S -o - a.glsl | sed ...
    $ ls
    -.d a.glsl
    $ cat ./-.d
    -: a.glsl

It doesn't make sense to write a dependency file when the compilation
output is stdout. So catch the error while validating command line
flags, emit a helpful error message, and fail.

Fixes: google#327
@versalinyaa
Copy link
Author

More investigation. I think glslc should allow -MD with -o -, but only when -MT <depfile> is also given.

@versalinyaa
Copy link
Author

NEVERMIND. glslc correctly behaves the same as gcc when given -o - with -M* options. Here is a test that demonstrates the gcc behavior.

#!/bin/bash

setup() {
    # Clean!
    rm -f hello* ./-*

    cat >hello.c <<-EOF
	#include "hello.h"
	
	int main(void) {
	    hello();
	    return 0;
	}
	EOF

    cat >hello.h <<-EOF
	#include <stdio.h>
	
	static inline void
	hello(void) {
	    printf("hello!\n");
	}
	EOF
}

start_test() {
    test_name="$1"
    echo "test $test_name ..."
}

pass() {
    echo "test $test_name ... pass"
}

fail() {
    echo "test $test_name ... fail"
    exit 1
}

testA() {
    start_test "A"
    setup || fail
    gcc -S -o - -MMD hello.c >/dev/null || fail
    [[ -f ./-.d ]] || fail
    [[ $(cat ./-.d) = "-: hello.c hello.h" ]] || fail
    pass
}

testB() {
    start_test "B"
    setup || fail
    gcc -S -o - -MMD -MF hello.o.d -MT hello.o hello.c >/dev/null || fail
    [[ -f hello.o.d ]] || fail
    [[ $(cat hello.o.d) = "hello.o: hello.c hello.h" ]] || fail
    pass
}

testA
testB

@dneto0
Copy link
Collaborator

dneto0 commented Apr 4, 2017

My favourite kind of bug. :-)

Thanks for the explanation. Yes, we used gcc as the model for this feature. I'm glad we are close enough to it in behaviour.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants