Skip to content
This repository has been archived by the owner on Oct 7, 2020. It is now read-only.

add possibility to run install.hs from cabal #1221

Merged
merged 22 commits into from
Jul 12, 2019
Merged

add possibility to run install.hs from cabal #1221

merged 22 commits into from
Jul 12, 2019

Conversation

samuelpilz
Copy link
Contributor

@samuelpilz samuelpilz commented Apr 30, 2019

closes #1179, for good!

I spoke with @hvr, who hinted at the possibility that install.hs could be run via cabal new-run install.hs and I got this working.

(planned) Features:

  • install.hs can be executed via cabal: cabal new-run install.hs --project-file shake.project <target>
  • the targets build and hie-* will use the same build-system

Tradeoffs and limitations:

  • shake.project is needed for similar reasons shake.yaml is required.
  • a own cabal-package in the folder install/ is required
  • ./install.hs as an executable is only possible for either stack or cabal
  • The argument --project-file shake.project is required and cannot be defined inside the script-comments. @hvr said that this could maybe be changed in the future.

Plan:

  • make install.hs executable via cabal new-run via a comment at the beginning
  • refactor install.hs logic into own cabal-package
  • mechanism for detecting if run from stack or cabal
  • make default targets (i.e. hie-*, build) use the same build-system as the install.hs has been called with
  • document this feature in readme

@samuelpilz samuelpilz requested a review from fendor June 17, 2019 09:34
install/src/Cabal.hs Show resolved Hide resolved
install/src/Help.hs Outdated Show resolved Hide resolved
install/src/Install.hs Outdated Show resolved Hide resolved
install/src/Print.hs Outdated Show resolved Hide resolved
install/src/Stack.hs Show resolved Hide resolved
install/src/Stack.hs Show resolved Hide resolved
install/src/Version.hs Show resolved Hide resolved
shake.project Outdated Show resolved Hide resolved
@samuelpilz
Copy link
Contributor Author

also fixes #1218. Tests have been successful

@samuelpilz
Copy link
Contributor Author

Currently, stack is still needed to get the .local/bin dir (stack path --local-bin). I'm unable to find a similar command using cabal only.

@samuelpilz samuelpilz changed the title WIP: add possibility to run install.hs from cabal add possibility to run install.hs from cabal Jun 29, 2019
@samuelpilz
Copy link
Contributor Author

This PR is now ready. I have done a lot of tests on archlinux and fedora.

README.md Outdated Show resolved Hide resolved
install/src/Cabal.hs Outdated Show resolved Hide resolved
@fendor
Copy link
Collaborator

fendor commented Jun 30, 2019

There seem to be a lot of problems on windows. The script is not executable on windows.

@jneira
Copy link
Member

jneira commented Jul 1, 2019

It seems the cabal script feature doesn't work in windows as-is.
I've been able to run hie-install:

  • adding an executable stanza to install/hie-install.cabal:
executable install
  main-is: ../install.hs
  build-depends:      base >= 4.9 && < 5
                    , hie-install
  default-language:    Haskell2010
  • Adding ./installas package in project.cabal
  • Running cabal v2-run install -- help
  • Or running cabal v2-run install --project-file install/shake.project -- helpwithout adding it to cabal.project

But it is not a "script" anymore, right? Dont know if we lose anything tough (it is even shorter if you add it to cabal.project!)

The error i've got with cabal new-run install.hs (removing the { -stack .. .} part just in case) is

# cabal v2-run install.hs --project-file install/shake.project help
Resolving dependencies...
Build profile: -w ghc-8.6.5 -O1
In order, the following will be built (use -v for more details):
 - fake-package-0 (exe:script) (configuration changed)
Configuring executable 'script' for fake-package-0..
Preprocessing executable 'script' for fake-package-0..
Building executable 'script' for fake-package-0..
[1 of 1] Compiling Main             ( Main.hs, path\to\haskell-ide-engine\dist-newstyle\build\x86_64-windows\ghc-8.6.5\fake-package-0\x\script\build\script\script-tmp\Main.o )

Main.hs:1:1: error:
    Could not load module `Prelude'
    It is a member of the hidden package `base-4.12.0.0'.
    Perhaps you need to add `base' to the build-depends in your .cabal file.
    it is a hidden module in the package `hackage-security-0.5.3.0'
    Use -v to see a list of the files searched for.
  |
