@@ -176,6 +176,8 @@ project.ext {
176
176
buildDir = new File (scriptDirectory, " build" )
177
177
// Directory for testing.
178
178
testDir = new File (scriptDirectory, " test_output" )
179
+ // Version of the plugin (update this with CHANGELOG.md on each release).
180
+ pluginVersion = " 1.2.144"
179
181
// Directory that contains the template plugin.
180
182
// Files under this directory are copied into the staging area for the
181
183
// plugin.
@@ -184,9 +186,14 @@ project.ext {
184
186
pluginStagingAreaDir = new File (buildDir, " staging" )
185
187
// Directory where the build plugin is unpacked to.
186
188
pluginExplodedDir = new File (scriptDirectory, " exploded" )
189
+ // Base filename of the released plugin.
190
+ currentPluginBasename = " external-dependency-manager"
187
191
// Where the exported plugin file is built before it's copied to the release
188
192
// location.
189
- pluginExportFile = new File (buildDir, " plugin.unitypackage" )
193
+ pluginExportFile = new File (buildDir, currentPluginBasename + " .unitypackage" )
194
+ // Where the exported UPM plugin file is built.
195
+ pluginUpmExportFile = new File (buildDir,
196
+ currentPluginBasename + pluginVersion + " .tgz" )
190
197
// Directory within the plugin staging area that just contains the plugin.
191
198
pluginAssetsDir = new File (" Assets" , " ExternalDependencyManager" )
192
199
// Directories within the staging area to export.
@@ -198,10 +205,6 @@ project.ext {
198
205
pluginSourceDir = new File (scriptDirectory, " source" )
199
206
// Solution which references all projects used by the plugin.
200
207
pluginSolutionFile = new File (pluginSourceDir, " ExternalDependencyManager.sln" )
201
- // Version of the plugin (update this with CHANGELOG.md on each release).
202
- pluginVersion = " 1.2.144"
203
- // Base filename of the released plugin.
204
- currentPluginBasename = " external-dependency-manager"
205
208
// Versioned release plugin file.
206
209
pluginReleaseFile = new File (scriptDirectory,
207
210
sprintf (" %s-%s.unitypackage" ,
@@ -212,6 +215,12 @@ project.ext {
212
215
sprintf (" %s-latest.unitypackage" ,
213
216
currentPluginBasename))
214
217
218
+ // Location of the Unity asset uploader application.
219
+ unityAssetUploaderDir = new File (pluginSourceDir, " UnityAssetUploader" )
220
+
221
+ // Location of the export_unity_package application.
222
+ exportUnityPackageDir = new File (pluginSourceDir, " ExportUnityPackage" )
223
+
215
224
// Common arguments used to execute Unity in batch mode.
216
225
unityBatchModeArguments = [" -batchmode" , " -nographics" ]
217
226
// Extension for Unity asset metadata files.
@@ -221,9 +230,13 @@ project.ext {
221
230
// Changelog file.
222
231
changelog = new File (scriptDirectory, " CHANGELOG.md" )
223
232
pythonBootstrapDir = new File (buildDir, " python_bootstrap" )
233
+ pythonBinDir = new File (new File (pythonBootstrapDir, " python" ), " bin" )
224
234
// Python binary after it has been bootstrapped.
225
- pythonExe = new File (new File (new File (pythonBootstrapDir, " python" ), " bin" ),
226
- " python3" )
235
+ pythonExe = new File (pythonBinDir, " python3" )
236
+ // Pip binary after it has been bootstrapped.
237
+ pipExe = new File (pythonBinDir, " pip3" )
238
+ // Python packages required by export_unity_package.py
239
+ exportUnityPackageRequirements = [" absl-py" , " PyYAML" ]
227
240
}
228
241
229
242
// Configure com.jetbrains.python.envs to bootstrap a Python install.
@@ -405,26 +418,31 @@ List<String> splitFilenameExtension(File fileObj) {
405
418
406
419
/*
407
420
* Construct the name of a versioned asset from the source filename and version
408
- * string. The encoded string takes the form
421
+ * string. If fullVersionPrefix is true, the encoded string takes the form
422
+ * ${filename}_version-${version}.${extension}
423
+ * if fullVersionPrefix is false, the string takes the form
409
424
* ${filename}_v${version}.${extension}
410
425
* where extension is derived from the specified filename.
411
426
*
412
427
* @param fileObj File to add version to.
428
+ * @param fullVersionPrefix if true uses the "_version-" otherwise uses "_v-".
429
+ * @param postfix Optional string to add before the extensioon.
413
430
*
414
431
* @returns File which includes an encoded version.
415
432
*/
416
- File versionedAssetFile (File fileObj ) {
433
+ File versionedAssetFile (File fileObj , Boolean fullVersionPrefix ,
434
+ String postfix ) {
417
435
String basename
418
436
String extension
419
437
(basename, extension) = splitFilenameExtension(fileObj)
420
438
// Encode the DLL version and target names into the DLL in the form...
421
- // ${dllname}_v ${version}.dll
439
+ // ${dllname}_version- ${version}.dll
422
440
String targetName = basename
423
441
String version = project. ext. pluginVersion
424
442
if (! (version == null || version. isEmpty())) {
425
- targetName + = " _v" + version
443
+ targetName + = (fullVersionPrefix ? " _version- " : " _v" ) + version
426
444
}
427
- String filename = targetName + extension
445
+ String filename = targetName + postfix + extension
428
446
return fileObj. parent != null ? new File (fileObj. parent, filename) :
429
447
new File (filename)
430
448
}
@@ -440,10 +458,16 @@ File unversionedAssetFile(File fileObj) {
440
458
String basename
441
459
String extension
442
460
(basename, extension) = splitFilenameExtension(fileObj)
443
- def versionRegEx = / ^(.*)_(v[^v]+)$/
444
- def versionMatch = basename =~ versionRegEx
461
+ def versionRegExFull = / ^(.*)_(version-[^-]+)$/
462
+ def versionRegExShort = / ^(.*)_(v[^v]+)$/
463
+ def versionMatch = basename =~ versionRegExShort
445
464
if (versionMatch. matches()) {
446
465
basename = versionMatch. group(1 )
466
+ } else {
467
+ versionMatch = basename =~ versionRegExFull
468
+ if (versionMatch. matches()) {
469
+ basename = versionMatch. group(1 )
470
+ }
447
471
}
448
472
String filename = basename + extension
449
473
return fileObj. parent != null ?
@@ -725,7 +749,7 @@ Task createBuildPluginDllTask(String componentName,
725
749
return [
726
750
unversionedFile. path,
727
751
versionDll ?
728
- versionedAssetFile(unversionedOutputFile) :
752
+ versionedAssetFile(unversionedOutputFile, false , " " ) :
729
753
unversionedOutputFile]
730
754
}
731
755
@@ -1046,6 +1070,29 @@ Task compileResolverLibTests = createXbuildTask(
1046
1070
doFirst { checkNUnitDllPath() }
1047
1071
}
1048
1072
1073
+ /*
1074
+ * Install Python packages.
1075
+ *
1076
+ * @param taskName Name of the task to create.
1077
+ * @param description Description of the task.
1078
+ * @param dependsOn Dependencies of the new task.
1079
+ * @param packages Packages to install.
1080
+ *
1081
+ * @returns Task which executes pip to install packages
1082
+ */
1083
+ Task createInstallPythonPackageTask (String taskName , String description ,
1084
+ Iterable<Task > dependsOn ,
1085
+ Iterable<String > packages ) {
1086
+ Task installPythonPackageTask = tasks. create(
1087
+ name : taskName,
1088
+ description : sprintf (" Run Pip to %s" , description),
1089
+ type : Exec ,
1090
+ dependsOn : dependsOn + [" build_envs" ]). with {
1091
+ executable project. ext. pipExe
1092
+ args ([" -q" , " install" ] + packages)
1093
+ }
1094
+ }
1095
+
1049
1096
/*
1050
1097
* Create a task to execute Python.
1051
1098
*
@@ -1054,25 +1101,87 @@ Task compileResolverLibTests = createXbuildTask(
1054
1101
* @param dependsOn Dependencies of the new task.
1055
1102
* @param script Python script to run.
1056
1103
* @param arguments Command line arguments to pass to the Python script.
1057
- * @param inputFiles Files that are required by the script.
1058
- * @param outputFiles Files generated by the script.
1104
+ * @param packages Optional Python packages to install.
1059
1105
*
1060
1106
* @returns Task which executes Python.
1061
1107
*/
1062
1108
Task createPythonTask (String taskName , String description ,
1063
1109
Iterable<Task > dependsOn ,
1064
- File script , Iterable<String > arguments ) {
1110
+ File script , Iterable<String > arguments ,
1111
+ Iterable<String > packages ) {
1112
+ List<Task > installPackagesTask = []
1113
+ if (packages) {
1114
+ installPackagesTask = [
1115
+ createInstallPythonPackageTask(
1116
+ taskName + " InstallPipPackages" ,
1117
+ sprintf (" install packages %s for %s" , packages. toString(), taskName),
1118
+ [],
1119
+ packages)
1120
+ ]
1121
+ }
1065
1122
Task pythonTask = tasks. create(
1066
1123
name : taskName,
1067
1124
description : sprintf (" Run Python to %s" , description),
1068
1125
type : Exec ,
1069
- dependsOn : dependsOn + [" build_envs" ]). with {
1126
+ dependsOn : ( dependsOn + installPackagesTask + [" build_envs" ]) ). with {
1070
1127
executable project. ext. pythonExe
1071
1128
args ([script. absolutePath] + arguments)
1072
1129
}
1073
1130
return pythonTask
1074
1131
}
1075
1132
1133
+ /*
1134
+ * Creates a task that packages a Unity plugin with export_unity_package.py.
1135
+ *
1136
+ * @param taskName Name of the task to create.
1137
+ * @param description Description of the task.
1138
+ * @param dependsOn Dependencies of the new task.
1139
+ * @param configFile Configuration file which specifies input files.
1140
+ * @param guidsFile Optional GUIDs database file.
1141
+ * @param assetsDir Input directory for assets referenced by the configFile.
1142
+ * @param generateUnitypackage Whether to create a .unitypackage.
1143
+ * @param generateUpmTarball Whether to create a UPM tarball.
1144
+ * @param pluginsVersion Version to apply to exported plugins.
1145
+ * @param outputDir Directory to write the the exported archives.
1146
+ * @param arguments Additional arguments for export_unity_package.py
1147
+ */
1148
+ Task createExportUnityPackageTask (String taskName ,
1149
+ String description ,
1150
+ Iterable<Task > dependsOn ,
1151
+ File configFile ,
1152
+ File guidsFile ,
1153
+ File assetsDir ,
1154
+ Boolean generateUnityPackage ,
1155
+ Boolean generateUpmTarball ,
1156
+ String pluginVersion ,
1157
+ File outputDir ,
1158
+ Iterable<String > arguments ) {
1159
+ File exportScript = new File (project. ext. exportUnityPackageDir,
1160
+ " export_unity_package.py" )
1161
+ Task exportUnityPackageTask = createPythonTask(
1162
+ taskName,
1163
+ description,
1164
+ dependsOn,
1165
+ exportScript,
1166
+ [" --config_file" , configFile,
1167
+ " --assets_dir" , assetsDir,
1168
+ " --plugins_version" , pluginVersion,
1169
+ " --output_dir" , outputDir] +
1170
+ [generateUnityPackage ?
1171
+ " --output_unitypackage" : " --nooutput_unitypackage" ] +
1172
+ [generateUpmTarball ? " --output_upm" : " --nooutput_upm" ] +
1173
+ (guidsFile ? [" --guids_file" , guidsFile] : []) +
1174
+ arguments,
1175
+ exportUnityPackageRequirements)
1176
+ exportUnityPackageTask. with {
1177
+ inputs. files ([configFile] +
1178
+ (guidsFile ? [guidsFile] : []) +
1179
+ fileTree(assetsDir) +
1180
+ [exportScript])
1181
+ }
1182
+ return exportUnityPackageTask
1183
+ }
1184
+
1076
1185
Task testResolverLibTests = createNUnitTask(
1077
1186
" testResolverLibTests" ,
1078
1187
" Runs the tests for the deprecated Jar Resolver library" ,
@@ -1094,9 +1203,26 @@ createPythonTask(
1094
1203
" testPackageUploader" ,
1095
1204
" Test the unity_asset_uploader.py application." ,
1096
1205
[],
1097
- new File (project. ext. scriptDirectory, " source/UnityAssetUploader/unity_asset_uploader_test.py" ),
1206
+ new File (project. ext. unityAssetUploaderDir, " unity_asset_uploader_test.py" ),
1207
+ [],
1098
1208
[])
1099
1209
1210
+ createPythonTask(
1211
+ " testExportUnityPackage" ,
1212
+ " Test the export_unity_package.py application" ,
1213
+ [],
1214
+ new File (project. ext. exportUnityPackageDir, " export_unity_package_test.py" ),
1215
+ [],
1216
+ exportUnityPackageRequirements)
1217
+
1218
+ createPythonTask(
1219
+ " testGenGuids" ,
1220
+ " Test the gen_guids.py application" ,
1221
+ [],
1222
+ new File (project. ext. exportUnityPackageDir, " gen_guids_test.py" ),
1223
+ [],
1224
+ [" absl-py" ])
1225
+
1100
1226
task updateEmbeddedGradleWrapper (type : Zip ) {
1101
1227
description " Update the gradle wrapper in gradle-template.zip"
1102
1228
from project. ext. scriptDirectory
@@ -1219,9 +1345,9 @@ task generatePluginManifest(dependsOn: [preparePluginStagingAreaDir,
1219
1345
project. ext. pluginEditorDllDir. path),
1220
1346
unversionedManifestName + project. ext. unityMetadataExtension)
1221
1347
File manifestFile = versionedAssetFile(
1222
- new File (outputDir, unversionedManifestName))
1348
+ new File (outputDir, unversionedManifestName), true , " _manifest " )
1223
1349
File manifestMetadataFile = versionedAssetFile(
1224
- new File (outputDir, manifestMetadataTemplateFile. name))
1350
+ new File (outputDir, manifestMetadataTemplateFile. name), true , " _manifest " )
1225
1351
1226
1352
description " Generate a manifest for the files in the plug-in."
1227
1353
inputs. files files(manifestMetadataTemplateFile)
@@ -1246,8 +1372,9 @@ task generatePluginManifest(dependsOn: [preparePluginStagingAreaDir,
1246
1372
}
1247
1373
}
1248
1374
1249
- Task buildPlugin = createUnityTask(
1250
- " buildPlugin" , " build_plugin" , [generatePluginManifest],
1375
+ // Deprecated target for packaging the plugin.
1376
+ Task buildPluginWithUnity = createUnityTask(
1377
+ " buildPluginWithUnity" , " build_plugin" , [generatePluginManifest],
1251
1378
project. ext. pluginStagingAreaDir. name,
1252
1379
project. ext. buildDir,
1253
1380
[" -g.building" ,
@@ -1256,13 +1383,46 @@ Task buildPlugin = createUnityTask(
1256
1383
[project. ext. pluginExportFile. absolutePath,
1257
1384
" -gvh_disable" ,
1258
1385
" -quit" ], true , null )
1259
- buildPlugin. with {
1260
- description " Exports the plugin staging area directory as a Unity package."
1386
+ buildPluginWithUnity. with {
1387
+ description (" (Deprecated) Exports the plugin staging area directory as " +
1388
+ " a Unity package." )
1261
1389
inputs. files files(copyPluginTemplateToStagingArea. outputs. files,
1262
1390
copyPluginComponentsToStagingArea. outputs. files)
1263
1391
outputs. files files(project. ext. pluginExportFile)
1264
1392
}
1265
1393
1394
+ Task buildPlugin = createExportUnityPackageTask(
1395
+ " buildPlugin" ,
1396
+ " Package the .unitypackage with export_unity_package.py." ,
1397
+ [generatePluginManifest],
1398
+ new File (project. ext. scriptDirectory, " export_unity_package_config.json" ),
1399
+ new File (project. ext. scriptDirectory, " export_unity_package_guids.json" ),
1400
+ new File (project. ext. pluginStagingAreaDir, " Assets" ),
1401
+ true , // Enable .unitypackage export.
1402
+ false , // Disable UPM export.
1403
+ project. ext. pluginVersion,
1404
+ project. ext. pluginExportFile. parentFile,
1405
+ [" --enabled_sections" , " unitypackage" ])
1406
+ buildPlugin. with {
1407
+ outputs. files project. ext. pluginExportFile. absolutePath
1408
+ }
1409
+
1410
+ Task buildUpmPlugin = createExportUnityPackageTask(
1411
+ " buildUpmPlugin" ,
1412
+ " Package the .unitypackage with export_unity_package.py." ,
1413
+ [generatePluginManifest],
1414
+ new File (project. ext. scriptDirectory, " export_unity_package_config.json" ),
1415
+ new File (project. ext. scriptDirectory, " export_unity_package_guids.json" ),
1416
+ new File (project. ext. pluginStagingAreaDir, " Assets" ),
1417
+ false , // Disable .unitypackage export.
1418
+ true , // Enable UPM export.
1419
+ project. ext. pluginVersion,
1420
+ project. ext. pluginUpmExportFile. parentFile,
1421
+ [])
1422
+ buildUpmPlugin. with {
1423
+ outputs. files project. ext. pluginUpmExportFile. absolutePath
1424
+ }
1425
+
1266
1426
task releasePlugin (dependsOn : buildPlugin) {
1267
1427
Map<File , File > pluginTemplateFilesMap = files(
1268
1428
copyPluginTemplateToStagingArea. outputs. files,
@@ -1468,7 +1628,8 @@ createUnityTestBatchAndNonBatch(
1468
1628
" VersionHandlerImpl" ),
1469
1629
" test" ),
1470
1630
" webrequest_launcher.py" ),
1471
- runnerArgs)
1631
+ runnerArgs,
1632
+ [])
1472
1633
})
1473
1634
1474
1635
createUnityTestBatchAndNonBatch(
0 commit comments