diff --git a/CMakeLists.txt b/CMakeLists.txt index 2006a247b1..1b71eaf7fc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -33,6 +33,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 #------------------------------------------------------------------------------ @@ -81,9 +86,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}") diff --git a/cmake/utils.cmake b/cmake/utils.cmake index bb129c41c4..1c106386ac 100644 --- a/cmake/utils.cmake +++ b/cmake/utils.cmake @@ -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 "$") + +# +# 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() diff --git a/lib/mayaHydra/hydraExtensions/CMakeLists.txt b/lib/mayaHydra/hydraExtensions/CMakeLists.txt index e8997ec658..4b23d883ca 100644 --- a/lib/mayaHydra/hydraExtensions/CMakeLists.txt +++ b/lib/mayaHydra/hydraExtensions/CMakeLists.txt @@ -11,6 +11,7 @@ target_sources(${TARGET_NAME} hydraUtils.cpp interfaceImp.cpp mayaUtils.cpp + mhBuildInfo.cpp mixedUtils.cpp mayaHydraSceneProducer.cpp ) @@ -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 @@ -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} diff --git a/lib/mayaHydra/hydraExtensions/mhBuildInfo.cpp b/lib/mayaHydra/hydraExtensions/mhBuildInfo.cpp new file mode 100644 index 0000000000..2f538cb383 --- /dev/null +++ b/lib/mayaHydra/hydraExtensions/mhBuildInfo.cpp @@ -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 + +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 diff --git a/lib/mayaHydra/hydraExtensions/mhBuildInfo.h.src b/lib/mayaHydra/hydraExtensions/mhBuildInfo.h.src new file mode 100644 index 0000000000..d6c9eb152f --- /dev/null +++ b/lib/mayaHydra/hydraExtensions/mhBuildInfo.h.src @@ -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 +#include + +#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 diff --git a/lib/mayaHydra/mayaPlugin/CMakeLists.txt b/lib/mayaHydra/mayaPlugin/CMakeLists.txt index 598192b3da..d06d73e95b 100644 --- a/lib/mayaHydra/mayaPlugin/CMakeLists.txt +++ b/lib/mayaHydra/mayaPlugin/CMakeLists.txt @@ -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}) diff --git a/lib/mayaHydra/mayaPlugin/plugin.cpp b/lib/mayaHydra/mayaPlugin/plugin.cpp index 59c86f4673..c75f7516b5 100644 --- a/lib/mayaHydra/mayaPlugin/plugin.cpp +++ b/lib/mayaHydra/mayaPlugin/plugin.cpp @@ -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 gsRenderOverrides; +static std::vector 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) @@ -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; } @@ -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(desc); + auto mtohRenderer = std::make_unique(desc); MStatus status = renderer->registerOverride(mtohRenderer.get()); if (status == MS::kSuccess) { gsRenderOverrides.push_back(mtohRenderer.release()); diff --git a/lib/mayaHydra/mayaPlugin/viewCommand.cpp b/lib/mayaHydra/mayaPlugin/viewCommand.cpp index 9f7bd7b882..1f079b21d8 100644 --- a/lib/mayaHydra/mayaPlugin/viewCommand.cpp +++ b/lib/mayaHydra/mayaPlugin/viewCommand.cpp @@ -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. @@ -20,27 +21,16 @@ #include "renderOverride.h" #include +#include +#include #include #include #include -#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"); @@ -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"; @@ -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; } @@ -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 +} diff --git a/lib/mayaHydra/mayaPlugin/viewCommand.h b/lib/mayaHydra/mayaPlugin/viewCommand.h index bd212277ac..630afc1e26 100644 --- a/lib/mayaHydra/mayaPlugin/viewCommand.h +++ b/lib/mayaHydra/mayaPlugin/viewCommand.h @@ -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. @@ -16,11 +17,11 @@ #ifndef MTOH_CMD_H #define MTOH_CMD_H -#include +#include #include -PXR_NAMESPACE_OPEN_SCOPE +namespace MAYAHYDRA_NS_DEF { class MtohViewCmd : public MPxCommand { @@ -33,6 +34,6 @@ class MtohViewCmd : public MPxCommand MStatus doIt(const MArgList& args) override; }; -PXR_NAMESPACE_CLOSE_SCOPE +} #endif // MTOH_CMD_H diff --git a/test/lib/mayaUsd/render/mayaToHydra/testMtohCommand.py b/test/lib/mayaUsd/render/mayaToHydra/testMtohCommand.py index 07b4feb2fb..becc9c44aa 100644 --- a/test/lib/mayaUsd/render/mayaToHydra/testMtohCommand.py +++ b/test/lib/mayaUsd/render/mayaToHydra/testMtohCommand.py @@ -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 @@ -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())