Skip to content

Commit

Permalink
Report build and version information from the mayaHydra plugin (#10)
Browse files Browse the repository at this point in the history
* Working version and build information reporting.

* Moved code to MayaHydra namespace.

* Added unit test for version and build info.

* Read build information from CMake.

* Implement build date support.

* Addressed code review comments.

* Removed obsolete MAYAHYDRA_CUT_ID support.
  • Loading branch information
ppt-adsk authored Nov 16, 2023
1 parent debf297 commit 6bbfbcb
Show file tree
Hide file tree
Showing 10 changed files with 173 additions and 57 deletions.
8 changes: 5 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ option(CMAKE_WANT_MATERIALX_BUILD "Enable building with MaterialX (experimental)
set(PXR_OVERRIDE_PLUGINPATH_NAME PXR_PLUGINPATH_NAME
CACHE STRING "Name of env var USD searches to find plugins")

# Build-related information, expected to be passed in by the parent build.
set(MAYAHYDRA_BUILD_NUMBER 0 CACHE STRING "Build number.")
set(MAYAHYDRA_GIT_COMMIT "Unknown_Git_commit" CACHE STRING "Build commit.")
set(MAYAHYDRA_GIT_BRANCH "Unknown_Git_branch" CACHE STRING "Build branch.")

#------------------------------------------------------------------------------
# internal flags to control build
#------------------------------------------------------------------------------
Expand Down Expand Up @@ -80,9 +85,6 @@ endif()

include(cmake/mayahydra_version.info)
set(MAYAHYDRA_VERSION "${MAYAHYDRA_MAJOR_VERSION}.${MAYAHYDRA_MINOR_VERSION}.${MAYAHYDRA_PATCH_LEVEL}")
if(DEFINED ENV{PLUGIN_CUT_ID})
set(MAYAHYDRA_CUT_ID $ENV{PLUGIN_CUT_ID})
endif()

include(cmake/flowViewport_version.info)
set(FLOWVIEWPORT_VERSION "${FLOWVIEWPORT_MAJOR_VERSION}.${FLOWVIEWPORT_MINOR_VERSION}.${FLOWVIEWPORT_PATCH_LEVEL}")
Expand Down
23 changes: 23 additions & 0 deletions cmake/utils.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -309,3 +309,26 @@ endfunction(get_external_project_default_values)

# Create one for all the project using the default list separator
get_external_project_default_values(MAYAUSD_EXTERNAL_PROJECT_GENERAL_SETTINGS "$<SEMICOLON>")

#
# Adapted from peptide_compute_timestamps()
#
function(mayaHydra_compute_timestamp)
# The date is formated the same way Maya formats its date.
# weekdday month/day/fullyear, CONCAT(fullyear + month + day + fullhour + minute)
string(TIMESTAMP WEEKDAY "%w")
set(MH_WEEK_DAYS "Sun" "Mon" "Tue" "Wed" "Thu" "Fri" "Sat")
list(GET MH_WEEK_DAYS ${WEEKDAY} WEEKDAY)
string(TIMESTAMP BUILD_DATE "\"${WEEKDAY} %m/%d/%Y, %Y%m%d%H%M\"")

set(MAYAHYDRA_BUILD_DATE "${BUILD_DATE}" CACHE STRING "Build Date")

# For build pipeline builds, force a new timestamp. For developer builds,
# resetting the timestamps is annoying as it causes all the version file to
# be regenerated and thus all libraries and executable to be relinked.
# Therefore, don't reset the timestamps unless a clean build is made.
if (NOT MAYAHYDRA_BUILD_NUMBER EQUAL 0)
set(MAYAHYDRA_BUILD_DATE "${BUILD_DATE}" CACHE STRING "Build Date" FORCE)
endif()
endfunction(mayaHydra_compute_timestamp)
mayaHydra_compute_timestamp()
11 changes: 5 additions & 6 deletions lib/mayaHydra/hydraExtensions/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ target_sources(${TARGET_NAME}
hydraUtils.cpp
interfaceImp.cpp
mayaUtils.cpp
mhBuildInfo.cpp
mixedUtils.cpp
mayaHydraSceneProducer.cpp
)
Expand Down Expand Up @@ -89,12 +90,6 @@ if(DEFINED MAYAHYDRA_VERSION)
MAYAHYDRA_VERSION=${MAYAHYDRA_VERSION}
)
endif()
if(DEFINED MAYAHYDRA_CUT_ID)
target_compile_definitions(${TARGET_NAME}
PRIVATE
MAYAHYDRA_CUT_ID=${MAYAHYDRA_CUT_ID}
)
endif()

# -----------------------------------------------------------------------------
# link libraries
Expand Down Expand Up @@ -146,6 +141,10 @@ set(SRCFILE ${CMAKE_CURRENT_SOURCE_DIR}/mayaHydra.h.src)
set(DSTFILE ${CMAKE_BINARY_DIR}/include/mayaHydraLib/mayaHydra.h)
configure_file(${SRCFILE} ${DSTFILE})

set(SRCFILE ${CMAKE_CURRENT_SOURCE_DIR}/mhBuildInfo.h.src)
set(DSTFILE ${CMAKE_BINARY_DIR}/include/mayaHydraLib/mhBuildInfo.h)
configure_file(${SRCFILE} ${DSTFILE})

mayaUsd_promoteHeaderList(
HEADERS
${HEADERS}
Expand Down
26 changes: 26 additions & 0 deletions lib/mayaHydra/hydraExtensions/mhBuildInfo.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//
// Copyright 2023 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.
// 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 <mayaHydraLib/mhBuildInfo.h>

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::buildDate() { return MAYAHYDRA_BUILD_DATE; }

} // namespace MAYAHYDRA_NS_DEF
41 changes: 41 additions & 0 deletions lib/mayaHydra/hydraExtensions/mhBuildInfo.h.src
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
//
// Copyright 2023 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.
// 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 LIB_MAYAHYDRA_HYDRAEXTENSIONS_MHBUILDINFO_H
#define LIB_MAYAHYDRA_HYDRAEXTENSIONS_MHBUILDINFO_H

#include <mayaHydraLib/api.h>
#include <mayaHydraLib/mayaHydra.h>

#define MAYAHYDRA_BUILD_NUMBER ${MAYAHYDRA_BUILD_NUMBER}
#define MAYAHYDRA_GIT_COMMIT "${MAYAHYDRA_GIT_COMMIT}"
#define MAYAHYDRA_GIT_BRANCH "${MAYAHYDRA_GIT_BRANCH}"
#define MAYAHYDRA_BUILD_DATE ${MAYAHYDRA_BUILD_DATE}

namespace MAYAHYDRA_NS_DEF {

class MAYAHYDRALIB_API MhBuildInfo
{
public:
static int buildNumber();
static const char* gitCommit();
static const char* gitBranch();
static const char* buildDate();
};

}

#endif // LIB_MAYAHYDRA_HYDRAEXTENSIONS_MHBUILDINFO_H
6 changes: 0 additions & 6 deletions lib/mayaHydra/mayaPlugin/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,6 @@ if(DEFINED MAYAHYDRA_VERSION)
MAYAHYDRA_VERSION=${MAYAHYDRA_VERSION}
)
endif()
if(DEFINED MAYAHYDRA_CUT_ID)
target_compile_definitions(${TARGET_NAME}
PRIVATE
MAYAHYDRA_CUT_ID=${MAYAHYDRA_CUT_ID}
)
endif()

