浏览代码

Improved build.py for more options.
Improved vscode build, clean workflow.
Moved common config to target folder and later use for platform specific target resources.

Sean Taylor 4 年之前
父节点
当前提交
c93fb9d565
共有 7 个文件被更改,包括 153 次插入63 次删除
  1. 1 1
      .vscode/extensions.json
  2. 65 3
      .vscode/tasks.json
  3. 78 46
      build.py
  4. 0 1
      premake5.lua
  5. 3 5
      setup.bat
  6. 4 5
      setup.sh
  7. 2 2
      source/gameplay/Config.cpp

+ 1 - 1
.vscode/extensions.json

@@ -3,6 +3,6 @@
 	// for the documentation about the extensions.json format
 	"recommendations": [
 		"ms-vscode.cpptools",
-		"ms-python.python",
+		"ms-python.python"
 	]
 }

+ 65 - 3
.vscode/tasks.json

@@ -4,11 +4,73 @@
     "version": "2.0.0",
     "tasks": [
         {
-            "label": "build",
+            "label": "Build (debug)",
             "type": "shell",
-            "command": "./build.sh ",
+            "command": "./build.sh -b --configuration=debug",
             "windows": {
-                "command": ".\\build.bat"
+                "command": ".\\build.bat -b --configuration=debug"
+            },
+            "problemMatcher": {
+                "owner": "cpp",
+                "fileLocation": [
+                    "relative",
+                    "${workspaceRoot}/_compiler/vs2019/gameplay"
+                ],
+                "pattern": {
+                    "regexp": "^(.*):(\\d+): \\s+(warning|error):\\s+(.*)$",
+                    "file": 1,
+                    "line": 2,
+                    "severity": 3,
+                    "message": 4
+                }
+            },
+            "group": {
+                "kind": "build",
+                "isDefault": true
+            },
+            "presentation": {
+                "reveal": "always",
+                "panel": "dedicated",
+                "clear": true
+            }
+        },
+        {
+            "label": "Build (release)",
+            "type": "shell",
+            "command": "./build.sh -b --configuration=release",
+            "windows": {
+                "command": ".\\build.bat -b --configuration=release"
+            },
+            "problemMatcher": {
+                "owner": "cpp",
+                "fileLocation": [
+                    "relative",
+                    "${workspaceRoot}/_compiler/vs2019/gameplay"
+                ],
+                "pattern": {
+                    "regexp": "^(.*):(\\d+): \\s+(warning|error):\\s+(.*)$",
+                    "file": 1,
+                    "line": 2,
+                    "severity": 3,
+                    "message": 4
+                }
+            },
+            "group": {
+                "kind": "build",
+                "isDefault": true
+            },
+            "presentation": {
+                "reveal": "always",
+                "panel": "dedicated",
+                "clear": true
+            }
+        },
+        {
+            "label": "Clean (all)",
+            "type": "shell",
+            "command": "./build.sh -c" ,
+            "windows": {
+                "command": ".\\build.bat -c"
             },
             "problemMatcher": {
                 "owner": "cpp",

+ 78 - 46
build.py

@@ -1,7 +1,8 @@
 ##############################################################################
-# Packaging script for building and packaging gameplay-deps-<platform>.zip 
+# build.py script
 ##############################################################################
 import os
+import argparse
 import glob
 import platform
 import subprocess
@@ -12,25 +13,25 @@ import zipfile
 from pathlib import Path
 from distutils.dir_util import copy_tree
 
-# constants
+# build.py arguments
 ##############################################################################
+parser = argparse.ArgumentParser()
+parser.add_argument("-c", "--clean_only", help="Clean only", action="store_true")
+parser.add_argument("-g", "--generate_only", help="Generates only", action="store_true")
+parser.add_argument("-b", "--build_only", help="Builds only", action="store_true")
+parser.add_argument("-w", "--wait_keypress", help="Builds only", action="store_true")
+parser.add_argument("--configuration", help="Specify the configuration. (all,debug,release)", default="all")
+parser.add_argument("--toolchain",  help="Toolchain override.")
+args = parser.parse_args()
 
-TOOLS_FOLDER = "_tools"
-COMPILER_FOLDER = "_compiler"
-BUILD_FOLDER = "_build"
-
-# platform-architecture
+# constants
 ##############################################################################
-platform_arch = ""
-if sys.platform == "win32":
-    platform_arch = "windows-x86_64"
-elif sys.platform == "darwin":
-    platform_arch = "macos-x86_64"
-else:
-    platform_arch = "linux-x86_64"
 
+BUILD_FOLDER = "_build"
+COMPILER_FOLDER = "_compiler"
+DEPS_FOLDER = "_deps"
 
-# function utils
+# utility functions
 ##############################################################################
 
 def clear_dir(dir_path):
@@ -64,43 +65,74 @@ def init_vsvars():
 # building
 ##############################################################################
 
-# arguments
-argc = len(sys.argv)
-generate_only = False
-arg0 = ""
-if argc > 1:
-    arg0 = sys.argv[1]
-    if arg0 == "-g":
-        generate_only = True
-
-# generate/premake
 current_dir = os.getcwd()
-if sys.platform == "win32":
-    compiler_args = "vs2019"
-elif sys.platform == "darwin":
-    compiler_args = "xcode4"
-else:
-    compiler_args = "gmake"
-tools_dir = os.path.join(current_dir, TOOLS_FOLDER)
-premake_proc = subprocess.Popen(f"{tools_dir}/premake/premake5 --file=premake5.lua {compiler_args}", cwd=current_dir, shell=True)
-premake_proc.wait()
 
-# build
-if not generate_only:
-    compiler_dir =  os.path.join(current_dir, COMPILER_FOLDER)
+# generate premake for toolchain (specified or host detected)
+if args.toolchain:
+    toolchain = args.toolchain
+else:
     if sys.platform == "win32":
+        toolchain = "vs2019"
+    elif sys.platform == "linux":
+        toolchain = "gmake"        
+    elif sys.platform == "darwin":
+        toolchain = "xcode4"
+
+# premake
+if not args.build_only and not args.clean_only:    
+    deps_dir = os.path.join(current_dir, DEPS_FOLDER)
+    premake_proc = subprocess.Popen(f"{deps_dir}/premake/premake5 --file=premake5.lua {toolchain}", cwd=current_dir, shell=True)
+    premake_proc.wait()
+
+# clean build check
+clean_build = False
+if args.clean_only and os.path.exists(os.path.join(current_dir, BUILD_FOLDER)):
+    clean_build = True
+
+# build configurations
+config_debug = False
+config_release = False
+if args.configuration == "all":
+    config_debug = True
+    config_release = True
+elif args.configuration == "debug":
+    config_debug = True
+elif args.configuration == "release":
+    config_release = True
+
+# build compiler/toolchain (skip if generate_only is specified)
+if not args.generate_only:
+    compiler_dir = os.path.join(current_dir, COMPILER_FOLDER)
+    if toolchain == "vs2019":
         compiler_dir = os.path.join(compiler_dir, "vs2019")
         init_vsvars()
         os.chdir(compiler_dir)
-        subprocess.run("msbuild gameplay.sln /property:Configuration=Debug")
-        subprocess.run("msbuild gameplay.sln /property:Configuration=Release")
-    elif sys.platform == "darwin":
+        clean_build_args = ""
+        if clean_build:
+            clean_build_args=" -t:Clean"
+        if config_debug:
+            subprocess.run(f"msbuild gameplay.sln /property:Configuration=Debug{clean_build_args}")
+        if config_release:
+            subprocess.run(f"msbuild gameplay.sln /property:Configuration=Release{clean_build_args}")
+    elif toolchain == "gmake":
+        compiler_dir = os.path.join(compiler_dir, "gmake")
+        os.chdir(compiler_dir)
+        clean_build_args = ""
+        if clean_build:
+            clean_build_args=" clean"
+        if config_debug:
+            subprocess.run(f"make config=debug_x86_64{clean_build_args}", shell=True)
+        if config_release:
+            subprocess.run(f"make config=release_x86_6 {clean_build_args}", shell=True)
+    elif toolchain == "xcode4":
         compiler_dir = os.path.join(compiler_dir, "xcode4")
         os.chdir(compiler_dir)
-        subprocess.run("xcodebuild -workspace gameplay.xcworkspace -configuration Debug build")
-        subprocess.run("xcodebuild -workspace gameplay.xcworkspace -configuration Release build")
+        clean_build_args = ""
+        if clean_build:
+            clean_build_args=" clean"
+        if config_debug:
+            subprocess.run(f"xcodebuild{clean_build_args} -workspace gameplay.xcworkspace -configuration Debug build", shell=True)
+        if config_release:
+            subprocess.run(f"xcodebuild{clean_build_args} -workspace gameplay.xcworkspace -configuration Release build", shell=True)
     else:
-        compiler_dir = os.path.join(compiler_dir, "gmake")
-        os.chdir(compiler_dir)
-        subprocess.run("make config=debug_x86_64", shell=True)
-        subprocess.run("make config=release_x86_64", shell=True)
+        print("Error: Compiler toolchain not supported.")

+ 0 - 1
premake5.lua

@@ -4,7 +4,6 @@ workspace "gameplay"
     if _ACTION ~= nill then project_action = _ACTION end
     
     local platform = "%{cfg.system}-%{cfg.platform}"
-
     local target_dir = path.join(os.getcwd(), "_build/"..platform.."/%{cfg.buildcfg}")
     local workspace_dir = path.join(os.getcwd(), "_compiler/"..project_action)
     local deps_dir = path.join(os.getcwd(), "_deps")

+ 3 - 5
setup.bat

@@ -2,20 +2,18 @@
 rem
 rem setup.bat 
 rem
-rem Tools
-set install_path=%cd%\_tools
+rem download + install: premake-<platform>.zip -> _deps
+set install_path=%cd%\_deps
 set package_url=https://github.com/gameplay3d/gameplay-deps/releases/download/v4.0.0/
 set filename=premake-5.0.0-windows
 set zipfile=%filename%.zip
-
 if not exist %install_path% mkdir %install_path%
 echo Downloading %prefix%%zipfile%...
 powershell -Command "([Net.ServicePointManager]::SecurityProtocol=\"tls12, tls11, tls\") -AND ($ProgressPreference='SilentlyContinue') -AND (Invoke-WebRequest '%package_url%/%filename%.zip' -OutFile '%filename%.zip') | Out-Null"
 echo Extracting %filename%.zip... please standby...
 powershell -Command "Expand-Archive %filename%.zip -Force -DestinationPath %install_path%" 
 powershell -Command "Remove-Item %filename%.zip -Force"
-rem Dependencies
-set install_path=%cd%\\_deps
+rem download + install: gameplay-deps-<platform>.zip -> _deps
 set package_url=https://github.com/gameplay3d/gameplay/releases/download/v4.0.0/
 set filename=gameplay-deps-windows
 set zipfile=%filename%.zip

+ 4 - 5
setup.sh

@@ -9,18 +9,17 @@ elif [ "$(expr substr $(uname -s) 1 5)" == "Linux" ]; then
 else
     platform=windows
 fi
-# _tools
-mkdir -p _tools
+mkdir -p _deps
+# download + install: premake-<platform>.zip -> _deps
 package_url=https://github.com/gameplay3d/gameplay-deps/releases/download/v4.0.0
 filename=premake-5.0.0-$platform.zip
 echo Downloading $filename from $package_url...
 curl -# -LO $package_url/$filename
 echo Extracting $filename... please standby...
-unzip -q $filename -d _tools
+unzip -q $filename -d _deps
 echo Cleaning up...
 rm $filename
-# _deps
-mkdir -p _deps
+# download + install: gameplay-deps-<platform>.zip -> _deps
 package_url=https://github.com/gameplay3d/gameplay/releases/download/v4.0.0
 filename=gameplay-deps-$platform.zip
 echo Downloading $filename from $prefix...

+ 2 - 2
source/gameplay/Config.cpp

@@ -11,7 +11,7 @@
 #define GP_CONFIG_SETTING "config"
 #define GP_CONFIG_EXT ".toml"
 #define GP_CONFIG_FILE_DEFAULT "app.config.toml"
-#define GP_CONFIG_DEV_DIR "../../../config"
+#define GP_CONFIG_TARGET_DIR "../../../target"
 
 namespace gameplay
 {
@@ -134,7 +134,7 @@ void Config::load(int argc, char** argv)
         _impl->configPath = Path(appExecutablePath).get_parent().join(Path(GP_CONFIG_FILE_DEFAULT)).get_absolute();
         if (!fs->exists(_impl->configPath.c_str()))
         {
-            _impl->configPath = Path(appExecutablePath).get_parent().join(Path(GP_CONFIG_DEV_DIR)).join(Path(GP_CONFIG_FILE_DEFAULT)).get_absolute();
+            _impl->configPath = Path(appExecutablePath).get_parent().join(Path(GP_CONFIG_TARGET_DIR)).join(Path(GP_CONFIG_FILE_DEFAULT)).get_absolute();
             if (!fs->exists(_impl->configPath.c_str()))
             {
                 configFound = false;