From 224618d26d2a7fcb791f0c51d40df9260f1d9907 Mon Sep 17 00:00:00 2001 From: Reece Date: Sun, 6 Mar 2022 15:17:50 +0000 Subject: [PATCH] [+] Protobuf support --- .gitignore | 6 + Core/Actions/Actions.lua | 4 +- Core/Actions/buildActionBootstrap.lua | 1 + Core/JSON/jsonProjectHandlers.lua | 9 +- Core/Protobuf/Protobuf.lua | 34 ++++ Core/Protobuf/run.lua | 38 +++++ Core/ResourceCompiler/run.lua | 16 ++ Public/api.lua | 5 + Utilities/Utilities.lua | 8 + aurora.gitignore | 218 ++++++++++++++++++++++++++ 10 files changed, 336 insertions(+), 3 deletions(-) create mode 100644 Core/Protobuf/run.lua create mode 100644 aurora.gitignore diff --git a/.gitignore b/.gitignore index 675acaa..e397102 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,9 @@ +# Compilers/platform specific binaries + +Win32/* +bin/* + + # Aurora's general purpose JS/TS/C/C++/Go vs/vscode/intellij/codelite gitignore reference # Almost usable for Java and Qt diff --git a/Core/Actions/Actions.lua b/Core/Actions/Actions.lua index e14277d..0e73ebb 100644 --- a/Core/Actions/Actions.lua +++ b/Core/Actions/Actions.lua @@ -124,7 +124,9 @@ local addBuildCommand = function(when, scriptType, path, cwdRelToProject, args) sRelWd = Aurora.Settings.sRelWd, sRelSymbols = Aurora.Settings.sRelSymbols, sRelLinkLibs = Aurora.Settings.sRelLinkLibs, - sRelCompilerWd = Aurora.Settings.sRelCompilerWd + sRelCompilerWd = Aurora.Settings.sRelCompilerWd, + sRelWin32 = Aurora.Settings.sRelWin32, + sRelUnixBins = Aurora.Settings.sRelUnixBins, } command = command .. " --settings=" .. base64.encode(json.encode(settings)) diff --git a/Core/Actions/buildActionBootstrap.lua b/Core/Actions/buildActionBootstrap.lua index 1e0525a..e2369a7 100644 --- a/Core/Actions/buildActionBootstrap.lua +++ b/Core/Actions/buildActionBootstrap.lua @@ -9,6 +9,7 @@ end local function escapeBinaryPath(bin) bin = path.translate(bin, path.getDefaultSeparator()) + bin = os.realpath(bin) if (os.host() == "windows") then return "\"" .. bin .. "\"" diff --git a/Core/JSON/jsonProjectHandlers.lua b/Core/JSON/jsonProjectHandlers.lua index 8eca6f8..9a344ab 100644 --- a/Core/JSON/jsonProjectHandlers.lua +++ b/Core/JSON/jsonProjectHandlers.lua @@ -307,6 +307,10 @@ local function auBlockProjectKeyResourceScript(processor, value, map, tasks) end, processor) end +local function auBlockProjectKeyProtobuf(processor, value) + __pushFilter(value, "value", auProtobufFiles, processor, true) +end + local function auBlockProjectKeySoftDepends(processor, value) __pushFilter(value, "value", function(obj) handleDepends(processor, obj, true) @@ -384,7 +388,8 @@ auProjectBlockHandlers = events = auBlockProjectKeyBuildEvent, actions = auBlockProjectKeyBuildAction, features = auBlockKeyFeature, - resourceScript = auBlockProjectKeyResourceScript + resourceScript = auBlockProjectKeyResourceScript, + protobuf = auBlockProjectKeyProtobuf } auProjectBlockHandlers["soft-depends"] = auBlockProjectKeySoftDepends @@ -413,7 +418,7 @@ auProjectRefHandlers["depends"] = auBlockProjectRefKeyDepends "impInclude", "implInclude", "impIncludes", "implIncludes", "clangIgnore", "msvcIgnore", "excludes", "depends", "require", "eval", "lua", "events", "actions", "staticImpDefines", "features", - "links", "soft-depends", "resourceScript" + "links", "soft-depends", "resourceScript", "protobuf" } local kReferenceTasks = {"eval", "includes", "include", "includes"} --, "features"} diff --git a/Core/Protobuf/Protobuf.lua b/Core/Protobuf/Protobuf.lua index e69de29..9ea7451 100644 --- a/Core/Protobuf/Protobuf.lua +++ b/Core/Protobuf/Protobuf.lua @@ -0,0 +1,34 @@ +local function addProtobufFiles(files) + local projName = auGetCurrentProject() + local proj = auGetCurrentProjectMeta() + + local basePath = Aurora.Settings.sAbsRoot + + if (proj and proj.path) then + basePath = proj.path + end + + local baseProto = path.join(Aurora.Settings.sAbsCompilerWd, "ProtobufTemp") + + local targetBase = nil + if (projName) then + targetBase = path.join(Aurora.Settings.sAbsCompilerWd, "ProtobufTemp", projName) + else + targetBase = path.join(Aurora.Settings.sAbsCompilerWd, "ProtobufTemp") + end + + os.mkdir(baseProto) + os.mkdir(targetBase) + + local compiledFiles = auMap(files, function(file) + local rel = path.getrelative(basePath, file) + return path.join(targetBase, rel:sub(1, #rel - 6)) .. ".pb.cc" + end) + + includedirs(targetBase) + _G.files(compiledFiles) + + auAddResource(files, {targetBase = targetBase, basePath = basePath}, path.join(Aurora.Settings.sAbsScripts, "Core", "Protobuf", "run.lua")) +end + +return addProtobufFiles \ No newline at end of file diff --git a/Core/Protobuf/run.lua b/Core/Protobuf/run.lua new file mode 100644 index 0000000..1dfd970 --- /dev/null +++ b/Core/Protobuf/run.lua @@ -0,0 +1,38 @@ +print("Compiling protobuf files...") +print("Changed: ", json.encode_pretty(auResourceCompiler.changedFiles)) +print("Unchanged: ", json.encode_pretty(auResourceCompiler.unchangedFiles)) + +if (#auResourceCompiler.changedFiles == 0) then return end + +local function escapeBinaryPath(bin) + bin = path.translate(bin, path.getDefaultSeparator()) + bin = os.realpath(bin) + + if (os.host() == "windows") then + return "\"" .. bin .. "\"" + end + + return bin:gsub(" ", "\\ ") +end + +local compiler = nil + +if (os.host() == "windows") then + compiler = path.join(Aurora.Settings.sAbsWin32, "protoc.exe") +elseif (os.isfile("protoc")) then + compiler = "protoc" +else + compiler = path.join(Aurora.Settings.sRelUnixBins, "protoc") +end + +compiler = escapeBinaryPath(compiler) + +local cmd = compiler +cmd = cmd .. " --cpp_out=\"" .. auResourceCompiler.arguments.targetBase .. "\"" +cmd = cmd .. " --proto_path=\"" .. auResourceCompiler.arguments.basePath .. "\"" + +auForEach(auResourceCompiler.changedFiles, function(file) + cmd = cmd .. " \"" .. file .. "\"" +end) + +resourceRunAndExit(cmd) \ No newline at end of file diff --git a/Core/ResourceCompiler/run.lua b/Core/ResourceCompiler/run.lua index 04fe510..d8763aa 100644 --- a/Core/ResourceCompiler/run.lua +++ b/Core/ResourceCompiler/run.lua @@ -36,4 +36,20 @@ auResourceCompiler = { arguments = auBuild.args.ext } +function resourceExit(exitCode) + if (not exitCode) then + os.remove(cachePath) + end + + os.exit(exitCode) +end + +function resourceRunAndExit(cmd) + if (os.host() == "windows") then + resourceExit(os.execute("call " .. cmd)) + else + resourceExit(os.execute(cmd)) + end +end + auRequireAbs(auBuild.args.script) \ No newline at end of file diff --git a/Public/api.lua b/Public/api.lua index c5d4fb0..6ad1f9c 100644 --- a/Public/api.lua +++ b/Public/api.lua @@ -3,6 +3,7 @@ local buildAction = auRequire("Core/Actions") local target = auRequire("Core/Target") local main = auRequire("Core/Main") local resourceCompiler = auRequire("Core/ResourceCompiler") +local protobuf = auRequire("Core/Protobuf") -- executes inline under iprocessor::process function auAddBuildAction(...) @@ -154,4 +155,8 @@ end function auAddResource(...) resourceCompiler(...) +end + +function auProtobufFiles(files) + protobuf(files) end \ No newline at end of file diff --git a/Utilities/Utilities.lua b/Utilities/Utilities.lua index b661a19..602b3b7 100644 --- a/Utilities/Utilities.lua +++ b/Utilities/Utilities.lua @@ -18,4 +18,12 @@ function table.copy(t) for k, v in pairs(t) do u[k] = v end --setmetatable(u, getmetatable(t)) return u +end + +function auMap(array, func) + local tbl = {} + auForEach(array, function(value) + table.insert(tbl, func(value)) + end) + return tbl end \ No newline at end of file diff --git a/aurora.gitignore b/aurora.gitignore new file mode 100644 index 0000000..675acaa --- /dev/null +++ b/aurora.gitignore @@ -0,0 +1,218 @@ +# Aurora's general purpose JS/TS/C/C++/Go vs/vscode/intellij/codelite gitignore reference +# Almost usable for Java and Qt + +# Aurora build configuration +Build_CompilerWorkingDirectory/* +Build_Developers/* +Build_Ship/* +Build_Internal/* +Build_Develop/* +Build_Stage/* +Build_Ship/* +Build_Workspace/* +Build_Symbols/* +Build_Link/* +Build/Developers/* +Build/Ship/* +Build/Develop/* +Build/Stage/* +Build/Ship/* +Build/Workspace/* +Build/Symbols/* +Build/Link/* + +# License Headers VS extension +*.licenseheader + +# Binaries / object files +*.dll +*.exe +*.obj +*.so +*.so.* +*.la +*.lai +*.pdb +*.idb +*.exe~ +*.obj +*.dynlib +*.dylib +*.lib +*.d +*.o +*.a +*.la +*.slo +*.lo +*.out +# go unit test +*.test + +# Autogenerated project files +compile_flags.txt +*.mk +*.project +*cmake +Makefile +*.vcxproj +*.xcodeproj + +# IDE trash +.vscode +.vs +/*.gcno +.intellij +.clion +*.vcxproj.filters +*.vcxproj.user +*.tlog + +# OSX +.DS_Store +.AppleDouble +.LSOverride +xcuserdata/ + +# Win32 +Thumbs.db +Thumbs.db:encryptable +ehthumbs.db +ehthumbs_vista.db +*.lnk + +# Linux is trash and cant hotswap like NT +.nfs* +.fuse_hidden* + +# Ninja +.ninja_deps +.ninja_log + +# PID locks +*.pid +*.pid.lock + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties + +# JetBrains +# User-specific stuff +.idea/**/workspace.xml +.idea/**/tasks.xml +.idea/**/usage.statistics.xml +.idea/**/dictionaries +.idea/**/shelf + +# AWS User-specific +.idea/**/aws.xml + +# Generated files +.idea/**/contentModel.xml + +# Sensitive or high-churn files +.idea/**/dataSources/ +.idea/**/dataSources.ids +.idea/**/dataSources.local.xml +.idea/**/sqlDataSources.xml +.idea/**/dynamic.xml +.idea/**/uiDesigner.xml +.idea/**/dbnavigator.xml + +# Gradle +.idea/**/gradle.xml +.idea/**/libraries + +# CMake +cmake-build-*/ + +# Android Studio +.idea/caches/build_file_checksums.ser + +# why would we ever ship this dir? +.idea/caches/* + +# NodeJS +npm-debug.log* +yarn-debug.log* +yarn-error.log* +lerna-debug.log* +.pnpm-debug.log* + +# node-waf configuration +.lock-wscript + +# Dependency directories +node_modules/ +jspm_packages/ + +# Snowpack dependency directory (https://snowpack.dev/) +web_modules/ + +# TypeScript cache +*.tsbuildinfo + +# Optional npm cache directory +.npm + +# Optional eslint cache +.eslintcache + +# yarn v2 +.yarn/cache +.yarn/unplugged +.yarn/build-state.yml +.yarn/install-state.gz +.pnp.* + +# VS Code Extensions +.vscode-test + +# Qt unit tests +target_wrapper.* + +# QtCreator +*.autosave + +# QtCreator Qml +*.qmlproject.user +*.qmlproject.user.* + +# QtCreator CMake +CMakeLists.txt.user* + +# QtCreator 4.8< compilation database +compile_commands.json + +# QtCreator local machine specific files for imported projects +*creator.user* + +*_qmlcache.qrc + +# QT cache and user files +/.qmake.cache +/.qmake.stash +*.pro.user +*.pro.user.* +*.qbs.user +*.qbs.user.* +*.moc + +# Java trash +hs_err_pid* +.gradle +gradle-app.setting +!gradle-wrapper.jar +.gradletasknamecache +pom.xml.tag +pom.xml.releaseBackup +pom.xml.versionsBackup +pom.xml.next +release.properties +dependency-reduced-pom.xml +buildNumber.properties +.mvn/timing.properties +.mvn/wrapper/maven-wrapper.jar \ No newline at end of file