summaryrefslogtreecommitdiffstats
path: root/bitbake
diff options
context:
space:
mode:
authorMark Asselstine <mark.asselstine@windriver.com>2023-02-24 15:43:44 -0500
committerRichard Purdie <richard.purdie@linuxfoundation.org>2023-02-26 11:49:41 +0000
commit67d5541f65f4d2538b2d92a388af65d3f2fb14ee (patch)
treedbeba1ce0afe34a05d2713dfd014fcd0b75846e3 /bitbake
parentc1f1422a95e1939e00d8cda9523b1a99d051cd14 (diff)
downloadpoky-67d5541f65f4d2538b2d92a388af65d3f2fb14ee.tar.gz
bitbake: fetch/npmsw: add more short forms for git operations
>From the npm-install documentation [1] the CLI provides a set of short forms when the install fetches from git. These include "github:" example: npm install github:mygithubuser/myproject "gist:" example: npm install gist:101a11beef "gitlab:" example: npm install gitlab:mygitlabuser/myproject "bitbucket:" example: npm install bitbucket:mybitbucketuser/myproject Commit 1d8af6aed0a9 [fetch2: npmsw: Add support for github prefix in npm shrinkwrap version] by Stefan Herbrechtsmeier added support for the "github:" but the others would marked as 'Unsupported dependency'. The other prefixes are added in this commit, along with extending the tests to cover some of these. However, there is one more short form for github which npm-install allows which forgoes the prefix altogether. example: npm install mygithubuser/myproject Unfortunately this format is a bit problematic as it lacks any easily identifiable 'marker' to match against, and it could be either the github short form or install from folder format. Experimentation shows that the folder format requires a leading './' or '/', so we use this to rule out the ambiguity. If this approach to folder and github formats disambiguation is incorrect it won't matter anyways as the folder format is unrecognized by the code as-is and thus with this change or without, things would fail. Since we have to be less strict in the check for git operations we move it to be the last install format which we check, such that the less ambiguous formats can be sorted out first. [1] https://docs.npmjs.com/cli/v9/commands/npm-install [Yocto #14236] (Bitbake rev: 0ac6f6cb5d807919ed13a8b7bb3fb551b79c5a71) Signed-off-by: Mark Asselstine <mark.asselstine@windriver.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake')
-rw-r--r--bitbake/lib/bb/fetch2/npmsw.py26
-rw-r--r--bitbake/lib/bb/tests/fetch.py39
2 files changed, 58 insertions, 7 deletions
diff --git a/bitbake/lib/bb/fetch2/npmsw.py b/bitbake/lib/bb/fetch2/npmsw.py
index a8c4d3528f..36fcbfba15 100644
--- a/bitbake/lib/bb/fetch2/npmsw.py
+++ b/bitbake/lib/bb/fetch2/npmsw.py
@@ -129,10 +129,28 @@ class NpmShrinkWrap(FetchMethod):
129 129
130 localpath = os.path.join(d.getVar("DL_DIR"), localfile) 130 localpath = os.path.join(d.getVar("DL_DIR"), localfile)
131 131
132 # Handle local tarball and link sources
133 elif version.startswith("file"):
134 localpath = version[5:]
135 if not version.endswith(".tgz"):
136 unpack = False
137
132 # Handle git sources 138 # Handle git sources
133 elif version.startswith("git"): 139 elif version.startswith(("git", "bitbucket","gist")) or (
140 not version.endswith((".tgz", ".tar", ".tar.gz"))
141 and not version.startswith((".", "@", "/"))
142 and "/" in version
143 ):
134 if version.startswith("github:"): 144 if version.startswith("github:"):
135 version = "git+https://github.com/" + version[len("github:"):] 145 version = "git+https://github.com/" + version[len("github:"):]
146 elif version.startswith("gist:"):
147 version = "git+https://gist.github.com/" + version[len("gist:"):]
148 elif version.startswith("bitbucket:"):
149 version = "git+https://bitbucket.org/" + version[len("bitbucket:"):]
150 elif version.startswith("gitlab:"):
151 version = "git+https://gitlab.com/" + version[len("gitlab:"):]
152 elif not version.startswith(("git+","git:")):
153 version = "git+https://github.com/" + version
136 regex = re.compile(r""" 154 regex = re.compile(r"""
137 ^ 155 ^
138 git\+ 156 git\+
@@ -158,12 +176,6 @@ class NpmShrinkWrap(FetchMethod):
158 176
159 url = str(uri) 177 url = str(uri)
160 178
161 # Handle local tarball and link sources
162 elif version.startswith("file"):
163 localpath = version[5:]
164 if not version.endswith(".tgz"):
165 unpack = False
166
167 else: 179 else:
168 raise ParameterError("Unsupported dependency: %s" % name, ud.url) 180 raise ParameterError("Unsupported dependency: %s" % name, ud.url)
169 181
diff --git a/bitbake/lib/bb/tests/fetch.py b/bitbake/lib/bb/tests/fetch.py
index 54148b3fdf..73eefc5938 100644
--- a/bitbake/lib/bb/tests/fetch.py
+++ b/bitbake/lib/bb/tests/fetch.py
@@ -2666,6 +2666,45 @@ class NPMTest(FetcherTest):
2666 2666
2667 @skipIfNoNpm() 2667 @skipIfNoNpm()
2668 @skipIfNoNetwork() 2668 @skipIfNoNetwork()
2669 def test_npmsw_git(self):
2670 swfile = self.create_shrinkwrap_file({
2671 'dependencies': {
2672 'cookie': {
2673 'version': 'github:jshttp/cookie.git#aec1177c7da67e3b3273df96cf476824dbc9ae09',
2674 'from': 'github:jshttp/cookie.git'
2675 }
2676 }
2677 })
2678 fetcher = bb.fetch.Fetch(['npmsw://' + swfile], self.d)
2679 fetcher.download()
2680 self.assertTrue(os.path.exists(os.path.join(self.dldir, 'git2', 'github.com.jshttp.cookie.git')))
2681
2682 swfile = self.create_shrinkwrap_file({
2683 'dependencies': {
2684 'cookie': {
2685 'version': 'jshttp/cookie.git#aec1177c7da67e3b3273df96cf476824dbc9ae09',
2686 'from': 'jshttp/cookie.git'
2687 }
2688 }
2689 })
2690 fetcher = bb.fetch.Fetch(['npmsw://' + swfile], self.d)
2691 fetcher.download()
2692 self.assertTrue(os.path.exists(os.path.join(self.dldir, 'git2', 'github.com.jshttp.cookie.git')))
2693
2694 swfile = self.create_shrinkwrap_file({
2695 'dependencies': {
2696 'nodejs': {
2697 'version': 'gitlab:gitlab-examples/nodejs.git#892a1f16725e56cc3a2cb0d677be42935c8fc262',
2698 'from': 'gitlab:gitlab-examples/nodejs'
2699 }
2700 }
2701 })
2702 fetcher = bb.fetch.Fetch(['npmsw://' + swfile], self.d)
2703 fetcher.download()
2704 self.assertTrue(os.path.exists(os.path.join(self.dldir, 'git2', 'gitlab.com.gitlab-examples.nodejs.git')))
2705
2706 @skipIfNoNpm()
2707 @skipIfNoNetwork()
2669 def test_npmsw_dev(self): 2708 def test_npmsw_dev(self):
2670 swfile = self.create_shrinkwrap_file({ 2709 swfile = self.create_shrinkwrap_file({
2671 'dependencies': { 2710 'dependencies': {