[Bf-blender-cvs] [0cdc75ccd28] master: Fluid: Cleanup build system for extern mantaflow

Sebastián Barschkis noreply at git.blender.org
Fri Jul 17 16:27:19 CEST 2020


Commit: 0cdc75ccd28c607677c302014cd40df542d85d35
Author: Sebastián Barschkis
Date:   Fri Jul 17 15:58:13 2020 +0200
Branches: master
https://developer.blender.org/rB0cdc75ccd28c607677c302014cd40df542d85d35

Fluid: Cleanup build system for extern mantaflow

No longer including unused dependencies. Should numpy IO be needed at some point, the Manta source update script can be configured so that the required dependencies are included again.

===================================================================

M	extern/mantaflow/CMakeLists.txt
M	extern/mantaflow/UPDATE.sh
D	extern/mantaflow/dependencies/cnpy/LICENSE
D	extern/mantaflow/dependencies/cnpy/cnpy.cpp
D	extern/mantaflow/dependencies/cnpy/cnpy.h
M	extern/mantaflow/preprocessed/fileio/iogrids.cpp
M	extern/mantaflow/preprocessed/fileio/ioutil.cpp
M	extern/mantaflow/preprocessed/gitinfo.h

===================================================================

diff --git a/extern/mantaflow/CMakeLists.txt b/extern/mantaflow/CMakeLists.txt
index bbf75039782..712aeb238c9 100644
--- a/extern/mantaflow/CMakeLists.txt
+++ b/extern/mantaflow/CMakeLists.txt
@@ -35,15 +35,25 @@ set(MANTAVERSION "0.13")
 
 add_definitions(-DWITH_FLUID=1)
 
-set(MANTA_DEP
-  dependencies
-)
+# Compile Mantaflow dependencies too (e.g. cnpy for numpy file IO).
+# Make sure that dependencies exist before enabling this option by updating the source files in extern/
+set(WITH_MANTA_DEPENDENCIES 0)
+
+if(NOT WITH_MANTA_DEPENDENCIES)
+  add_definitions(-DNO_CNPY=1)
+endif()
+
 set(MANTA_HLP
   helper
 )
 set(MANTA_PP
   preprocessed
 )
+if(WITH_MANTA_DEPENDENCIES)
+  set(MANTA_DEP
+    dependencies
+  )
+endif()
 
 if(WITH_TBB)
   add_definitions(-DTBB=1)
