diff --git a/mesonbuild/compilers/d.py b/mesonbuild/compilers/d.py
index 32919e42a..a74dc957e 100644
--- a/mesonbuild/compilers/d.py
+++ b/mesonbuild/compilers/d.py
@@ -19,6 +19,7 @@ from ..mesonlib import (
     EnvironmentException, MachineChoice, version_compare,
 )
 
+from ..arglist import CompilerArgs
 from .compilers import (
     d_dmd_buildtype_args,
     d_gdc_buildtype_args,
@@ -426,6 +427,9 @@ class DmdLikeCompilerMixin:
             args = [a.replace('-L=', '-Xcc=-Wl,') for a in args]
         return args
 
+class DCompilerArgs(CompilerArgs):
+    prepend_prefixes = ('-I', '-L')
+    dedup2_prefixes = ('-I')
 
 class DCompiler(Compiler):
     mscrt_args = {
@@ -599,6 +603,9 @@ class DCompiler(Compiler):
         args += extra_args
         return args
 
+    def compiler_args(self, args: T.Optional[T.Iterable[str]] = None) -> DCompilerArgs:
+        return DCompilerArgs(self, args)
+
     def compiles(self, code, env, *, extra_args=None, dependencies=None, mode='compile'):
         args = self._get_compiler_check_args(env, extra_args, dependencies, mode)
 
diff --git a/mesonbuild/scripts/depfixer.py b/mesonbuild/scripts/depfixer.py
index 4176b9a03..f92769303 100644
--- a/mesonbuild/scripts/depfixer.py
+++ b/mesonbuild/scripts/depfixer.py
@@ -307,17 +307,20 @@ class Elf(DataSizes):
         self.bf.seek(rp_off)
 
         old_rpath = self.read_str()
-        new_rpaths = []
+        # Some rpath entries may come from multiple sources.
+        # Only add each one once.
+        new_rpaths = OrderedSet()
         if new_rpath:
-            new_rpaths.append(new_rpath)
+            new_rpaths.add(new_rpath)
         if old_rpath:
             # Filter out build-only rpath entries
             # added by get_link_dep_subdirs() or
             # specified by user with build_rpath.
-            for dir in old_rpath.split(b':'):
-                if not (dir in rpath_dirs_to_remove or
-                        dir == (b'X' * len(dir))):
-                    new_rpaths.append(dir)
+            for rpath_dir in old_rpath.split(b':'):
+                if not (rpath_dir in rpath_dirs_to_remove or
+                        rpath_dir == (b'X' * len(rpath_dir))):
+                    if rpath_dir:
+                        new_rpaths.add(rpath_dir)
 
         # Prepend user-specified new entries while preserving the ones that came from pkgconfig etc.
         new_rpath = b':'.join(new_rpaths)

[possible regression in 0.55] New rpath must not be longer than the old one
Several projects fail to build with meson with the error from the subject.
For example devel/gnome-builder: http://package22.nyi.freebsd.org/data/113amd64-default-PR244008/2020-07-15_21h37m37s/logs/errors/gnome-builder-3.28.4_4.log
See the list here: https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=247935#c2

Could you please comment on this? Why did these build before and not with 0.55?

FreeBSD 12.1

Thanks,
Yuri
diff --git a/run_unittests.py b/run_unittests.py
index 9cd95f0b5..0ff80356a 100755
--- a/run_unittests.py
+++ b/run_unittests.py
@@ -376,6 +376,12 @@ class InternalTests(unittest.TestCase):
         a += ['-I.', '-I./tests2/']
         self.assertEqual(a, ['-I.', '-I./tests2/', '-I./tests/', '-I..'])
 
+    def test_compiler_args_class_d(self):
+        d = mesonbuild.compilers.DCompiler([], 'fake', MachineChoice.HOST, 'info', 'arch', False, None)
+        # check include order is kept when deduplicating
+        a = d.compiler_args(['-Ifirst', '-Isecond', '-Ithird'])
+        a += ['-Ifirst']
+        self.assertEqual(a, ['-Ifirst', '-Isecond', '-Ithird'])
 
     def test_compiler_args_class(self):
         cc = mesonbuild.compilers.CCompiler([], 'fake', False, MachineChoice.HOST, mock.Mock())

pip install -e .
parse_log_pytest
pytest
pytest
python3 -m pip install ninja
3.9
pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning
exceptiongroup @ file:///croot/exceptiongroup_1706031385326/work
iniconfig @ file:///home/linux1/recipes/ci/iniconfig_1610983019677/work
-e git+https://github.com/mesonbuild/meson.git@6fc067344d035c0c16fb33c11f5f0ace5c99c558#egg=meson
ninja==1.11.1.4
packaging @ file:///croot/packaging_1734472117206/work
pluggy @ file:///croot/pluggy_1733169602837/work
pytest @ file:///croot/pytest_1738938843180/work
tomli @ file:///opt/conda/conda-bld/tomli_1657175507142/work

name: meson
channels:
  - defaults
  - https://repo.anaconda.com/pkgs/main
  - https://repo.anaconda.com/pkgs/r
  - conda-forge
dependencies:
  - _libgcc_mutex=0.1=main
  - _openmp_mutex=5.1=1_gnu
  - ca-certificates=2025.2.25=h06a4308_0
  - exceptiongroup=1.2.0=py39h06a4308_0
  - iniconfig=1.1.1=pyhd3eb1b0_0
  - ld_impl_linux-64=2.40=h12ee557_0
  - libffi=3.4.4=h6a678d5_1
  - libgcc-ng=11.2.0=h1234567_1
  - libgomp=11.2.0=h1234567_1
  - libstdcxx-ng=11.2.0=h1234567_1
  - ncurses=6.4=h6a678d5_0
  - openssl=3.0.16=h5eee18b_0
  - packaging=24.2=py39h06a4308_0
  - pip=25.0=py39h06a4308_0
  - pluggy=1.5.0=py39h06a4308_0
  - pytest=8.3.4=py39h06a4308_0
  - python=3.9.21=he870216_1
  - readline=8.2=h5eee18b_0
  - setuptools=75.8.0=py39h06a4308_0
  - sqlite=3.45.3=h5eee18b_0
  - tk=8.6.14=h39e8969_0
  - tomli=2.0.1=py39h06a4308_0
  - tzdata=2025a=h04d1e81_0
  - wheel=0.45.1=py39h06a4308_0
  - xz=5.6.4=h5eee18b_1
  - zlib=1.2.13=h5eee18b_1
  - pip:
      - meson==0.55.999
      - ninja==1.11.1.4
prefix: /opt/conda/envs/meson

run_unittests.py::InternalTests::test_compiler_args_class_d
run_unittests.py::DataTests::test_compiler_options_documented run_unittests.py::DataTests::test_json_grammar_syntax_highlighting run_unittests.py::AllPlatformTests::test_absolute_prefix_libdir run_unittests.py::AllPlatformTests::test_always_prefer_c_compiler_for_asm run_unittests.py::AllPlatformTests::test_check_module_linking run_unittests.py::AllPlatformTests::test_compiler_detection run_unittests.py::AllPlatformTests::test_configure run_unittests.py::AllPlatformTests::test_default_options_prefix run_unittests.py::AllPlatformTests::test_introspect_ast_source run_unittests.py::AllPlatformTests::test_introspect_buildoptions_without_configured_build run_unittests.py::AllPlatformTests::test_introspect_config_update run_unittests.py::AllPlatformTests::test_introspect_dependencies_from_source run_unittests.py::AllPlatformTests::test_introspect_file_dump_equals_all run_unittests.py::AllPlatformTests::test_introspect_json_dump run_unittests.py::AllPlatformTests::test_introspect_meson_info run_unittests.py::AllPlatformTests::test_introspect_targets_from_source run_unittests.py::AllPlatformTests::test_link_language_linker run_unittests.py::AllPlatformTests::test_meson_compile run_unittests.py::AllPlatformTests::test_noop_changes_cause_no_rebuilds run_unittests.py::AllPlatformTests::test_preprocessor_checks_CPPFLAGS run_unittests.py::AllPlatformTests::test_templates run_unittests.py::AllPlatformTests::test_warning_level_0 run_unittests.py::FailureTests::test_assert_default_message run_unittests.py::FailureTests::test_boost_BOOST_ROOT_dependency run_unittests.py::FailureTests::test_boost_notfound_dependency run_unittests.py::FailureTests::test_dependency_invalid_method run_unittests.py::FailureTests::test_dict_forbids_duplicate_keys run_unittests.py::FailureTests::test_dict_forbids_integer_key run_unittests.py::FailureTests::test_extraframework_dependency_method run_unittests.py::FailureTests::test_get_variable_on_not_found_project run_unittests.py::FailureTests::test_gnustep_notfound_dependency run_unittests.py::FailureTests::test_llvm_dependency run_unittests.py::FailureTests::test_message run_unittests.py::FailureTests::test_missing_subproject_not_required_and_required run_unittests.py::FailureTests::test_override_dependency_twice run_unittests.py::FailureTests::test_override_resolved_dependency run_unittests.py::FailureTests::test_sdl2_notfound_dependency run_unittests.py::FailureTests::test_using_recent_feature run_unittests.py::FailureTests::test_using_too_recent_feature run_unittests.py::FailureTests::test_using_too_recent_feature_dependency run_unittests.py::FailureTests::test_vcs_tag_featurenew_build_always_stale run_unittests.py::FailureTests::test_warning run_unittests.py::FailureTests::test_wrap_nofallback run_unittests.py::FailureTests::test_wx_notfound_dependency run_unittests.py::LinuxlikeTests::test_build_rpath run_unittests.py::LinuxlikeTests::test_compiler_check_flags_order run_unittests.py::LinuxlikeTests::test_compiler_cpp_stds run_unittests.py::LinuxlikeTests::test_cpp_std_override run_unittests.py::LinuxlikeTests::test_global_rpath run_unittests.py::LinuxlikeTests::test_ld_environment_variable_cpp run_unittests.py::LinuxlikeTests::test_pch_with_address_sanitizer run_unittests.py::RewriterTests::test_default_options_delete run_unittests.py::RewriterTests::test_default_options_set run_unittests.py::RewriterTests::test_kwargs_add run_unittests.py::RewriterTests::test_kwargs_delete run_unittests.py::RewriterTests::test_kwargs_info run_unittests.py::RewriterTests::test_kwargs_remove run_unittests.py::RewriterTests::test_kwargs_remove_regex run_unittests.py::RewriterTests::test_kwargs_set run_unittests.py::RewriterTests::test_target_add_sources run_unittests.py::RewriterTests::test_target_add_sources_abs run_unittests.py::RewriterTests::test_target_remove run_unittests.py::RewriterTests::test_target_remove_sources run_unittests.py::RewriterTests::test_target_same_name_skip run_unittests.py::RewriterTests::test_target_source_list run_unittests.py::RewriterTests::test_target_source_sorting run_unittests.py::RewriterTests::test_tatrget_add run_unittests.py::NativeFileTests::test_builtin_options run_unittests.py::NativeFileTests::test_builtin_options_env_overrides_conf run_unittests.py::NativeFileTests::test_cpp_compiler run_unittests.py::NativeFileTests::test_python_module run_unittests.py::CrossFileTests::test_builtin_options run_unittests.py::CrossFileTests::test_builtin_options_env_overrides_conf run_unittests.py::CrossFileTests::test_builtin_options_per_machine
run_unittests.py::InternalTests::test_compiler_args_class run_unittests.py::InternalTests::test_compiler_args_class_gnuld run_unittests.py::InternalTests::test_compiler_args_class_none_flush run_unittests.py::InternalTests::test_compiler_args_remove_system run_unittests.py::InternalTests::test_dependency_factory_order run_unittests.py::InternalTests::test_depfile run_unittests.py::InternalTests::test_extract_as_list run_unittests.py::InternalTests::test_find_library_patterns run_unittests.py::InternalTests::test_listify run_unittests.py::InternalTests::test_log_once run_unittests.py::InternalTests::test_log_once_ansi run_unittests.py::InternalTests::test_mode_symbolic_to_bits run_unittests.py::InternalTests::test_needs_exe_wrapper_override run_unittests.py::InternalTests::test_pkgconfig_module run_unittests.py::InternalTests::test_quote_arg run_unittests.py::InternalTests::test_sort_libpaths run_unittests.py::InternalTests::test_split_args run_unittests.py::InternalTests::test_string_templates_substitution run_unittests.py::InternalTests::test_unholder run_unittests.py::InternalTests::test_version_compare run_unittests.py::InternalTests::test_version_number run_unittests.py::DataTests::test_all_functions_defined_in_ast_interpreter run_unittests.py::DataTests::test_builtin_options_documented run_unittests.py::DataTests::test_cpu_families_documented run_unittests.py::DataTests::test_markdown_files_in_sitemap run_unittests.py::DataTests::test_mesondata_is_up_to_date run_unittests.py::DataTests::test_snippets run_unittests.py::DataTests::test_vim_syntax_highlighting run_unittests.py::AllPlatformTests::test_alias_target run_unittests.py::AllPlatformTests::test_all_forbidden_targets_tested run_unittests.py::AllPlatformTests::test_array_option_bad_change run_unittests.py::AllPlatformTests::test_array_option_change run_unittests.py::AllPlatformTests::test_array_option_empty_equivalents run_unittests.py::AllPlatformTests::test_build_by_default run_unittests.py::AllPlatformTests::test_buildtype_setting run_unittests.py::AllPlatformTests::test_clike_get_library_dirs run_unittests.py::AllPlatformTests::test_command_line run_unittests.py::AllPlatformTests::test_commands_documented run_unittests.py::AllPlatformTests::test_compiler_run_command run_unittests.py::AllPlatformTests::test_configure_file_warnings run_unittests.py::AllPlatformTests::test_conflicting_d_dash_option run_unittests.py::AllPlatformTests::test_cross_file_constants run_unittests.py::AllPlatformTests::test_custom_target_changes_cause_rebuild run_unittests.py::AllPlatformTests::test_custom_target_exe_data_deterministic run_unittests.py::AllPlatformTests::test_dash_d_dedup run_unittests.py::AllPlatformTests::test_default_options_prefix_dependent_defaults run_unittests.py::AllPlatformTests::test_dirs run_unittests.py::AllPlatformTests::test_dist_git run_unittests.py::AllPlatformTests::test_dist_git_script run_unittests.py::AllPlatformTests::test_dist_hg run_unittests.py::AllPlatformTests::test_do_conf_file_by_format run_unittests.py::AllPlatformTests::test_do_conf_file_preserve_newlines run_unittests.py::AllPlatformTests::test_env_ops_dont_stack run_unittests.py::AllPlatformTests::test_error_location_path run_unittests.py::AllPlatformTests::test_feature_check_usage_subprojects run_unittests.py::AllPlatformTests::test_flock run_unittests.py::AllPlatformTests::test_force_fallback_for run_unittests.py::AllPlatformTests::test_forcefallback run_unittests.py::AllPlatformTests::test_free_stringarray_setting run_unittests.py::AllPlatformTests::test_guessed_linker_dependencies run_unittests.py::AllPlatformTests::test_identical_target_name_in_subdir_flat_layout run_unittests.py::AllPlatformTests::test_identical_target_name_in_subproject_flat_layout run_unittests.py::AllPlatformTests::test_identity_cross run_unittests.py::AllPlatformTests::test_install_introspection run_unittests.py::AllPlatformTests::test_install_introspection_multiple_outputs run_unittests.py::AllPlatformTests::test_install_log_content run_unittests.py::AllPlatformTests::test_install_subdir_introspection run_unittests.py::AllPlatformTests::test_internal_include_order run_unittests.py::AllPlatformTests::test_introspect_projectinfo_subproject_dir run_unittests.py::AllPlatformTests::test_introspect_projectinfo_subproject_dir_from_source run_unittests.py::AllPlatformTests::test_introspect_projectinfo_subprojects run_unittests.py::AllPlatformTests::test_introspect_projectinfo_without_configured_build run_unittests.py::AllPlatformTests::test_introspection_target_subproject run_unittests.py::AllPlatformTests::test_libdir_must_be_inside_prefix run_unittests.py::AllPlatformTests::test_meson_configure_from_source_does_not_crash run_unittests.py::AllPlatformTests::test_minor_version_does_not_reconfigure_wipe run_unittests.py::AllPlatformTests::test_multi_output_custom_target_no_warning run_unittests.py::AllPlatformTests::test_ndebug_if_release_disabled run_unittests.py::AllPlatformTests::test_ndebug_if_release_enabled run_unittests.py::AllPlatformTests::test_permitted_method_kwargs run_unittests.py::AllPlatformTests::test_prebuilt_object run_unittests.py::AllPlatformTests::test_prebuilt_shared_lib run_unittests.py::AllPlatformTests::test_prebuilt_static_lib run_unittests.py::AllPlatformTests::test_prefix_dependent_defaults run_unittests.py::AllPlatformTests::test_reconfigure run_unittests.py::AllPlatformTests::test_rpath_uses_ORIGIN run_unittests.py::AllPlatformTests::test_run_target_files_path run_unittests.py::AllPlatformTests::test_same_d_option_twice run_unittests.py::AllPlatformTests::test_same_d_option_twice_configure run_unittests.py::AllPlatformTests::test_same_dash_option_twice run_unittests.py::AllPlatformTests::test_same_dash_option_twice_configure run_unittests.py::AllPlatformTests::test_same_project_d_option_twice run_unittests.py::AllPlatformTests::test_same_project_d_option_twice_configure run_unittests.py::AllPlatformTests::test_source_changes_cause_rebuild run_unittests.py::AllPlatformTests::test_source_generator_program_cause_rebuild run_unittests.py::AllPlatformTests::test_spurious_reconfigure_built_dep_file run_unittests.py::AllPlatformTests::test_static_compile_order run_unittests.py::AllPlatformTests::test_static_library_lto run_unittests.py::AllPlatformTests::test_static_library_overwrite run_unittests.py::AllPlatformTests::test_subproject_promotion run_unittests.py::AllPlatformTests::test_subproject_promotion_wrap run_unittests.py::AllPlatformTests::test_suite_selection run_unittests.py::AllPlatformTests::test_summary run_unittests.py::AllPlatformTests::test_target_construct_id_from_path run_unittests.py::AllPlatformTests::test_testsetup_default run_unittests.py::AllPlatformTests::test_testsetup_selection run_unittests.py::AllPlatformTests::test_uninstall run_unittests.py::AllPlatformTests::test_unstable_coredata run_unittests.py::AllPlatformTests::test_warning_location run_unittests.py::AllPlatformTests::test_wipe_from_builddir run_unittests.py::AllPlatformTests::test_wrap_git run_unittests.py::FailureTests::test_dict_requires_key_value_pairs run_unittests.py::FailureTests::test_exception_exit_status run_unittests.py::FailureTests::test_objc_cpp_detection run_unittests.py::FailureTests::test_subproject_variables run_unittests.py::FailureTests::test_version_checked_before_parsing_options run_unittests.py::LinuxlikeTests::test_basic_soname run_unittests.py::LinuxlikeTests::test_compiler_c_stds run_unittests.py::LinuxlikeTests::test_compiler_libs_static_dedup run_unittests.py::LinuxlikeTests::test_cross_find_program run_unittests.py::LinuxlikeTests::test_custom_soname run_unittests.py::LinuxlikeTests::test_deterministic_dep_order run_unittests.py::LinuxlikeTests::test_deterministic_rpath_order run_unittests.py::LinuxlikeTests::test_identity_cross run_unittests.py::LinuxlikeTests::test_identity_cross_env run_unittests.py::LinuxlikeTests::test_install_subdir_symlinks run_unittests.py::LinuxlikeTests::test_install_subdir_symlinks_with_default_umask run_unittests.py::LinuxlikeTests::test_install_subdir_symlinks_with_default_umask_and_mode run_unittests.py::LinuxlikeTests::test_install_umask run_unittests.py::LinuxlikeTests::test_installed_modes run_unittests.py::LinuxlikeTests::test_installed_modes_extended run_unittests.py::LinuxlikeTests::test_installed_soname run_unittests.py::LinuxlikeTests::test_introspect_installed run_unittests.py::LinuxlikeTests::test_ld_environment_variable_bfd run_unittests.py::LinuxlikeTests::test_ld_environment_variable_gold run_unittests.py::LinuxlikeTests::test_ld_environment_variable_objc run_unittests.py::LinuxlikeTests::test_no_rpath_for_static run_unittests.py::LinuxlikeTests::test_override_with_exe_dep run_unittests.py::LinuxlikeTests::test_pic run_unittests.py::LinuxlikeTests::test_pkg_unfound run_unittests.py::LinuxlikeTests::test_reconfigure run_unittests.py::LinuxlikeTests::test_run_installed run_unittests.py::LinuxlikeTests::test_soname run_unittests.py::LinuxlikeTests::test_unity_subproj run_unittests.py::LinuxlikeTests::test_wrap_with_file_url run_unittests.py::RewriterTests::test_target_add_subdir run_unittests.py::RewriterTests::test_target_remove_subdir run_unittests.py::RewriterTests::test_target_subdir run_unittests.py::NativeFileTests::test_builtin_options_compiler_properties run_unittests.py::NativeFileTests::test_builtin_options_compiler_properties_legacy run_unittests.py::NativeFileTests::test_builtin_options_paths run_unittests.py::NativeFileTests::test_builtin_options_paths_legacy run_unittests.py::NativeFileTests::test_builtin_options_subprojects run_unittests.py::NativeFileTests::test_builtin_options_subprojects_inherits_parent_override run_unittests.py::NativeFileTests::test_builtin_options_subprojects_overrides_buildfiles run_unittests.py::NativeFileTests::test_compile_sys_path run_unittests.py::NativeFileTests::test_find_program run_unittests.py::NativeFileTests::test_multiple_native_files run_unittests.py::NativeFileTests::test_multiple_native_files_override run_unittests.py::NativeFileTests::test_native_file_dirs run_unittests.py::NativeFileTests::test_native_file_dirs_overriden run_unittests.py::NativeFileTests::test_native_file_is_pipe run_unittests.py::NativeFileTests::test_option_bool run_unittests.py::NativeFileTests::test_option_integer run_unittests.py::NativeFileTests::test_python3_module run_unittests.py::NativeFileTests::test_user_options run_unittests.py::NativeFileTests::test_user_options_command_line_overrides run_unittests.py::NativeFileTests::test_user_options_subproject run_unittests.py::CrossFileTests::test_cross_exe_passed_no_wrapper run_unittests.py::CrossFileTests::test_cross_file_dirs run_unittests.py::CrossFileTests::test_cross_file_dirs_chain run_unittests.py::CrossFileTests::test_cross_file_dirs_overriden run_unittests.py::CrossFileTests::test_cross_file_system_paths run_unittests.py::CrossFileTests::test_needs_exe_wrapper_false run_unittests.py::CrossFileTests::test_needs_exe_wrapper_true run_unittests.py::CrossFileTests::test_needs_exe_wrapper_true_wrapper run_unittests.py::CrossFileTests::test_user_options run_unittests.py::TAPParserTests::test_diagnostics run_unittests.py::TAPParserTests::test_directive_case run_unittests.py::TAPParserTests::test_directive_explanation run_unittests.py::TAPParserTests::test_empty run_unittests.py::TAPParserTests::test_empty_line run_unittests.py::TAPParserTests::test_empty_plan run_unittests.py::TAPParserTests::test_many_early_plan run_unittests.py::TAPParserTests::test_many_late_plan run_unittests.py::TAPParserTests::test_middle_plan run_unittests.py::TAPParserTests::test_one_test_early_plan run_unittests.py::TAPParserTests::test_one_test_late_plan run_unittests.py::TAPParserTests::test_one_test_not_ok run_unittests.py::TAPParserTests::test_one_test_ok run_unittests.py::TAPParserTests::test_one_test_skip run_unittests.py::TAPParserTests::test_one_test_skip_failure run_unittests.py::TAPParserTests::test_one_test_todo run_unittests.py::TAPParserTests::test_one_test_with_name run_unittests.py::TAPParserTests::test_one_test_with_number run_unittests.py::TAPParserTests::test_out_of_order run_unittests.py::TAPParserTests::test_plan_directive run_unittests.py::TAPParserTests::test_too_few run_unittests.py::TAPParserTests::test_too_few_bailout run_unittests.py::TAPParserTests::test_too_many run_unittests.py::TAPParserTests::test_too_many_plans run_unittests.py::TAPParserTests::test_unexpected run_unittests.py::TAPParserTests::test_version run_unittests.py::TAPParserTests::test_yaml
mesonbuild/compilers/d.py mesonbuild/scripts/depfixer.py
mesonbuild/compilers/d.py mesonbuild/scripts/depfixer.py