Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: fix #412 #622 iOS resolver reference when iOS module not installed #714

Draft
wants to merge 8 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Fetch All builds
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
with:
path: built_artifact

Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/build_macos.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
fail-fast: false

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- id: build_setup
uses: ./gha/build_setup
Expand Down Expand Up @@ -89,15 +89,15 @@ jobs:
fi

- name: Upload build results artifact
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
if: ${{ !cancelled() }}
with:
name: ${{ env.assetPackageArtifactName }}
path: build/external-dependency-manager.unitypackage
retention-days: ${{ env.artifactRetentionDays }}

- name: Upload build results artifact
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
if: ${{ !cancelled() }}
with:
name: ${{ env.tarballPackageArtifactName }}
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ jobs:
strategy:
fail-fast: false
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- id: build_setup
uses: ./gha/build_setup
timeout-minutes: 30
Expand Down Expand Up @@ -168,7 +168,7 @@ jobs:
release_license: "true"

- name: Upload build logs
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
if: ${{ !cancelled() }}
with:
name: logs
Expand Down
80 changes: 59 additions & 21 deletions export_unity_package_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,37 +5,71 @@
"imports": [
{
"importer": "PluginImporter",
"platforms": ["Editor"],
"platforms": [
"Editor"
],
"paths": [
"ExternalDependencyManager/Editor/Google.VersionHandler.*"
]
},
{
"importer": "PluginImporter",
"platforms": [],
"labels": ["gvhp_targets-editor"],
"labels": [
"gvhp_targets-editor"
],
"paths": [
"ExternalDependencyManager/Editor/*/Google.IOSResolver.*",
"ExternalDependencyManager/Editor/*/Google.JarResolver.*",
"ExternalDependencyManager/Editor/*/Google.VersionHandlerImpl.*",
"ExternalDependencyManager/Editor/*/Google.PackageManagerResolver.*"
],
"override_metadata_upm": {
"PluginImporter": {
"platformData": [ {
"first" : {
"Editor": "Editor"
"defineConstraints": [
"UNITY_EDITOR",
"UNITY_IOS"
],
"platformData": [
{
"first": {
"Editor": "Editor"
},
"second": {
"enabled": 1
}
}
]
}
}
},
{
"importer": "PluginImporter",
"platforms": [],
"labels": [
"gvhp_targets-editor"
],
"paths": [
"ExternalDependencyManager/Editor/*/Google.IOSResolver.*"
],
"override_metadata_upm": {
"PluginImporter": {
"platformData": [
{
"first": {
"Editor": "Editor"
},
"second": {
"enabled": 1
"enabled": 1
}
}
]
}
}
},
{
"sections": ["documentation"],
"sections": [
"documentation"
],
"importer": "DefaultImporter",
"paths": [
"ExternalDependencyManager/Editor/README.md",
Expand All @@ -50,21 +84,21 @@
]
},
{
"sections": ["unitypackage"],
"sections": [
"unitypackage"
],
"importer": "DefaultImporter",
"paths": [
"PlayServicesResolver/Editor/play-services-resolver_v1.2.137.0.txt"
"PlayServicesResolver/Editor/play-services-resolver_v1.2.137.0.txt"
]
}
],
"manifest_path": "ExternalDependencyManager/Editor",

"readme": "ExternalDependencyManager/Editor/README.md",
"license": "ExternalDependencyManager/Editor/LICENSE",
"changelog": "ExternalDependencyManager/Editor/CHANGELOG.md",
"documentation": "ExternalDependencyManager/Editor/README.md",

"common_manifest" : {
"common_manifest": {
"name": "com.google.external-dependency-manager",
"display_name": "External Dependency Manager for Unity",
"description": [
Expand All @@ -74,23 +108,27 @@
"and/or management of Unity Package Manager registries."
],
"keywords": [
"Google", "Android", "Gradle", "Cocoapods", "Dependency",
"Unity Package Manager", "Unity",
"Google",
"Android",
"Gradle",
"Cocoapods",
"Dependency",
"Unity Package Manager",
"Unity",
"vh-name:play-services-resolver",
"vh-name:unity-jar-resolver"
],
"author": {
"name" : "Google LLC",
"name": "Google LLC",
"url": "https://github.com/googlesamples/unity-jar-resolver"
}
},

"export_upm" : 1,
"upm_package_config" : {
"manifest" : {
"export_upm": 1,
"upm_package_config": {
"manifest": {
"unity": "2019.1"
}
}
}
]
}
}
4 changes: 2 additions & 2 deletions gha/build_setup/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ runs:
using: 'composite'
steps:
# Download GHA tools and requirements from Firebase Unity SDK repo
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
repository: firebase/firebase-unity-sdk
path: external/firebase-unity-sdk
Expand All @@ -51,7 +51,7 @@ runs:
sparse-checkout-cone-mode: false

- name: Setup python
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ inputs.python_version }}

Expand Down
46 changes: 39 additions & 7 deletions source/ExportUnityPackage/export_unity_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -1281,7 +1281,8 @@ def disable_unsupported_platforms(importer_metadata, filename):
return importer_metadata

platform_data = safe_dict_get_value(plugin_importer, "platformData",
default_value={})
default_value={},
value_classes=[dict, list])
disable_platforms = sorted(set(platform_data).difference(
set(supported_platforms)))
# Disable the Any platform if any platforms are disabled.
Expand Down Expand Up @@ -1339,7 +1340,8 @@ def set_cpu_for_desktop_platforms(importer_metadata):