@@ -96,9 +106,6 @@ if(WITH_OPENVDB)
 endif()
 
 set(SRC
-  ${MANTA_DEP}/cnpy/cnpy.cpp
-  ${MANTA_DEP}/cnpy/cnpy.h
-
   ${MANTA_PP}/commonkernels.h
   ${MANTA_PP}/commonkernels.h.reg.cpp
   ${MANTA_PP}/conjugategrad.cpp
@@ -221,6 +228,13 @@ set(SRC
   ${MANTA_HLP}/util/vectorbase.h
 )
 
+if(WITH_MANTA_DEPENDENCIES)
+  list(APPEND SRC
+    ${MANTA_DEP}/cnpy/cnpy.cpp
+    ${MANTA_DEP}/cnpy/cnpy.h
+  )
+endif()
+
 set(LIB
   ${PYTHON_LINKFLAGS}
   ${PYTHON_LIBRARIES}
diff --git a/extern/mantaflow/UPDATE.sh b/extern/mantaflow/UPDATE.sh
index 3feb1ba9226..62395fde7cd 100644
--- a/extern/mantaflow/UPDATE.sh
+++ b/extern/mantaflow/UPDATE.sh
@@ -13,6 +13,9 @@ BLENDER_INSTALLATION=/Users/sebbas/Developer/Blender/fluid-mantaflow
 # Try to check out Mantaflow repository before building?
 CLEAN_REPOSITORY=0
 
+# Skip copying dependency files?
+WITH_DEPENDENCIES=0
+
 # Choose which multithreading platform to use for Mantaflow preprocessing
 USE_OMP=0
 USE_TBB=1
@@ -50,17 +53,21 @@ fi
 MANTA_BUILD_PATH=$MANTA_INSTALLATION/build_blender/
 mkdir -p $MANTA_BUILD_PATH
 cd $MANTA_BUILD_PATH
-cmake ../mantaflowgit -DGUI=OFF -DOPENMP=$USE_OMP -DTBB=$USE_TBB -DBLENDER=ON -DPREPDEBUG=ON && make -j8
+cmake ../mantaflowgit -DGUI=0 -DOPENMP=$USE_OMP -DTBB=$USE_TBB -DBLENDER=1 -DPREPDEBUG=1 && make -j8
 
 # ==================== 3) COPY MANTAFLOW FILES TO BLENDER ROOT ===========================
 
-mkdir -p $BLENDER_INSTALLATION/blender/tmp/dependencies/ && cp -Rf $MANTA_INSTALLATION/mantaflowgit/dependencies/cnpy "$_"
+if [[ "$WITH_DEPENDENCIES" -eq "1" ]]; then
+  mkdir -p $BLENDER_INSTALLATION/blender/tmp/dependencies/ && cp -Rf $MANTA_INSTALLATION/mantaflowgit/dependencies/cnpy "$_"
+fi
 mkdir -p $BLENDER_INSTALLATION/blender/tmp/helper/ && cp -Rf $MANTA_INSTALLATION/mantaflowgit/source/util "$_"
 mkdir -p $BLENDER_INSTALLATION/blender/tmp/helper/ && cp -Rf $MANTA_INSTALLATION/mantaflowgit/source/pwrapper "$_"
 mkdir -p $BLENDER_INSTALLATION/blender/tmp/preprocessed/ && cp -Rf $MANTA_INSTALLATION/build_blender/pp/source/. "$_"
 
 # Remove some files that are not need in Blender
-rm $BLENDER_INSTALLATION/blender/tmp/dependencies/cnpy/example1.cpp
+if [[ "$WITH_DEPENDENCIES" -eq "1" ]]; then
+  rm $BLENDER_INSTALLATION/blender/tmp/dependencies/cnpy/example1.cpp
+fi
 rm $BLENDER_INSTALLATION/blender/tmp/helper/pwrapper/pymain.cpp
 rm $BLENDER_INSTALLATION/blender/tmp/preprocessed/*.reg
 rm $BLENDER_INSTALLATION/blender/tmp/preprocessed/python/*.reg
@@ -82,8 +89,13 @@ BLENDER_TMP_DEP=$BLENDER_TMP/dependencies
 BLENDER_TMP_HLP=$BLENDER_TMP/helper
 BLENDER_TMP_PP=$BLENDER_TMP/preprocessed
 
+# Before moving new files, delete all existing file in the Blender repository
+rm -Rf $BLENDER_MANTA_EXTERN/dependencies $BLENDER_MANTA_EXTERN/helper $BLENDER_MANTA_EXTERN/preprocessed
+
 # Move files from tmp dir to extern/
-cp -Rf $BLENDER_TMP_DEP $BLENDER_MANTA_EXTERN
+if [[ "$WITH_DEPENDENCIES" -eq "1" ]]; then
+  cp -Rf $BLENDER_TMP_DEP $BLENDER_MANTA_EXTERN
+fi
 cp -Rf $BLENDER_TMP_HLP $BLENDER_MANTA_EXTERN
 cp -Rf $BLENDER_TMP_PP $BLENDER_MANTA_EXTERN
 
diff --git a/extern/mantaflow/dependencies/cnpy/LICENSE b/extern/mantaflow/dependencies/cnpy/LICENSE
deleted file mode 100644
index e60eadbccb3..00000000000
--- a/extern/mantaflow/dependencies/cnpy/LICENSE
+++ /dev/null
@@ -1,21 +0,0 @@
-The MIT License
-
-Copyright (c) Carl Rogers, 2011
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
diff --git a/extern/mantaflow/dependencies/cnpy/cnpy.cpp b/extern/mantaflow/dependencies/cnpy/cnpy.cpp
deleted file mode 100644
index 7f0ce21ece8..00000000000
--- a/extern/mantaflow/dependencies/cnpy/cnpy.cpp
+++ /dev/null
@@ -1,385 +0,0 @@
-// Copyright (C) 2011  Carl Rogers
-// Released under MIT License
-// license available in LICENSE file, or at http://www.opensource.org/licenses/mit-license.php
-
-#include "cnpy.h"
-#include <complex>
-#include <cstdlib>
-#include <algorithm>
-#include <cstring>
-#include <iomanip>
-#include <stdint.h>
-#include <stdexcept>
-#include <regex>
-
-char cnpy::BigEndianTest()
-{
-  int x = 1;
-  return (((char *)&x)[0]) ? '<' : '>';
-}
-
-char cnpy::map_type(const std::type_info &t)
-{
-  if (t == typeid(float))
-    return 'f';
-  if (t == typeid(double))
-    return 'f';
-  if (t == typeid(long double))
-    return 'f';
-
-  if (t == typeid(int))
-    return 'i';
-  if (t == typeid(char))
-    return 'i';
-  if (t == typeid(short))
-    return 'i';
-  if (t == typeid(long))
-    return 'i';
-  if (t == typeid(long long))
-    return 'i';
-
-  if (t == typeid(unsigned char))
-    return 'u';
-  if (t == typeid(unsigned short))
-    return 'u';
-  if (t == typeid(unsigned long))
-    return 'u';
-  if (t == typeid(unsigned long long))
-    return 'u';
-  if (t == typeid(unsigned int))
-    return 'u';
-
-  if (t == typeid(bool))
-    return 'b';
-
-  if (t == typeid(std::complex<float>))
-    return 'c';
-  if (t == typeid(std::complex<double>))
-    return 'c';
-  if (t == typeid(std::complex<long double>))
-    return 'c';
-
-  else
-    return '?';
-}
-
-template<> std::vector<char> &cnpy::operator+=(std::vector<char> &lhs, const std::string rhs)
-{
-  lhs.insert(lhs.end(), rhs.begin(), rhs.end());
-  return lhs;
-}
-
-template<> std::vector<char> &cnpy::operator+=(std::vector<char> &lhs, const char *rhs)
-{
-  // write in little endian
-  size_t len = strlen(rhs);
-  lhs.reserve(len);
-  for (size_t byte = 0; byte < len; byte++) {
-    lhs.push_back(rhs[byte]);
-  }
-  return lhs;
-}
-
-void cnpy::parse_npy_header(unsigned char *buffer,
-                            size_t &word_size,
-                            std::vector<size_t> &shape,
-                            bool &fortran_order)
-{
-  // std::string magic_string(buffer,6);
-  uint8_t major_version = *reinterpret_cast<uint8_t *>(buffer + 6);
-  uint8_t minor_version = *reinterpret_cast<uint8_t *>(buffer + 7);
-  uint16_t header_len = *reinterpret_cast<uint16_t *>(buffer + 8);
-  std::string header(reinterpret_cast<char *>(buffer + 9), header_len);
-
-  size_t loc1, loc2;
-
-  // fortran order
-  loc1 = header.find("fortran_order") + 16;
-  fortran_order = (header.substr(loc1, 4) == "True" ? true : false);
-
-  // shape
-  loc1 = header.find("(");
-  loc2 = header.find(")");
-
-  std::regex num_regex("[0-9][0-9]*");
-  std::smatch sm;
-  shape.clear();
-
-  std::string str_shape = header.substr(loc1 + 1, loc2 - loc1 - 1);
-  while (std::regex_search(str_shape, sm, num_regex)) {
-    shape.push_back(std::stoi(sm[0].str()));
-    str_shape = sm.suffix().str();
-  }
-
-  // endian, word size, data type
-  // byte order code | stands for not applicable.
-  // not sure when this applies except for byte array
-  loc1 = header.find("descr") + 9;
-  bool littleEndian = (header[loc1] == '<' || header[loc1] == '|' ? true : false);
-  assert(littleEndian);
-
-  // char type = header[loc1+1];
-  // assert(type == map_type(T));
-
-  std::string str_ws = header.substr(loc1 + 2);
-  loc2 = str_ws.find("'");
-  word_size = atoi(str_ws.substr(0, loc2).c_str());
-}
-
-void cnpy::parse_npy_header(FILE *fp,
-                            size_t &word_size,
-                            std::vector<size_t> &shape,
-                            bool &fortran_order)
-{
-  char buffer[256];
-  size_t res = fread(buffer, sizeof(char), 11, fp);
-  if (res != 11)
-    throw std::runtime_error("parse_npy_header: failed fread");
-  std::string header = fgets(buffer, 256, fp);
-  assert(header[header.size() - 1] == '\n');
-
-  size_t loc1, loc2;
-
-  // fortran order
-  loc1 = header.find("fortran_order");
-  if (loc1 == std::string::npos)
-    throw std::runtime_error("parse_npy_header: failed to find header keyword: 'fortran_order'");
-  loc1 += 16;
-  fortran_order = (header.substr(loc1, 4) == "True" ? true : false);
-
-  // shape
-  loc1 = header.find("(");
-  loc2 = header.find(")");
-  if (loc1 == std::string::npos || loc2 == std::string::npos)
-    throw std::runtime_error("parse_npy_header: failed to find header keyword: '(' or ')'");
-
-  std::regex num_regex("[0-9][0-9]*");
-  std::smatch sm;
-  shape.clear();
-
-  std::string str_shape = header.substr(loc1 + 1, loc2 - loc1 - 1);
-  while (std::regex_search(str_shape, sm, num_regex)) {
-    shape.push_back(std::stoi(sm[0].str()));
-    str_shape = sm.suffix().str();
-  }
-
-  // endian, word size, data type
-  // byte order code | stands for not applicable.
-  // not sure when this applies except for byte array
-  loc1 = header.find("descr");


@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list