Skip to content

Commit 19d3514

Browse files
committed
Use _SCRIPT_DIR instead of os.getcwd().
1 parent 28ac93d commit 19d3514

File tree

10 files changed

+21
-20
lines changed

10 files changed

+21
-20
lines changed

modules/gmake/tests/cpp/test_make_pch.lua

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
pchheader "include/myproject.h"
6565
prepareVars()
6666
test.capture [[
67-
PCH = include/myproject.h
67+
PCH = ../modules/gmake/tests/include/myproject.h
6868
GCH = $(OBJDIR)/$(notdir $(PCH)).gch
6969
]]
7070
end
@@ -79,7 +79,7 @@
7979
includedirs { "../../../src/host" }
8080
prepareVars()
8181
test.capture [[
82-
PCH = ../../../src/host/premake.h
82+
PCH = src/host/premake.h
8383
]]
8484
end
8585

@@ -137,6 +137,6 @@ endif
137137
includedirs { "../../../src/host" }
138138
prepareVars()
139139
test.capture [[
140-
PCH = ../../../../src/host/premake.h
140+
PCH = ../src/host/premake.h
141141
]]
142142
end

modules/gmake2/tests/test_gmake2_pch.lua

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020

2121
local wks, prj
2222
function suite.setup()
23-
os.chdir(_TESTS_DIR)
2423
gmake2.cpp.initialize()
2524
wks, prj = test.createWorkspace()
2625
end
@@ -103,7 +102,7 @@ GCH = $(PCH_PLACEHOLDER).gch
103102
includedirs { "../../../src/host" }
104103
prepareVars()
105104
test.capture [[
106-
PCH = ../../../src/host/premake.h
105+
PCH = premake.h
107106
]]
108107
end
109108

@@ -173,7 +172,7 @@ endif
173172
includedirs { "../../../src/host" }
174173
prepareVars()
175174
test.capture [[
176-
PCH = ../../../../src/host/premake.h
175+
PCH = ../premake.h
177176
]]
178177
end
179178

modules/self-test/test_runner.lua

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,9 @@
8989
local hooks = _.installTestingHooks()
9090

9191
_TESTS_DIR = test.suite._TESTS_DIR
92-
_SCRIPT_DIR = test.suite._SCRIPT_DIR
92+
-- Currently the test suite paths are tested against as if all tests are
93+
-- running with the repository root as their working directory.
94+
_SCRIPT_DIR = _MAIN_SCRIPT_DIR
9395

9496
m.suiteName = test.suiteName
9597
m.testName = test.testName

src/base/api.lua

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@
148148
-- if I have an existing instance, create a new configuration
149149
-- block for it so I don't pick up an old filter
150150
if instance then
151-
configset.addFilter(instance, {}, os.getcwd())
151+
configset.addFilter(instance, {}, _SCRIPT_DIR)
152152
end
153153

154154
-- otherwise, a new instance
@@ -163,7 +163,7 @@
163163
-- (recursive call, so needs to be its own function)
164164
api._clearContainerChildren(class)
165165

166-
-- active this container, as well as it ancestors
166+
-- active this container, as well as its ancestors
167167
if not class.placeholder then
168168
api.scope.current = instance
169169
end
@@ -716,7 +716,7 @@
716716
table.remove(api.scope.global.blocks, i)
717717
end
718718

719-
configset.addFilter(api.scope.current, {}, os.getcwd())
719+
configset.addFilter(api.scope.current, {}, _SCRIPT_DIR)
720720
end
721721

722722

@@ -1087,7 +1087,7 @@
10871087
premake.field.kind("path", {
10881088
paths = true,
10891089
store = function(field, current, value, processor)
1090-
return path.deferredjoin(os.getcwd(), value)
1090+
return path.deferredjoin(_SCRIPT_DIR, value)
10911091
end,
10921092
compare = function(field, a, b, processor)
10931093
return (a == b)
@@ -1152,7 +1152,7 @@
11521152
if (type(terms) == "table" and #terms == 1 and terms[1] == "*") or (terms == "*") then
11531153
terms = nil
11541154
end
1155-
local ok, err = configset.addFilter(api.scope.current, {terms}, os.getcwd())
1155+
local ok, err = configset.addFilter(api.scope.current, {terms}, _SCRIPT_DIR)
11561156
if not ok then
11571157
error(err, 2)
11581158
end

src/base/container.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878
self.name = name
7979
self.filename = name
8080
self.script = _SCRIPT
81-
self.basedir = os.getcwd()
81+
self.basedir = _SCRIPT_DIR
8282
self.external = false
8383

8484
for childClass in container.eachChildClass(class) do

src/base/context.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
-- expected that the creator of the context will set this value using
5050
-- the setbasedir() function.
5151

52-
ctx._basedir = os.getcwd()
52+
ctx._basedir = _SCRIPT_DIR
5353

5454
-- when a missing field is requested, fetch it from my config
5555
-- set, and then cache the value for future lookups

tests/api/test_path_kind.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,5 @@
3434

3535
function suite.convertsToAbsolute()
3636
testapi "self/local.h"
37-
test.isequal(os.getcwd() .. "/self/local.h", api.scope.project.testapi)
37+
test.isequal(_SCRIPT_DIR .. "/self/local.h", api.scope.project.testapi)
3838
end

tests/config/test_linkinfo.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
function suite.directoryIsTargetDir_onTargetDir()
3636
targetdir "../bin"
3737
i = prepare()
38-
test.isequal("../bin", path.getrelative(os.getcwd(), i.directory))
38+
test.isequal("../bin", path.getrelative(_SCRIPT_DIR, i.directory))
3939
end
4040

4141

@@ -48,7 +48,7 @@
4848
targetdir "../bin"
4949
implibdir "../lib"
5050
i = prepare()
51-
test.isequal("../lib", path.getrelative(os.getcwd(), i.directory))
51+
test.isequal("../lib", path.getrelative(_SCRIPT_DIR, i.directory))
5252
end
5353

5454

tests/test_lua.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
--
1212

1313
function suite.loadfile()
14-
local file = path.join(_SCRIPT_DIR, "test_lua_loaded_noenv.lua")
14+
local file = path.join(_TESTS_DIR, "test_lua_loaded_noenv.lua")
1515
local fn = assert(loadfile(file, nil))
1616
local ret, value = pcall(fn)
1717
test.isequal(10, value)
@@ -25,7 +25,7 @@ end
2525
--
2626

2727
function suite.loadfile_with_env()
28-
local file = path.join(_SCRIPT_DIR, "test_lua_loaded.lua")
28+
local file = path.join(_TESTS_DIR, "test_lua_loaded.lua")
2929
local value = 0
3030
local env = {
3131
["foobar"] = function(n) value = n end

website/docs/basedir.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Sets the base directory for a configuration, from with other paths contained by
44
basedir ("value")
55
```
66

7-
You do not normally need to set this value, as it is filled in automatically with the current working directory at the time the configuration block is created by the script.
7+
You do not normally need to set this value, as it is filled in automatically with the current script directory ([`_SCRIPT_DIR`](globals/premake_MAIN_SCRIPT_DIR.md)) at the time the configuration block is created by the script.
88

99
### Parameters ###
1010

0 commit comments

Comments
 (0)