evmar / n2

n2 ("into"), a ninja compatible build system

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Variable references in build inputs don't take into account the build's bindings

Colecf opened this issue · comments

rule touch
    command = touch $out

rule copy
    command = cp $in $out

build out/a: copy ${my_dep}
    my_dep = out/b

build out/b: touch

default out/a

This build file works in ninja, but not n2. Android has this case. I've only found one occurance that was trivial to remove so far, but I haven't gotten a full build working yet. If possible, maybe it's better not to fix it if it allows faster parsing.

This is #39 and it is dumb that I didn't make it work, but I was greedy.

The reason for my greed is that n2 currently expands everything right while it parses, so when it sees ${my_dep} it wants to expand it to the final value without waiting to parse down through the definition of my_dep = . This means it never needs to buffer any of these intermediate strings. But it also means it's just plain incorrect relative to Ninja.

Now that I look at your example, I wonder if I could do some trick around assuming things will go the fast way and then if I see a variable reference later going back and re-expanding. Or if I should just buffer everything anyway. It would probably help for me to actually profile before I micro-optimize in this manner.

Relevant expansion inline code, I think maybe that ought to consult more scopes than it currently does too...

Oh, feel free to close as a duplicate then. Interestingly, this issue also causes parse errors:

rule touch
    command = touch $out

rule copy
    command = cp $in $out

my_var = out/b

build out/a: copy out/b | ${my_dep} out/d
    my_dep = out/c

build out/b: touch
build out/c: touch
build out/d: touch

default out/a


Produces:

n2: error: parse error: expected '\n', got ' '
build.ninja:9: build out/a: copy out/b | ${my_dep} out/...
                                                  ^

I actually think this will need to be properly fixed for the android build. Not all of these search results, but many of them, suffer from this issue.

(Sorry for not responding yet -- your other patches were obvious merges, but this one is more subtle so I want to give it proper attention and I have some life stuff going on the next week or so.)

Thanks for the update, I'll hold off on new PRs for now then.