프로그래밍 Programming

하스켈 패키지 삭제하기 How to uninstall a Haskell package installed with stack?

문장전달자 2018. 2. 6. 18:32
728x90


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
 
(blackbriar) root@gcloudx:~/blackbriar/blackbriar# stack --help
stack - The Haskell Tool Stack
 
Usage: stack [--help] [--version] [--numeric-version] [--hpack-numeric-version]
             [--docker*] [--nix*] ([--verbosity VERBOSITY] | [-v|--verbose] |
             [--silent]) [--[no-]time-in-log] [--stack-root STACK-ROOT]
             [--work-dir WORK-DIR] [--[no-]system-ghc] [--[no-]install-ghc]
             [--arch ARCH] [--ghc-variant VARIANT] [--ghc-build BUILD]
             [-j|--jobs JOBS] [--extra-include-dirs DIR] [--extra-lib-dirs DIR]
             [--with-gcc PATH-TO-GCC] [--[no-]skip-ghc-check] [--[no-]skip-msys]
             [--local-bin-path DIR] [--[no-]modify-code-page]
             [--[no-]allow-different-user] [--[no-]dump-logs]
             [--resolver RESOLVER] [--compiler COMPILER] [--[no-]terminal]
             [--color WHEN] [--stack-yaml STACK-YAML] COMMAND|FILE
 
Available options:
  --help                   Show this help text
  --version                Show version
  --numeric-version        Show only version number
  --hpack-numeric-version  Show only hpack's version number
  --docker*                Run 'stack --docker-help' for details
  --nix*                   Run 'stack --nix-help' for details
  --verbosity VERBOSITY    Verbosity: silent, error, warn, info, debug
  -v,--verbose             Enable verbose mode: verbosity level "debug"
  --silent                 Enable silent mode: verbosity level "silent"
  --[no-]time-in-log       Enable/disable inclusion of timings in logs, for the
                           purposes of using diff with logs
  --stack-root STACK-ROOT  Absolute path to the global stack root directory
                           (Overrides any STACK_ROOT environment variable)
  --work-dir WORK-DIR      Relative path of work directory (Overrides any
                           STACK_WORK environment variable, default is
                           '.stack-work')
  --[no-]system-ghc        Enable/disable using the system installed GHC (on the
                           PATH) if available and a matching version. Disabled
                           by default.
  --[no-]install-ghc       Enable/disable downloading and installing GHC if
                           necessary (can be done manually with stack setup)
  --arch ARCH              System architecture, e.g. i386, x86_64
  --ghc-variant VARIANT    Specialized GHC variant, e.g. integersimple
                           (incompatible with --system-ghc)
  --ghc-build BUILD        Specialized GHC build, e.g. 'gmp4' or 'standard'
                           (usually auto-detected)
  -j,--jobs JOBS           Number of concurrent jobs to run
  --extra-include-dirs DIR Extra directories to check for C header files
  --extra-lib-dirs DIR     Extra directories to check for libraries
  --with-gcc PATH-TO-GCC   Use gcc found at PATH-TO-GCC
  --[no-]skip-ghc-check    Enable/disable skipping the GHC version and
                           architecture check
  --[no-]skip-msys         Enable/disable skipping the local MSYS installation
                           (Windows only)
  --local-bin-path DIR     Install binaries to DIR
  --[no-]modify-code-page  Enable/disable setting the codepage to support UTF-8
                           (Windows only)
  --[no-]allow-different-user
                           Enable/disable permission for users other than the
                           owner of the stack root directory to use a stack
                           installation (POSIX only)
  --[no-]dump-logs         Enable/disable dump the build output logs for local
                           packages to the console
  --resolver RESOLVER      Override resolver in project file
  --compiler COMPILER      Use the specified compiler
  --[no-]terminal          Enable/disable overriding terminal detection in the
                           case of running in a false terminal
  --color WHEN             Specify when to use color in output; WHEN is
                           'always', 'never', or 'auto'
  --stack-yaml STACK-YAML  Override project stack.yaml file (overrides any
                           STACK_YAML environment variable)
 
