From 44b53fd0a582f15858fad9d8b49180153932e5ca Mon Sep 17 00:00:00 2001 From: kaetemi Date: Thu, 27 Jan 2022 17:15:20 +0800 Subject: [PATCH] Generate toolchain configuration base --- tool/quick_start/README.md | 1 + tool/quick_start/common.py | 38 +++++++ tool/quick_start/common_config.py | 49 +++------ tool/quick_start/config_default.json | 5 +- tool/quick_start/configure_toolchains.py | 34 ++++++ tool/quick_start/find_external.py | 128 +++++++++++++++++++++++ tool/quick_start/find_vstudio.py | 15 +-- tool/quick_start/test.bat | 2 +- 8 files changed, 224 insertions(+), 48 deletions(-) create mode 100644 tool/quick_start/README.md create mode 100644 tool/quick_start/common.py create mode 100644 tool/quick_start/configure_toolchains.py create mode 100644 tool/quick_start/find_external.py diff --git a/tool/quick_start/README.md b/tool/quick_start/README.md new file mode 100644 index 000000000..c3fc20a57 --- /dev/null +++ b/tool/quick_start/README.md @@ -0,0 +1 @@ +Scripts to auto-configure the build pipeline for every possible build target that can be built from the local machine diff --git a/tool/quick_start/common.py b/tool/quick_start/common.py new file mode 100644 index 000000000..672c9d81d --- /dev/null +++ b/tool/quick_start/common.py @@ -0,0 +1,38 @@ + +from common_config import * + +import os + +NeLCodeDir = os.path.join(NeLRootDir, NeLConfig["Paths"]["Code"]) +if not os.path.isdir(NeLCodeDir): + exit("NeL Code directory (" + NeLCodeDir + ") does not exist.") +NeLLeveldesignDir = os.path.join(NeLRootDir, NeLConfig["Paths"]["Leveldesign"]) +if not os.path.isdir(NeLLeveldesignDir): + exit("NeL Leveldesign directory (" + NeLLeveldesignDir + ") does not exist.") +NeLGraphicsDir = os.path.join(NeLRootDir, NeLConfig["Paths"]["Graphics"]) +if not os.path.isdir(NeLGraphicsDir): + exit("NeL Graphics directory (" + NeLGraphicsDir + ") does not exist.") +NeLSoundDir = os.path.join(NeLRootDir, NeLConfig["Paths"]["Sound"]) +if not os.path.isdir(NeLSoundDir): + exit("NeL Sound directory (" + NeLSoundDir + ") does not exist.") +NeLBuildDir = os.path.join(NeLRootDir, NeLConfig["Paths"]["Build"]) +if not os.path.isdir(NeLBuildDir): + exit("NeL Build directory (" + NeLBuildDir + ") does not exist.") +NeLPipelineDir = os.path.join(NeLRootDir, NeLConfig["Paths"]["Pipeline"]) +if not os.path.isdir(NeLPipelineDir): + exit("NeL Pipeline directory (" + NeLPipelineDir + ") does not exist.") + +NeLPython27Dir = os.path.join(NeLRootDir, NeLConfig["Paths"]["Tools"]["Python27"]) +NeLRRDtoolDir = os.path.join(NeLRootDir, NeLConfig["Paths"]["Tools"]["RRDtool"]) +NeLMariaDBDir = os.path.join(NeLRootDir, NeLConfig["Paths"]["Tools"]["MariaDB"]) +NeLNginxDir = os.path.join(NeLRootDir, NeLConfig["Paths"]["Tools"]["Nginx"]) +NeLPHPDir = os.path.join(NeLRootDir, NeLConfig["Paths"]["Tools"]["PHP"]) +NeLphpMyAdminDir = os.path.join(NeLRootDir, NeLConfig["Paths"]["Tools"]["phpMyAdmin"]) +NeL3dsMaxDir = os.path.join(NeLRootDir, NeLConfig["Paths"]["Tools"]["3dsMax"]) + +#print(NeLRootDir) +#print(NeLConfigDir) +#print(NeLConfig["Domain"]) +#print(NeLConfig["Paths"]["Code"]) + +#print(NeLExternalDir) diff --git a/tool/quick_start/common_config.py b/tool/quick_start/common_config.py index 52db9116d..31558a062 100644 --- a/tool/quick_start/common_config.py +++ b/tool/quick_start/common_config.py @@ -20,42 +20,17 @@ NeLUserConfig["Paths"] = NeLConfig["Paths"] NeLConfig.update(NeLUserConfig) fi.close() +if os.path.isfile(os.path.join(NeLConfigDir, "toolchains_default.json")): + fi = open(os.path.join(NeLConfigDir, "toolchains_default.json"), "r") + NeLToolchains = json.load(fi) + fi.close() +else: + NeLToolchains = {} + +if os.path.isfile(os.path.join(NeLConfigDir, "toolchains.json")): + fi = open(os.path.join(NeLConfigDir, "toolchains.json"), "r") + NeLToolchains.update(json.load(fi)) + fi.close() + del NeLUserConfig del fi - -NeLCodeDir = os.path.join(NeLRootDir, NeLConfig["Paths"]["Code"]) -if not os.path.isdir(NeLCodeDir): - exit("NeL Code directory (" + NeLCodeDir + ") does not exist.") -NeLLeveldesignDir = os.path.join(NeLRootDir, NeLConfig["Paths"]["Leveldesign"]) -if not os.path.isdir(NeLLeveldesignDir): - exit("NeL Leveldesign directory (" + NeLLeveldesignDir + ") does not exist.") -NeLGraphicsDir = os.path.join(NeLRootDir, NeLConfig["Paths"]["Graphics"]) -if not os.path.isdir(NeLGraphicsDir): - exit("NeL Graphics directory (" + NeLGraphicsDir + ") does not exist.") -NeLSoundDir = os.path.join(NeLRootDir, NeLConfig["Paths"]["Sound"]) -if not os.path.isdir(NeLSoundDir): - exit("NeL Sound directory (" + NeLSoundDir + ") does not exist.") -NeLBuildDir = os.path.join(NeLRootDir, NeLConfig["Paths"]["Build"]) -if not os.path.isdir(NeLBuildDir): - exit("NeL Build directory (" + NeLBuildDir + ") does not exist.") -NeLPipelineDir = os.path.join(NeLRootDir, NeLConfig["Paths"]["Pipeline"]) -if not os.path.isdir(NeLPipelineDir): - exit("NeL Pipeline directory (" + NeLPipelineDir + ") does not exist.") -NeLExternalDir = os.path.join(NeLRootDir, NeLConfig["Paths"]["External"]) -if not os.path.isdir(NeLExternalDir): - exit("NeL External directory (" + NeLExternalDir + ") does not exist.") - -NeLPython27Dir = os.path.join(NeLRootDir, NeLConfig["Paths"]["Tools"]["Python27"]) -NeLRRDtoolDir = os.path.join(NeLRootDir, NeLConfig["Paths"]["Tools"]["RRDtool"]) -NeLMariaDBDir = os.path.join(NeLRootDir, NeLConfig["Paths"]["Tools"]["MariaDB"]) -NeLNginxDir = os.path.join(NeLRootDir, NeLConfig["Paths"]["Tools"]["Nginx"]) -NeLPHPDir = os.path.join(NeLRootDir, NeLConfig["Paths"]["Tools"]["PHP"]) -NeLphpMyAdminDir = os.path.join(NeLRootDir, NeLConfig["Paths"]["Tools"]["phpMyAdmin"]) -NeL3dsMaxDir = os.path.join(NeLRootDir, NeLConfig["Paths"]["Tools"]["3dsMax"]) - -#print(NeLRootDir) -#print(NeLConfigDir) -#print(NeLConfig["Domain"]) -#print(NeLConfig["Paths"]["Code"]) - -#print(NeLExternalDir) diff --git a/tool/quick_start/config_default.json b/tool/quick_start/config_default.json index f9c2d0f57..19fd9b50f 100644 --- a/tool/quick_start/config_default.json +++ b/tool/quick_start/config_default.json @@ -7,7 +7,6 @@ "Sound": "sound", "Build": "build", "Pipeline": "pipeline", - "External": "external", "Tools": { "Python27": "external/python27", "RRDtool": "external/rrdtool", @@ -15,9 +14,7 @@ "Nginx": "external/nginx", "PHP": "external/php", "phpMyAdmin": "external/phpmyadmin", - "3dsMax": "C:\\Program Files\\Autodesk\\3ds Max 2022", - "VisualStudio32": "C:\\Program Files (x86)\\Microsoft Visual Studio 9.0", - "VisualStudio64": "C:\\Program Files\\Microsoft Visual Studio\\2022\\Professional", + "3dsMax": "C:\\Program Files\\Autodesk\\3ds Max 2022" } } } \ No newline at end of file diff --git a/tool/quick_start/configure_toolchains.py b/tool/quick_start/configure_toolchains.py new file mode 100644 index 000000000..8cce1a052 --- /dev/null +++ b/tool/quick_start/configure_toolchains.py @@ -0,0 +1,34 @@ + +# This script generates a configuration file listing all the available toolchains + +from common import * +from find_vstudio import * +from find_external import * + +Toolchains = {} + + +# Only include one VS version per toolset +ByToolset = {} +SortedToolsets = [] +for vs in FoundVisualStudio: + if not vs["Toolset"] in ByToolset: + SortedToolsets += [ vs["Toolset"] ] + if not vs["Toolset"] in ByToolset or ByToolset[vs["Toolset"]]["Version"] < vs["Version"]: + ByToolset[vs["Toolset"]] = vs; + +VSPlatforms = [ "x86", "x64" ] +for ts in SortedToolsets: + vs = ByToolset[ts] + for platform in VSPlatforms: + toolchain = {} + toolchain["Generator"] = vs["Name"] + toolchain["Platform"] = platform + toolchain["Toolset"] = ts + toolchain["Prefix"] = FindVSPrefixPaths(ts, platform) + Toolchains["MSVC/" + ts + "/" + platform] = toolchain + +with open(os.path.join(NeLConfigDir, "toolchains_default.json"), 'w') as fo: + json.dump(Toolchains, fo, indent=2) + +# end of file diff --git a/tool/quick_start/find_external.py b/tool/quick_start/find_external.py new file mode 100644 index 000000000..a9e8c0b3b --- /dev/null +++ b/tool/quick_start/find_external.py @@ -0,0 +1,128 @@ + +# This script detects all external library paths +# Useful for locating all dynamic libraries + +from common_config import * + +import os + +def FilterExternalDirs(libs): + filterMap = { + "assimp": "include/assimp/mesh.h", + "boost": "include/boost/algorithm/algorithm.hpp", + "curl": "include/curl/curl.h", + "ffmpeg": "include/libavcodec/codec.h", + "freetype2": "include/freetype2/ft2build.h", + "gl": "include/GL/glcorearb.h", + "gles": "include/GLES2/gl2.h", + "iconv": "include/iconv.h", + "libjpeg": "include/jpeglib.h", + "libpng": "include/png.h", + "libxml2": "include/libxml2/libxml/xmlreader.h", + "lua": "include/lua.h", + "luabind": "include/luabind/luabind.hpp", + "mariadb": "include/mariadb/mysql.h", + "msquic": "include/msquic.h", + "ogg": "include/ogg/ogg.h", + "openal": "include/AL/al.h", + "openssl": "include/openssl/opensslconf.h", + "protobuf": "include/google/protobuf/message.h", + "qt5": "include/QtCore/QBuffer", + "squish": "include/squish.h", + "vorbis": "include/vorbis/codec.h", + "zlib": "include/zlib.h" + } + res = [] + for dir in FoundExternalDirs: + for lib in libs: + file = os.path.join(dir, filterMap[lib]) + if os.path.isfile(file): + res += [ dir ] + break + return res + +# The list of folders to potentially pass to CMake as PREFIX +def FindPrefixPaths(externalDir): + def DirHasAny(dir, includeSearch): + for search in includeSearch: + if os.path.isfile(os.path.join(dir, os.path.normcase(search))): + return True + return False + + tempExternal = {} + tempExternalBinaries = {} + + # Headers to include + includeSearch = [ + "include/assimp/mesh.h", + "include/boost/algorithm/algorithm.hpp", + "include/curl/curl.h", + "include/libavcodec/codec.h", + "include/freetype2/ft2build.h", + "include/GL/glcorearb.h", + "include/GLES2/gl2.h", + "include/iconv.h", + "include/jpeglib.h", + "include/png.h", + "include/libxml2/libxml/xmlreader.h", + "include/lua.h", + "include/luabind/luabind.hpp", + "include/mariadb/mysql.h", + "include/msquic.h", + "include/ogg/ogg.h", + "include/AL/al.h", + "include/openssl/opensslconf.h", + "include/google/protobuf/message.h", + "include/QtCore/QBuffer", + "include/squish.h", + "include/vorbis/codec.h", + "include/zlib.h" + ] + + # Only search one level deep + if DirHasAny(externalDir, includeSearch): + tempExternal[externalDir] = True + for di in os.listdir(externalDir): + if di.startswith("."): + continue + sdi = os.path.join(externalDir, di) + if not os.path.isdir(sdi): + continue + if DirHasAny(sdi, includeSearch): + tempExternal[sdi] = True + res = [] + for dir in tempExternal: + res += [ dir ] + return res + +# The list of folders to potentially pass into the Visual Studio debug PATH env var +def FindBinPaths(prefixPaths): + for dir in prefixPaths: + for subDir in os.listdir(dir): + if subDir.startswith("."): + continue + binDir = os.path.join(dir, subDir) + if not os.path.isdir(binDir): + continue + for file in os.listdir(binDir): + if not file.startswith(".") and (file.endswith(".exe") or file.endswith(".dll")): + tempExternalBinaries[binDir] = True + break + res = [] + for dir in tempExternalBinaries: + res += [ dir ] + return res + +def FindVSPrefixPaths(toolset, platform): + # 2021q4_external_v143_x64 + dirExt = "_external_" + toolset + "_" + platform + found = [] + for dir in os.listdir("C:\\"): + if not dir.startswith(".") and dir.endswith(dirExt): + found += [ dir ] + found.sort(reverse = True) + if len(found): + return FindPrefixPaths(os.path.join("C:\\", found[0])) + return [] + +# end of file diff --git a/tool/quick_start/find_vstudio.py b/tool/quick_start/find_vstudio.py index a979d4c6d..7ddc0f040 100644 --- a/tool/quick_start/find_vstudio.py +++ b/tool/quick_start/find_vstudio.py @@ -64,13 +64,13 @@ for majorVersion in range(8, 15): folderA = "C:\\Program Files (x86)\\Microsoft Visual Studio " + str(majorVersion) folderB = folderA + ".0" if os.path.isfile(os.path.join(folderA, "Common7\\IDE\\VCExpress.exe")): - FoundVisualStudio += [ { "Name": "Visual Studio " + str(majorVersion) + " " + str(VSVersions[majorVersion]), "DisplayName": "Visual C++ " + str(VSVersions[majorVersion]) + " Express", "Path": folderA, "Version": majorVersion, "Toolchain": "v" + str(majorVersion) + "0", "HasMFC": HasMFC(folderB) } ] + FoundVisualStudio += [ { "Name": "Visual Studio " + str(majorVersion) + " " + str(VSVersions[majorVersion]), "DisplayName": "Visual C++ " + str(VSVersions[majorVersion]) + " Express", "Path": folderA, "Version": majorVersion, "Toolset": "v" + str(majorVersion) + "0", "HasMFC": HasMFC(folderB) } ] if os.path.isfile(os.path.join(folderB, "Common7\\IDE\VCExpress.exe")): - FoundVisualStudio += [ { "Name": "Visual Studio " + str(majorVersion) + " " + str(VSVersions[majorVersion]), "DisplayName": "Visual C++ " + str(VSVersions[majorVersion]) + " Express", "Path": folderB, "Version": majorVersion, "Toolchain": "v" + str(majorVersion) + "0", "HasMFC": HasMFC(folderB) } ] + FoundVisualStudio += [ { "Name": "Visual Studio " + str(majorVersion) + " " + str(VSVersions[majorVersion]), "DisplayName": "Visual C++ " + str(VSVersions[majorVersion]) + " Express", "Path": folderB, "Version": majorVersion, "Toolset": "v" + str(majorVersion) + "0", "HasMFC": HasMFC(folderB) } ] if os.path.isfile(os.path.join(folderA, "Common7\\IDE\\devenv.exe")): - FoundVisualStudio += [ { "Name": "Visual Studio " + str(majorVersion) + " " + str(VSVersions[majorVersion]), "DisplayName": "Visual Studio " + str(VSVersions[majorVersion]), "Path": folderA, "Version": majorVersion, "Toolchain": "v" + str(majorVersion) + "0", "HasMFC": HasMFC(folderB) } ] + FoundVisualStudio += [ { "Name": "Visual Studio " + str(majorVersion) + " " + str(VSVersions[majorVersion]), "DisplayName": "Visual Studio " + str(VSVersions[majorVersion]), "Path": folderA, "Version": majorVersion, "Toolset": "v" + str(majorVersion) + "0", "HasMFC": HasMFC(folderB) } ] if os.path.isfile(os.path.join(folderB, "Common7\\IDE\\devenv.exe")): - FoundVisualStudio += [ { "Name": "Visual Studio " + str(majorVersion) + " " + str(VSVersions[majorVersion]), "DisplayName": "Visual Studio " + str(VSVersions[majorVersion]), "Path": folderB, "Version": majorVersion, "Toolchain": "v" + str(majorVersion) + "0", "HasMFC": HasMFC(folderB) } ] + FoundVisualStudio += [ { "Name": "Visual Studio " + str(majorVersion) + " " + str(VSVersions[majorVersion]), "DisplayName": "Visual Studio " + str(VSVersions[majorVersion]), "Path": folderB, "Version": majorVersion, "Toolset": "v" + str(majorVersion) + "0", "HasMFC": HasMFC(folderB) } ] del folderA del folderB @@ -94,7 +94,7 @@ def ProcessYearPath(yearVersion, yearPath): del fi mfcPath = os.path.join(editionPath, "VC\\Tools\\MSVC\\" + toolsVersion + "\\atlmfc\\include\\afx.h") hasMFC = os.path.isfile(mfcPath) - FoundVisualStudio += [ { "Name": "Visual Studio " + str(VSMajor[yearVersion]) + " " + yearVersion, "DisplayName": "Visual Studio " + yearVersion + " " + edition, "Path": editionPath, "Version": VSMajor[yearVersion], "Toolchain": toolchain, "HasMFC": hasMFC } ] + FoundVisualStudio += [ { "Name": "Visual Studio " + str(VSMajor[yearVersion]) + " " + yearVersion, "DisplayName": "Visual Studio " + yearVersion + " " + edition, "Path": editionPath, "Version": VSMajor[yearVersion], "Toolset": toolchain, "HasMFC": hasMFC } ] for yearVersion in os.listdir("C:\\Program Files (x86)\\Microsoft Visual Studio"): if yearVersion.startswith("."): continue @@ -109,5 +109,8 @@ for yearVersion in os.listdir("C:\\Program Files\\Microsoft Visual Studio"): del yearPath del ProcessYearPath +del VSVersions +del VSMajor + +#print(FoundVisualStudio) -print(FoundVisualStudio) diff --git a/tool/quick_start/test.bat b/tool/quick_start/test.bat index 4bb5a8678..0cccac36c 100644 --- a/tool/quick_start/test.bat +++ b/tool/quick_start/test.bat @@ -1 +1 @@ -..\..\..\external\python27\python.exe find_vstudio.py +..\..\..\external\python27\python.exe configure_toolchains.py