Skip to content

Commit

Permalink
Add Maya command plugin to querry build info
Browse files Browse the repository at this point in the history
  • Loading branch information
roopavr-adsk committed Aug 28, 2024
1 parent c90379b commit 22b2e14
Show file tree
Hide file tree
Showing 5 changed files with 155 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/mayaHydra/hydraExtensions/mhBuildInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 2 additions & 0 deletions lib/mayaHydra/hydraExtensions/mhBuildInfo.h.src
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -33,6 +34,7 @@ public:
static int buildNumber();
static const char* gitCommit();
static const char* gitBranch();
static const char* cutId();
static const char* buildDate();
};

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

set(HEADERS
Expand Down Expand Up @@ -48,6 +49,7 @@ target_include_directories(${TARGET_NAME}
PRIVATE
$<$<BOOL:${UFE_FOUND}>:${UFE_INCLUDE_DIR}>
$<$<BOOL:${MayaUsd_FOUND}>:${MAYAUSD_INCLUDE_DIR}>
${CMAKE_BINARY_DIR}
)

if(DEFINED MAYAUSD_VERSION)
Expand Down
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 MAYAUSD_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;

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

} // namespace MAYAUSD_NS_DEF
#endif // MAYAHYDRA_PULINGINFO_CMD_H

0 comments on commit 22b2e14

Please sign in to comment.