Skip to content

Commit 2530164

Browse files
LoopedBard3Copilot
andcommitted
Address second-round PR review feedback
Make _inject_bdn_extensions idempotent - Re-running the scenario locally (or retry on the same checkout) used to append a fresh ItemGroup with Label="PerfLabInjected" and a fresh ProjectReference to BDN.Extensions every time, leaving stale entries that produce duplicate-reference build errors. - Now the helper removes any prior PerfLabInjected ItemGroups before inserting the new one, so the patched csproj converges on a single injected ItemGroup regardless of how many times the scenario runs. Forward unknown args to BenchmarkDotNet - --bdn-args was declared with nargs='*', which argparse will not populate with values that start with '--'. The flag was effectively unusable for forwarding BDN options. - Drop --bdn-args entirely and switch parse_args() to parser.parse_known_args(), so any unrecognized arguments (filters, iteration counts, etc.) flow straight through to BenchmarkDotNet. - Documented in the parser epilog. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent dc9ad8d commit 2530164

2 files changed

Lines changed: 28 additions & 8 deletions

File tree

src/scenarios/mauiDesktopBenchmarks/test.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -251,21 +251,25 @@ def build_maui_dependencies(repo_dir: str = MAUI_REPO_DIR):
251251

252252

253253
def parse_args():
254-
parser = ArgumentParser(description='Run MAUI desktop BDN benchmarks')
254+
parser = ArgumentParser(
255+
description='Run MAUI desktop BDN benchmarks',
256+
epilog='Any unrecognized arguments are forwarded to BenchmarkDotNet '
257+
'(e.g. --filter MyBenchmark*).')
255258
parser.add_argument('--framework', '-f', default='net11.0',
256259
help='Target .NET framework (determines MAUI repo branch)')
257260
parser.add_argument('--suite', choices=['core', 'xaml', 'graphics', 'all'],
258261
default='all', help='Which benchmark suite to run')
259-
parser.add_argument('--bdn-args', nargs='*', default=[],
260-
help='Additional arguments to pass to BenchmarkDotNet')
261262
parser.add_argument('--upload-to-perflab-container', action='store_true',
262263
help='Upload results to perflab container')
263-
return parser.parse_args()
264+
# Forward unknown args to BenchmarkDotNet. argparse's nargs='*' would
265+
# not capture values that start with '--' (BDN flags), so use
266+
# parse_known_args() instead and pass the remainder through.
267+
return parser.parse_known_args()
264268

265269

266270
if __name__ == '__main__':
267271
setup_loggers(True)
268-
args = parse_args()
272+
args, extra_bdn_args = parse_args()
269273

270274
# MAUI-specific: clone repo and build dependencies
271275
branch = get_branch(args.framework)
@@ -284,8 +288,9 @@ def parse_args():
284288
# MAUI-specific: build BuildTasks solution filter
285289
build_maui_dependencies()
286290

287-
# Run the generic BDN workflow
288-
bdn_args = list(args.bdn_args)
291+
# Run the generic BDN workflow. Forward any args we didn't consume
292+
# (e.g. --filter, --maxIterationCount overrides) to BenchmarkDotNet.
293+
bdn_args = list(extra_bdn_args)
289294
if EXCLUDED_BENCHMARKS:
290295
bdn_args.extend(['--exclusion-filter'] + EXCLUDED_BENCHMARKS)
291296
helper.runtests(args.suite, bdn_args, args.upload_to_perflab_container)

src/scenarios/shared/bdndesktop.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,13 @@ def _find_bdn_extensions(self) -> str:
164164
return candidate
165165

166166
def _inject_bdn_extensions(self, csproj_path: str, bdn_ext_abs: str):
167-
'''Add a ProjectReference to BDN.Extensions and remove existing BDN PackageRef.'''
167+
'''Add a ProjectReference to BDN.Extensions and remove existing BDN PackageRef.
168+
169+
Idempotent: removes any prior ItemGroup with Label="PerfLabInjected"
170+
before adding the new one so re-running against an existing
171+
checkout does not accumulate duplicate ProjectReference entries
172+
(which produce build errors).
173+
'''
168174
log = getLogger()
169175
log.info(f'Injecting BDN.Extensions reference into {os.path.basename(csproj_path)}')
170176

@@ -178,6 +184,15 @@ def _inject_bdn_extensions(self, csproj_path: str, bdn_ext_abs: str):
178184
if root.tag.startswith('{'):
179185
ns = root.tag.split('}')[0] + '}'
180186

187+
# Remove any prior PerfLabInjected ItemGroup so re-runs don't
188+
# accumulate duplicate ProjectReferences.
189+
existing_injected = [ig for ig in root.findall(f'{ns}ItemGroup')
190+
if ig.get('Label') == 'PerfLabInjected']
191+
for ig in existing_injected:
192+
root.remove(ig)
193+
if existing_injected:
194+
log.info(f' Removed {len(existing_injected)} prior PerfLabInjected ItemGroup(s)')
195+
181196
# Remove BDN package references that conflict with the injected
182197
# ProjectReference to BenchmarkDotNet.Extensions (which itself
183198
# references BenchmarkDotNet + BenchmarkDotNet.Annotations as

0 commit comments

Comments
 (0)