mayaHydra_compile_config(${TARGET_NAME})

Expand Down
14 changes: 5 additions & 9 deletions lib/mayaHydra/mayaPlugin/plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,20 +47,16 @@
#error Maya API version 2024+ required
#endif

PXR_NAMESPACE_USING_DIRECTIVE
using namespace MayaHydra;

// Don't use smart pointers in the static vector: when Maya is doing its
// default "quick exit" that does not uninitialize plugins, the atexit
// destruction of the overrides in the vector will crash on destruction,
// because Hydra has already destroyed structures these rely on. Simply leak
// the render overrides in this case.
static std::vector<MtohRenderOverride*> gsRenderOverrides;
static std::vector<PXR_NS::MtohRenderOverride*> gsRenderOverrides;

#if defined(MAYAUSD_VERSION)
#define STRINGIFY(x) #x
#define TOSTRING(x) STRINGIFY(x)
#define PLUGIN_VERSION TOSTRING(MAYAUSD_VERSION)
#elif defined(MAYAHYDRA_VERSION)
#if defined(MAYAHYDRA_VERSION)
#define STRINGIFY(x) #x
#define TOSTRING(x) STRINGIFY(x)
#define PLUGIN_VERSION TOSTRING(MAYAHYDRA_VERSION)
Expand Down Expand Up @@ -101,7 +97,7 @@ PLUGIN_EXPORT MStatus initializePlugin(MObject obj)
// Call one time registration of plugins compiled for same USD version as MayaUSD plugin.
MayaUsd::registerVersionedPlugins();
#endif
ret = MayaHydraAdapter::Initialize();
ret = PXR_NS::MayaHydraAdapter::Initialize();
if (!ret) {
return ret;
}
Expand All @@ -126,7 +122,7 @@ PLUGIN_EXPORT MStatus initializePlugin(MObject obj)