if serialized_version == 1:
platform_data = safe_dict_get_value(plugin_importer, "platformData",
default_value={})
default_value={},
value_classes=[dict, list])
for platform_name, options in platform_data.items():
if not safe_dict_get_value(options, "enabled", default_value=0):
continue
Expand All @@ -1353,7 +1355,8 @@ def set_cpu_for_desktop_platforms(importer_metadata):
options["settings"] = settings
else:
platform_data = safe_dict_get_value(plugin_importer, "platformData",
default_value=[])
default_value=[],
value_classes=[dict, list])
for entry in platform_data:
# Parse the platform name tuple from the "first" dictionary.
first, second = Asset.platform_data_get_entry(entry)
Expand Down Expand Up @@ -1392,7 +1395,8 @@ def set_cpu_for_android(importer_metadata, cpu_string):

if serialized_version == 1:
platform_data = safe_dict_get_value(plugin_importer, "platformData",
default_value={})
default_value={},
value_classes=[dict, list])
for platform_name, options in platform_data.items():
if not safe_dict_get_value(options, "enabled", default_value=0):
continue
Expand All @@ -1404,7 +1408,8 @@ def set_cpu_for_android(importer_metadata, cpu_string):
options["settings"] = settings
else:
platform_data = safe_dict_get_value(plugin_importer, "platformData",
default_value=[])
default_value=[],
value_classes=[dict, list])
for entry in platform_data:
# Parse the platform name tuple from the "first" dictionary.
first, second = Asset.platform_data_get_entry(entry)
Expand Down Expand Up @@ -1440,7 +1445,8 @@ def apply_any_platform_selection(importer_metadata):

if serialized_version == 1:
platform_data = safe_dict_get_value(plugin_importer, "platformData",
default_value={})
default_value={},
value_classes=[dict, list])
# Check PluginImporter.platformData.Any.enabled for the Any platform
# enabled in Unity 4 & early 5 metadata.
any_enabled = platform_data.get("Any", {}).get("enabled", 0)
Expand All @@ -1459,7 +1465,8 @@ def apply_any_platform_selection(importer_metadata):
# Search for the Any platform and retrieve if it's present and
# enabled / disabled if Unity 5.4+ metadata.
platform_data = safe_dict_get_value(plugin_importer, "platformData",
default_value=[])
default_value=[],
value_classes=[dict, list])
any_enabled = 0
for entry in platform_data:
first, second = Asset.platform_data_get_entry(entry)
Expand Down Expand Up @@ -1502,6 +1509,22 @@ def apply_any_platform_selection(importer_metadata):
plugin_importer["platformData"] = new_platform_data
return importer_metadata

@staticmethod
def set_define_constraints(importer_metadata):
"""Set define constraints for the target platform.

Args:
importer_metadata: Metadata to modify. This is modified in-place.

Returns:
Modified importer_metadata.
"""
plugin_importer = safe_dict_get_value(importer_metadata, "PluginImporter", default_value={})
define_constraints = plugin_importer.get("defineConstraints")
if define_constraints:
importer_metadata["PluginImporter"]["defineConstraints"] = define_constraints
return importer_metadata

@property
def importer_metadata_original(self):
"""Get the original metadata section used to import this asset.
Expand Down Expand Up @@ -1548,6 +1571,7 @@ def importer_metadata(self):
metadata = Asset.disable_unsupported_platforms(metadata, self._filename)
metadata = Asset.apply_any_platform_selection(metadata)
metadata = Asset.set_cpu_for_desktop_platforms(metadata)
metadata = Asset.set_define_constraints(metadata)
return metadata

@staticmethod
Expand Down Expand Up @@ -1851,6 +1875,14 @@ def importer_metadata(self):
if "Android" in platforms and cpu_string != "AnyCPU":
importer_metadata = Asset.set_cpu_for_android(
importer_metadata, cpu_string)

# set define constraints
define_constraints = safe_dict_get_value(self._json, "defineConstraints",
default_value=None,
value_classes=[dict, list])
if define_constraints:
importer_metadata["PluginImporter"]["defineConstraints"] = define_constraints

else:
raise ProjectConfigurationError(
"Unknown importer type %s for package %s, paths %s" % (
Expand Down
27 changes: 27 additions & 0 deletions source/ExportUnityPackage/export_unity_package_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2181,6 +2181,33 @@ def test_importer_metadata_standalone_only_x86_64(self):
"platforms": ["Standalone"],
"cpu": "x86_64"}).importer_metadata)

def test_importer_define_constraints(self):
"""Test defineConstraints property."""
define_constraints = ["UNITY_EDITOR", "UNITY_IOS"]
self.plugin_metadata["PluginImporter"]["defineConstraints"] = define_constraints
self.assertEqual(
self.plugin_metadata,
export_unity_package.AssetConfiguration(
self.package, {
"importer": "PluginImporter",
"defineConstraints": define_constraints
}).importer_metadata)

def test_importer_define_constraints_upm(self):
"""Test defineConstraints property for UPM."""
define_constraints = ["UNITY_EDITOR", "UNITY_IOS"]
self.plugin_metadata["PluginImporter"]["defineConstraints"] = define_constraints
self.assertEqual(
self.plugin_metadata,
export_unity_package.AssetConfiguration(
self.package, {
"importer": "PluginImporter",
"override_metadata_upm": {
"PluginImporter": {
"defineConstraints": define_constraints
}
}
}).override_metadata_upm)

class AssetPackageAndProjectFileOperationsTest(absltest.TestCase):
"""Tests for file operation methods."""
Expand Down