Skip to content

Commit

Permalink
Merge pull request #3639 from Autodesk/donnels/EMSUSD-1024/new_comman…
Browse files Browse the repository at this point in the history
…d_to_report_build_info

EMSUSD-1024 - Provide a mechanism to retrieve an unambigous version f…
  • Loading branch information
seando-adsk authored Mar 19, 2024
2 parents 1de33b1 + 5ecb43f commit 9ee0a00
Show file tree
Hide file tree
Showing 11 changed files with 344 additions and 0 deletions.
29 changes: 29 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,35 @@ option(CMAKE_WANT_VALIDATE_UNDO_ITEM "Enable validating undo items list." OFF)
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.

# Build number corresponding to this build
#
# This is used to report version information about the build number that
# has produced this binary. When unset, the default value "0" is used
# instead as this usually corresponds to developers local builds.
set(MAYAUSD_BUILD_NUMBER "0" CACHE STRING "Build number corresponding to this build.")

# Git commit hash corresponding to this build
#
# This is used to report version information of the Git commit has that
# corresponds to a build. When unset, the default value DEVBLD is used
# instead as this usually corresponds to a developers local build.
set(MAYAUSD_GIT_COMMIT "DEVBLD" CACHE STRING "Git commit hash corresponding to this build.")

# Git branch corresponding to this build
#
# This is used to report version information about the Git branch of a
# build. When unset, the default value DEVBR is used instead as this
# usually corresponds to developers local builds.
set(MAYAUSD_GIT_BRANCH "DEVBR" CACHE STRING "Change set identifier corresponding to this build.")

# MayaUsd cut-id

# This is used to distinguish daily builds from one another. It is a
# usually a combination of the date & git commit hash.
set(MAYAUSD_CUT_ID "DEVBLD" CACHE STRING "MayaUsd cut-id corresponding to this build.")

#------------------------------------------------------------------------------
# internal flags to control build
#------------------------------------------------------------------------------
Expand Down
22 changes: 22 additions & 0 deletions cmake/utils.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -313,3 +313,25 @@ 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>")

function(mayaUsd_compute_timestamp)
# The date is formated the same way Maya formats its date.
# weekday 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(MAYAUSD_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 MAYAUSD_BUILD_NUMBER EQUAL 0)
set(MAYAUSD_BUILD_DATE "${BUILD_DATE}" CACHE STRING "Build Date" FORCE)
endif()
endfunction(mayaUsd_compute_timestamp)

# Compute the build timestamp.
mayaUsd_compute_timestamp()
6 changes: 6 additions & 0 deletions lib/mayaUsd/base/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# -----------------------------------------------------------------------------
target_sources(${PROJECT_NAME}
PRIVATE
buildInfo.cpp
debugCodes.cpp
tokens.cpp
)
Expand All @@ -25,6 +26,11 @@ if (NOT EXISTS ${dstFile})
endif()
configure_file(${SRCFILE} ${DSTFILE})

# Configure the build information file so that it gets the build and version info.
set(SRCFILE ${CMAKE_CURRENT_SOURCE_DIR}/buildInfo.h.src)
set(DSTFILE ${CMAKE_BINARY_DIR}/include/mayaUsd/buildInfo.h)
configure_file(${SRCFILE} ${DSTFILE})

mayaUsd_promoteHeaderList(HEADERS ${HEADERS} SUBDIR base)

# -----------------------------------------------------------------------------
Expand Down
27 changes: 27 additions & 0 deletions lib/mayaUsd/base/buildInfo.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//
// 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.
// 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 <mayaUsd/buildInfo.h>

namespace MAYAUSD_NS_DEF {

int MayaUsdBuildInfo::buildNumber() { return MAYAUSD_BUILD_NUMBER; }
const char* MayaUsdBuildInfo::gitCommit() { return MAYAUSD_GIT_COMMIT; }
const char* MayaUsdBuildInfo::gitBranch() { return MAYAUSD_GIT_BRANCH; }
const char* MayaUsdBuildInfo::cutId() { return MAYAUSD_CUT_ID; }
const char* MayaUsdBuildInfo::buildDate() { return MAYAUSD_BUILD_DATE; }

} // namespace MAYAUSD_NS_DEF
42 changes: 42 additions & 0 deletions lib/mayaUsd/base/buildInfo.h.src
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
//
// 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.
// 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 MAYAUSD_BUILDINFO_H
#define MAYAUSD_BUILDINFO_H

#include <mayaUsd/base/api.h>

#define MAYAUSD_BUILD_NUMBER ${MAYAUSD_BUILD_NUMBER}
#define MAYAUSD_GIT_COMMIT "${MAYAUSD_GIT_COMMIT}"
#define MAYAUSD_GIT_BRANCH "${MAYAUSD_GIT_BRANCH}"
#define MAYAUSD_CUT_ID "${MAYAUSD_CUT_ID}"
#define MAYAUSD_BUILD_DATE ${MAYAUSD_BUILD_DATE}

