Nasal-Interpreter/tools/pack.py

69 lines
2.2 KiB
Python
Raw Normal View History

import tarfile
import pathlib
import os
import platform
import shutil
2024-03-03 23:27:44 +08:00
build_directory = pathlib.Path("build")
if not os.path.exists(build_directory):
print("pack binaries failed: build directory not found")
exit(-1)
nasal_executable = pathlib.Path("nasal")
nasal_standard_library = pathlib.Path("std")
if not os.path.exists(nasal_executable):
print("pack binaries failed: nasal executable not found")
exit(-1)
if not os.path.exists(nasal_standard_library):
print("pack binaries failed: nasal standard library not found")
exit(-1)
2024-03-03 23:27:44 +08:00
nasal_module_directory = pathlib.Path("module")
if not os.path.exists(nasal_module_directory):
print("pack binaries failed: nasal module directory not found")
exit(-1)
dynamic_library_suffix = ""
if platform.system()=="Windows":
dynamic_library_suffix = ".dll"
else:
dynamic_library_suffix = ".so"
nasal_modules = []
for m in ["libfib", "libkey", "libmat", "libnasock"]:
path = pathlib.Path("module").joinpath(m + dynamic_library_suffix)
if not os.path.exists(path):
print("pack binaries failed: nasal module `{}` not found".format(m))
exit(-1)
lib = pathlib.Path("module").joinpath(m + ".nas")
if not os.path.exists(lib):
print("pack binaries failed: nasal module lib `{}.nas` not found".format(m))
exit(-1)
nasal_modules.append(path)
nasal_modules.append(lib)
2024-03-03 23:27:44 +08:00
tar_file_name = "nasal-{}".format(platform.system())
2024-05-12 11:51:28 +08:00
2024-03-03 23:27:44 +08:00
# create package directory in build directory and copy files needed
package_directory = build_directory.joinpath(tar_file_name)
if not os.path.exists(package_directory):
os.mkdir(package_directory)
os.mkdir(package_directory.joinpath("module"))
2024-05-12 11:51:28 +08:00
print("pack nasal executable")
shutil.copy(nasal_executable, package_directory.joinpath(nasal_executable))
2024-05-12 11:51:28 +08:00
print("pack nasal standard library")
shutil.copytree(nasal_standard_library, package_directory.joinpath(nasal_standard_library))
2024-05-12 11:51:28 +08:00
for m in nasal_modules:
print("pack nasal module:", m)
shutil.copy(m, package_directory.joinpath(m))
file = tarfile.open(name=tar_file_name + ".tar", mode="w")
file.add(package_directory)
2024-05-12 11:51:28 +08:00
print("pack succeeded")
file.close()