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

n2 re-runs generator on first build #40

Open
tru opened this issue Apr 5, 2022 · 12 comments
Open

n2 re-runs generator on first build #40

tru opened this issue Apr 5, 2022 · 12 comments
Labels
bug Something isn't working

Comments

@tru
Copy link
Contributor

tru commented Apr 5, 2022

  • Grab latest LLVM
  • Install n2 as ninja in the PATH
  • cmake -GNinja ../llvm
  • ninja -> cmake being re-built

This might be something in the LLVM CMake scripts of course, but I wanted to report it anyway since using it for LLVM would give some good benefits.

@evmar evmar changed the title CMake being re-run when using n2 on LLVM n2 re-runs generator on first build Apr 5, 2022
@evmar
Copy link
Owner

evmar commented Apr 5, 2022

I retitled this about the larger issue, which is that n2 doesn't recognize when your build files have been generated outside of n2. I have been thinking about this issue and I'm still not quite sure what to do about it.

BTW the gn build of llvm (https://llvm.org/devmtg/2018-10/slides/Weber-FunnerLLVMDevelopment.pdf) generates so quickly you don't notice this happening. :)

@evmar evmar added the bug Something isn't working label Apr 5, 2022
@evmar
Copy link
Owner

evmar commented Apr 5, 2022

My current best thought is to have some sort of adopt subcommand where you tell n2 "trust me, file foo and all its dependencies are up to date relative to its inputs", and then somehow automatically adopt generated build files. But I'm not sure how to tell apart the case where you ran CMake manually vs the case where you've e.g. directly
edited a generated build file and we ought to rebuild it.

@tru
Copy link
Contributor Author

tru commented Apr 5, 2022

How does ninja do this currently? Guessing it keeps track of the files another way? I seem to remember that CMake automatically calls ninja after each configure to clean up the dep tree or something. Maybe n2 could hijack those tools in an ugly way.

@jhasse
Copy link

jhasse commented Apr 12, 2022

CMake calls ninja -t restat to fix this, see ninja-build/ninja#1376

evmar added a commit that referenced this issue Jun 29, 2023
@evmar evmar closed this as completed in 6270aef Jun 29, 2023
evmar added a commit that referenced this issue Jun 29, 2023
@evmar evmar reopened this Jun 29, 2023
@evmar
Copy link
Owner

evmar commented Jun 29, 2023

I am kinda unhappy with my solution here, I am thinking it over still so I am gonna leave this bug open.

@evmar
Copy link
Owner

evmar commented Jun 29, 2023

Notes to self, there are two broad situations we care about:

  1. User generates build files the first time, invokes n2.
  2. User invokes ninja generator manually atop existing build.

The -t restat thing solves both of these by having CMake directly call ninja to inform it that it did something, but it requires we install n2 as the ninja binary found by CMake.

But we could solve case #1, which is the only case this bug was initially filed about, by just saying "if there was no .n2_db file, mark build.ninja as up to date immediately", which requires much less user intervention. And case 2 is possibly a relatively rare user scenario (?)

@evmar evmar changed the title n2 re-runs generator on first build n2 re-runs generator on first build unless installed as 'ninja' Jul 12, 2023
@evmar evmar changed the title n2 re-runs generator on first build unless installed as 'ninja' n2 re-runs generator on first build Jul 12, 2023
@tru
Copy link
Contributor Author

tru commented Jan 5, 2024

I just retested this today and n2 re-runs CMake everytime on windows. I can check on it if you think it should work, then it might be another Windows specific issue.

@tru
Copy link
Contributor Author

tru commented Jan 8, 2024

@evmar ping on this again, with the other issues handled now, this is the one that's blocking me from using n2 daily. It re-runs CMake on every invocation. Any tips on how to debug that?

@evmar
Copy link
Owner

evmar commented Jan 8, 2024

Argh, sorry! I have reproed locally, taking a look.

@evmar evmar closed this as completed in 438506a Jan 8, 2024
@evmar
Copy link
Owner

evmar commented Jan 8, 2024

Please let me know if that works for you, I hope I got it right this time...

@tru
Copy link
Contributor Author

tru commented Jan 10, 2024

Hi! Yeah it seems like it worked on the initial test, I will use n2 as my default ninja for a while and let you know if I ever encounter it again!

@evmar
Copy link
Owner

evmar commented Jan 8, 2025

I am back to thinking about this again because Meson also triggers this.

Relevant code only invokes -t restat if there is a .ninja_log file in the build dir, which is to say Ninja was already run once.

In n2's case it rebuilds in any case where it doesn't know the provenance of generated files, so that is not enough. And the current thing where to make CMake work we require you to install n2 as your ninja binary is a seriously gross hack, so it would be nice to have a more principled fix here.

@evmar evmar reopened this Jan 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants