@@ -119,6 +119,183 @@ def test_workspace(west_update_tmpdir):
119119 assert wct .join ('zephyr' , 'subsys' , 'bluetooth' , 'code.c' ).check (file = 1 )
120120
121121
122+ def test_workspace_modify_url_replace (tmpdir , repos_tmpdir ):
123+ remotes_dir = repos_tmpdir / 'repos'
124+ workspace_dir = tmpdir / 'workspace'
125+ workspace_dir .mkdir ()
126+
127+ # use remote zephyr
128+ remote_zephyr = tmpdir / 'repos' / 'zephyr'
129+
130+ # create a local base project with a west.yml
131+ project_base = remotes_dir / 'base'
132+ create_repo (project_base )
133+ add_commit (
134+ project_base ,
135+ 'manifest commit' ,
136+ # zephyr revision is implicitly master:
137+ files = {
138+ 'west.yml' : textwrap .dedent ('''
139+ manifest:
140+ import-modifications:
141+ url-replace:
142+ - old: xxx
143+ new: yyy
144+ remotes:
145+ - name: upstream
146+ url-base: xxx
147+ projects:
148+ - name: zephyr
149+ remote: upstream
150+ path: zephyr-rtos
151+ import: True
152+ ''' )
153+ },
154+ )
155+
156+ # create another project with another west.yml (stacked on base)
157+ project_middle = remotes_dir / 'middle'
158+ create_repo (project_middle )
159+ add_commit (
160+ project_middle ,
161+ 'manifest commit' ,
162+ # zephyr revision is implicitly master:
163+ files = {
164+ 'west.yml' : f'''
165+ manifest:
166+ import-modifications:
167+ url-replace:
168+ - old: yyy
169+ new: zzz
170+ projects:
171+ - name: base
172+ url: { project_base }
173+ import: True
174+ '''
175+ },
176+ )
177+
178+ # create an app that uses middle project
179+ project_app = workspace_dir / 'app'
180+ project_app .mkdir ()
181+ with open (project_app / 'west.yml' , 'w' ) as f :
182+ f .write (
183+ textwrap .dedent (f'''\
184+ manifest:
185+ import-modifications:
186+ url-replace:
187+ - old: zzz
188+ new: { os .path .dirname (remote_zephyr )}
189+ projects:
190+ - name: middle
191+ url: { project_middle }
192+ import: True
193+ ''' )
194+ )
195+
196+ # init workspace in projects_dir (project_app's parent)
197+ cmd (['init' , '-l' , project_app ])
198+
199+ # update workspace in projects_dir
200+ cmd ('update' , cwd = workspace_dir )
201+
202+ # zephyr projects from base are cloned
203+ for project_subdir in [
204+ Path ('subdir' ) / 'Kconfiglib' ,
205+ 'tagged_repo' ,
206+ 'net-tools' ,
207+ 'zephyr-rtos' ,
208+ ]:
209+ assert (workspace_dir / project_subdir ).check (dir = 1 )
210+ assert (workspace_dir / project_subdir / '.git' ).check (dir = 1 )
211+
212+
213+ def test_workspace_modify_url_replace_with_self_import (repos_tmpdir ):
214+ remote_zephyr = repos_tmpdir / 'repos' / 'zephyr'
215+ projects_dir = repos_tmpdir / 'projects'
216+ projects_dir .mkdir ()
217+
218+ # create a local base project with a west.yml
219+ project_base = projects_dir / 'base'
220+ project_base .mkdir ()
221+ with open (project_base / 'west.yml' , 'w' ) as f :
222+ f .write (
223+ textwrap .dedent ('''\
224+ manifest:
225+ remotes:
226+ - name: upstream
227+ url-base: nonexistent
228+ projects:
229+ - name: zephyr
230+ remote: upstream
231+ path: zephyr-rtos
232+ import: True
233+ ''' )
234+ )
235+
236+ # create another project with another west.yml (stacked on base)
237+ project_middle = projects_dir / 'middle'
238+ project_middle .mkdir ()
239+ with open (project_middle / 'west.yml' , 'w' ) as f :
240+ f .write (
241+ textwrap .dedent ('''\
242+ manifest:
243+ self:
244+ import: ../base
245+ ''' )
246+ )
247+
248+ # create another project with another west.yml (stacked on base)
249+ project_another = projects_dir / 'another'
250+ project_another .mkdir ()
251+ with open (project_another / 'west.yml' , 'w' ) as f :
252+ f .write (
253+ textwrap .dedent ('''\
254+ manifest:
255+ # this should not have any effect since there are no imports
256+ import-modifications:
257+ url-replace:
258+ - old: nonexistent
259+ new: from-another
260+ ''' )
261+ )
262+
263+ # create another project with another west.yml (stacked on base)
264+ project_app = projects_dir / 'app'
265+ project_app .mkdir ()
266+ with open (project_app / 'west.yml' , 'w' ) as f :
267+ f .write (
268+ textwrap .dedent (f'''\
269+ manifest:
270+ import-modifications:
271+ url-replace:
272+ - old: nonexistent
273+ new: { os .path .dirname (remote_zephyr )}
274+ self:
275+ import:
276+ - ../another
277+ - ../middle
278+ ''' )
279+ )
280+
281+ # init workspace in projects_dir (project_app's parent)
282+ cmd (['init' , '-l' , project_app ])
283+
284+ # update workspace in projects_dir
285+ cmd ('update' , cwd = projects_dir )
286+
287+ ws = projects_dir
288+ # zephyr projects from base are cloned
289+ for project_subdir in [
290+ Path ('subdir' ) / 'Kconfiglib' ,
291+ 'tagged_repo' ,
292+ 'net-tools' ,
293+ 'zephyr-rtos' ,
294+ ]:
295+ assert (ws / project_subdir ).check (dir = 1 )
296+ assert (ws / project_subdir / '.git' ).check (dir = 1 )
297+
298+
122299def test_list (west_update_tmpdir ):
123300 # Projects shall be listed in the order they appear in the manifest.
124301 # Check the behavior for some format arguments of interest as well.
0 commit comments