Skip to content

Commit efc709a

Browse files
committed
Introduce InvocationContext
For script caching we started storing script paths as absolute, but displayed paths are generally relative to the starting directory. This was hacked in as `script.base_directory`. Introducing the `InvocationContext`. To avoid global state, things that need information about how cyan itself was invoked should take this as a parameter. Right now it only contains the initial directory and project root directory.
1 parent bbd1d53 commit efc709a

File tree

17 files changed

+173
-65
lines changed

17 files changed

+173
-65
lines changed

build/cyan/cli.lua

Lines changed: 8 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/cyan/command.lua

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/cyan/commands/build.lua

Lines changed: 8 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/cyan/commands/check-gen.lua

Lines changed: 11 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/cyan/commands/initialize.lua

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/cyan/commands/run.lua

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/cyan/invocation-context.lua

Lines changed: 46 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/cyan/script.lua

Lines changed: 4 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cyan-dev-1.rockspec

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ build = {
3535
["cyan.fs"] = "build/cyan/fs.lua",
3636
["cyan.graph"] = "build/cyan/graph.lua",
3737
["cyan.interaction"] = "build/cyan/interaction.lua",
38+
["cyan.invocation-context"] = "build/cyan/invocation-context.lua",
3839
["cyan.log"] = "build/cyan/log.lua",
3940
["cyan.meta"] = "build/cyan/meta.lua",
4041
["cyan.sandbox"] = "build/cyan/sandbox.lua",
@@ -56,6 +57,7 @@ build = {
5657
["cyan.fs"] = "src/cyan/fs.tl",
5758
["cyan.graph"] = "src/cyan/graph.tl",
5859
["cyan.interaction"] = "src/cyan/interaction.tl",
60+
["cyan.invocation-context"] = "src/cyan/invocation-context.tl",
5961
["cyan.log"] = "src/cyan/log.tl",
6062
["cyan.meta"] = "src/cyan/meta.tl",
6163
["cyan.sandbox"] = "src/cyan/sandbox.tl",

src/cyan/cli.tl

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ local common <const> = require("cyan.tlcommon")
1010
local config <const> = require("cyan.config")
1111
local decoration <const> = require("cyan.decoration")
1212
local fs <const> = require("cyan.fs")
13+
local invocation_context <const> = require("cyan.invocation-context")
14+
local lexical_path <const> = require("lexical-path")
1315
local log <const> = require("cyan.log")
1416
local script <const> = require("cyan.script")
1517
local util <const> = require("cyan.util")
@@ -107,15 +109,18 @@ command.new{
107109
}
108110

109111
local starting_dir <const> = assert(fs.current_directory())
110-
script.base_directory = starting_dir
111112
local config_path <const> = config.find()
113+
local project_dir: lexical_path.Path
112114
if config_path then
113115
local config_dir <const> = config_path:copy()
114116
table.remove(config_dir)
115117
log.debug("Changing directory into: ", config_dir)
116-
fs.change_directory(config_dir)
118+
assert(fs.change_directory(config_dir))
119+
project_dir = config_dir
117120
end
118121

122+
local context <const> = invocation_context.new(starting_dir, project_dir)
123+
119124
local loaded_config, config_errors <const>, config_warnings <const>
120125
= config.load()
121126

@@ -181,7 +186,7 @@ do
181186
end
182187

183188
local ok <const>, res <const> = xpcall(function()
184-
exit = cmd.exec(args, loaded_config, starting_dir)
189+
exit = cmd.exec(args, loaded_config, context)
185190
end, debug.traceback as function()) as (boolean, string)
186191
if not ok then
187192
log.err("Error executing command\n ", res)

0 commit comments

Comments
 (0)