Make Hadrian CWD-aware
As discussed previously at https://github.com/snowleopard/hadrian/issues/685, there have been many requests from Hadrian users to make it CWD-aware, i.e that just like
make, when you pass it no target, it can deduce from the current directory an "implicit" target: rebuild ghc library if running hadrian from
compiler/, run the parser tests that are expected to fail if running hadrian from
As far as I can tell, there are 3 components to supporting such a workflow as smoothly:
- being able to call hadrian easily from everywhere (by having it in
PATHI suppose), instead of having to type the relative path to one of the
- detecting the CWD's path as well as the top of the GHC tree and passing it all to Hadrian;
- making Hadrian react appropriately to the CWD (build everything, rebuild current package or run all tests under that dir).
I have the last two steps implemented in alp/ghc@bf58b772 - I'll submit that as a merge request soon. I'd like to discuss how we want to implement the first point (see end of this comment). But anyway, while hadrian would previously error out when called from a directory other than the top of GHC's source tree, with that patch:
$ hadrian/build.sh -j # complete GHC build, as before # edit, say, compiler/hsSyn/HsExpr.hs, then: $ cd compiler; ../hadrian/build.sh -j; cd .. # only rebuilds up to the <finalStage> ghc library (1) # run all the tests under testsuite/tests/parser/should_fail, # listed in the all.T file in that directory. $ cd testsuite/tests/parser/should_fail; ../../../../hadrian/build.sh -j; cd ../../../../ # edit, say, libraries/base/GHC/Generics.hs, then: $ cd libraries/base; ../../hadrian/build.sh -j; cd ../../ # only rebuilds up to the <finalStage> base library # run all the tests under libraries/base/tests/Concurrent, # listed in the all.T file in that directory $ cd libraries/base/tests/Concurrent; ../../../../hadrian/build.sh -j; cd ../../../../ # running hadrian from outside of the GHC tree $ cd /tmp; path/to/ghc/tree/hadrian/build.sh -j; cd path/to/ghc/tree Error when running Shake build system: at action, called at src/Rules.hs:70:19 in main:Rules at error, called at src/Rules.hs:87:15 in main:Rules * Raised the exception: --target-dir=/tmp: doesn't belong to a package or test
In (1) above, and more generally in the case where Hadrian is called with no target from a package's directory, what the patch does is basically
need the suitable
<finalStage>:[lib|exe]:<pkgname> target, which will rebuild everything affected up to the given package, included. In this particular case, we'd rebuild the stage 1 compiler and what not until we end up building the
ghc library with stage 1. Is that what we want, or do we instead want it to rebuild just that package at stage
finalStage, as if we were using Shake's
Other than this "detail", I think this is all working pretty well. I'll create a MR with the patch soon, to get feedback on the implementation.
I'd like to discuss how we can achieve the missing step, making hadrian available everywhere easily, without having to write annoying relative paths. @snowleopard Any idea there?