Giter Site home page Giter Site logo

mob-sakai / gitdependencyresolverforunity Goto Github PK

View Code? Open in Web Editor NEW
240.0 9.0 32.0 168 KB

This plugin resolves git url dependencies in the package for Unity Package Manager. You can use a git url as a package dependency!

License: MIT License

C# 100.00%
unity unity3d package-manager git package dependency

gitdependencyresolverforunity's Introduction

Git Dependency Resolver For Unity

This plugin resolves git-based dependencies in the package for Unity Package Manager.
You can use git repositories url as a package dependencies! ๐Ÿ‘

logo

PRs Welcome

<< Description | Install | Usage | Development Note | Contributing | Change log >>





Description

In Unity 2018.3, the Unity Package Manager (UPM) supported Git. :)

This update allows us to quickly install packages on code hosting services such as GitHub.

However, UPM does not support git-based dependencies in the package. :(

[ package-a/package.json ]
{
  "name": "com.coffee.package-a",
  "version": "0.1.0",
  "dependencies": {
    "com.coffee.core-a" : "https://github.com/mob-sakai/GitPackageTest#core-a-0.1.0"
  }
}

When the above package is installed, the following error occur. console

Git-based dependencies in packages feature is on the roadmap for 2020, but no specific ETA.


This plugin resolves git-based dependencies in the package.
You can use git repositories url as a package dependencies! ๐Ÿ‘

Features

  • Easy to use: just install
  • Resolve git-based dependencies in packages
  • Automatically uninstall unused packages that is installed by this plugin
  • Support GitHub, Bitbucket, GitLab, etc.
  • Support private repository
  • Support Unity 2018.3 or later
  • Support .Net 3.5 and 4.x
  • Update package with a specific tag/branch/hash
  • Deterministic package installation
  • Support CI environment
  • Support path query parameter (sub-directory) even Unity 2019.2 or earlier
    • path must be a relative path to the root of the repository.
    • path query parameter must be placed before the revision anchor. The reverse order will fail.
    • A package manifest (package.json) is expected in the specified path.
    • e.g. With Path query parameter: https://github.com/user/repo.git?path=/example/folder
    • e.g. With revision anchor and path query parameter: https://github.com/user/repo.git?path=/example/folder#v1.2.3

Notes

From: https://forum.unity.com/threads/git-support-on-package-manager.573673/page-3#post-4552084

There is no conflict detection and/or resolution algorithm. The lastest package found with the same name is used. This is not how the package manager resolve dependency (See https://docs.unity3d.com/Manual/upm-conflicts-auto.html).

In Unity's algorithm, package conflicts are resolved by "dependency-level from root".
The all packages resolved by this plugin are "dependency-level=1".
Therefore, in some cases, the package of the intended version may not be installed.

For example, in the case of a project with a dependency graph like this:

project (root)
 โ”œ package A: 1.0.0
 โ”‚  โ”” package X: 2.0.0
 โ”” package B: 1.0.0
    โ”” package C: 2.0.0
       โ”” package X: 2.0.1

This plugin's algorithm

Install -> A: 1.0.0, B: 1.0.0, C: 2.0.0, X: 2.0.1

Unity's algorithm

Install -> A: 1.0.0, B: 1.0.0, C: 2.0.0, X: 2.0.0





Installation

Requirement

  • Unity 2018.3 or later

Using OpenUPM

This package is available on OpenUPM. You can install it via openupm-cli.

openupm add com.coffee.git-dependency-resolver

Using Git

Find the manifest.json file in the Packages directory in your project and edit it as follows:

{
  "dependencies": {
    "com.coffee.git-dependency-resolver": "https://github.com/mob-sakai/GitDependencyResolverForUnity.git",
    ...
  },
}

To update the package, change suffix #{version} to the target version.

  • e.g. "com.coffee.git-dependency-resolver": "https://github.com/mob-sakai/GitDependencyResolverForUnity.git#1.2.0",

Or, use UpmGitExtension to install and update the package.





Usage

For package user

  • Install this plugin.
  • If the dependencies are not resolved successfully, reopen the project. If that does not work, try the following:
    1. Close the project.
    2. Delete Library/ScriptAssemblies directory in the project.
    3. Open the project.
  • When Unity Package Manager Error window is opens, click Continue.
    window
  • Add Packages/.* to .gitignore to hide auto-installed package.

For package developer

  • Find the package.json file in your package and edit it as follows:
{
  ...
  "gitDependencies": {
    "your.package": "https://github.com/yourname/yourpackage.git#v1.2.3",
    ...
  }
}
  • You can use path query parameter (sub-directory) even Unity 2019.2 or earlier.
    • e.g. "your.package": "https://github.com/yourname/yourpackage.git?path=/pkg/dir#v1.2.3"
    • path must be a relative path to the root of the repository.
    • path query parameter must be placed before the revision anchor. The reverse order will fail.
    • A package manifest (package.json) is expected in the specified path.
  • You must use gitDependencies instead of dependencies to define git-based dependencies for the package.
    • This plugin also supports dependencies to resolve git-based dependencies, but if dependencies include packages that UPM can't resolve, it will fail to start Unity in CI environment.
  • You must announce to your package users that they must install com.coffee.git-dependency-resolver.
  • It is recommended to use SemVer as a tag or branch name.
    • e.g. 1.0.0, 0.5.0-preview10, 0.1.0-alpha+daily5





Contributing

Issues

Issues are very valuable to this project.

  • Ideas are a valuable source of contributions others can make
  • Problems show where this project is lacking
  • With a question you show where contributors can improve the user experience

Pull Requests

Pull requests are, a great way to get your ideas into this repository.
See CONTRIBUTING.md.

Support

This is an open source project that I am developing in my spare time.
If you like it, please support me.
With your support, I can spend more time on development. :)






License

Author

mob-sakai

See Also

gitdependencyresolverforunity's People

Contributors

mob-sakai avatar semantic-release-bot avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

gitdependencyresolverforunity's Issues

[2021.3.15] Users need to alt-tab in and out of Unity after dependency packages have been added to get rid off Compile errors

Users need to alt-tab out/in of Unity after dependency packages have been added to get rid off Compile errors.

To Reproduce
Add a package A with dependencies to package B.
Wait for the package A to have been downloaded and B to have been clone.
Notice that the console shows an error of some code in A not finding references to thing in B.
Interact with the rest of Unity and see the error remaining.
Alt-tab out/in of Unity and notice the compiling/refresh bar; and see that the error goes away.

Expected behavior
Unity should auto-refresh without user intervention after the dependency packages have been added.

Environment (please complete the following information):

  • Version 2.0.0
  • Platform: Editor Windows
  • Unity version: 2021.3.15f1 (I suspect this regressed with an earlier version)
  • Build options: [e.g. IL2CPP, .Net 4.x, LWRP]

Additional context

1.0.0 Release Summary

This plugin resolves git url dependencies in the package for Unity Package Manager.

You can use a git url as a package dependency as the following!

{
  "name": "com.coffee.package-a",
  "version": "0.1.0",
  "dependencies": {
    "com.coffee.core-a": "https://github.com/mob-sakai/GitPackageTest.git#core-a-0.1.0"
  }
}

Simply doesn't work

Using all three suggested methods:
SemVer on both depender and dependency, deleting library. restarting unity.

Upon first test received : System.UnauthorizedAccessException: Access to the path is denied

Hey there,
I went to import and test this out, but on my first go of trying to import I received the following message:

Error Message
System.UnauthorizedAccessException: Access to the path is denied.
  at System.IO.Directory.Move (System.String sourceDirName, System.String destDirName) [0x000dd] in <9577ac7a62ef43179789031239ba8798>:0 
  at Coffee.GitDependencyResolver.DirUtils.Move (System.String srcDir, System.String dstDir, System.Func`2[T,TResult] pred) [0x00073] in E:\GitHub\instance-id\LocalPackages\Library\PackageCache\com.coffee.git-dependency-resolver@726d5e4aa9\Editor\DirUtils.cs:24 
  at Coffee.GitDependencyResolver.Resolver.StartResolve () [0x002da] in E:\GitHub\instance-id\LocalPackages\Library\PackageCache\com.coffee.git-dependency-resolver@726d5e4aa9\Editor\GitDependencyResolver.cs:190 
  at Coffee.GitDependencyResolver.Resolver..cctor () [0x00013] in E:\GitHub\instance-id\LocalPackages\Library\PackageCache\com.coffee.git-dependency-resolver@726d5e4aa9\Editor\GitDependencyResolver.cs:35 
UnityEditor.EditorAssemblies:ProcessInitializeOnLoadAttributes(Type[])

This is in Unity 2019.4.14f1 - Fresh project, all default settings. I did try changing it to .Net 4.x to see if it would make a difference, but it did not.

The items added to my manifest.json are as follows,

Project Manifest.json
{
  "dependencies": {
    "com.coffee.git-dependency-resolver": "https://github.com/mob-sakai/GitDependencyResolverForUnity.git",
    "com.gameframe.packages": "file:../Packages/instance.id/UnityPackages",
    "id.instance.aboveaverageinspector": "https://github.com/instance-id/AboveAverageInspector.git#upm", // My package I am trying to test importing with dependencies
	// ...
  }
}

The dependencies for my AboveAverageInspector package that I was testing out are as follows:

Dependencies in package.json
	"gitDependencies": {
		"id.instance.extensions": "https://github.com/instance-id/Extensions.git#v0.1.2"
	},

I believe I have everything set up correctly, but I don't recall reading anything about there being any changes to permissions necessary? Not sure what to make of this.
Thanks,
-MH

GUID refs to a dependency package are broken.

GUID do not resolve properly between a package B depending on a package A and using one its public classes.

To Reproduce
Steps to reproduce the behavior:

  1. In package manager, add this package: https://github.com/ThomasBousquet/PackageB.git
  2. Notice that package A is added to the Custom packages automatically.
  3. See error in Console
  4. browse to Package B editor Script Definition and notice the broken GUID

NOTE:

  1. Restarting the editor does not resolve the issue
  2. if the user adds another package, the error sometimes goes away, and the GUID ref do not appear broken anymore.
  3. adding packageA then package B manually does not produce the error.

Expected behavior
The GUID refs are properly maintained.

Screenshots
ConsoleError
ASMDEF in other project
ASMDEF in Package project
PackageManager

Environment

  • Version 2.0.0
  • Platform: Editor Windows
  • Unity version: 2020.3.9f1

Support to Branch without SemVer

Hello again @mob-sakai , i thinking if its okey to you to add support to Non-SemVer dependence resolver. I already implemented inside my project to manage this.

The logic behind is:

if (Has any previous InstalledPackage with this name && dependence.version == null)
{
//Keep any previous downloaded version
}
else if(InstalledPackage with this name not present)
{
//Download using dependence URL (probably is a head or a branch, like UPM branch)
}

IMPLEMENTATION

PackageMeta.cs

		public static PackageMeta FromNameAndUrl (string name, string url)
		{
. . .
				if (first.Contains ("://"))
				{
					meta.path = first;
					meta.branch = 0 < second.Length ? second : "HEAD";
					SemVersion version;
					if (!SemVersion.TryParse(meta.branch, out version))
						version = null;//empty version
					meta.version = version;
				}
. . .
		}

GitDependencyResolver.cs

		static void UninstallUnusedPackages ()
		{
. . .		
				// Collect unused pakages.
				var unusedPackages = autoInstalledPackages
					.Where (x => Path.GetFileName(x.path).StartsWith (".", Ordinal))         // Directory name starts with '.'. This is 'auto-installed package'
					.Where (x => !allDependencies.Any (y => y.name == x.name && (y.version == null || y.version == x.version)))   // No depended from other packages
					;
. . .
		}
		static void StartResolve ()
		{
. . .
			// Check all dependencies.
			foreach (var dependency in dependencies)
			{
                // Is the depended package installed already?
                bool isInstalled = installedPackages
                        .Concat(requestedPackages)
                        .Any(x => dependency.name == x.name && ((dependency.version != null && dependency.version <= x.version) || (dependency.version == null)));

				// Install the depended package later.
				if (!isInstalled)
				{
					requestedPackages.RemoveAll (x => dependency.name == x.name);
					requestedPackages.Add (dependency);
				}
			}
. . .
		}

Best Regards
Rafael

Use new Events from package manager in Unity 2020

Hello,

The current solution uses the domain reload which generate a lot of check and import of git package. Also it uses the git and file systems.

As of 2020, the package manager provides Events that could be used isntead of the domain reload resulting in a cleaner implementation.

Also the use of the dedicated method from the Client class under the package manager domain would avoid using file system and git protocol.

UnityEditor.PackageManager.Events.registeredPackages
Client.Add(GIT_URL);

Unfortunalty I did not see any option to mark added package as indirect dependencies so the resolution and cleanup should still be manual.

Resolve package conflicts with the same algorithm as Unity

from https://forum.unity.com/threads/git-support-on-package-manager.573673/page-3#post-4552084

There is no conflict detection and/or resolution algorithm. The last package found with the same name is used. This is not how the package manager resolve dependency (See https://docs.unity3d.com/Manual/upm-conflicts-auto.html)

When the Package Manager computes package dependencies, and finds requests for multiple versions of the same package, it automatically selects the package with the fewest dependency levels from the root. In the case of a tie, the Package Manager chooses the highest version among the versions that are tied. It then displays a description of the conflict in the Unity console.

project (root)
  โ”œ package A: 1.0.0
  โ”‚  โ””  package X: 2.0.0
  โ””  package B: 1.0.0
      โ””  package C: 2.0.0
          โ””  package X: 2.0.1

Before
A: 1.0.0, B: 1.0.0, C: 2.0.0, X: 2.0.1

After
A: 1.0.0, B: 1.0.0, C: 2.0.0, X: 2.0.0

guids for git-dependency-resolver conflict with upm-git-extension

Unity 2018.3.02f
upm-git-extension 0.9.1
git-dependency-resolver 1.1.0

GUID [06608ad179f2043e5a26ec668de262d6] for asset 'Packages/com.coffee.git-dependency-resolver/CHANGELOG.md' conflicts with:
'Packages/com.coffee.upm-git-extension/CHANGELOG.md'
We can't assign a new GUID because the asset is in an immutable folder. The asset will be ignored.

Examining CHANGELOG.md.meta (using the github interface) on both the git-depency-resolver and the upm-git-extension repositories shows that they have the same GUID:

guid: 06608ad179f2043e5a26ec668de262d6

Normally Unity would generate a new meta file but because the packages are in the PackageCache, they are immutable.

This error occurs for many files.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.