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

For non-Custom packages, replace sdist with hand-rolled rebuild checking #3985

Merged
merged 2 commits into from
Oct 18, 2016

Conversation

ezyang
Copy link
Contributor

@ezyang ezyang commented Oct 16, 2016

For non-Custom packages, replace sdist with hand-rolled rebuild checking.

New module Distribution.Client.SourceFiles implements
'needElaboratedConfiguredPackage', which if run in the 'Rebuild'
monad is sufficient to ensure all source files that participate
in a build are monitored.

Fixes #3401. It also fixes the "we didn't detect a new file
appearing" problem.

@mention-bot
Copy link

@ezyang, thanks for your PR! By analyzing the history of the files in this pull request, we identified @23Skidoo, @dcoutts and @hvr to be potential reviewers.

@ezyang ezyang added this to the 2.0 milestone Oct 16, 2016
@ezyang ezyang self-assigned this Oct 16, 2016
@ezyang ezyang force-pushed the pr/nix-sdist-replacement branch from f103542 to 64da514 Compare October 16, 2016 05:17
@grayjay
Copy link
Collaborator

grayjay commented Oct 16, 2016

Sorry, I accidentally restarted the build. Appveyor passed the first time: https://ci.appveyor.com/project/23Skidoo/cabal/build/%232330%20(master)

Copy link
Contributor

@dcoutts dcoutts left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice. Thanks!

Suggesting a couple small changes.

let trySdist = allPackageSourceFiles verbosity scriptOptions srcdir
-- This is just a hack, to get semi-reasonable file
-- listings for the monitor
tryFallback = do
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Our fallback could now be the needElaboratedConfiguredPackage rather than the really dumb getDirectoryContentsRecursive

ElabPackage epkg -> needElaboratedPackage elab epkg

needElaboratedPackage :: ElaboratedConfiguredPackage -> ElaboratedPackage -> Rebuild ()
needElaboratedPackage elab epkg = do
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

superfluous do

root <- askRoot
exists <- liftIO $ doesFileExist (root </> f)
-- TODO: If the file exists, should we really monitor the entire
-- file?!
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In principle we'd take an arg, passed through findFileMonitored etc that says if we care about content or mere existence, and all the new uses of it would use the full content. So I wouldn't bother, but we can update the TODO here to say this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand this comment.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well whether we should monitorFileHashed or monitorFile depends on how the caller is going to want to use it. As it happens we always want one, but if we wanted different cases at different call sites then we'd want a param.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The gist of this comment is different. monitorFile sets up a dependence on the timestamp of the file. But consider a build process which tests if a file exists, and does A if it does and B otherwise. We do NOT need to rebuild if the timestamp on the file updates. But there is no way to express this in the current MonitorFile data structure.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh! Well, funny you should ask for it. Internally this is supported (and is used for globs), it just wasn't exposed for individual files since we didn't have a use case (and I couldn't think of one).

So just add to the FileMonitor module:

-- | Monitor a single file for existence only. The monitored file is
-- considered to have changed if it no longer exists.
--
monitorFileExistence :: FilePath -> MonitorFilePath
monitorFileExistence = MonitorFile FileExists DirNotExists

then need "Setup.hs"
else do
lhsExists <- doesFileExistMonitored "Setup.lhs"
when lhsExists $ need "Setup.lhs"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or:

_ <- findFirstFileMonitored id ["Setup.hs", "Setup.lhs"]
return ()

-- extension.
Nothing -> findFileMonitored (hsSourceDirs bi) mainPath
>>= maybe (return ()) need
Just pp -> need pp
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice

-- in extra-src-files changes (most of these won't affect
-- compilation). It would be even better if we knew on a
-- per-component basis which headers would be used but that
-- seems to be too difficult.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah. Eventually we should make extraSrcFiles be per-component, and data files.

@ezyang ezyang force-pushed the pr/nix-sdist-replacement branch from 64da514 to 9d90e3e Compare October 16, 2016 21:45
@ezyang
Copy link
Contributor Author

ezyang commented Oct 16, 2016

OK, addressed all comments except the last one.

@23Skidoo
Copy link
Member

Are we going to deprecate sdist hooks for 2.0 as well?

@ezyang ezyang dismissed dcoutts’s stale review October 16, 2016 22:12

Applied all requested changes

@ezyang
Copy link
Contributor Author

ezyang commented Oct 16, 2016

...I wasn't planning to. Sounds tricky, because it seems like sometimes that is an operation you want to hook?

@dcoutts
Copy link
Contributor

dcoutts commented Oct 16, 2016

Though we could do better in terms of an API than re-using sdist.


-- | Monitor a single file
need :: FilePath -> Rebuild ()
need f = monitorFiles [monitorFile f]
Copy link
Contributor

@dcoutts dcoutts Oct 16, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, this should be monitorFileHashed in all cases shouldn't it? Well, ok, it's only used once, but in that one place it should be monitoring the content too (since it'll be a source file, and so the usual git checkout use case applies).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes you're right.

@ezyang ezyang force-pushed the pr/nix-sdist-replacement branch 2 times, most recently from dec2282 to 6ffd85f Compare October 17, 2016 21:18
@dcoutts
Copy link
Contributor

dcoutts commented Oct 18, 2016

Added a suggestion about monitorFileExistence, but either way this should be ready to merge as far as I can see.

Signed-off-by: Edward Z. Yang <[email protected]>
…ing.

New module Distribution.Client.SourceFiles implements
'needElaboratedConfiguredPackage', which if run in the 'Rebuild'
monad is sufficient to ensure all source files that participate
in a build are monitored.

Fixes haskell#3401.  It also fixes the "we didn't detect a new file
appearing" problem.

Signed-off-by: Edward Z. Yang <[email protected]>
@ezyang ezyang force-pushed the pr/nix-sdist-replacement branch from 6ffd85f to 19b8c68 Compare October 18, 2016 18:49
@ezyang
Copy link
Contributor Author

ezyang commented Oct 18, 2016

FileMonitor handled

@dcoutts
Copy link
Contributor

dcoutts commented Oct 18, 2016

LGTM.

@ezyang ezyang merged commit a46658e into haskell:master Oct 18, 2016
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

Successfully merging this pull request may close these issues.

Replace new-build's call to sdist with new command which lists sources of things that will be built
5 participants