Skip to content

Commit

Permalink
Merge pull request #1182 from Autodesk/sabrih/MAYA-109891/ghc_file_sy…
Browse files Browse the repository at this point in the history
…stemf

MAYA-109891: Remove dependency on boost filesystem/system.
  • Loading branch information
Krystian Ligenza authored Feb 22, 2021
2 parents 49ec9d0 + 119b3bf commit aed181f
Show file tree
Hide file tree
Showing 15 changed files with 94 additions and 69 deletions.
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,11 @@ endif()
#------------------------------------------------------------------------------
include(cmake/compiler_config.cmake)

#------------------------------------------------------------------------------
# gulark filesystem
#------------------------------------------------------------------------------
include(cmake/gulark.cmake)

#------------------------------------------------------------------------------
# test
#------------------------------------------------------------------------------
Expand Down
29 changes: 29 additions & 0 deletions cmake/gulark.cmake
Original file line number Diff line number Diff line change
@@ -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)
4 changes: 2 additions & 2 deletions doc/build.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
7 changes: 5 additions & 2 deletions doc/codingGuidelines.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 1 addition & 3 deletions lib/mayaUsd/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -119,8 +118,7 @@ target_link_libraries(${PROJECT_NAME}
${MAYA_LIBRARIES}
mayaUsdUtils
PRIVATE
Boost::filesystem
Boost::system
ghc_filesystem
)

# -----------------------------------------------------------------------------
Expand Down
4 changes: 2 additions & 2 deletions lib/mayaUsd/nodes/proxyShapeBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
#include <maya/MTime.h>
#include <maya/MViewport2Renderer.h>

#include <boost/filesystem.hpp>
#include <ghc/filesystem.hpp>

#include <map>
#include <string>
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions lib/mayaUsd/render/vp2RenderDelegate/material.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
#include <maya/MUintArray.h>
#include <maya/MViewport2Renderer.h>

#include <boost/filesystem.hpp>
#include <ghc/filesystem.hpp>

#include <iostream>
#include <string>
Expand Down Expand Up @@ -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";
Expand Down
39 changes: 32 additions & 7 deletions lib/mayaUsd/utils/utilFileSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,30 @@
#include <maya/MGlobal.h>
#include <maya/MItDependencyNodes.h>

#include <boost/filesystem.hpp>
#include <ghc/filesystem.hpp>

#include <random>
#include <system_error>

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

Expand All @@ -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)
Expand Down Expand Up @@ -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();
Expand All @@ -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();
}
11 changes: 1 addition & 10 deletions lib/usd/translators/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
# -----------------------------------------------------------------------------
Expand Down Expand Up @@ -90,8 +82,7 @@ target_link_libraries(${TARGET_NAME}
mayaUsd
mayaUsd_Schemas
basePxrUsdPreviewSurface
Boost::filesystem
Boost::system
ghc_filesystem
)

# -----------------------------------------------------------------------------
Expand Down
10 changes: 5 additions & 5 deletions lib/usd/translators/shading/usdFileTextureWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,10 @@
#include <maya/MStatus.h>
#include <maya/MString.h>

#include <boost/filesystem.hpp>
#include <ghc/filesystem.hpp>

#include <regex>
#include <system_error>

PXR_NAMESPACE_OPEN_SCOPE

Expand Down Expand Up @@ -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();
}
Expand Down
11 changes: 1 addition & 10 deletions plugin/al/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand All @@ -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
Expand Down
11 changes: 4 additions & 7 deletions plugin/al/lib/AL_USDMaya/AL/usdmaya/nodes/LayerManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@
#include <maya/MItDependencyNodes.h>
#include <maya/MPlugArray.h>

#include <boost/thread.hpp>
#include <boost/thread/shared_lock_guard.hpp>

#include <mutex>

namespace {
Expand Down Expand Up @@ -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<boost::shared_mutex> lock(m_layersMutex);
std::unique_lock<std::shared_timed_mutex> lock(m_layersMutex);
return m_layerDatabase.addLayer(layerRef, identifier);
}

Expand All @@ -366,14 +363,14 @@ bool LayerManager::removeLayer(SdfLayerHandle layer)
MGlobal::displayError("LayerManager::removeLayer - given layer is no longer valid");
return false;
}
boost::unique_lock<boost::shared_mutex> lock(m_layersMutex);
std::unique_lock<std::shared_timed_mutex> lock(m_layersMutex);
return m_layerDatabase.removeLayer(layerRef);
}

//----------------------------------------------------------------------------------------------------------------------
SdfLayerHandle LayerManager::findLayer(std::string identifier)
{
boost::shared_lock_guard<boost::shared_mutex> lock(m_layersMutex);
std::shared_lock<std::shared_timed_mutex> lock(m_layersMutex);
return m_layerDatabase.findLayer(identifier);
}

Expand Down Expand Up @@ -404,7 +401,7 @@ MStatus LayerManager::populateSerialisationAttributes()
MArrayDataHandle layersArrayHandle = dataBlock.outputArrayValue(m_layers, &status);
AL_MAYA_CHECK_ERROR(status, errorString);
{
boost::shared_lock_guard<boost::shared_mutex> lock(m_layersMutex);
std::shared_lock<std::shared_timed_mutex> lock(m_layersMutex);
MArrayDataBuilder builder(&dataBlock, layers(), m_layerDatabase.max_size(), &status);
AL_MAYA_CHECK_ERROR(status, errorString);
std::string temp;
Expand Down
16 changes: 2 additions & 14 deletions plugin/al/lib/AL_USDMaya/AL/usdmaya/nodes/LayerManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,7 @@

#include <map>
#include <set>

// 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 <boost/thread.hpp>
#ifdef _MSC_VER
#pragma warning(pop)
#endif
#include <shared_mutex>

PXR_NAMESPACE_USING_DIRECTIVE

Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions plugin/al/lib/AL_USDMaya/AL/usdmaya/nodes/ProxyShape.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
#include <maya/MTime.h>
#include <maya/MViewport2Renderer.h>

#include <boost/filesystem.hpp>
#include <ghc/filesystem.hpp>

#if defined(WANT_UFE_BUILD)
#include "ufe/path.h"
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 1 addition & 3 deletions plugin/al/lib/AL_USDMaya/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -209,18 +209,16 @@ target_link_libraries(${LIBRARY_NAME}
usdImagingGL
vt
${Boost_PYTHON_LIBRARY}
$<IF:$<VERSION_GREATER_EQUAL:${Boost_VERSION},${boost_1_70_0_ver_string}>,Boost::thread,${Boost_THREAD_LIBRARY}>
$<$<BOOL:${IS_WINDOWS}>:Boost::chrono>
$<$<BOOL:${IS_WINDOWS}>:Boost::date_time>
$<$<BOOL:${NEED_BOOST_FILESYSTEM}>:Boost::filesystem>
$<$<BOOL:${NEED_BOOST_FILESYSTEM}>:Boost::system>
${MAYA_Foundation_LIBRARY}
${MAYA_OpenMayaAnim_LIBRARY}
${MAYA_OpenMayaUI_LIBRARY}
${MAYA_OpenMaya_LIBRARY}
${MAYA_OpenMayaRender_LIBRARY}
mayaUsd
$<$<BOOL:${UFE_FOUND}>:${UFE_LIBRARY}>
ghc_filesystem
)

install(TARGETS ${LIBRARY_NAME}
Expand Down

0 comments on commit aed181f

Please sign in to comment.