Available commands:
  build                    Build the package(s) in this directory/configuration
  install                  Shortcut for 'build --copy-bins'
  uninstall                DEPRECATED: This command performs no actions, and is
                           present for documentation only
  test                     Shortcut for 'build --test'
  bench                    Shortcut for 'build --bench'
  haddock                  Shortcut for 'build --haddock'
  new                      Create a new project from a template. Run `stack
                           templates' to see available templates.
  templates                List the templates available for `stack new'.
  init                     Create stack project config from cabal or hpack
                           package specifications
  solver                   Add missing extra-deps to stack project config
  setup                    Get the appropriate GHC for your project
  path                     Print out handy path information
  unpack                   Unpack one or more packages locally
  update                   Update the package index
  upgrade                  Upgrade to the latest stack
  upload                   Upload a package to Hackage
  sdist                    Create source distribution tarballs
  dot                      Visualize your project's dependency graph using
                           Graphviz dot
  ghc                      Run ghc
  hoogle                   Run hoogle, the Haskell API search engine. Use 'stack
                           exec' syntax to pass Hoogle arguments, e.g. stack
                           hoogle -- --count=20
  exec                     Execute a command
  ghci                     Run ghci in the context of package(s) (experimental)
  repl                     Run ghci in the context of package(s) (experimental)
                           (alias for 'ghci')
  runghc                   Run runghc
  runhaskell               Run runghc (alias for 'runghc')
  script                   Run a Stack Script
  eval                     Evaluate some haskell code inline. Shortcut for
                           'stack exec ghc -- -e CODE'
  clean                    Clean the local packages
  list-dependencies        List the dependencies
  query                    Query general build information (experimental)
  ide                      IDE-specific commands
  docker                   Subcommands specific to Docker use
  config                   Subcommands specific to modifying stack.yaml files
  image                    Subcommands specific to imaging
  hpc                      Subcommands specific to Haskell Program Coverage
 
stack's documentation is available at https://docs.haskellstack.org/
cs

위의 stack --help 에서 확인할 수 있는 것처럼, uninstall 은 아무런 기능도 수행하지 않는다. 그러므로 공식적으로는 패키지를 제거하기 위해 스택을 사용할 방법은 없다. 그럼 패키지를 제거하기 위해서는 수동으로 진행할 수 밖에 없다. 아래에서 살펴보자. 항상 기억해야할 것은 “Cabal is not a Package Manager” 라는 사실이다.


패키지를 삭제하기 위해서는 다음과 같은 형식으로 명령어를 실행한다. 만약 해당 패키지에 의존하고 있는 패키지가 있다면 다음과 같이 연결이 끊어지는 오류가 발생할 수 있다는 메시지를 받는다.


1
2
3
4
5
6
7
# ghc-pkg list xhtml
/usr/lib/ghc/package.conf.d
   xhtml-3000.2.1
/root/.ghc/x86_64-linux-7.10.3/package.conf.d
 
# ghc-pkg unregister xhtml-3000.2.1
ghc-pkg: unregistering would break the following packages: cgi-3001.2.2.2 (use --force to override)
cs


관계없다면 --force 플래그를 추가해서 다음과 같이 삭제한다. 해당 패키지를 다시 조회해보면 다음과 같이 broken package 가 있음을 알 수 있다.

1
2
3
4
5
6
7
# ghc-pkg unregister --force xhtml-3000.2.1
unregistering would break the following packages: cgi-3001.2.2.2 (ignoring)
 
# ghc-pkg list xhtml
WARNING: there are broken packages.  Run 'ghc-pkg check' for more details.
/usr/lib/ghc/package.conf.d
/root/.ghc/x86_64-linux-7.10.3/package.conf.d
cs


그럼, 깨진 패키지도 제거하자. ghc-pkg check 를 통해 깨진 패키지의 이름을 확인할 수 있다. 다음과 같이 해당 패키지를 제거한다.    

1
2
3
4
5
6
7
8
9
10
# ghc-pkg check
There are problems in package cgi-3001.2.2.2:
  dependency "xhtml-3000.2.1-e005917157f780654d68110616d034e8" doesn't exist
The following packages are broken, either because they have a problem
listed above, or because they depend on a broken package.
cgi-3001.2.2.2
 
# ghc-pkg unregister cgi-3001.2.2.2
 
# ghc-pkg check
cs


추가적으로 cabal-gc 등을 통해 가비지 콜렉션을 할 수도 있다.
















728x90