@@ -3,39 +3,14 @@ Copyright (c) 2021 Mac Malone. All rights reserved.
3
3
Released under Apache 2.0 license as described in the file LICENSE.
4
4
Authors: Mac Malone
5
5
-/
6
- import Lean.Elab.Frontend
7
6
import Lake.DSL.Attributes
8
- import Lake.DSL.Extensions
9
7
import Lake.Config.FacetConfig
10
8
import Lake.Config.TargetConfig
11
- import Lake.Load.Config
9
+ import Lake.Load.Elab
12
10
13
11
namespace Lake
14
12
open Lean System
15
13
16
- /-- Main module `Name` of a Lake configuration file. -/
17
- def configModuleName : Name := `lakefile
18
-
19
- deriving instance BEq, Hashable for Import
20
-
21
- /- Cache for the imported header environment of Lake configuration files. -/
22
- initialize importEnvCache : IO.Ref (Std.HashMap (List Import) Environment) ← IO.mkRef {}
23
-
24
- /-- Like `Lean.Elab.processHeader`, but using `importEnvCache`. -/
25
- def processHeader (header : Syntax) (opts : Options) (trustLevel : UInt32)
26
- (inputCtx : Parser.InputContext) : StateT MessageLog IO Environment := do
27
- try
28
- let imports := Elab.headerToImports header
29
- if let some env := (← importEnvCache.get).find? imports then
30
- return env
31
- let env ← importModules imports opts trustLevel
32
- importEnvCache.modify (·.insert imports env)
33
- return env
34
- catch e =>
35
- let pos := inputCtx.fileMap.toPosition <| header.getPos?.getD 0
36
- modify (·.add { fileName := inputCtx.fileName, data := toString e, pos })
37
- mkEmptyEnvironment
38
-
39
14
/-- Like `Lean.Environment.evalConstCheck` but with plain universe-polymorphic `Except`. -/
40
15
unsafe def evalConstCheck (env : Environment) (opts : Options) (α) (type : Name) (const : Name) : Except String α :=
41
16
match env.find? const with
@@ -144,30 +119,4 @@ the given directory with the given configuration file.
144
119
-/
145
120
def Package.load (dir : FilePath) (configOpts : NameMap String)
146
121
(configFile := dir / defaultConfigFile) (leanOpts := Options.empty) : LogIO Package := do
147
-
148
- -- Read file and initialize environment
149
- let input ← IO.FS.readFile configFile
150
- let inputCtx := Parser.mkInputContext input configFile.toString
151
- let (header, parserState, messages) ← Parser.parseHeader inputCtx
152
- let (env, messages) ← processHeader header leanOpts 1024 inputCtx messages
153
- let env := env.setMainModule configModuleName
154
-
155
- -- Configure extensions
156
- let env := dirExt.setState env dir
157
- let env := optsExt.setState env configOpts
158
-
159
- -- Elaborate File
160
- let commandState := Elab.Command.mkState env messages leanOpts
161
- let s ← Elab.IO.processCommands inputCtx parserState commandState
162
-
163
- -- Report errors
164
- for msg in s.commandState.messages.toList do
165
- match msg.severity with
166
- | MessageSeverity.information => logInfo (← msg.toString)
167
- | MessageSeverity.warning => logWarning (← msg.toString)
168
- | MessageSeverity.error => logError (← msg.toString)
169
- if s.commandState.messages.hasErrors then
170
- error s! "package configuration `{ configFile} ` has errors"
171
-
172
- -- Load package from the environment
173
- Package.loadFromEnv s.commandState.env
122
+ Package.loadFromEnv (← elabConfigFile dir configOpts configFile leanOpts)
0 commit comments