Skip to content

Commit 9865bc0

Browse files
committed
- change build files folder, add vscode generator support
1 parent 75ec6e9 commit 9865bc0

11 files changed

Lines changed: 541 additions & 13 deletions

File tree

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,9 @@ PSXToolchain/CDSrc/REDRIVER2.cue
3535
PSXToolchain/CDSrc/*.txt
3636
src_rebuild/dependencies/*
3737
src_rebuild/.vs/*
38+
src_rebuild/.vscode/*
3839
src_rebuild/bin/*
3940
src_rebuild/obj/*
40-
src_rebuild/project_*
41+
src_rebuild/build*
4142
src_rebuild/*.make
4243
src_rebuild/Makefile

linux_dev_prepare.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/usr/bin/env bash
2+
3+
# Install
4+
export PREMAKE_URL="https://github.com/premake/premake-core/releases/download/v5.0.0-beta1/premake-5.0.0-beta1-linux.tar.gz"
5+
6+
curl "$PREMAKE_URL" -Lo premake5.tar.gz
7+
tar xvf premake5.tar.gz
8+
rm -f premake5.tar.gz
9+
10+
PREMAKE=$(pwd)/premake5
11+
12+
# Configure
13+
cd "src_rebuild"
14+
$PREMAKE gmake2
15+
$PREMAKE vscode
16+
cd project_gmake2_linux
17+
18+

src_rebuild/premake5.lua

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
require "premake_modules/usage"
44
require "premake_modules/emscripten"
5+
require "premake_modules/vscode"
56

67
IS_ANDROID = (_ACTION == "androidndk")
78

@@ -35,7 +36,15 @@ end
3536
------------------------------------------
3637

3738
workspace "REDRIVER2"
38-
location "project_%{_ACTION}_%{os.target()}"
39+
if _ACTION ~= "vscode" then
40+
location "build"
41+
else
42+
-- setup VSCode generator settings
43+
vscode_makefile "build"
44+
vscode_launch_cwd ("${workspaceRoot}/../data")
45+
--vscode_launch_environment { }
46+
end
47+
3948
configurations { "Debug", "Release", "Release_dev" }
4049

4150
defines { VERSION }
@@ -150,13 +159,8 @@ workspace "REDRIVER2"
150159
cppdialect "C++11"
151160

152161
filter {"system:Linux", "platforms:x86"}
153-
buildoptions {
154-
"-m32"
155-
}
156-
157-
linkoptions {
158-
"-m32"
159-
}
162+
buildoptions { "-m32" }
163+
linkoptions { "-m32" }
160164

161165
filter "system:Windows"
162166
disablewarnings { "4996", "4554", "4244", "4101", "4838", "4309" }

src_rebuild/premake5_font_tool.lua

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ project "FontTool"
1515
"utils/targa.*",
1616
}
1717

18-
defines { }
19-
2018
includedirs {
2119
"utils",
2220
"PsyCross/include/psx"

src_rebuild/premake5_psycross.lua

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ project "PsyCross"
1717
"PsyCross/**.CPP",
1818
}
1919

20-
defines { }
21-
2220
includedirs {
2321
SDL2_DIR.."/include",
2422
OPENAL_DIR.."/include",
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2020 Yehonatan Ballas
4+
Copyright (c) 2022-2023 Jan "GamesTrap" Schürkamp
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a copy
7+
of this software and associated documentation files (the "Software"), to deal
8+
in the Software without restriction, including without limitation the rights
9+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
copies of the Software, and to permit persons to whom the Software is
11+
furnished to do so, subject to the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included in all
14+
copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
SOFTWARE.
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Premake-VSCodeGen
2+
3+
[Visual Studio Code](https://code.visualstudio.com/) workspace generator for [Premake](https://github.com/premake/premake-core).
4+
5+
Supports GCC (& Clang, untested) through Make and MSVC through MSBuild.
6+
7+
## Usage
8+
9+
1. Put these files in a `vscode` subdirectory in one of [Premake's search paths](https://premake.github.io/docs/Locating-Scripts/).
10+
2. Add the line `require "vscode"` preferably to your [premake-system.lua](https://premake.github.io/docs/System-Scripts/), or to your premake5.lua script.
11+
3. Generate project files and then VSCode workspace
12+
13+
```
14+
premake5 gmake2/vs2022
15+
premake5 vscode
16+
```
17+
18+
Note: On Windows make sure that `msbuild.exe` is accessible from CMD.
19+
20+
## Limitations
21+
22+
Currently this generater only supports a single [Premake Workspace](https://premake.github.io/docs/workspace/).
23+
Currently the generated tasks will only use 3/4 of the available CPU threads (guaranteed minimum is 1 thread).
24+
This generator only supports C/C++, all other project types are ignored.
25+
26+
## What files get generated
27+
28+
This generator generates the following files:
29+
30+
- \<WorkspaceName\>.code-workspace (only if not already exists)
31+
- .vscode/c_cpp_properties.json
32+
- .vscode/launch.json
33+
- .vscode/tasks.json
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
--
2+
-- Name: _manifest.lua
3+
-- Purpose: Define the cmake action.
4+
-- Author: Ryan Pusztai
5+
-- Modified by: Andrea Zanellato
6+
-- Andrew Gough
7+
-- Manu Evans
8+
-- Yehonatan Ballas
9+
-- Jan "GamesTrap" Schürkamp
10+
-- Created: 2013/05/06
11+
-- Updated: 2022/12/29
12+
-- Copyright: (c) 2008-2020 Jason Perkins and the Premake project
13+
-- (c) 2022 Jan "GamesTrap" Schürkamp
14+
--
15+
16+
return
17+
{
18+
"_preload.lua",
19+
"vscode.lua",
20+
"vscode_project.lua",
21+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
--
2+
-- Name: _preload.lua
3+
-- Purpose: Define the cmake action.
4+
-- Author: Ryan Pusztai
5+
-- Modified by: Andrea Zanellato
6+
-- Andrew Gough
7+
-- Manu Evans
8+
-- Yehonatan Ballas
9+
-- Jan "GamesTrap" Schürkamp
10+
-- Created: 2013/05/06
11+
-- Updated: 2022/12/29
12+
-- Copyright: (c) 2008-2020 Jason Perkins and the Premake project
13+
-- (c) 2022 Jan "GamesTrap" Schürkamp
14+
--
15+
16+
local p = premake
17+
18+
newaction
19+
{
20+
trigger = "vscode",
21+
shortname = "VSCode",
22+
description = "Generate Visual Studio Code workspace",
23+
24+
onWorkspace = function(wks)
25+
p.modules.vscode.generateWorkspace(wks)
26+
end,
27+
}
28+
29+
return function(cfg)
30+
return (_ACTION == "vscode")
31+
end
Lines changed: 176 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
1+
--
2+
-- Name: vscode.lua
3+
-- Purpose: Define the vscode action(s).
4+
-- Author: Ryan Pusztai
5+
-- Modified by: Andrea Zanellato
6+
-- Andrew Gough
7+
-- Manu Evans
8+
-- Jason Perkins
9+
-- Yehonatan Ballas
10+
-- Jan "GamesTrap" Schürkamp
11+
-- Created: 2013/05/06
12+
-- Updated: 2022/12/29
13+
-- Copyright: (c) 2008-2020 Jason Perkins and the Premake project
14+
-- (c) 2022-2023 Jan "GamesTrap" Schürkamp
15+
--
16+
17+
local p = premake
18+
19+
p.modules.vscode = {}
20+
p.modules.vscode._VERSION = p._VERSION
21+
22+
local vscode = p.modules.vscode
23+
local project = p.project
24+
25+
p.api.register {
26+
name = "vscode_makefile",
27+
scope = "workspace",
28+
display = "[vscode] makefile location",
29+
description = "Location of the makefile",
30+
kind = "string",
31+
tokens = true,
32+
}
33+
34+
p.api.register {
35+
name = "vscode_solution",
36+
scope = "workspace",
37+
display = "[VSCode] sln location",
38+
description = "Location of the solution file",
39+
kind = "string",
40+
tokens = true,
41+
}
42+
43+
p.api.register {
44+
name = "vscode_launch_visualizerFile",
45+
scope = "project",
46+
display = "[VSCode] launchdebugger NatVis file",
47+
description = "Debugger NatVis file",
48+
kind = "string",
49+
tokens = true,
50+
}
51+
52+
p.api.register {
53+
name = "vscode_launch_cwd",
54+
scope = "config",
55+
display = "[VSCode] launch working directory",
56+
description = "Working directory of launched app",
57+
kind = "string",
58+
tokens = true,
59+
}
60+
61+
p.api.register {
62+
name = "vscode_launch_environment",
63+
scope = "config",
64+
display = "[VSCode] launch environment strings",
65+
description = "Environment strings of launched app",
66+
kind = "table",
67+
tokens = true,
68+
}
69+
70+
p.api.register {
71+
name = "vscode_launch_args",
72+
scope = "config",
73+
display = "[VSCode] launch arguments",
74+
description = "Launched app arguments",
75+
kind = "list:string",
76+
tokens = true,
77+
}
78+
79+
local function splitStr(instr, separator)
80+
if separator == nil then
81+
separator = "%s"
82+
end
83+
local t = {}
84+
for str in string.gmatch(instr, "([^".. separator .. "]+)") do
85+
table.insert(t, str)
86+
end
87+
return t
88+
end
89+
90+
local function longestCommonPath(prj)
91+
local files = {}
92+
for _, f in ipairs(prj.files) do
93+
table.insert(files, f)
94+
end
95+
if #files == 0 then return './' end
96+
97+
local commonParts = splitStr(files[1], "/")
98+
for i = 2, #files do
99+
local parts = splitStr(files[i], "/")
100+
for j = #commonParts, 1, -1 do
101+
if parts[j] ~= commonParts[j] then
102+
commonParts[j] = nil
103+
end
104+
end
105+
end
106+
local commonPartsClean = {}
107+
for _, v in ipairs(commonParts) do
108+
if v ~= nil then
109+
table.insert(commonPartsClean, v)
110+
end
111+
end
112+
113+
local result = table.concat(commonPartsClean, "/")
114+
if files[1]:sub(1, 1) == "/" then
115+
result = "/" .. result
116+
end
117+
118+
return result
119+
end
120+
121+
function vscode.generateWorkspace(wks)
122+
-- Only create workspace file if it doesnt already exist
123+
124+
local codeWorkspaceFile = io.open(wks.location .. "/" .. wks.name .. ".code-workspace", "w")
125+
codeWorkspaceFile:write('{\n\t"folders":\n\t[')
126+
codeWorkspaceFile:write('\n\t\t{\n\t\t\t"path": ".",\n\t\t},')
127+
128+
local makefileLocation = ''
129+
if wks.vscode_makefile ~= nil then
130+
makefileLocation = '/'..wks.vscode_makefile
131+
end
132+
133+
-- Create tasks.json file
134+
local tasksFile = io.open(wks.location .. "/.vscode/tasks.json", "w")
135+
tasksFile:write('{\n\t"version": "2.0.0",\n\t"options":\n\t{\n')
136+
tasksFile:write(string.format('\t\t"cwd": "${workspaceRoot}%s",\n\t},\n', makefileLocation))
137+
tasksFile:write('\t"tasks":\n\t[\n')
138+
139+
-- Create launch.json file
140+
local launchFile = io.open(wks.location .. "/.vscode/launch.json", "w")
141+
launchFile:write('{\n\t"version": "2.0.0",\n\t"configurations":\n\t[\n')
142+
143+
-- Create c_cpp_properties.json file
144+
local propsFile = io.open(wks.location .. "/.vscode/c_cpp_properties.json", "w")
145+
propsFile:write('{\n\t"version": 4,\n\t"configurations":\n\t[\n')
146+
147+
-- For each project
148+
for prj in p.workspace.eachproject(wks) do
149+
if project.isc(prj) or project.iscpp(prj) then
150+
vscode.project.vscode_tasks(prj, tasksFile)
151+
vscode.project.vscode_launch(prj, launchFile)
152+
vscode.project.vscode_c_cpp_properties(prj, propsFile)
153+
154+
--local sourcePath = path.getrelative(prj.workspace.location, longestCommonPath(prj))
155+
--codeWorkspaceFile:write(string.format('\n\t\t{\n\t\t\t"name": "%s",\n\t\t\t"path": "%s",\n\t\t},', prj.name, sourcePath))
156+
end
157+
end
158+
159+
propsFile:write('\t]\n}\n')
160+
propsFile:close()
161+
162+
launchFile:write('\t]\n}\n')
163+
launchFile:close()
164+
165+
tasksFile:write('\t]\n}\n')
166+
tasksFile:close()
167+
168+
codeWorkspaceFile:write('\n\t],\n}\n')
169+
codeWorkspaceFile:close()
170+
end
171+
172+
include("vscode_project.lua")
173+
174+
include("_preload.lua")
175+
176+
return vscode

0 commit comments

Comments
 (0)