Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HYDRA-951 : Add Maya command plugin to query build info #163

Merged
merged 8 commits into from
Aug 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
117 changes: 117 additions & 0 deletions doc/mayaHydraCommands.md
Original file line number Diff line number Diff line change
@@ -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.


3 changes: 2 additions & 1 deletion lib/mayaHydra/hydraExtensions/mhBuildInfo.cpp
Original file line number Diff line number Diff line change
@@ -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
4 changes: 3 additions & 1 deletion lib/mayaHydra/hydraExtensions/mhBuildInfo.h.src
Original file line number Diff line number Diff line change
@@ -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();
};

1 change: 1 addition & 0 deletions lib/mayaHydra/mayaPlugin/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -16,6 +16,7 @@ target_sources(${TARGET_NAME}
renderOverride.cpp
tokens.cpp
viewCommand.cpp
pluginBuildInfoCommand.cpp
)

set(HEADERS
13 changes: 13 additions & 0 deletions lib/mayaHydra/mayaPlugin/plugin.cpp
Original file line number Diff line number Diff line change
@@ -20,6 +20,7 @@
#include "renderGlobals.h"
#include "renderOverride.h"
#include "viewCommand.h"
#include "pluginBuildInfoCommand.h"

#include <mayaHydraLib/adapters/adapter.h>

@@ -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<PXR_NS::MtohRenderOverride>(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;
}
113 changes: 113 additions & 0 deletions lib/mayaHydra/mayaPlugin/pluginBuildInfoCommand.cpp
Original file line number Diff line number Diff line change
@@ -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 <mayaHydraLib/mhBuildInfo.h>

#include <maya/MArgParser.h>
#include <maya/MSyntax.h>

#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
37 changes: 37 additions & 0 deletions lib/mayaHydra/mayaPlugin/pluginBuildInfoCommand.h
Original file line number Diff line number Diff line change
@@ -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 <mayaHydraLib/mayaHydra.h>
#include <maya/MPxCommand.h>

namespace MAYAHYDRA_NS_DEF {

class MayaHydraPluginInfoCommand : public MPxCommand
{
public:
static void* creator() { return new MayaHydraPluginInfoCommand(); }
static MSyntax createSyntax();

static const MString commandName;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where this member was used?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did you mean to ask about commandName ?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, commandName

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we have a ticket to remove it from the mayaHydra command?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. A file was missed to be added to this PR. Added now.


MStatus doIt(const MArgList& args) override;
};

} // namespace MAYAHYDRA_NS_DEF
#endif // MAYAHYDRA_PULINGINFO_CMD_H
46 changes: 2 additions & 44 deletions lib/mayaHydra/mayaPlugin/viewCommand.cpp
Original file line number Diff line number Diff line change
@@ -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);
29 changes: 15 additions & 14 deletions test/lib/mayaUsd/render/mayaToHydra/testMtohCommand.py
Original file line number Diff line number Diff line change
@@ -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())