if (auto* renderer = MHWRender::MRenderer::theRenderer()) {
for (const auto& desc : MayaHydra::MtohGetRendererDescriptions()) {
auto mtohRenderer = std::make_unique<MtohRenderOverride>(desc);
auto mtohRenderer = std::make_unique<PXR_NS::MtohRenderOverride>(desc);
MStatus status = renderer->registerOverride(mtohRenderer.get());
if (status == MS::kSuccess) {
gsRenderOverrides.push_back(mtohRenderer.release());
Expand Down
76 changes: 47 additions & 29 deletions lib/mayaHydra/mayaPlugin/viewCommand.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//
// Copyright 2019 Luma Pictures
// Copyright 2023 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.
Expand All @@ -20,27 +21,16 @@
#include "renderOverride.h"

#include <mayaHydraLib/delegates/delegateRegistry.h>
#include <mayaHydraLib/mhBuildInfo.h>
#include <mayaHydraLib/mayaHydra.h>

#include <maya/MArgDatabase.h>
#include <maya/MGlobal.h>
#include <maya/MSyntax.h>

#if defined(MAYAHYDRA_CUT_ID)
#define STRINGIFY(x) #x
#define TOSTRING(x) STRINGIFY(x)
#define PLUGIN_CUT_ID TOSTRING(MAYAHYDRA_CUT_ID)
#else
#pragma message("MAYAHYDRA_CUT_ID is not defined")
#define PLUGIN_CUT_ID "Maya-Hydra unknown cut"
#endif

PXR_NAMESPACE_OPEN_SCOPE
// Bring the MayaHydra namespace into scope.
// The following code currently lives inside the pxr namespace, but it would make more sense to
// have it inside the MayaHydra namespace. This using statement allows us to use MayaHydra symbols
// from within the pxr namespace as if we were in the MayaHydra namespace.
// Remove this once the code has been moved to the MayaHydra namespace.
using namespace MayaHydra;
PXR_NAMESPACE_USING_DIRECTIVE

namespace MAYAHYDRA_NS_DEF {

const MString MtohViewCmd::name("mayaHydra");

Expand Down Expand Up @@ -79,10 +69,22 @@ constexpr auto _visibleOnlyLong = "-visibleOnly";
constexpr auto _sceneDelegateId = "-sid";
constexpr auto _sceneDelegateIdLong = "-sceneDelegateId";

// MAYA-127221: We will need to replace this with a flag inside of the pluginInfo command in an
// upcoming release.
constexpr auto _pluginInfoCutId = "-cid";
constexpr auto _pluginInfoCutIdLong = "-pluginInfoCut";
// Versioning and build information.
constexpr auto _majorVersion = "-mjv";
constexpr auto _minorVersion = "-mnv";
constexpr auto _patchVersion = "-pv";
constexpr auto _majorVersionLong = "-majorVersion";
constexpr auto _minorVersionLong = "-minorVersion";
constexpr auto _patchVersionLong = "-patchVersion";

constexpr auto _buildNumber = "-bn";
constexpr auto _gitCommit = "-gc";
constexpr auto _gitBranch = "-gb";
constexpr auto _buildDate = "-bd";
constexpr auto _buildNumberLong = "-buildNumber";
constexpr auto _gitCommitLong = "-gitCommit";
constexpr auto _gitBranchLong = "-gitBranch";
constexpr auto _buildDateLong = "-buildDate";

constexpr auto _rendererId = "-r";
constexpr auto _rendererIdLong = "-renderer";
Expand Down Expand Up @@ -160,7 +162,16 @@ MSyntax MtohViewCmd::createSyntax()

syntax.addFlag(_sceneDelegateId, _sceneDelegateIdLong, MSyntax::kString);

syntax.addFlag(_pluginInfoCutId, _pluginInfoCutIdLong);
// Versioning and build information flags.

syntax.addFlag(_majorVersion, _majorVersionLong);
syntax.addFlag(_minorVersion, _minorVersionLong);
syntax.addFlag(_patchVersion, _patchVersionLong);

syntax.addFlag(_buildNumber, _buildNumberLong);
syntax.addFlag(_gitCommit, _gitCommitLong);
syntax.addFlag(_gitBranch, _gitBranchLong);
syntax.addFlag(_buildDate, _buildDateLong);

return syntax;
}
Expand Down Expand Up @@ -274,15 +285,22 @@ MStatus MtohViewCmd::doIt(const MArgList& args)
SdfPath delegateId = MtohRenderOverride::RendererSceneDelegateId(
renderDelegateName, TfToken(sceneDelegateName.asChar()));
setResult(MString(delegateId.GetText()));
} else if (db.isFlagSet(_pluginInfoCutId)) {
#ifdef MAYAHYDRA_CUT_ID
setResult(MString(PLUGIN_CUT_ID));
#else
MGlobal::displayError(MString("MayaHydra cut id is not available"));
return MS::kInvalidParameter;
#endif
} else if (db.isFlagSet(_majorVersion)) {
setResult(MAYAHYDRA_MAJOR_VERSION);
} else if (db.isFlagSet(_minorVersion)) {
setResult(MAYAHYDRA_MINOR_VERSION);
} else if (db.isFlagSet(_patchVersion)) {
setResult(MAYAHYDRA_PATCH_LEVEL);
} else if (db.isFlagSet(_buildNumber)) {
setResult(MhBuildInfo::buildNumber());
} else if (db.isFlagSet(_gitCommit)) {
setResult(MhBuildInfo::gitCommit());
} else if (db.isFlagSet(_gitBranch)) {
setResult(MhBuildInfo::gitBranch());
} else if (db.isFlagSet(_buildDate)) {
setResult(MhBuildInfo::buildDate());
}
return MS::kSuccess;
}

PXR_NAMESPACE_CLOSE_SCOPE
}
7 changes: 4 additions & 3 deletions lib/mayaHydra/mayaPlugin/viewCommand.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//
// Copyright 2019 Luma Pictures
// Copyright 2023 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.
Expand All @@ -16,11 +17,11 @@
#ifndef MTOH_CMD_H
#define MTOH_CMD_H

#include <pxr/pxr.h>
#include <mayaHydraLib/mayaHydra.h>

#include <maya/MPxCommand.h>

PXR_NAMESPACE_OPEN_SCOPE
namespace MAYAHYDRA_NS_DEF {

class MtohViewCmd : public MPxCommand
{
Expand All @@ -33,6 +34,6 @@ class MtohViewCmd : public MPxCommand
MStatus doIt(const MArgList& args) override;
};

PXR_NAMESPACE_CLOSE_SCOPE
}

#endif // MTOH_CMD_H
18 changes: 17 additions & 1 deletion test/lib/mayaUsd/render/mayaToHydra/testMtohCommand.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
import sys
import unittest

import maya.cmds as cmds
Expand Down Expand Up @@ -115,6 +114,23 @@ def test_createRenderGlobals(self):
self.assertFalse(cmds.getAttr(
"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)

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), '')

if __name__ == '__main__':
fixturesUtils.runTests(globals())

0 comments on commit 6bbfbcb

Please sign in to comment.