Skip to content

Commit 0826268

Browse files
committed
Make plugin export more reliable
1 parent 1a8f720 commit 0826268

2 files changed

Lines changed: 28 additions & 5 deletions

File tree

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ endif()
147147

148148
message(STATUS "Packaging resources")
149149
if(BUILD_CUSTOM_PLUGIN)
150-
execute_process(COMMAND ${Python3_EXECUTABLE} package_custom_resources.py ${CUSTOM_PLUGIN_PATH} ${CMAKE_CURRENT_BINARY_DIR}/Resources WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/Resources/Scripts RESULT_VARIABLE PACKAGE_RESOURCES_RESULT)
150+
execute_process(COMMAND ${Python3_EXECUTABLE} package_custom_resources.py ${CUSTOM_PLUGIN_PATH} ${CUSTOM_PLUGIN_NAME} ${CMAKE_CURRENT_BINARY_DIR}/Resources WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/Resources/Scripts RESULT_VARIABLE PACKAGE_RESOURCES_RESULT)
151151
else()
152152
execute_process(COMMAND ${Python3_EXECUTABLE} package_resources.py ${ENABLE_GEM} ${CMAKE_CURRENT_BINARY_DIR}/Resources WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/Resources/Scripts RESULT_VARIABLE PACKAGE_RESOURCES_RESULT)
153153
endif()

Resources/Scripts/package_custom_resources.py

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
}
2222

2323
plugin_path = sys.argv[1];
24-
output_dir = sys.argv[2]
24+
plugin_name = sys.argv[2];
25+
output_dir = sys.argv[3]
2526

2627
# Utility filesystem functions
2728

@@ -83,6 +84,29 @@ def makeArchive(name, root_dir, base_dir):
8384
full_path = os.path.join(root_dir, base_dir)
8485
tar.add(full_path, arcname=base_dir)
8586

87+
def extractWithName(zip_path, output_dir, new_root_name):
88+
with zipfile.ZipFile(zip_path, 'r') as zip_ref:
89+
members = zip_ref.namelist()
90+
top_level = {member.split('/')[0] for member in members if member.strip('/')}
91+
zip_ref.extractall(output_dir)
92+
93+
new_root_path = os.path.join(output_dir, new_root_name)
94+
95+
if os.path.exists(new_root_path):
96+
shutil.rmtree(new_root_path)
97+
98+
if len(top_level) == 1 and os.path.isdir(os.path.join(output_dir, list(top_level)[0])):
99+
# Case 1: Single folder at top level — rename it
100+
original_root = os.path.join(output_dir, list(top_level)[0])
101+
shutil.move(original_root, new_root_path)
102+
else:
103+
# Case 2: Multiple top-level items — create new folder and move them in
104+
os.makedirs(new_root_path, exist_ok=True)
105+
for name in top_level:
106+
src_path = os.path.join(output_dir, name)
107+
dst_path = os.path.join(new_root_path, name)
108+
shutil.move(src_path, dst_path)
109+
86110
def split(a, n):
87111
k, m = divmod(len(a), n)
88112
return (a[i*k+min(i, m):(i+1)*k+min(i+1, m)] for i in range(n))
@@ -249,10 +273,9 @@ def generate_binary_data(output_dir, file_list):
249273
# copyFile("../../Patches/beat.pd", "./Abstractions")
250274

251275
if os.path.isfile(plugin_path):
252-
with zipfile.ZipFile(plugin_path, 'r') as zip_ref:
253-
zip_ref.extractall(os.path.join(output_dir, "plugdata_version"))
276+
extractWithName(plugin_path, os.path.join(output_dir, "plugdata_version"), plugin_name)
254277
elif os.path.isdir(plugin_path):
255-
copyDir(plugin_path, os.path.join(output_dir, "plugdata_version", os.path.basename(plugin_path)))
278+
copyDir(plugin_path, os.path.join(output_dir, "plugdata_version", plugin_name))
256279

257280
makeDir("Extra")
258281
copyDir(project_root + "/Libraries/pd-else/Documentation/Extra-files", "Extra/else")

0 commit comments

Comments
 (0)