namespace MAYAUSD_NS_DEF {

class MAYAUSD_CORE_PUBLIC MayaUsdBuildInfo
{
public:
static int buildNumber();
static const char* gitCommit();
static const char* gitBranch();
static const char* cutId();
static const char* buildDate();
};

} // namespace MAYAUSD_NS_DEF

#endif // MAYAUSD_BUILDINFO_H
1 change: 1 addition & 0 deletions plugin/adsk/plugin/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ target_sources(${TARGET_NAME}
exportTranslator.cpp
ProxyShape.cpp
ProxyShapeListener.cpp
mayaUsdInfoCommand.cpp
)

if (CMAKE_UFE_V3_FEATURES_AVAILABLE)
Expand Down
113 changes: 113 additions & 0 deletions plugin/adsk/plugin/mayaUsdInfoCommand.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 "mayaUsdInfoCommand.h"

#include <mayaUsd/buildInfo.h>

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

#define XSTR(x) STR(x)
#define STR(x) #x

namespace MAYAUSD_NS_DEF {

const MString MayaUsdInfoCommand::commandName("mayaUsd");

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 MayaUsdInfoCommand::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 MayaUsdInfoCommand::doIt(const MArgList& args)
{
MStatus st;
MArgParser argData(syntax(), args, &st);
if (!st)
return st;

if (argData.isFlagSet(kMajorVersion)) {
setResult(MAYAUSD_MAJOR_VERSION); // int
} else if (argData.isFlagSet(kMinorVersion)) {
setResult(MAYAUSD_MINOR_VERSION); // int
} else if (argData.isFlagSet(kPatchVersion)) {
setResult(MAYAUSD_PATCH_LEVEL); // int
} else if (argData.isFlagSet(kVersion)) {
setResult(XSTR(MAYAUSD_VERSION)); // convert to string
} else if (argData.isFlagSet(kCutId)) {
setResult(MayaUsdBuildInfo::cutId());
} else if (argData.isFlagSet(kBuildNumber)) {
setResult(MayaUsdBuildInfo::buildNumber());
} else if (argData.isFlagSet(kGitCommit)) {
setResult(MayaUsdBuildInfo::gitCommit());
} else if (argData.isFlagSet(kGitBranch)) {
setResult(MayaUsdBuildInfo::gitBranch());
} else if (argData.isFlagSet(kBuildDate)) {
setResult(MayaUsdBuildInfo::buildDate());
}

return MS::kSuccess;
}

} // namespace MAYAUSD_NS_DEF
38 changes: 38 additions & 0 deletions plugin/adsk/plugin/mayaUsdInfoCommand.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//
// 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 MAYAUSD_MAYAUSD_CMD_H
#define MAYAUSD_MAYAUSD_CMD_H

#include <mayaUsd/mayaUsd.h>

#include <maya/MPxCommand.h>

namespace MAYAUSD_NS_DEF {

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

static const MString commandName;

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

} // namespace MAYAUSD_NS_DEF
#endif // MAYAUSD_MAYAUSD_CMD_H
3 changes: 3 additions & 0 deletions plugin/adsk/plugin/plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "exportTranslator.h"
#include "geomNode.h"
#include "importTranslator.h"
#include "mayaUsdInfoCommand.h"

#include <mayaUsd/base/api.h>
#include <mayaUsd/commands/editTargetCommand.h>
Expand Down Expand Up @@ -164,6 +165,7 @@ MStatus initializePlugin(MObject obj)
registerCommandCheck<MayaUsd::ADSKMayaUSDImportCommand>(plugin);
registerCommandCheck<MayaUsd::EditTargetCommand>(plugin);
registerCommandCheck<MayaUsd::LayerEditorCommand>(plugin);
registerCommandCheck<MayaUsd::MayaUsdInfoCommand>(plugin);
#if defined(WANT_QT_BUILD)
registerCommandCheck<MayaUsd::LayerEditorWindowCommand>(plugin);
#endif
Expand Down Expand Up @@ -337,6 +339,7 @@ MStatus uninitializePlugin(MObject obj)
deregisterCommandCheck<MayaUsd::ADSKMayaUSDImportCommand>(plugin);
deregisterCommandCheck<MayaUsd::EditTargetCommand>(plugin);
deregisterCommandCheck<MayaUsd::LayerEditorCommand>(plugin);
deregisterCommandCheck<MayaUsd::MayaUsdInfoCommand>(plugin);
#if defined(WANT_QT_BUILD)
deregisterCommandCheck<MayaUsd::LayerEditorWindowCommand>(plugin);
MayaUsd::LayerEditorWindowCommand::cleanupOnPluginUnload();
Expand Down
1 change: 1 addition & 0 deletions test/lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ set(TEST_SCRIPT_FILES
testMayaUsdLayerEditorCommands.py
testMayaUsdProxyAccessor.py
testMayaUsdCacheId.py
testMayaUsdInfoCommand.py
)

# Interactive Unit test scripts.
Expand Down
Loading

0 comments on commit 9ee0a00

Please sign in to comment.