1 | {- cabal:
  | ^

Main.hs:12:1: error:
    Could not load module `HieInstall'
    It is a member of the hidden package `hie-install-0.8.0.0'.
    Perhaps you need to add `hie-install' to the build-depends in your .cabal file.
    Use -v to see a list of the files searched for.
   |
12 | import HieInstall (defaultMain)
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

@jneira
Copy link
Member

jneira commented Jul 1, 2019

Although we would add hie-install to the set of project local packages, i would vote to not use the cabal script feature and go for cabal new-run install -- <command>, for all systems.
Or even better, to avoid confusions, cabal new-run hie-install -- <command>, moving install dir to hie-install.

@jneira
Copy link
Member

jneira commented Jul 1, 2019

@jneira
Copy link
Member

jneira commented Jul 1, 2019

Another option is only add the executable stanza and inform windows users that their command would be cabal new-run install --project-file=install\shake.project -- <command>: /~https://github.com/power-fungus/haskell-ide-engine/compare/install-via-cabal...jneira:install-via-cabal-win?expand=1

However, i think it would be desirable that the command would be the same for all systems.
The cost will be that we should add executable config options (like new dependencies) to the executable stanza and the install.hs script

@jneira
Copy link
Member

jneira commented Jul 1, 2019

Opened a ticket upstream: haskell/cabal#6122

@fendor
Copy link
Collaborator

fendor commented Jul 1, 2019

Adding hie-install to cabal.project defeats the purpose of the script. It would require the user to manually initialise the submodules, of which previously the install script took care of. I would prefer it if this script stays independent of hie's dependencies.

Since cabal-new-install does not work on windows with version 2.4.1.0, I think we can safely assume, that nobody on windows can use the cabal script. So, windows only has the possibility to run the stack script, while linux users can do both, I suggest we we wait until the issue is resolved upstream and we update this install script to work with cabal 3.0.0.0.

@jneira
Copy link
Member

jneira commented Jul 1, 2019

@fendor ok, we can wait to full cabal support having an alternative for windows

@samuelpilz
Copy link
Contributor Author

@jneira I appreciate your review.

I like the idea of the the commit you proposed. You added an executable to hie-install with main-is: ../install.hs. Does this work even if install.hs does not have a module-header and starts with #!...? How is this supposed to be called? cabal v2-build --project-file install/shake.project && cabal v2-run exe:hie-install --project-file install/shake.project?
Could you add an additional line in the install.hs to document how to call this and I am happy to accept an PR for this cange.

The CI build shows that the script works fine on windows when run with stack 🎉 For me, this is a good first step.

I will do a bit more experiments in the next few days and integrate the install.hs process into the azure-ci pipeline.

@jneira
Copy link
Member

jneira commented Jul 1, 2019

@power-fungus Yeah it would work even without any header cause it only has to be a simple haskell module with main :: IO(). However it is unusual to point in a executable stanza to a module in the parent folder of the .cabal file (so arguably it is kinda a hack)
Otoh it seems that cabal support scripting for windows in the dev 2.4 branch so i think we can wait to the next cabal release that hopefully will have support for scripting and v2-installing for windows, as suggested by @fendor.
I am just building cabal from master to test the branch.

@jneira
Copy link
Member

jneira commented Jul 1, 2019

With cabal built from 2.4 branch the script works

@fendor
Copy link
Collaborator

fendor commented Jul 4, 2019

So, stack works for windows right?
Maybe for now, we could document in the readme that on windows, only execution with stack is supported. Otherwise, I am in favour of merging this!

@samuelpilz
Copy link
Contributor Author

@fendor
Copy link
Collaborator

fendor commented Jul 7, 2019

This PR is looking great, I think. We should wait for the next release, and merge it after it, so we can do some dog fooding.

@samuelpilz
Copy link
Contributor Author

Let me rebase this and add ci integration and this is ready to merge

README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
azure-pipelines.yml Show resolved Hide resolved
@fendor fendor merged commit 58461a0 into haskell:master Jul 12, 2019
@alanz alanz added this to the 2019-07 milestone Aug 3, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Explain how to install with cabal in README
4 participants