Skip to content

Commit cf5eba6

Browse files
Added test for import-modifications
Test that import-modifications feature works to override west project urls that directly specified in west manifest or imported via submanifests.
1 parent 157c7af commit cf5eba6

File tree

1 file changed

+177
-0
lines changed

1 file changed

+177
-0
lines changed

tests/test_project.py

Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,183 @@ def test_workspace(west_update_tmpdir):
121121
assert wct.join('zephyr', 'subsys', 'bluetooth', 'code.c').check(file=1)
122122

123123

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

0 commit comments

Comments
 (0)