diff --git a/doc/mayaHydraCommands.md b/doc/mayaHydraCommands.md new file mode 100644 index 0000000000..5a4a7e33c5 --- /dev/null +++ b/doc/mayaHydraCommands.md @@ -0,0 +1,117 @@ +# Maya command plugins used in MayaHydra + +# MayaHydra Command Plugin + +The `MayaHydra` command plugin provides a set of utilities for interacting with the Hydra rendering framework within Maya. Below are the available flags and their descriptions. + +## Basic Usage + +```bash +mayaHydra [flags] +``` +Available Flags +``` +-listDelegates / -ld: +``` +Returns the names of available scene delegates. +``` +-listRenderers / -lr: +``` +Returns the names of available render delegates. +``` +-listActiveRenderers / -lar: +``` +Returns the names of render delegates that are in use in at least one viewport. + +Renderer-Specific Commands +``` +-renderer / -r [RENDERER]: +``` +Specifies the renderer to target for the commands below. +``` +-getRendererDisplayName / -gn: +``` +Returns the display name for the given render delegate. +``` +-createRenderGlobals / -crg: +``` +Creates the render globals, optionally targeting a specific renderer. +``` +-userDefaults / -ud: +``` +A flag for -createRenderGlobals to restore user defaults on create. +``` +-updateRenderGlobals / -urg [ATTRIBUTE]: +``` +Forces the update of the render globals for the viewport, optionally targeting a specific renderer or setting. + +Advanced / Debugging Flags +To access advanced and debugging flags, use the -verbose / -v flag. + +Debug Flags +``` +-listRenderIndex / -lri -r [RENDERER]: +``` +Returns a list of all the rprims in the render index for the given render delegate. +``` +-visibleOnly / -vo: +``` +Affects the behavior of -listRenderIndex. If provided, only visible items in the render index are returned. +``` +-sceneDelegateId / -sid [SCENE_DELEGATE] -r [RENDERER]: +``` +Returns the path ID corresponding to the given render delegate and scene delegate pair. + +# MayaHydra Versioning and Build Information Flags + +The following flags are used to retrieve versioning and build information for the `MayaHydra` plugin. Each flag has both a short and a long form. + +## Usage Example + +To retrieve the full version of the `MayaHydra` plugin, use the following command: + +```bash +mayaHydraBuildInfo [-flags] +``` +## Version Information + +- **`-mjv` / `-majorVersion`**: + Returns the major version number of the plugin. + +- **`-mnv` / `-minorVersion`**: + Returns the minor version number of the plugin. + +- **`-pv` / `-patchVersion`**: + Returns the patch version number of the plugin. + +- **`-v` / `-version`**: + Returns the full version string of the plugin, which may include major, minor, and patch version numbers. + +## Build Information + +This information is expected to be set by a parent build system that has access and/or generates the following information. + +- **`-c` / `-cutIdentifier`**: + Returns the cut identifier associated with this build of the plugin. + +- **`-bn` / `-buildNumber`**: + Returns the build number for the plugin, typically representing the incremental number assigned during the build process. + +- **`-gc` / `-gitCommit`**: + Returns the Git commit hash that the build is based on, useful for tracing the exact source code used. + +- **`-gb` / `-gitBranch`**: + Returns the Git branch name that the build was created from. + +- **`-bd` / `-buildDate`**: + Returns the date on which the plugin was built. + + +### Summary +- **Version Information Flags**: Cover major, minor, and patch version details, as well as the full version string. +- **Build Information Flags**: Include cut identifier, build number, Git commit, Git branch, and build date. +- **Usage Examples**: Show how to retrieve specific pieces of information using the provided flags. + +This Markdown document provides a clear and concise reference for users who need to access versioning and build information for the `MayaHydra` plugin. + + diff --git a/lib/mayaHydra/hydraExtensions/mhBuildInfo.cpp b/lib/mayaHydra/hydraExtensions/mhBuildInfo.cpp index 2f538cb383..9db308208b 100644 --- a/lib/mayaHydra/hydraExtensions/mhBuildInfo.cpp +++ b/lib/mayaHydra/hydraExtensions/mhBuildInfo.cpp @@ -1,5 +1,5 @@ // -// Copyright 2023 Autodesk, Inc. All rights reserved. +// Copyright 2024 Autodesk, Inc. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -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..bf0e4ce2b6 100644 --- a/lib/mayaHydra/hydraExtensions/mhBuildInfo.h.src +++ b/lib/mayaHydra/hydraExtensions/mhBuildInfo.h.src @@ -1,5 +1,5 @@ // -// Copyright 2023 Autodesk, Inc. All rights reserved. +// Copyright 2024 Autodesk, Inc. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -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..904d23c284 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 diff --git a/lib/mayaHydra/mayaPlugin/plugin.cpp b/lib/mayaHydra/mayaPlugin/plugin.cpp index 6551e2fa33..8624510a47 100644 --- a/lib/mayaHydra/mayaPlugin/plugin.cpp +++ b/lib/mayaHydra/mayaPlugin/plugin.cpp @@ -20,6 +20,7 @@ #include "renderGlobals.h" #include "renderOverride.h" #include "viewCommand.h" +#include "pluginBuildInfoCommand.h" #include @@ -150,6 +151,13 @@ PLUGIN_EXPORT MStatus initializePlugin(MObject obj) return ret; } + if (!plugin.registerCommand( + MayaHydraPluginInfoCommand::commandName, MayaHydraPluginInfoCommand::creator, MayaHydraPluginInfoCommand::createSyntax)) { + ret = MS::kFailure; + ret.perror("Error registering MayaHydraPluginInfo command!"); + return ret; + } + if (auto* renderer = MHWRender::MRenderer::theRenderer()) { for (const auto& desc : MayaHydra::MtohGetRendererDescriptions()) { auto mtohRenderer = std::make_unique(desc); @@ -235,5 +243,10 @@ PLUGIN_EXPORT MStatus uninitializePlugin(MObject obj) ret.perror("Error deregistering mayaHydra command!"); } + if (!plugin.deregisterCommand(MayaHydraPluginInfoCommand::commandName)) { + ret = MS::kFailure; + ret.perror("Error deregistering MayaHydraPluginInfo command!"); + } + return ret; } diff --git a/lib/mayaHydra/mayaPlugin/pluginBuildInfoCommand.cpp b/lib/mayaHydra/mayaPlugin/pluginBuildInfoCommand.cpp new file mode 100644 index 0000000000..50445c775f --- /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 MAYAHYDRA_NS_DEF diff --git a/lib/mayaHydra/mayaPlugin/pluginBuildInfoCommand.h b/lib/mayaHydra/mayaPlugin/pluginBuildInfoCommand.h new file mode 100644 index 0000000000..27fdeffed3 --- /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 MAYAHYDRA_NS_DEF +#endif // MAYAHYDRA_PULINGINFO_CMD_H diff --git a/lib/mayaHydra/mayaPlugin/viewCommand.cpp b/lib/mayaHydra/mayaPlugin/viewCommand.cpp index 960c517b9f..db8309cb70 100644 --- a/lib/mayaHydra/mayaPlugin/viewCommand.cpp +++ b/lib/mayaHydra/mayaPlugin/viewCommand.cpp @@ -65,9 +65,6 @@ constexpr auto _updateRenderGlobalsLong = "-updateRenderGlobals"; constexpr auto _help = "-h"; constexpr auto _helpLong = "-help"; -constexpr auto _verbose = "-v"; -constexpr auto _verboseLong = "-verbose"; - constexpr auto _listRenderIndex = "-lri"; constexpr auto _listRenderIndexLong = "-listRenderIndex"; @@ -103,40 +100,8 @@ constexpr auto _rendererIdLong = "-renderer"; constexpr auto _userDefaultsId = "-u"; constexpr auto _userDefaultsIdLong = "-userDefaults"; -constexpr auto _helpText = R"HELP( -Maya to Hydra utility function. -Usage: mayaHydra [flags] --listDelegates/-ld : Returns the names of available scene delegates. --listRenderers/-lr : Returns the names of available render delegates. --listActiveRenderers/-lar : Returns the names of render delegates that are in - use in at least one viewport. - --renderer/-r [RENDERER]: Renderer to target for the commands below. --getRendererDisplayName/-gn : Returns the display name for the given render delegate. --createRenderGlobals/-crg: Creates the render globals, optionally targetting a - specific renderer. --userDefaults/-ud: Flag for createRenderGlobals to restore user defaults on create. --updateRenderGlobals/-urg [ATTRIBUTE]: Forces the update of the render globals - for the viewport, optionally targetting a specific renderer or setting. -)HELP"; - -constexpr auto _helpNonVerboseText = R"HELP( -Use -verbose/-v to see advanced / debugging flags - -)HELP"; - -constexpr auto _helpVerboseText = R"HELP( -Debug flags: - --listRenderIndex/-lri -r [RENDERER]: Returns a list of all the rprims in the - render index for the given render delegate. - --visibleOnly/-vo: Flag which affects the behavior of -listRenderIndex - if - given, then only visible items in the render index are returned. - --sceneDelegateId/-sid [SCENE_DELEGATE] -r [RENDERER]: Returns the path id - corresponding to the given render delegate / scene delegate pair. - +constexpr auto _helpText = R"HELP(For details on args usage please see +https://github.com/Autodesk/maya-hydra/tree/dev/doc/mayaHydraCommads.md )HELP"; } // namespace @@ -165,8 +130,6 @@ MSyntax MtohViewCmd::createSyntax() syntax.addFlag(_help, _helpLong); - syntax.addFlag(_verbose, _verboseLong); - // Debug / testing flags syntax.addFlag(_listRenderIndex, _listRenderIndexLong); @@ -243,11 +206,6 @@ MStatus MtohViewCmd::doIt(const MArgList& args) setResult(MString(dn.c_str())); } else if (db.isFlagSet(_help)) { MString helpText = _helpText; - if (db.isFlagSet(_verbose)) { - helpText += _helpVerboseText; - } else { - helpText += _helpNonVerboseText; - } MGlobal::displayInfo(helpText); } else if (db.isFlagSet(_createRenderGlobals)) { bool userDefaults = db.isFlagSet(_userDefaultsId); diff --git a/test/lib/mayaUsd/render/mayaToHydra/testMtohCommand.py b/test/lib/mayaUsd/render/mayaToHydra/testMtohCommand.py index f7d0e77d8e..4de5b12b7c 100644 --- a/test/lib/mayaUsd/render/mayaToHydra/testMtohCommand.py +++ b/test/lib/mayaUsd/render/mayaToHydra/testMtohCommand.py @@ -110,22 +110,23 @@ def test_createRenderGlobals(self): "defaultRenderGlobals.mtohMotionSampleStart")) def test_versionInfo(self): - self.assertGreaterEqual(cmds.mayaHydra(majorVersion=True), 0) - self.assertGreaterEqual(cmds.mayaHydra(mjv=True), 0) - self.assertGreaterEqual(cmds.mayaHydra(minorVersion=True), 0) - self.assertGreaterEqual(cmds.mayaHydra(mnv=True), 0) - self.assertGreaterEqual(cmds.mayaHydra(patchVersion=True), 0) - self.assertGreaterEqual(cmds.mayaHydra(pv=True), 0) + self.assertGreaterEqual(cmds.mayaHydraBuildInfo(majorVersion=True), 0) + self.assertGreaterEqual(cmds.mayaHydraBuildInfo(mjv=True), 0) + self.assertGreaterEqual(cmds.mayaHydraBuildInfo(minorVersion=True), 0) + self.assertGreaterEqual(cmds.mayaHydraBuildInfo(mnv=True), 0) + self.assertGreaterEqual(cmds.mayaHydraBuildInfo(patchVersion=True), 0) + self.assertGreaterEqual(cmds.mayaHydraBuildInfo(pv=True), 0) def test_buildInfo(self): - self.assertGreaterEqual(cmds.mayaHydra(buildNumber=True), 0) - self.assertGreaterEqual(cmds.mayaHydra(bn=True), 0) - self.assertNotEqual(cmds.mayaHydra(gitCommit=True), '') - self.assertNotEqual(cmds.mayaHydra(gc=True), '') - self.assertNotEqual(cmds.mayaHydra(gitBranch=True), '') - self.assertNotEqual(cmds.mayaHydra(gb=True), '') - self.assertNotEqual(cmds.mayaHydra(buildDate=True), '') - self.assertNotEqual(cmds.mayaHydra(bd=True), '') + self.assertGreaterEqual(cmds.mayaHydraBuildInfo(buildNumber=True), 0) + self.assertGreaterEqual(cmds.mayaHydraBuildInfo(bn=True), 0) + self.assertNotEqual(cmds.mayaHydraBuildInfo(gitCommit=True), '') + self.assertNotEqual(cmds.mayaHydraBuildInfo(gc=True), '') + self.assertNotEqual(cmds.mayaHydraBuildInfo(gitBranch=True), '') + self.assertNotEqual(cmds.mayaHydraBuildInfo(gb=True), '') + self.assertNotEqual(cmds.mayaHydraBuildInfo(buildDate=True), '') + self.assertNotEqual(cmds.mayaHydraBuildInfo(bd=True), '') + self.assertNotEqual(cmds.mayaHydraBuildInfo(cutIdentifier=True), "DEVBLD") if __name__ == '__main__': fixturesUtils.runTests(globals())