From 22b2e14dbc20aacca0757bc75a958611b3aced09 Mon Sep 17 00:00:00 2001 From: Rakesh Roopavataram Date: Wed, 28 Aug 2024 14:55:58 -0400 Subject: [PATCH] Add Maya command plugin to querry build info --- lib/mayaHydra/hydraExtensions/mhBuildInfo.cpp | 1 + .../hydraExtensions/mhBuildInfo.h.src | 2 + lib/mayaHydra/mayaPlugin/CMakeLists.txt | 2 + .../mayaPlugin/pluginBuildInfoCommand.cpp | 113 ++++++++++++++++++ .../mayaPlugin/pluginBuildInfoCommand.h | 37 ++++++ 5 files changed, 155 insertions(+) create mode 100644 lib/mayaHydra/mayaPlugin/pluginBuildInfoCommand.cpp create mode 100644 lib/mayaHydra/mayaPlugin/pluginBuildInfoCommand.h diff --git a/lib/mayaHydra/hydraExtensions/mhBuildInfo.cpp b/lib/mayaHydra/hydraExtensions/mhBuildInfo.cpp index 2f538cb383..cb42e046e6 100644 --- a/lib/mayaHydra/hydraExtensions/mhBuildInfo.cpp +++ b/lib/mayaHydra/hydraExtensions/mhBuildInfo.cpp @@ -21,6 +21,7 @@ namespace MAYAHYDRA_NS_DEF { int MhBuildInfo::buildNumber() { return MAYAHYDRA_BUILD_NUMBER; } const char* MhBuildInfo::gitCommit() { return MAYAHYDRA_GIT_COMMIT; } const char* MhBuildInfo::gitBranch() { return MAYAHYDRA_GIT_BRANCH; } +const char* MhBuildInfo::cutId() { return MAYAHYDRA_CUT_ID; } const char* MhBuildInfo::buildDate() { return MAYAHYDRA_BUILD_DATE; } } // namespace MAYAHYDRA_NS_DEF diff --git a/lib/mayaHydra/hydraExtensions/mhBuildInfo.h.src b/lib/mayaHydra/hydraExtensions/mhBuildInfo.h.src index d6c9eb152f..d162c36422 100644 --- a/lib/mayaHydra/hydraExtensions/mhBuildInfo.h.src +++ b/lib/mayaHydra/hydraExtensions/mhBuildInfo.h.src @@ -24,6 +24,7 @@ #define MAYAHYDRA_GIT_COMMIT "${MAYAHYDRA_GIT_COMMIT}" #define MAYAHYDRA_GIT_BRANCH "${MAYAHYDRA_GIT_BRANCH}" #define MAYAHYDRA_BUILD_DATE ${MAYAHYDRA_BUILD_DATE} +#define MAYAHYDRA_CUT_ID "${MAYAHYDRA_CUT_ID}" namespace MAYAHYDRA_NS_DEF { @@ -33,6 +34,7 @@ public: static int buildNumber(); static const char* gitCommit(); static const char* gitBranch(); + static const char* cutId(); static const char* buildDate(); }; diff --git a/lib/mayaHydra/mayaPlugin/CMakeLists.txt b/lib/mayaHydra/mayaPlugin/CMakeLists.txt index 67c9b74968..3ad8cb89b2 100644 --- a/lib/mayaHydra/mayaPlugin/CMakeLists.txt +++ b/lib/mayaHydra/mayaPlugin/CMakeLists.txt @@ -16,6 +16,7 @@ target_sources(${TARGET_NAME} renderOverride.cpp tokens.cpp viewCommand.cpp + pluginBuildInfoCommand.cpp ) set(HEADERS @@ -48,6 +49,7 @@ target_include_directories(${TARGET_NAME} PRIVATE $<$:${UFE_INCLUDE_DIR}> $<$:${MAYAUSD_INCLUDE_DIR}> + ${CMAKE_BINARY_DIR} ) if(DEFINED MAYAUSD_VERSION) diff --git a/lib/mayaHydra/mayaPlugin/pluginBuildInfoCommand.cpp b/lib/mayaHydra/mayaPlugin/pluginBuildInfoCommand.cpp new file mode 100644 index 0000000000..0649b39c88 --- /dev/null +++ b/lib/mayaHydra/mayaPlugin/pluginBuildInfoCommand.cpp @@ -0,0 +1,113 @@ +// +// Copyright 2024 Autodesk +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +#include "pluginBuildInfoCommand.h" + +#include + +#include +#include + +#define XSTR(x) STR(x) +#define STR(x) #x + +namespace MAYAHYDRA_NS_DEF { + +const MString MayaHydraPluginInfoCommand::commandName("mayaHydraBuildInfo"); + +namespace { + +// Versioning and build information. +constexpr auto kMajorVersion = "-mjv"; +constexpr auto kMajorVersionLong = "-majorVersion"; + +constexpr auto kMinorVersion = "-mnv"; +constexpr auto kMinorVersionLong = "-minorVersion"; + +constexpr auto kPatchVersion = "-pv"; +constexpr auto kPatchVersionLong = "-patchVersion"; + +constexpr auto kVersion = "-v"; +constexpr auto kVersionLong = "-version"; + +constexpr auto kCutId = "-c"; +constexpr auto kCutIdLong = "-cutIdentifier"; + +constexpr auto kBuildNumber = "-bn"; +constexpr auto kBuildNumberLong = "-buildNumber"; + +constexpr auto kGitCommit = "-gc"; +constexpr auto kGitCommitLong = "-gitCommit"; + +constexpr auto kGitBranch = "-gb"; +constexpr auto kGitBranchLong = "-gitBranch"; + +constexpr auto kBuildDate = "-bd"; +constexpr auto kBuildDateLong = "-buildDate"; + +} // namespace + +MSyntax MayaHydraPluginInfoCommand::createSyntax() +{ + MSyntax syntax; + syntax.enableQuery(false); + syntax.enableEdit(false); + + // Versioning and build information flags. + syntax.addFlag(kMajorVersion, kMajorVersionLong); + syntax.addFlag(kMinorVersion, kMinorVersionLong); + syntax.addFlag(kPatchVersion, kPatchVersionLong); + syntax.addFlag(kVersion, kVersionLong); + syntax.addFlag(kCutId, kCutIdLong); + syntax.addFlag(kBuildNumber, kBuildNumberLong); + syntax.addFlag(kGitCommit, kGitCommitLong); + syntax.addFlag(kGitBranch, kGitBranchLong); + syntax.addFlag(kBuildDate, kBuildDateLong); + + return syntax; +} + +MStatus MayaHydraPluginInfoCommand::doIt(const MArgList& args) +{ + MStatus st; + MArgParser argData(syntax(), args, &st); + if (!st) + return st; + + if (argData.isFlagSet(kMajorVersion)) { + setResult(MAYAHYDRA_MAJOR_VERSION); // int + } else if (argData.isFlagSet(kMinorVersion)) { + setResult(MAYAHYDRA_MINOR_VERSION); // int + } else if (argData.isFlagSet(kPatchVersion)) { + setResult(MAYAHYDRA_PATCH_LEVEL); // int + } else if (argData.isFlagSet(kVersion)) { + setResult(XSTR(MAYAHYDRA_VERSION)); // convert to string + } else if (argData.isFlagSet(kCutId)) { + setResult(MhBuildInfo::cutId()); + } else if (argData.isFlagSet(kBuildNumber)) { + setResult(MhBuildInfo::buildNumber()); + } else if (argData.isFlagSet(kGitCommit)) { + setResult(MhBuildInfo::gitCommit()); + } else if (argData.isFlagSet(kGitBranch)) { + setResult(MhBuildInfo::gitBranch()); + } else if (argData.isFlagSet(kBuildDate)) { + setResult(MhBuildInfo::buildDate()); + } + + return MS::kSuccess; +} + +} // namespace MAYAUSD_NS_DEF diff --git a/lib/mayaHydra/mayaPlugin/pluginBuildInfoCommand.h b/lib/mayaHydra/mayaPlugin/pluginBuildInfoCommand.h new file mode 100644 index 0000000000..18d23bbf63 --- /dev/null +++ b/lib/mayaHydra/mayaPlugin/pluginBuildInfoCommand.h @@ -0,0 +1,37 @@ +// +// Copyright 2024 Autodesk +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +#ifndef MAYAHYDRA_PULINGINFO_CMD_H +#define MAYAHYDRA_PULINGINFO_CMD_H + +#include +#include + +namespace MAYAHYDRA_NS_DEF { + +class MayaHydraPluginInfoCommand : public MPxCommand +{ +public: + static void* creator() { return new MayaHydraPluginInfoCommand(); } + static MSyntax createSyntax(); + + static const MString commandName; + + MStatus doIt(const MArgList& args) override; +}; + +} // namespace MAYAUSD_NS_DEF +#endif // MAYAHYDRA_PULINGINFO_CMD_H