@@ -122,6 +122,248 @@ def test_workspace(west_update_tmpdir):
122122 assert wct .join ('zephyr' , 'subsys' , 'bluetooth' , 'code.c' ).check (file = 1 )
123123
124124
125+ def test_workspace_stacked_imports (repos_tmpdir ):
126+ remote_zephyr = repos_tmpdir / 'repos' / 'zephyr'
127+ projects_dir = repos_tmpdir / 'projects'
128+ projects_dir .mkdir ()
129+
130+ # create a local base project with a west.yml
131+ project_base = projects_dir / 'base'
132+ project_base .mkdir ()
133+ with open (project_base / 'west.yml' , 'w' ) as f :
134+ f .write (
135+ textwrap .dedent (f'''\
136+ manifest:
137+ remotes:
138+ - name: upstream
139+ url-base: { os .path .dirname (remote_zephyr )}
140+ projects:
141+ - name: zephyr
142+ remote: upstream
143+ path: zephyr-rtos
144+ import: True
145+ ''' )
146+ )
147+
148+ # create another project with another west.yml (stacked on base)
149+ project_middle = projects_dir / 'middle'
150+ project_middle .mkdir ()
151+ with open (project_middle / 'west.yml' , 'w' ) as f :
152+ f .write (
153+ textwrap .dedent ('''\
154+ manifest:
155+ self:
156+ import: ../base
157+ ''' )
158+ )
159+
160+ # create another project with another west.yml (stacked on base)
161+ project_app = projects_dir / 'app'
162+ project_app .mkdir ()
163+ with open (project_app / 'west.yml' , 'w' ) as f :
164+ f .write (
165+ textwrap .dedent ('''\
166+ manifest:
167+ self:
168+ import: ../middle
169+ ''' )
170+ )
171+
172+ # init workspace in projects_dir (project_app's parent)
173+ cmd (['init' , '-l' , project_app ])
174+
175+ # update workspace in projects_dir
176+ cmd ('update' , cwd = projects_dir )
177+
178+ ws = projects_dir
179+ # zephyr projects from base are cloned
180+ for project_subdir in [
181+ Path ('subdir' ) / 'Kconfiglib' ,
182+ 'tagged_repo' ,
183+ 'net-tools' ,
184+ 'zephyr-rtos' ,
185+ ]:
186+ assert (ws / project_subdir ).check (dir = 1 )
187+ assert (ws / project_subdir / '.git' ).check (dir = 1 )
188+
189+
190+ def test_workspace_modify_url_replace (tmpdir , repos_tmpdir ):
191+ remotes_dir = repos_tmpdir / 'repos'
192+ workspace_dir = tmpdir / 'workspace'
193+ workspace_dir .mkdir ()
194+
195+ # use remote zephyr
196+ remote_zephyr = tmpdir / 'repos' / 'zephyr'
197+
198+ # create a local base project with a west.yml
199+ project_base = remotes_dir / 'base'
200+ create_repo (project_base )
201+ add_commit (
202+ project_base ,
203+ 'manifest commit' ,
204+ # zephyr revision is implicitly master:
205+ files = {
206+ 'west.yml' : textwrap .dedent ('''
207+ manifest:
208+ import-modifications:
209+ url-replace:
210+ - old: xxx
211+ new: yyy
212+ remotes:
213+ - name: upstream
214+ url-base: xxx
215+ projects:
216+ - name: zephyr
217+ remote: upstream
218+ path: zephyr-rtos
219+ import: True
220+ ''' )
221+ },
222+ )
223+
224+ # create another project with another west.yml (stacked on base)
225+ project_middle = remotes_dir / 'middle'
226+ create_repo (project_middle )
227+ add_commit (
228+ project_middle ,
229+ 'manifest commit' ,
230+ # zephyr revision is implicitly master:
231+ files = {
232+ 'west.yml' : f'''
233+ manifest:
234+ import-modifications:
235+ url-replace:
236+ - old: yyy
237+ new: zzz
238+ projects:
239+ - name: base
240+ url: { project_base }
241+ import: True
242+ '''
243+ },
244+ )
245+
246+ # create an app that uses middle project
247+ project_app = workspace_dir / 'app'
248+ project_app .mkdir ()
249+ with open (project_app / 'west.yml' , 'w' ) as f :
250+ f .write (
251+ textwrap .dedent (f'''\
252+ manifest:
253+ import-modifications:
254+ url-replace:
255+ - old: zzz
256+ new: { os .path .dirname (remote_zephyr )}
257+ projects:
258+ - name: middle
259+ url: { project_middle }
260+ import: True
261+ ''' )
262+ )
263+
264+ # init workspace in projects_dir (project_app's parent)
265+ cmd (['init' , '-l' , project_app ])
266+
267+ # update workspace in projects_dir
268+ cmd ('update' , cwd = workspace_dir )
269+
270+ # zephyr projects from base are cloned
271+ for project_subdir in [
272+ Path ('subdir' ) / 'Kconfiglib' ,
273+ 'tagged_repo' ,
274+ 'net-tools' ,
275+ 'zephyr-rtos' ,
276+ ]:
277+ assert (workspace_dir / project_subdir ).check (dir = 1 )
278+ assert (workspace_dir / project_subdir / '.git' ).check (dir = 1 )
279+
280+
281+ def test_workspace_modify_url_replace_with_self_import (repos_tmpdir ):
282+ remote_zephyr = repos_tmpdir / 'repos' / 'zephyr'
283+ projects_dir = repos_tmpdir / 'projects'
284+ projects_dir .mkdir ()
285+
286+ # create a local base project with a west.yml
287+ project_base = projects_dir / 'base'
288+ project_base .mkdir ()
289+ with open (project_base / 'west.yml' , 'w' ) as f :
290+ f .write (
291+ textwrap .dedent ('''\
292+ manifest:
293+ remotes:
294+ - name: upstream
295+ url-base: nonexistent
296+ projects:
297+ - name: zephyr
298+ remote: upstream
299+ path: zephyr-rtos
300+ import: True
301+ ''' )
302+ )
303+
304+ # create another project with another west.yml (stacked on base)
305+ project_middle = projects_dir / 'middle'
306+ project_middle .mkdir ()
307+ with open (project_middle / 'west.yml' , 'w' ) as f :
308+ f .write (
309+ textwrap .dedent ('''\
310+ manifest:
311+ self:
312+ import: ../base
313+ ''' )
314+ )
315+
316+ # create another project with another west.yml (stacked on base)
317+ project_another = projects_dir / 'another'
318+ project_another .mkdir ()
319+ with open (project_another / 'west.yml' , 'w' ) as f :
320+ f .write (
321+ textwrap .dedent ('''\
322+ manifest:
323+ # this should not have any effect since there are no imports
324+ import-modifications:
325+ url-replace:
326+ - old: nonexistent
327+ new: from-another
328+ ''' )
329+ )
330+
331+ # create another project with another west.yml (stacked on base)
332+ project_app = projects_dir / 'app'
333+ project_app .mkdir ()
334+ with open (project_app / 'west.yml' , 'w' ) as f :
335+ f .write (
336+ textwrap .dedent (f'''\
337+ manifest:
338+ import-modifications:
339+ url-replace:
340+ - old: nonexistent
341+ new: { os .path .dirname (remote_zephyr )}
342+ self:
343+ import:
344+ - ../another
345+ - ../middle
346+ ''' )
347+ )
348+
349+ # init workspace in projects_dir (project_app's parent)
350+ cmd (['init' , '-l' , project_app ])
351+
352+ # update workspace in projects_dir
353+ cmd ('update' , cwd = projects_dir )
354+
355+ ws = projects_dir
356+ # zephyr projects from base are cloned
357+ for project_subdir in [
358+ Path ('subdir' ) / 'Kconfiglib' ,
359+ 'tagged_repo' ,
360+ 'net-tools' ,
361+ 'zephyr-rtos' ,
362+ ]:
363+ assert (ws / project_subdir ).check (dir = 1 )
364+ assert (ws / project_subdir / '.git' ).check (dir = 1 )
365+
366+
125367def test_list (west_update_tmpdir ):
126368 # Projects shall be listed in the order they appear in the manifest.
127369 # Check the behavior for some format arguments of interest as well.
0 commit comments