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

make2graph output discrepancy if file already exists #12

Open
romangrothausmann opened this issue Feb 12, 2016 · 9 comments
Open

make2graph output discrepancy if file already exists #12

romangrothausmann opened this issue Feb 12, 2016 · 9 comments

Comments

@romangrothausmann
Copy link
Contributor

Considering this simple Makefile:

%.a:
echo "$@" > $@

%.b : %.a
echo "$@" > $@

%.z : %.b
echo "$@" > $@

If 1.a does not exist make2graph yields:
rm 1.a
/opt/make-4.1/bin/make -Bnd 1.z | make2graph | dot -Tpng -o Makefile_1.png

makefile_1

However, if 1.a already exists an additional (false?) dependency is drawn:
touch 1.a
/opt/make-4.1/bin/make -Bnd 1.z | make2graph | dot -Tpng -o Makefile_2.png

makefile_2

Same problem with make-3.81 or j4make

@lindenb
Copy link
Owner

lindenb commented Feb 12, 2016

I quickly looked at the following Makefile

%.b: %.a
    touch $@

%.z:%.b
    touch $@

%.a:
    touch $@

all: x.z

I confirme I get the same output as you, but the output of Make in debug mode shows me a depency. Pruning filex.a'.`
I think it comes from the fact that you're using pattern rules.

 make -nrd | grep -vE '(Considering |Found|Trying pattern|Trying impli|Looking for|Avoiding im|Finished pre)'

output:

Updating goal targets....
 File `all' does not exist.
   File `x.z' does not exist.
     No need to remake target `x.a'.
    File `x.b' does not exist.
     Pruning file `x.a'.
   Must remake target `x.b'.
touch x.b
   Successfully remade target file `x.b'.
  Must remake target `x.z'.
touch x.z
  Successfully remade target file `x.z'.
Must remake target `all'.
Successfully remade target file `all'.
Removing intermediate files...
rm x.b

sorry, there is not much I can do.

P.

@romangrothausmann
Copy link
Contributor Author

Hm, would this then be a bug in the debug output of make?
Would it work to ignore any "Pruning file XYZ" if a "No need to remake target XYZ" appears before on the same dependency level?

@lindenb
Copy link
Owner

lindenb commented Feb 12, 2016

Hm, would this then be a bug in the debug output of make?

yes and no, make is not supposed to know I want to use the information :-)

Would it work to ignore any "Pruning file XYZ" if a "No need to remake target XYZ" appears before on the same dependency level?

no that would break everything.

@romangrothausmann
Copy link
Contributor Author

I just noticed that if the files make would create actually exist, the visualization/"make -nd output" is correct. E.g. add to the Makefile a line with:
.SECONDARY

run make without -n to create all files
make 1.z
and then run again:
make -Bnd 1.z | make2graph | dot -Tpng -o Makefile_3.png

@romangrothausmann
Copy link
Contributor Author

Using make -Bt first lets make2graph work correctly even without .SECONDARY in the Makefile, as make does not remove intermediate files that were crated by -t.

@deryni
Copy link

deryni commented Apr 20, 2016

Having looked at this for only a few minutes (and not having looked at the actual code for make2graph yet) it looks like (from the make -rRd output of this makefile in the two states that it should be possible to match up the prerequisite with the correct target.

The output indented under the processing of x.b stops at Trying implicit prerequisite 'x.a' in the partial case (where it continues in the clean case).

In the partial case the Considering target file 'x.a' output then appears under the Found an implicit rule for 'x.z' line but at the indentation level of the x.b lines from earlier (and not at the indentation level of the Considering target file 'x.b' lines that follow it shortly.

Similarly the No need to remake target 'x.a'. line in the output above is indented at the x.b prerequisite level and not at the x.z prerequisite level.

I don't know if that's enough to be canonical or reliable but it looks (from this limited subset of outputs) that it might be.

@romangrothausmann
Copy link
Contributor Author

Thanks Etan for looking into this and Your suggestion to regard the indentation level.
As far as I understand the code of make2graph.c, it does not take into account the indentation level but seems to strip space (https://github.com/lindenb/makefile2graph/blob/master/make2graph.c#L191).
Pierre, how difficult would You think it will be to adjust the code to take indentation levels into account?

@lindenb
Copy link
Owner

lindenb commented May 11, 2016

Pierre, how difficult would You think it will be to adjust the code to take indentation levels into account?

I don't know, it shouldn't be difficult, but honestly I don't currently have the time for this.

@lindenb
Copy link
Owner

lindenb commented Jun 24, 2016

Looks nice now

lindenb added a commit that referenced this issue Jun 24, 2016
Fix for "output discrepancy if file already exists" (Issue #12)
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

3 participants