diff --git a/CMakeLists.txt b/CMakeLists.txt index 73d7eb9226..5a50042119 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -151,6 +151,11 @@ endif() #------------------------------------------------------------------------------ include(cmake/compiler_config.cmake) +#------------------------------------------------------------------------------ +# gulark filesystem +#------------------------------------------------------------------------------ +include(cmake/gulark.cmake) + #------------------------------------------------------------------------------ # test #------------------------------------------------------------------------------ diff --git a/cmake/gulark.cmake b/cmake/gulark.cmake new file mode 100644 index 0000000000..b4e297c6db --- /dev/null +++ b/cmake/gulark.cmake @@ -0,0 +1,29 @@ +# +# Copyright 2021 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(FetchContent) + +set(FETCHCONTENT_QUIET OFF) + +FetchContent_Declare( + gulark + GIT_REPOSITORY https://github.com/gulrak/filesystem.git + GIT_TAG v1.5.0 + USES_TERMINAL_DOWNLOAD TRUE + GIT_CONFIG advice.detachedHead=false +) + +FetchContent_MakeAvailable(gulark) diff --git a/doc/build.md b/doc/build.md index 6390bfda83..a4cb25aa04 100644 --- a/doc/build.md +++ b/doc/build.md @@ -189,11 +189,11 @@ Test project /Users/sabrih/Desktop/workspace/build/Debug/plugin/al ##### Boost: -Currently the Animal Logic plugin has a dependency on some of the boost components ( e.g thread, filesystem ). When building Pixar USD, one needs to pass the following key,value paired arguments for boost to include those components: +Currently the Animal Logic plugin has a dependency on some of the boost components. When building Pixar USD, one needs to pass the following key,value paired arguments for boost to include those components: e.g ``` -python build_usd.py ~/Desktop/BUILD --build-args boost,"--with-date_time --with-thread --with-system --with-filesystem" +python build_usd.py ~/Desktop/BUILD --build-args boost,"--with-date_time" ``` ***NOTE:*** ```--build-args``` needs to be passed at the very end of command, after build/install location. diff --git a/doc/codingGuidelines.md b/doc/codingGuidelines.md index 0802978a47..2657939fc5 100644 --- a/doc/codingGuidelines.md +++ b/doc/codingGuidelines.md @@ -222,10 +222,13 @@ Recent extensions to the C++ standard introduce many features previously only fo Our library currently has the following boost dependencies: * `boost::python` * `boost::hash_combine` (see [this proposal](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/p0814r0.pdf) ) -* `boost::filesystem` (preferable to replace with Pixar USD arch/fileSystem) -* `boost::system` * `boost::make_shared` (preferable to replace with `std::shared_ptr`) +***Update:*** +* `boost::filesystem` and `boost::system` are removed. Until the transition to C++17 std::filesystem, [ghc::filesystem](https://github.com/gulrak/filesystem) must be used as an alternative across the project. + +* Dependency on `boost::thread` is removed from Animal Logic plugin. + ## Modern C++ Our goal is to develop [maya-usd](https://github.com/autodesk/maya-usd) following modern C++ practices. We’ll follow the [C++ Core Guidelines](http://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines) and pay attention to: * `using` (vs `typedef`) keyword diff --git a/lib/mayaUsd/CMakeLists.txt b/lib/mayaUsd/CMakeLists.txt index 046ddb5832..36dbf50500 100644 --- a/lib/mayaUsd/CMakeLists.txt +++ b/lib/mayaUsd/CMakeLists.txt @@ -26,7 +26,6 @@ endif() if(MAYAUSD_DEFINE_BOOST_DEBUG_PYTHON_FLAG) set(Boost_USE_DEBUG_PYTHON ON) endif() -find_package(Boost COMPONENTS filesystem system REQUIRED) # ----------------------------------------------------------------------------- # compiler configuration @@ -119,8 +118,7 @@ target_link_libraries(${PROJECT_NAME} ${MAYA_LIBRARIES} mayaUsdUtils PRIVATE - Boost::filesystem - Boost::system + ghc_filesystem ) # ----------------------------------------------------------------------------- diff --git a/lib/mayaUsd/nodes/proxyShapeBase.cpp b/lib/mayaUsd/nodes/proxyShapeBase.cpp index 371886f61b..8ae6491842 100644 --- a/lib/mayaUsd/nodes/proxyShapeBase.cpp +++ b/lib/mayaUsd/nodes/proxyShapeBase.cpp @@ -87,7 +87,7 @@ #include #include -#include +#include #include #include @@ -625,7 +625,7 @@ MStatus MayaUsdProxyShapeBase::computeInStageDataCached(MDataBlock& dataBlock) "ProxyShapeBase::reloadStage original USD file path is %s\n", fileString.c_str()); - boost::filesystem::path filestringPath(fileString); + ghc::filesystem::path filestringPath(fileString); if (filestringPath.is_absolute()) { fileString = UsdMayaUtilFileSystem::resolvePath(fileString); TF_DEBUG(USDMAYA_PROXYSHAPEBASE) diff --git a/lib/mayaUsd/render/vp2RenderDelegate/material.cpp b/lib/mayaUsd/render/vp2RenderDelegate/material.cpp index 1d2a2261cd..26422f1cf4 100644 --- a/lib/mayaUsd/render/vp2RenderDelegate/material.cpp +++ b/lib/mayaUsd/render/vp2RenderDelegate/material.cpp @@ -42,7 +42,7 @@ #include #include -#include +#include #include #include @@ -677,7 +677,7 @@ void HdVP2Material::Sync( << _GenerateXMLString(dispNet) << "\n"; if (_surfaceShader) { - auto tmpDir = boost::filesystem::temp_directory_path(); + auto tmpDir = ghc::filesystem::temp_directory_path(); tmpDir /= "HdVP2Material_"; tmpDir += id.GetName(); tmpDir += ".txt"; diff --git a/lib/mayaUsd/utils/utilFileSystem.cpp b/lib/mayaUsd/utils/utilFileSystem.cpp index 90438a575e..0d081483c7 100644 --- a/lib/mayaUsd/utils/utilFileSystem.cpp +++ b/lib/mayaUsd/utils/utilFileSystem.cpp @@ -25,7 +25,30 @@ #include #include -#include +#include + +#include +#include + +namespace { +std::string generateUniqueName() +{ + const auto len { 6 }; + std::string uniqueName; + uniqueName.reserve(len); + + const std::string alphaNum { "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" }; + + std::random_device rd; + std::mt19937 gen(rd()); + std::uniform_int_distribution<> dis(0, alphaNum.size() - 1); + + for (auto i = 0; i < len; ++i) { + uniqueName += (alphaNum[dis(gen)]); + } + return uniqueName; +} +} // namespace PXR_NAMESPACE_USING_DIRECTIVE @@ -37,7 +60,7 @@ std::string UsdMayaUtilFileSystem::resolvePath(const std::string& filePath) std::string UsdMayaUtilFileSystem::getDir(const std::string& fullFilePath) { - return boost::filesystem::path(fullFilePath).parent_path().string(); + return ghc::filesystem::path(fullFilePath).parent_path().string(); } std::string UsdMayaUtilFileSystem::getMayaReferencedFileDir(const MObject& proxyShapeNode) @@ -130,8 +153,10 @@ std::string UsdMayaUtilFileSystem::resolveRelativePathWithinMayaContext( if (currentFileDir.empty()) return relativeFilePath; - boost::system::error_code errorCode; - auto path = boost::filesystem::canonical(relativeFilePath, currentFileDir, errorCode); + std::error_code errorCode; + auto path = ghc::filesystem::canonical( + ghc::filesystem::path(currentFileDir).append(relativeFilePath), errorCode); + if (errorCode) { // file does not exist return std::string(); @@ -145,10 +170,10 @@ std::string UsdMayaUtilFileSystem::getUniqueFileName( const std::string& basename, const std::string& ext) { - std::string fileNameModel = basename + "-%%%%%%." + ext; + const std::string fileNameModel = basename + '-' + generateUniqueName() + '.' + ext; - boost::filesystem::path pathModel(dir); + ghc::filesystem::path pathModel(dir); pathModel.append(fileNameModel); - return boost::filesystem::unique_path(pathModel).generic_string(); + return pathModel.generic_string(); } diff --git a/lib/usd/translators/CMakeLists.txt b/lib/usd/translators/CMakeLists.txt index 0dc70b384b..861ec4903a 100644 --- a/lib/usd/translators/CMakeLists.txt +++ b/lib/usd/translators/CMakeLists.txt @@ -10,14 +10,6 @@ set(LIBRARY_INSTALL_PATH add_library(${TARGET_NAME} SHARED) -#------------------------------------------------------------------------------ -# modules and definitions -#------------------------------------------------------------------------------ -if(NOT DEFINED ENV{BOOST_ROOT}) - set(ENV{BOOST_ROOT} ${PXR_USD_LOCATION}) -endif() -find_package(Boost COMPONENTS filesystem system REQUIRED) - # ----------------------------------------------------------------------------- # sources # ----------------------------------------------------------------------------- @@ -90,8 +82,7 @@ target_link_libraries(${TARGET_NAME} mayaUsd mayaUsd_Schemas basePxrUsdPreviewSurface - Boost::filesystem - Boost::system + ghc_filesystem ) # ----------------------------------------------------------------------------- diff --git a/lib/usd/translators/shading/usdFileTextureWriter.cpp b/lib/usd/translators/shading/usdFileTextureWriter.cpp index 58e2e13899..1f301b5ad2 100644 --- a/lib/usd/translators/shading/usdFileTextureWriter.cpp +++ b/lib/usd/translators/shading/usdFileTextureWriter.cpp @@ -47,9 +47,10 @@ #include #include -#include +#include #include +#include PXR_NAMESPACE_OPEN_SCOPE @@ -288,11 +289,10 @@ void PxrUsdTranslators_FileTextureWriter::Write(const UsdTimeCode& usdTime) const std::string fileName = _GetExportArgs().GetResolvedFileName(); TfToken fileExt(TfGetExtension(fileName)); if (fileExt != UsdMayaTranslatorTokens->UsdFileExtensionPackage) { - boost::filesystem::path usdDir(fileName); + ghc::filesystem::path usdDir(fileName); usdDir = usdDir.parent_path(); - boost::system::error_code ec; - boost::filesystem::path relativePath - = boost::filesystem::relative(fileTextureName, usdDir, ec); + std::error_code ec; + ghc::filesystem::path relativePath = ghc::filesystem::relative(fileTextureName, usdDir, ec); if (!ec && !relativePath.empty()) { fileTextureName = relativePath.generic_string(); } diff --git a/plugin/al/CMakeLists.txt b/plugin/al/CMakeLists.txt index 80970af0c6..def57bd664 100644 --- a/plugin/al/CMakeLists.txt +++ b/plugin/al/CMakeLists.txt @@ -7,7 +7,6 @@ if (POLICY CMP0026) cmake_policy(SET CMP0026 OLD) endif() -set(NEED_BOOST_FILESYSTEM ON) set(CMAKE_VERBOSE_MAKEFILE OFF) set(CMAKE_INCLUDE_CURRENT_DIR ON) if(NOT DEFINED ENV{BOOST_ROOT}) @@ -24,15 +23,7 @@ option(SKIP_USDMAYA_TESTS "Build tests" OFF) # FindBoost is particularly buggy, and doesn't like custom boost locations. # Adding specific components forces calls to _Boost_find_library, which # is the rationale for listing them here. -set(Boost_FIND_COMPONENTS - thread -) -if(NEED_BOOST_FILESYSTEM) - list(APPEND Boost_FIND_COMPONENTS - filesystem - system - ) -endif() +set(Boost_FIND_COMPONENTS "") if(WIN32) list(APPEND Boost_FIND_COMPONENTS chrono diff --git a/plugin/al/lib/AL_USDMaya/AL/usdmaya/nodes/LayerManager.cpp b/plugin/al/lib/AL_USDMaya/AL/usdmaya/nodes/LayerManager.cpp index 9dd68757e3..3ebb1054e7 100644 --- a/plugin/al/lib/AL_USDMaya/AL/usdmaya/nodes/LayerManager.cpp +++ b/plugin/al/lib/AL_USDMaya/AL/usdmaya/nodes/LayerManager.cpp @@ -31,9 +31,6 @@ #include #include -#include -#include - #include namespace { @@ -354,7 +351,7 @@ bool LayerManager::addLayer(SdfLayerHandle layer, const std::string& identifier) MGlobal::displayError("LayerManager::addLayer - given layer is no longer valid"); return false; } - boost::unique_lock lock(m_layersMutex); + std::unique_lock lock(m_layersMutex); return m_layerDatabase.addLayer(layerRef, identifier); } @@ -366,14 +363,14 @@ bool LayerManager::removeLayer(SdfLayerHandle layer) MGlobal::displayError("LayerManager::removeLayer - given layer is no longer valid"); return false; } - boost::unique_lock lock(m_layersMutex); + std::unique_lock lock(m_layersMutex); return m_layerDatabase.removeLayer(layerRef); } //---------------------------------------------------------------------------------------------------------------------- SdfLayerHandle LayerManager::findLayer(std::string identifier) { - boost::shared_lock_guard lock(m_layersMutex); + std::shared_lock lock(m_layersMutex); return m_layerDatabase.findLayer(identifier); } @@ -404,7 +401,7 @@ MStatus LayerManager::populateSerialisationAttributes() MArrayDataHandle layersArrayHandle = dataBlock.outputArrayValue(m_layers, &status); AL_MAYA_CHECK_ERROR(status, errorString); { - boost::shared_lock_guard lock(m_layersMutex); + std::shared_lock lock(m_layersMutex); MArrayDataBuilder builder(&dataBlock, layers(), m_layerDatabase.max_size(), &status); AL_MAYA_CHECK_ERROR(status, errorString); std::string temp; diff --git a/plugin/al/lib/AL_USDMaya/AL/usdmaya/nodes/LayerManager.h b/plugin/al/lib/AL_USDMaya/AL/usdmaya/nodes/LayerManager.h index 77c2a5c5a1..d8ed851a36 100644 --- a/plugin/al/lib/AL_USDMaya/AL/usdmaya/nodes/LayerManager.h +++ b/plugin/al/lib/AL_USDMaya/AL/usdmaya/nodes/LayerManager.h @@ -25,19 +25,7 @@ #include #include - -// On Windows, against certain versions of Maya and with strict compiler -// settings on, we are getting warning-as-error problems with a couple -// boost includes. Disabling those warnings for the specific includes -// for now instead of disabling the strict settings at a higher level. -#ifdef _MSC_VER -#pragma warning(push) -#pragma warning(disable : 4002) -#endif -#include -#ifdef _MSC_VER -#pragma warning(pop) -#endif +#include PXR_NAMESPACE_USING_DIRECTIVE @@ -383,7 +371,7 @@ class LayerManager // it COULDN'T be. (I haven't really looked into the way maya's new multi-threaded node // evaluation works, for instance.) This is essentially a globally shared resource, so I figured // better be safe... - boost::shared_mutex m_layersMutex; + std::shared_timed_mutex m_layersMutex; //-------------------------------------------------------------------------------------------------------------------- /// MPxNode overrides diff --git a/plugin/al/lib/AL_USDMaya/AL/usdmaya/nodes/ProxyShape.cpp b/plugin/al/lib/AL_USDMaya/AL/usdmaya/nodes/ProxyShape.cpp index 10c9d13e40..324950b308 100644 --- a/plugin/al/lib/AL_USDMaya/AL/usdmaya/nodes/ProxyShape.cpp +++ b/plugin/al/lib/AL_USDMaya/AL/usdmaya/nodes/ProxyShape.cpp @@ -63,7 +63,7 @@ #include #include -#include +#include #if defined(WANT_UFE_BUILD) #include "ufe/path.h" @@ -1246,7 +1246,7 @@ void ProxyShape::loadStage() } } } else { - boost::filesystem::path filestringPath(fileString); + ghc::filesystem::path filestringPath(fileString); if (filestringPath.is_absolute()) { fileString = UsdMayaUtilFileSystem::resolvePath(fileString); TF_DEBUG(ALUSDMAYA_TRANSLATORS) diff --git a/plugin/al/lib/AL_USDMaya/CMakeLists.txt b/plugin/al/lib/AL_USDMaya/CMakeLists.txt index 889b2abeac..b3be0bd1c3 100644 --- a/plugin/al/lib/AL_USDMaya/CMakeLists.txt +++ b/plugin/al/lib/AL_USDMaya/CMakeLists.txt @@ -209,11 +209,8 @@ target_link_libraries(${LIBRARY_NAME} usdImagingGL vt ${Boost_PYTHON_LIBRARY} - $,Boost::thread,${Boost_THREAD_LIBRARY}> $<$:Boost::chrono> $<$:Boost::date_time> - $<$:Boost::filesystem> - $<$:Boost::system> ${MAYA_Foundation_LIBRARY} ${MAYA_OpenMayaAnim_LIBRARY} ${MAYA_OpenMayaUI_LIBRARY} @@ -221,6 +218,7 @@ target_link_libraries(${LIBRARY_NAME} ${MAYA_OpenMayaRender_LIBRARY} mayaUsd $<$:${UFE_LIBRARY}> + ghc_filesystem ) install(TARGETS ${LIBRARY_NAME}