mirror of https://github.com/ecmwf/eccodes.git
ECC-917: eccodes_memfs (part 2). First working version
This commit is contained in:
parent
eacbe611d0
commit
a8f3f8c991
30
memfs.py
30
memfs.py
|
@ -39,9 +39,13 @@ except:
|
||||||
ascii = lambda x: str(x) # Python 2
|
ascii = lambda x: str(x) # Python 2
|
||||||
|
|
||||||
|
|
||||||
# The last argument is the path of the generated C file
|
# The last argument is the base name of the generated C file(s)
|
||||||
output_file_path = sys.argv[-1]
|
output_file_path = sys.argv[-1]
|
||||||
g = open(output_file_path, "w")
|
CHUNK = 7 * 1000 * 1000 # chunk size in bytes
|
||||||
|
totsize = 0 # amount written
|
||||||
|
fcount = 0
|
||||||
|
opath = output_file_path + "_" + str(fcount).zfill(3) + ".c"
|
||||||
|
g = open(opath, "w")
|
||||||
|
|
||||||
for directory in dirs:
|
for directory in dirs:
|
||||||
|
|
||||||
|
@ -63,6 +67,7 @@ for directory in dirs:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
fsize = os.path.getsize(full)
|
fsize = os.path.getsize(full)
|
||||||
|
totsize += fsize
|
||||||
full = full.replace("\\","/")
|
full = full.replace("\\","/")
|
||||||
fname = full[full.find("/%s/" % (dname,)):]
|
fname = full[full.find("/%s/" % (dname,)):]
|
||||||
#print("MEMFS add", fname)
|
#print("MEMFS add", fname)
|
||||||
|
@ -73,8 +78,7 @@ for directory in dirs:
|
||||||
FILES[name] = fname
|
FILES[name] = fname
|
||||||
SIZES[name] = fsize
|
SIZES[name] = fsize
|
||||||
|
|
||||||
print('static const unsigned char %s[] = {' % (name,), file=g)
|
print('const unsigned char %s[] = {' % (name,), file=g) #NEW
|
||||||
#print('const unsigned char %s[] = {' % (name,), file=g) #NEW
|
|
||||||
|
|
||||||
with open(full, 'rb') as f:
|
with open(full, 'rb') as f:
|
||||||
i = 0
|
i = 0
|
||||||
|
@ -94,6 +98,18 @@ for directory in dirs:
|
||||||
print("", file=g)
|
print("", file=g)
|
||||||
|
|
||||||
print('};', file=g)
|
print('};', file=g)
|
||||||
|
if totsize >= CHUNK:
|
||||||
|
g.close()
|
||||||
|
fcount += 1
|
||||||
|
opath = output_file_path + "_" + str(fcount).zfill(3) + ".c"
|
||||||
|
#print('....Now writing to ',opath)
|
||||||
|
g = open(opath, "w")
|
||||||
|
totsize = 0
|
||||||
|
|
||||||
|
g.close()
|
||||||
|
output_file_path = output_file_path + "_final.c"
|
||||||
|
#print('....Finally writing to ',output_file_path)
|
||||||
|
g = open(output_file_path, "w")
|
||||||
|
|
||||||
print("""
|
print("""
|
||||||
#include "eccodes_config.h"
|
#include "eccodes_config.h"
|
||||||
|
@ -108,9 +124,9 @@ print("""
|
||||||
#include "eccodes_windef.h"
|
#include "eccodes_windef.h"
|
||||||
""", file=g)
|
""", file=g)
|
||||||
|
|
||||||
# NEW
|
# Write extern variables with sizes
|
||||||
#for k, v in SIZES.items():
|
for k, v in SIZES.items():
|
||||||
# print ('extern const unsigned char %s[%d];' % (k, v), file=g)
|
print ('extern const unsigned char %s[%d];' % (k, v), file=g)
|
||||||
|
|
||||||
print("""
|
print("""
|
||||||
struct entry {
|
struct entry {
|
||||||
|
|
|
@ -4,18 +4,25 @@ if( NOT HAVE_PRODUCT_BUFR )
|
||||||
elseif( NOT HAVE_PRODUCT_GRIB )
|
elseif( NOT HAVE_PRODUCT_GRIB )
|
||||||
set( exclude -exclude grib )
|
set( exclude -exclude grib )
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
set( generated_c_files
|
||||||
|
${CMAKE_CURRENT_BINARY_DIR}/memfs_gen_000.c
|
||||||
|
${CMAKE_CURRENT_BINARY_DIR}/memfs_gen_001.c
|
||||||
|
${CMAKE_CURRENT_BINARY_DIR}/memfs_gen_002.c
|
||||||
|
${CMAKE_CURRENT_BINARY_DIR}/memfs_gen_final.c)
|
||||||
|
|
||||||
add_custom_command(
|
add_custom_command(
|
||||||
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/memfs.c
|
OUTPUT ${generated_c_files}
|
||||||
COMMAND ${PYTHON_EXECUTABLE} ${PROJECT_SOURCE_DIR}/memfs.py
|
COMMAND ${PYTHON_EXECUTABLE} ${PROJECT_SOURCE_DIR}/memfs.py
|
||||||
${exclude}
|
${exclude}
|
||||||
${PROJECT_SOURCE_DIR}/definitions
|
${PROJECT_SOURCE_DIR}/definitions
|
||||||
${PROJECT_SOURCE_DIR}/samples
|
${PROJECT_SOURCE_DIR}/samples
|
||||||
${PROJECT_SOURCE_DIR}/ifs_samples
|
${PROJECT_SOURCE_DIR}/ifs_samples
|
||||||
${CMAKE_CURRENT_BINARY_DIR}/memfs.c
|
${CMAKE_CURRENT_BINARY_DIR}/memfs_gen
|
||||||
DEPENDS ${PROJECT_SOURCE_DIR}/memfs.py)
|
DEPENDS ${PROJECT_SOURCE_DIR}/memfs.py)
|
||||||
|
|
||||||
set_source_files_properties(
|
set_source_files_properties(
|
||||||
${CMAKE_CURRENT_BINARY_DIR}/memfs.c PROPERTIES OBJECT_DEPENDS
|
${generated_c_files} PROPERTIES OBJECT_DEPENDS
|
||||||
"${PROJECT_SOURCE_DIR}/memfs.py"
|
"${PROJECT_SOURCE_DIR}/memfs.py"
|
||||||
# "${PROJECT_SOURCE_DIR}/memfs.py" ${definition_files}"
|
# "${PROJECT_SOURCE_DIR}/memfs.py" ${definition_files}"
|
||||||
)
|
)
|
||||||
|
@ -28,6 +35,6 @@ endif()
|
||||||
|
|
||||||
if( HAVE_MEMFS )
|
if( HAVE_MEMFS )
|
||||||
ecbuild_add_library(TARGET eccodes_memfs
|
ecbuild_add_library(TARGET eccodes_memfs
|
||||||
SOURCES ${CMAKE_CURRENT_BINARY_DIR}/memfs.c
|
SOURCES ${generated_c_files}
|
||||||
GENERATED ${CMAKE_CURRENT_BINARY_DIR}/memfs.c)
|
GENERATED ${generated_c_files})
|
||||||
endif()
|
endif()
|
||||||
|
|
Loading…
Reference in New Issue