* [RFC PATCH] treewide: add .clang-format configuration file
@ 2025-09-28 22:39 Rahul Sandhu
2025-09-28 22:48 ` [RFC PATCH v2] " Rahul Sandhu
0 siblings, 1 reply; 22+ messages in thread
From: Rahul Sandhu @ 2025-09-28 22:39 UTC (permalink / raw)
To: selinux; +Cc: Rahul Sandhu
Currently only an RFC.
Add the .clang-format configuration file, taken from the Linux kernel
repository. We don't have any official style guidelines in tree at
present, which makes it a bit unclear how to format C code for new
contributors. As well as this, different parts of the codebase seem to
been formatted with different styles on occasion, so using an automatic
formatter should resolve this.
.clang-format is also read by various editors and tooling for writing C
code. It may also be worth adding an editorconfig file in the future as
well?
It may well also be worth adding a `format` target to the Makefiles, is
that something that would be useful?
A few other things to consider to do in the future:
1. Reformat all existing code. I understand this is a big change, hence
the RFC, but we may as well get all code formatted if we go down
this route; afterall, it's not like this will cause any breaking
changes.
2. Possibly add a CI target to check that all code is formatted as per
the new clang-format configuration? The options `--dry-run` as well
as `-Werror` can be passed to clang-format for this.
Comments/feedback appreciated, thanks.
Signed-off-by: Rahul Sandhu <nvraxn@gmail.com>
---
.clang-format | 804 ++++++++++++++++++++++++++++++++++++++++++++++++
CONTRIBUTING.md | 2 +
2 files changed, 806 insertions(+)
create mode 100644 .clang-format
diff --git a/.clang-format b/.clang-format
new file mode 100644
index 00000000..48405c54
--- /dev/null
+++ b/.clang-format
@@ -0,0 +1,804 @@
+# SPDX-License-Identifier: GPL-2.0
+#
+# clang-format configuration file. Intended for clang-format >= 11.
+#
+# For more information, see:
+#
+# Documentation/dev-tools/clang-format.rst
+# https://clang.llvm.org/docs/ClangFormat.html
+# https://clang.llvm.org/docs/ClangFormatStyleOptions.html
+#
+---
+AccessModifierOffset: -4
+AlignAfterOpenBracket: Align
+AlignConsecutiveAssignments: false
+AlignConsecutiveDeclarations: false
+AlignEscapedNewlines: Left
+AlignOperands: true
+AlignTrailingComments: false
+AllowAllParametersOfDeclarationOnNextLine: false
+AllowShortBlocksOnASingleLine: false
+AllowShortCaseLabelsOnASingleLine: false
+AllowShortFunctionsOnASingleLine: None
+AllowShortIfStatementsOnASingleLine: false
+AllowShortLoopsOnASingleLine: false
+AlwaysBreakAfterDefinitionReturnType: None
+AlwaysBreakAfterReturnType: None
+AlwaysBreakBeforeMultilineStrings: false
+AlwaysBreakTemplateDeclarations: false
+BinPackArguments: true
+BinPackParameters: true
+BraceWrapping:
+ AfterClass: false
+ AfterControlStatement: false
+ AfterEnum: false
+ AfterFunction: true
+ AfterNamespace: true
+ AfterObjCDeclaration: false
+ AfterStruct: false
+ AfterUnion: false
+ AfterExternBlock: false
+ BeforeCatch: false
+ BeforeElse: false
+ IndentBraces: false
+ SplitEmptyFunction: true
+ SplitEmptyRecord: true
+ SplitEmptyNamespace: true
+BreakBeforeBinaryOperators: None
+BreakBeforeBraces: Custom
+BreakBeforeInheritanceComma: false
+BreakBeforeTernaryOperators: false
+BreakConstructorInitializersBeforeComma: false
+BreakConstructorInitializers: BeforeComma
+BreakAfterJavaFieldAnnotations: false
+BreakStringLiterals: false
+ColumnLimit: 80
+CommentPragmas: '^ IWYU pragma:'
+CompactNamespaces: false
+ConstructorInitializerAllOnOneLineOrOnePerLine: false
+ConstructorInitializerIndentWidth: 8
+ContinuationIndentWidth: 8
+Cpp11BracedListStyle: false
+DerivePointerAlignment: false
+DisableFormat: false
+ExperimentalAutoDetectBinPacking: false
+FixNamespaceComments: false
+
+# Taken from:
+# git grep -h '^#define [^[:space:]]*for_each[^[:space:]]*(' include/ tools/ \
+# | sed "s,^#define \([^[:space:]]*for_each[^[:space:]]*\)(.*$, - '\1'," \
+# | LC_ALL=C sort -u
+ForEachMacros:
+ - '__ata_qc_for_each'
+ - '__bio_for_each_bvec'
+ - '__bio_for_each_segment'
+ - '__evlist__for_each_entry'
+ - '__evlist__for_each_entry_continue'
+ - '__evlist__for_each_entry_from'
+ - '__evlist__for_each_entry_reverse'
+ - '__evlist__for_each_entry_safe'
+ - '__for_each_mem_range'
+ - '__for_each_mem_range_rev'
+ - '__for_each_thread'
+ - '__hlist_for_each_rcu'
+ - '__map__for_each_symbol_by_name'
+ - '__pci_bus_for_each_res0'
+ - '__pci_bus_for_each_res1'
+ - '__pci_dev_for_each_res0'
+ - '__pci_dev_for_each_res1'
+ - '__perf_evlist__for_each_entry'
+ - '__perf_evlist__for_each_entry_reverse'
+ - '__perf_evlist__for_each_entry_safe'
+ - '__rq_for_each_bio'
+ - '__shost_for_each_device'
+ - '__sym_for_each'
+ - '_for_each_counter'
+ - 'apei_estatus_for_each_section'
+ - 'ata_for_each_dev'
+ - 'ata_for_each_link'
+ - 'ata_qc_for_each'
+ - 'ata_qc_for_each_raw'
+ - 'ata_qc_for_each_with_internal'
+ - 'ax25_for_each'
+ - 'ax25_uid_for_each'
+ - 'bio_for_each_bvec'
+ - 'bio_for_each_bvec_all'
+ - 'bio_for_each_folio_all'
+ - 'bio_for_each_integrity_vec'
+ - 'bio_for_each_segment'
+ - 'bio_for_each_segment_all'
+ - 'bio_list_for_each'
+ - 'bip_for_each_vec'
+ - 'bond_for_each_slave'
+ - 'bond_for_each_slave_rcu'
+ - 'bpf_for_each'
+ - 'bpf_for_each_reg_in_vstate'
+ - 'bpf_for_each_reg_in_vstate_mask'
+ - 'bpf_for_each_spilled_reg'
+ - 'bpf_object__for_each_map'
+ - 'bpf_object__for_each_program'
+ - 'btree_for_each_safe128'
+ - 'btree_for_each_safe32'
+ - 'btree_for_each_safe64'
+ - 'btree_for_each_safel'
+ - 'card_for_each_dev'
+ - 'cgroup_taskset_for_each'
+ - 'cgroup_taskset_for_each_leader'
+ - 'cpu_aggr_map__for_each_idx'
+ - 'cpufreq_for_each_efficient_entry_idx'
+ - 'cpufreq_for_each_entry'
+ - 'cpufreq_for_each_entry_idx'
+ - 'cpufreq_for_each_valid_entry'
+ - 'cpufreq_for_each_valid_entry_idx'
+ - 'css_for_each_child'
+ - 'css_for_each_descendant_post'
+ - 'css_for_each_descendant_pre'
+ - 'damon_for_each_region'
+ - 'damon_for_each_region_from'
+ - 'damon_for_each_region_safe'
+ - 'damon_for_each_scheme'
+ - 'damon_for_each_scheme_safe'
+ - 'damon_for_each_target'
+ - 'damon_for_each_target_safe'
+ - 'damos_for_each_filter'
+ - 'damos_for_each_filter_safe'
+ - 'damos_for_each_ops_filter'
+ - 'damos_for_each_ops_filter_safe'
+ - 'damos_for_each_quota_goal'
+ - 'damos_for_each_quota_goal_safe'
+ - 'data__for_each_file'
+ - 'data__for_each_file_new'
+ - 'data__for_each_file_start'
+ - 'def_for_each_cpu'
+ - 'device_for_each_child_node'
+ - 'device_for_each_child_node_scoped'
+ - 'dma_fence_array_for_each'
+ - 'dma_fence_chain_for_each'
+ - 'dma_fence_unwrap_for_each'
+ - 'dma_resv_for_each_fence'
+ - 'dma_resv_for_each_fence_unlocked'
+ - 'do_for_each_ftrace_op'
+ - 'drm_atomic_crtc_for_each_plane'
+ - 'drm_atomic_crtc_state_for_each_plane'
+ - 'drm_atomic_crtc_state_for_each_plane_state'
+ - 'drm_atomic_for_each_plane_damage'
+ - 'drm_client_for_each_connector_iter'
+ - 'drm_client_for_each_modeset'
+ - 'drm_connector_for_each_possible_encoder'
+ - 'drm_exec_for_each_locked_object'
+ - 'drm_exec_for_each_locked_object_reverse'
+ - 'drm_for_each_bridge_in_chain'
+ - 'drm_for_each_connector_iter'
+ - 'drm_for_each_crtc'
+ - 'drm_for_each_crtc_reverse'
+ - 'drm_for_each_encoder'
+ - 'drm_for_each_encoder_mask'
+ - 'drm_for_each_fb'
+ - 'drm_for_each_legacy_plane'
+ - 'drm_for_each_plane'
+ - 'drm_for_each_plane_mask'
+ - 'drm_for_each_privobj'
+ - 'drm_gem_for_each_gpuvm_bo'
+ - 'drm_gem_for_each_gpuvm_bo_safe'
+ - 'drm_gpusvm_for_each_range'
+ - 'drm_gpuva_for_each_op'
+ - 'drm_gpuva_for_each_op_from_reverse'
+ - 'drm_gpuva_for_each_op_reverse'
+ - 'drm_gpuva_for_each_op_safe'
+ - 'drm_gpuvm_bo_for_each_va'
+ - 'drm_gpuvm_bo_for_each_va_safe'
+ - 'drm_gpuvm_for_each_va'
+ - 'drm_gpuvm_for_each_va_range'
+ - 'drm_gpuvm_for_each_va_range_safe'
+ - 'drm_gpuvm_for_each_va_safe'
+ - 'drm_mm_for_each_hole'
+ - 'drm_mm_for_each_node'
+ - 'drm_mm_for_each_node_in_range'
+ - 'drm_mm_for_each_node_safe'
+ - 'dsa_switch_for_each_available_port'
+ - 'dsa_switch_for_each_cpu_port'
+ - 'dsa_switch_for_each_cpu_port_continue_reverse'
+ - 'dsa_switch_for_each_port'
+ - 'dsa_switch_for_each_port_continue_reverse'
+ - 'dsa_switch_for_each_port_safe'
+ - 'dsa_switch_for_each_user_port'
+ - 'dsa_switch_for_each_user_port_continue_reverse'
+ - 'dsa_tree_for_each_cpu_port'
+ - 'dsa_tree_for_each_user_port'
+ - 'dsa_tree_for_each_user_port_continue_reverse'
+ - 'dso__for_each_symbol'
+ - 'elf_hash_for_each_possible'
+ - 'elf_symtab__for_each_symbol'
+ - 'evlist__for_each_cpu'
+ - 'evlist__for_each_entry'
+ - 'evlist__for_each_entry_continue'
+ - 'evlist__for_each_entry_from'
+ - 'evlist__for_each_entry_reverse'
+ - 'evlist__for_each_entry_safe'
+ - 'flow_action_for_each'
+ - 'for_each_acpi_consumer_dev'
+ - 'for_each_acpi_dev_match'
+ - 'for_each_active_dev_scope'
+ - 'for_each_active_drhd_unit'
+ - 'for_each_active_iommu'
+ - 'for_each_active_irq'
+ - 'for_each_active_route'
+ - 'for_each_aggr_pgid'
+ - 'for_each_alloc_capable_rdt_resource'
+ - 'for_each_and_bit'
+ - 'for_each_andnot_bit'
+ - 'for_each_available_child_of_node'
+ - 'for_each_available_child_of_node_scoped'
+ - 'for_each_bench'
+ - 'for_each_bio'
+ - 'for_each_board_func_rsrc'
+ - 'for_each_btf_ext_rec'
+ - 'for_each_btf_ext_sec'
+ - 'for_each_bvec'
+ - 'for_each_capable_rdt_resource'
+ - 'for_each_card_auxs'
+ - 'for_each_card_auxs_safe'
+ - 'for_each_card_components'
+ - 'for_each_card_dapms'
+ - 'for_each_card_pre_auxs'
+ - 'for_each_card_prelinks'
+ - 'for_each_card_rtds'
+ - 'for_each_card_rtds_safe'
+ - 'for_each_card_widgets'
+ - 'for_each_card_widgets_safe'
+ - 'for_each_cgroup_storage_type'
+ - 'for_each_child_of_node'
+ - 'for_each_child_of_node_scoped'
+ - 'for_each_child_of_node_with_prefix'
+ - 'for_each_clear_bit'
+ - 'for_each_clear_bit_from'
+ - 'for_each_clear_bitrange'
+ - 'for_each_clear_bitrange_from'
+ - 'for_each_cmd'
+ - 'for_each_cmsghdr'
+ - 'for_each_collection'
+ - 'for_each_comp_order'
+ - 'for_each_compatible_node'
+ - 'for_each_component_dais'
+ - 'for_each_component_dais_safe'
+ - 'for_each_conduit'
+ - 'for_each_console'
+ - 'for_each_console_srcu'
+ - 'for_each_cpu'
+ - 'for_each_cpu_and'
+ - 'for_each_cpu_andnot'
+ - 'for_each_cpu_from'
+ - 'for_each_cpu_or'
+ - 'for_each_cpu_wrap'
+ - 'for_each_dapm_widgets'
+ - 'for_each_dedup_cand'
+ - 'for_each_dev_addr'
+ - 'for_each_dev_scope'
+ - 'for_each_dma_cap_mask'
+ - 'for_each_dpcm_be'
+ - 'for_each_dpcm_be_rollback'
+ - 'for_each_dpcm_be_safe'
+ - 'for_each_dpcm_fe'
+ - 'for_each_drhd_unit'
+ - 'for_each_dss_dev'
+ - 'for_each_efi_memory_desc'
+ - 'for_each_efi_memory_desc_in_map'
+ - 'for_each_element'
+ - 'for_each_element_extid'
+ - 'for_each_element_id'
+ - 'for_each_enabled_cpu'
+ - 'for_each_endpoint_of_node'
+ - 'for_each_event'
+ - 'for_each_event_tps'
+ - 'for_each_evictable_lru'
+ - 'for_each_fib6_node_rt_rcu'
+ - 'for_each_fib6_walker_rt'
+ - 'for_each_file_lock'
+ - 'for_each_free_mem_pfn_range_in_zone_from'
+ - 'for_each_free_mem_range'
+ - 'for_each_free_mem_range_reverse'
+ - 'for_each_func_rsrc'
+ - 'for_each_gpiochip_node'
+ - 'for_each_group_evsel'
+ - 'for_each_group_evsel_head'
+ - 'for_each_group_member'
+ - 'for_each_group_member_head'
+ - 'for_each_hstate'
+ - 'for_each_hwgpio'
+ - 'for_each_hwgpio_in_range'
+ - 'for_each_if'
+ - 'for_each_inject_fn'
+ - 'for_each_insn'
+ - 'for_each_insn_op_loc'
+ - 'for_each_insn_prefix'
+ - 'for_each_intid'
+ - 'for_each_iommu'
+ - 'for_each_ip_tunnel_rcu'
+ - 'for_each_irq_desc'
+ - 'for_each_irq_nr'
+ - 'for_each_lang'
+ - 'for_each_link_ch_maps'
+ - 'for_each_link_codecs'
+ - 'for_each_link_cpus'
+ - 'for_each_link_platforms'
+ - 'for_each_lru'
+ - 'for_each_matching_node'
+ - 'for_each_matching_node_and_match'
+ - 'for_each_media_entity_data_link'
+ - 'for_each_mem_pfn_range'
+ - 'for_each_mem_range'
+ - 'for_each_mem_range_rev'
+ - 'for_each_mem_region'
+ - 'for_each_member'
+ - 'for_each_memory'
+ - 'for_each_migratetype_order'
+ - 'for_each_missing_reg'
+ - 'for_each_mle_subelement'
+ - 'for_each_mod_mem_type'
+ - 'for_each_mon_capable_rdt_resource'
+ - 'for_each_mp_bvec'
+ - 'for_each_net'
+ - 'for_each_net_continue_reverse'
+ - 'for_each_net_rcu'
+ - 'for_each_netdev'
+ - 'for_each_netdev_continue'
+ - 'for_each_netdev_continue_rcu'
+ - 'for_each_netdev_continue_reverse'
+ - 'for_each_netdev_dump'
+ - 'for_each_netdev_feature'
+ - 'for_each_netdev_in_bond_rcu'
+ - 'for_each_netdev_rcu'
+ - 'for_each_netdev_reverse'
+ - 'for_each_netdev_safe'
+ - 'for_each_new_connector_in_state'
+ - 'for_each_new_crtc_in_state'
+ - 'for_each_new_mst_mgr_in_state'
+ - 'for_each_new_plane_in_state'
+ - 'for_each_new_plane_in_state_reverse'
+ - 'for_each_new_private_obj_in_state'
+ - 'for_each_new_reg'
+ - 'for_each_nhlt_endpoint'
+ - 'for_each_nhlt_endpoint_fmtcfg'
+ - 'for_each_nhlt_fmtcfg'
+ - 'for_each_node'
+ - 'for_each_node_by_name'
+ - 'for_each_node_by_type'
+ - 'for_each_node_mask'
+ - 'for_each_node_numadist'
+ - 'for_each_node_state'
+ - 'for_each_node_with_cpus'
+ - 'for_each_node_with_property'
+ - 'for_each_nonreserved_multicast_dest_pgid'
+ - 'for_each_numa_hop_mask'
+ - 'for_each_of_allnodes'
+ - 'for_each_of_allnodes_from'
+ - 'for_each_of_cpu_node'
+ - 'for_each_of_graph_port'
+ - 'for_each_of_graph_port_endpoint'
+ - 'for_each_of_pci_range'
+ - 'for_each_old_connector_in_state'
+ - 'for_each_old_crtc_in_state'
+ - 'for_each_old_mst_mgr_in_state'
+ - 'for_each_old_plane_in_state'
+ - 'for_each_old_private_obj_in_state'
+ - 'for_each_oldnew_connector_in_state'
+ - 'for_each_oldnew_crtc_in_state'
+ - 'for_each_oldnew_mst_mgr_in_state'
+ - 'for_each_oldnew_plane_in_state'
+ - 'for_each_oldnew_plane_in_state_reverse'
+ - 'for_each_oldnew_private_obj_in_state'
+ - 'for_each_online_cpu'
+ - 'for_each_online_cpu_wrap'
+ - 'for_each_online_node'
+ - 'for_each_online_pgdat'
+ - 'for_each_or_bit'
+ - 'for_each_page_ext'
+ - 'for_each_path'
+ - 'for_each_pci_bridge'
+ - 'for_each_pci_dev'
+ - 'for_each_pcm_streams'
+ - 'for_each_physmem_range'
+ - 'for_each_populated_zone'
+ - 'for_each_possible_cpu'
+ - 'for_each_possible_cpu_wrap'
+ - 'for_each_present_blessed_reg'
+ - 'for_each_present_cpu'
+ - 'for_each_present_section_nr'
+ - 'for_each_prime_number'
+ - 'for_each_prime_number_from'
+ - 'for_each_probe_cache_entry'
+ - 'for_each_process'
+ - 'for_each_process_thread'
+ - 'for_each_prop_codec_conf'
+ - 'for_each_prop_dai_codec'
+ - 'for_each_prop_dai_cpu'
+ - 'for_each_prop_dlc_codecs'
+ - 'for_each_prop_dlc_cpus'
+ - 'for_each_prop_dlc_platforms'
+ - 'for_each_property_of_node'
+ - 'for_each_rdt_resource'
+ - 'for_each_reg'
+ - 'for_each_reg_filtered'
+ - 'for_each_reloc'
+ - 'for_each_reloc_from'
+ - 'for_each_requested_gpio'
+ - 'for_each_requested_gpio_in_range'
+ - 'for_each_reserved_child_of_node'
+ - 'for_each_reserved_mem_range'
+ - 'for_each_reserved_mem_region'
+ - 'for_each_rtd_ch_maps'
+ - 'for_each_rtd_codec_dais'
+ - 'for_each_rtd_components'
+ - 'for_each_rtd_cpu_dais'
+ - 'for_each_rtd_dais'
+ - 'for_each_rtd_dais_reverse'
+ - 'for_each_sband_iftype_data'
+ - 'for_each_script'
+ - 'for_each_sec'
+ - 'for_each_set_bit'
+ - 'for_each_set_bit_from'
+ - 'for_each_set_bit_wrap'
+ - 'for_each_set_bitrange'
+ - 'for_each_set_bitrange_from'
+ - 'for_each_set_clump8'
+ - 'for_each_sg'
+ - 'for_each_sg_dma_page'
+ - 'for_each_sg_page'
+ - 'for_each_sgtable_dma_page'
+ - 'for_each_sgtable_dma_sg'
+ - 'for_each_sgtable_page'
+ - 'for_each_sgtable_sg'
+ - 'for_each_sibling_event'
+ - 'for_each_sta_active_link'
+ - 'for_each_subelement'
+ - 'for_each_subelement_extid'
+ - 'for_each_subelement_id'
+ - 'for_each_sublist'
+ - 'for_each_subsystem'
+ - 'for_each_suite'
+ - 'for_each_supported_activate_fn'
+ - 'for_each_supported_inject_fn'
+ - 'for_each_sym'
+ - 'for_each_thread'
+ - 'for_each_token'
+ - 'for_each_unicast_dest_pgid'
+ - 'for_each_valid_link'
+ - 'for_each_vif_active_link'
+ - 'for_each_vma'
+ - 'for_each_vma_range'
+ - 'for_each_vsi'
+ - 'for_each_wakeup_source'
+ - 'for_each_zone'
+ - 'for_each_zone_zonelist'
+ - 'for_each_zone_zonelist_nodemask'
+ - 'func_for_each_insn'
+ - 'fwnode_for_each_available_child_node'
+ - 'fwnode_for_each_child_node'
+ - 'fwnode_for_each_parent_node'
+ - 'fwnode_graph_for_each_endpoint'
+ - 'gadget_for_each_ep'
+ - 'genradix_for_each'
+ - 'genradix_for_each_from'
+ - 'genradix_for_each_reverse'
+ - 'hash_for_each'
+ - 'hash_for_each_possible'
+ - 'hash_for_each_possible_rcu'
+ - 'hash_for_each_possible_rcu_notrace'
+ - 'hash_for_each_possible_safe'
+ - 'hash_for_each_rcu'
+ - 'hash_for_each_safe'
+ - 'hashmap__for_each_entry'
+ - 'hashmap__for_each_entry_safe'
+ - 'hashmap__for_each_key_entry'
+ - 'hashmap__for_each_key_entry_safe'
+ - 'hctx_for_each_ctx'
+ - 'hists__for_each_format'
+ - 'hists__for_each_sort_list'
+ - 'hlist_bl_for_each_entry'
+ - 'hlist_bl_for_each_entry_rcu'
+ - 'hlist_bl_for_each_entry_safe'
+ - 'hlist_for_each'
+ - 'hlist_for_each_entry'
+ - 'hlist_for_each_entry_continue'
+ - 'hlist_for_each_entry_continue_rcu'
+ - 'hlist_for_each_entry_continue_rcu_bh'
+ - 'hlist_for_each_entry_from'
+ - 'hlist_for_each_entry_from_rcu'
+ - 'hlist_for_each_entry_rcu'
+ - 'hlist_for_each_entry_rcu_bh'
+ - 'hlist_for_each_entry_rcu_notrace'
+ - 'hlist_for_each_entry_safe'
+ - 'hlist_for_each_entry_srcu'
+ - 'hlist_for_each_safe'
+ - 'hlist_nulls_for_each_entry'
+ - 'hlist_nulls_for_each_entry_from'
+ - 'hlist_nulls_for_each_entry_rcu'
+ - 'hlist_nulls_for_each_entry_safe'
+ - 'i3c_bus_for_each_i2cdev'
+ - 'i3c_bus_for_each_i3cdev'
+ - 'idr_for_each_entry'
+ - 'idr_for_each_entry_continue'
+ - 'idr_for_each_entry_continue_ul'
+ - 'idr_for_each_entry_ul'
+ - 'iio_for_each_active_channel'
+ - 'in_dev_for_each_ifa_rcu'
+ - 'in_dev_for_each_ifa_rtnl'
+ - 'in_dev_for_each_ifa_rtnl_net'
+ - 'inet_bind_bucket_for_each'
+ - 'interval_tree_for_each_span'
+ - 'intlist__for_each_entry'
+ - 'intlist__for_each_entry_safe'
+ - 'kcore_copy__for_each_phdr'
+ - 'key_for_each'
+ - 'key_for_each_safe'
+ - 'klp_for_each_func'
+ - 'klp_for_each_func_safe'
+ - 'klp_for_each_func_static'
+ - 'klp_for_each_object'
+ - 'klp_for_each_object_safe'
+ - 'klp_for_each_object_static'
+ - 'kunit_suite_for_each_test_case'
+ - 'kvm_for_each_memslot'
+ - 'kvm_for_each_memslot_in_gfn_range'
+ - 'kvm_for_each_vcpu'
+ - 'libbpf_nla_for_each_attr'
+ - 'list_for_each'
+ - 'list_for_each_codec'
+ - 'list_for_each_codec_safe'
+ - 'list_for_each_continue'
+ - 'list_for_each_entry'
+ - 'list_for_each_entry_continue'
+ - 'list_for_each_entry_continue_rcu'
+ - 'list_for_each_entry_continue_reverse'
+ - 'list_for_each_entry_from'
+ - 'list_for_each_entry_from_rcu'
+ - 'list_for_each_entry_from_reverse'
+ - 'list_for_each_entry_lockless'
+ - 'list_for_each_entry_rcu'
+ - 'list_for_each_entry_reverse'
+ - 'list_for_each_entry_safe'
+ - 'list_for_each_entry_safe_continue'
+ - 'list_for_each_entry_safe_from'
+ - 'list_for_each_entry_safe_reverse'
+ - 'list_for_each_entry_srcu'
+ - 'list_for_each_from'
+ - 'list_for_each_prev'
+ - 'list_for_each_prev_safe'
+ - 'list_for_each_rcu'
+ - 'list_for_each_safe'
+ - 'llist_for_each'
+ - 'llist_for_each_entry'
+ - 'llist_for_each_entry_safe'
+ - 'llist_for_each_safe'
+ - 'lwq_for_each_safe'
+ - 'map__for_each_symbol'
+ - 'map__for_each_symbol_by_name'
+ - 'mas_for_each'
+ - 'mas_for_each_rev'
+ - 'mci_for_each_dimm'
+ - 'media_device_for_each_entity'
+ - 'media_device_for_each_intf'
+ - 'media_device_for_each_link'
+ - 'media_device_for_each_pad'
+ - 'media_entity_for_each_pad'
+ - 'media_pipeline_for_each_entity'
+ - 'media_pipeline_for_each_pad'
+ - 'mlx5_lag_for_each_peer_mdev'
+ - 'mptcp_for_each_subflow'
+ - 'msi_domain_for_each_desc'
+ - 'msi_for_each_desc'
+ - 'mt_for_each'
+ - 'nanddev_io_for_each_block'
+ - 'nanddev_io_for_each_page'
+ - 'neigh_for_each_in_bucket'
+ - 'neigh_for_each_in_bucket_rcu'
+ - 'neigh_for_each_in_bucket_safe'
+ - 'netdev_for_each_lower_dev'
+ - 'netdev_for_each_lower_private'
+ - 'netdev_for_each_lower_private_rcu'
+ - 'netdev_for_each_mc_addr'
+ - 'netdev_for_each_synced_mc_addr'
+ - 'netdev_for_each_synced_uc_addr'
+ - 'netdev_for_each_uc_addr'
+ - 'netdev_for_each_upper_dev_rcu'
+ - 'netdev_hw_addr_list_for_each'
+ - 'nft_rule_for_each_expr'
+ - 'nla_for_each_attr'
+ - 'nla_for_each_attr_type'
+ - 'nla_for_each_nested'
+ - 'nla_for_each_nested_type'
+ - 'nlmsg_for_each_attr'
+ - 'nlmsg_for_each_msg'
+ - 'nr_neigh_for_each'
+ - 'nr_neigh_for_each_safe'
+ - 'nr_node_for_each'
+ - 'nr_node_for_each_safe'
+ - 'of_for_each_phandle'
+ - 'of_property_for_each_string'
+ - 'of_property_for_each_u32'
+ - 'pci_bus_for_each_resource'
+ - 'pci_dev_for_each_resource'
+ - 'pcl_for_each_chunk'
+ - 'pcl_for_each_segment'
+ - 'pcm_for_each_format'
+ - 'perf_config_items__for_each_entry'
+ - 'perf_config_sections__for_each_entry'
+ - 'perf_config_set__for_each_entry'
+ - 'perf_cpu_map__for_each_cpu'
+ - 'perf_cpu_map__for_each_cpu_skip_any'
+ - 'perf_cpu_map__for_each_idx'
+ - 'perf_evlist__for_each_entry'
+ - 'perf_evlist__for_each_entry_reverse'
+ - 'perf_evlist__for_each_entry_safe'
+ - 'perf_evlist__for_each_evsel'
+ - 'perf_evlist__for_each_mmap'
+ - 'perf_evsel_for_each_per_thread_period_safe'
+ - 'perf_hpp_list__for_each_format'
+ - 'perf_hpp_list__for_each_format_safe'
+ - 'perf_hpp_list__for_each_sort_list'
+ - 'perf_hpp_list__for_each_sort_list_safe'
+ - 'plist_for_each'
+ - 'plist_for_each_continue'
+ - 'plist_for_each_entry'
+ - 'plist_for_each_entry_continue'
+ - 'plist_for_each_entry_safe'
+ - 'plist_for_each_safe'
+ - 'pnp_for_each_card'
+ - 'pnp_for_each_dev'
+ - 'protocol_for_each_card'
+ - 'protocol_for_each_dev'
+ - 'queue_for_each_hw_ctx'
+ - 'radix_tree_for_each_slot'
+ - 'radix_tree_for_each_tagged'
+ - 'rb_for_each'
+ - 'rbtree_postorder_for_each_entry_safe'
+ - 'rdma_for_each_block'
+ - 'rdma_for_each_port'
+ - 'rdma_umem_for_each_dma_block'
+ - 'resource_list_for_each_entry'
+ - 'resource_list_for_each_entry_safe'
+ - 'rhl_for_each_entry_rcu'
+ - 'rhl_for_each_rcu'
+ - 'rht_for_each'
+ - 'rht_for_each_entry'
+ - 'rht_for_each_entry_from'
+ - 'rht_for_each_entry_rcu'
+ - 'rht_for_each_entry_rcu_from'
+ - 'rht_for_each_entry_safe'
+ - 'rht_for_each_from'
+ - 'rht_for_each_rcu'
+ - 'rht_for_each_rcu_from'
+ - 'rq_for_each_bvec'
+ - 'rq_for_each_segment'
+ - 'rq_list_for_each'
+ - 'rq_list_for_each_safe'
+ - 'sample_read_group__for_each'
+ - 'scsi_for_each_prot_sg'
+ - 'scsi_for_each_sg'
+ - 'sctp_for_each_hentry'
+ - 'sctp_skb_for_each'
+ - 'sec_for_each_insn'
+ - 'sec_for_each_insn_continue'
+ - 'sec_for_each_insn_from'
+ - 'sec_for_each_sym'
+ - 'shdma_for_each_chan'
+ - 'shost_for_each_device'
+ - 'sk_for_each'
+ - 'sk_for_each_bound'
+ - 'sk_for_each_bound_safe'
+ - 'sk_for_each_entry_offset_rcu'
+ - 'sk_for_each_from'
+ - 'sk_for_each_rcu'
+ - 'sk_for_each_safe'
+ - 'sk_nulls_for_each'
+ - 'sk_nulls_for_each_from'
+ - 'sk_nulls_for_each_rcu'
+ - 'snd_array_for_each'
+ - 'snd_pcm_group_for_each_entry'
+ - 'snd_soc_dapm_widget_for_each_path'
+ - 'snd_soc_dapm_widget_for_each_path_safe'
+ - 'snd_soc_dapm_widget_for_each_sink_path'
+ - 'snd_soc_dapm_widget_for_each_source_path'
+ - 'sparsebit_for_each_set_range'
+ - 'strlist__for_each_entry'
+ - 'strlist__for_each_entry_safe'
+ - 'sym_for_each_insn'
+ - 'sym_for_each_insn_continue_reverse'
+ - 'symbols__for_each_entry'
+ - 'tb_property_for_each'
+ - 'tcf_act_for_each_action'
+ - 'tcf_exts_for_each_action'
+ - 'test_suite__for_each_test_case'
+ - 'tool_pmu__for_each_event'
+ - 'ttm_bo_lru_for_each_reserved_guarded'
+ - 'ttm_resource_manager_for_each_res'
+ - 'udp_lrpa_for_each_entry_rcu'
+ - 'udp_portaddr_for_each_entry'
+ - 'udp_portaddr_for_each_entry_rcu'
+ - 'usb_hub_for_each_child'
+ - 'v4l2_device_for_each_subdev'
+ - 'v4l2_m2m_for_each_dst_buf'
+ - 'v4l2_m2m_for_each_dst_buf_safe'
+ - 'v4l2_m2m_for_each_src_buf'
+ - 'v4l2_m2m_for_each_src_buf_safe'
+ - 'virtio_device_for_each_vq'
+ - 'vkms_config_for_each_connector'
+ - 'vkms_config_for_each_crtc'
+ - 'vkms_config_for_each_encoder'
+ - 'vkms_config_for_each_plane'
+ - 'vkms_config_connector_for_each_possible_encoder'
+ - 'vkms_config_encoder_for_each_possible_crtc'
+ - 'vkms_config_plane_for_each_possible_crtc'
+ - 'while_for_each_ftrace_op'
+ - 'workloads__for_each'
+ - 'xa_for_each'
+ - 'xa_for_each_marked'
+ - 'xa_for_each_range'
+ - 'xa_for_each_start'
+ - 'xas_for_each'
+ - 'xas_for_each_conflict'
+ - 'xas_for_each_marked'
+ - 'xbc_array_for_each_value'
+ - 'xbc_for_each_key_value'
+ - 'xbc_node_for_each_array_value'
+ - 'xbc_node_for_each_child'
+ - 'xbc_node_for_each_key_value'
+ - 'xbc_node_for_each_subkey'
+ - 'ynl_attr_for_each'
+ - 'ynl_attr_for_each_nested'
+ - 'ynl_attr_for_each_payload'
+ - 'zorro_for_each_dev'
+
+IncludeBlocks: Preserve
+IncludeCategories:
+ - Regex: '.*'
+ Priority: 1
+IncludeIsMainRegex: '(Test)?$'
+IndentCaseLabels: false
+IndentGotoLabels: false
+IndentPPDirectives: None
+IndentWidth: 8
+IndentWrappedFunctionNames: false
+JavaScriptQuotes: Leave
+JavaScriptWrapImports: true
+KeepEmptyLinesAtTheStartOfBlocks: false
+MacroBlockBegin: ''
+MacroBlockEnd: ''
+MaxEmptyLinesToKeep: 1
+NamespaceIndentation: None
+ObjCBinPackProtocolList: Auto
+ObjCBlockIndentWidth: 8
+ObjCSpaceAfterProperty: true
+ObjCSpaceBeforeProtocolList: true
+
+# Taken from git's rules
+PenaltyBreakAssignment: 10
+PenaltyBreakBeforeFirstCallParameter: 30
+PenaltyBreakComment: 10
+PenaltyBreakFirstLessLess: 0
+PenaltyBreakString: 10
+PenaltyExcessCharacter: 100
+PenaltyReturnTypeOnItsOwnLine: 60
+
+PointerAlignment: Right
+ReflowComments: false
+SortIncludes: false
+SortUsingDeclarations: false
+SpaceAfterCStyleCast: false
+SpaceAfterTemplateKeyword: true
+SpaceBeforeAssignmentOperators: true
+SpaceBeforeCtorInitializerColon: true
+SpaceBeforeInheritanceColon: true
+SpaceBeforeParens: ControlStatementsExceptForEachMacros
+SpaceBeforeRangeBasedForLoopColon: true
+SpaceInEmptyParentheses: false
+SpacesBeforeTrailingComments: 1
+SpacesInAngles: false
+SpacesInContainerLiterals: false
+SpacesInCStyleCastParentheses: false
+SpacesInParentheses: false
+SpacesInSquareBrackets: false
+Standard: Cpp03
+TabWidth: 8
+UseTab: Always
+...
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index c501cf84..7ec8cb0f 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -53,6 +53,8 @@ When preparing patches, please follow these guidelines:
- Separate large patches into logical patches
- Patch descriptions must end with your "Signed-off-by" line. This means your
code meets the Developer's certificate of origin, see below.
+- C code should be formatted using clang-format, using the .clang-format
+ configuration file at the root of this repository.
When adding new, large features or tools it is best to discuss the
design on the mailing list prior to submitting the patch.
--
2.50.1
^ permalink raw reply related [flat|nested] 22+ messages in thread
* [RFC PATCH v2] treewide: add .clang-format configuration file
2025-09-28 22:39 [RFC PATCH] treewide: add .clang-format configuration file Rahul Sandhu
@ 2025-09-28 22:48 ` Rahul Sandhu
2025-10-06 16:52 ` Stephen Smalley
0 siblings, 1 reply; 22+ messages in thread
From: Rahul Sandhu @ 2025-09-28 22:48 UTC (permalink / raw)
To: nvraxn; +Cc: selinux
Currently only an RFC.
Add the .clang-format configuration file, taken from the Linux kernel
repository. We don't have any official style guidelines in tree at
present, which makes it a bit unclear how to format C code for new
contributors. As well as this, different parts of the codebase seem to
been formatted with different styles on occasion, so using an automatic
formatter should resolve this.
.clang-format is also read by various editors and tooling for writing C
code. It may also be worth adding an editorconfig file in the future as
well?
It may well also be worth adding a `format` target to the Makefiles, is
that something that would be useful?
A few other things to consider to do in the future:
1. Reformat all existing code. I understand this is a big change, hence
the RFC, but we may as well get all code formatted if we go down
this route; afterall, it's not like this will cause any breaking
changes.
2. Possibly add a CI target to check that all code is formatted as per
the new clang-format configuration? The options `--dry-run` as well
as `-Werror` can be passed to clang-format for this.
Comments/feedback appreciated, thanks.
Signed-off-by: Rahul Sandhu <nvraxn@gmail.com>
---
.clang-format | 130 ++++++++++++++++++++++++++++++++++++++++++++++++
CONTRIBUTING.md | 2 +
2 files changed, 132 insertions(+)
create mode 100644 .clang-format
v2: remove linux kernel ForEachMacros and replace them with ours
diff --git a/.clang-format b/.clang-format
new file mode 100644
index 00000000..35595d87
--- /dev/null
+++ b/.clang-format
@@ -0,0 +1,130 @@
+# SPDX-License-Identifier: GPL-2.0
+#
+# clang-format configuration file. Intended for clang-format >= 11.
+#
+# For more information, see:
+#
+# Documentation/dev-tools/clang-format.rst
+# https://clang.llvm.org/docs/ClangFormat.html
+# https://clang.llvm.org/docs/ClangFormatStyleOptions.html
+#
+---
+AccessModifierOffset: -4
+AlignAfterOpenBracket: Align
+AlignConsecutiveAssignments: false
+AlignConsecutiveDeclarations: false
+AlignEscapedNewlines: Left
+AlignOperands: true
+AlignTrailingComments: false
+AllowAllParametersOfDeclarationOnNextLine: false
+AllowShortBlocksOnASingleLine: false
+AllowShortCaseLabelsOnASingleLine: false
+AllowShortFunctionsOnASingleLine: None
+AllowShortIfStatementsOnASingleLine: false
+AllowShortLoopsOnASingleLine: false
+AlwaysBreakAfterDefinitionReturnType: None
+AlwaysBreakAfterReturnType: None
+AlwaysBreakBeforeMultilineStrings: false
+AlwaysBreakTemplateDeclarations: false
+BinPackArguments: true
+BinPackParameters: true
+BraceWrapping:
+ AfterClass: false
+ AfterControlStatement: false
+ AfterEnum: false
+ AfterFunction: true
+ AfterNamespace: true
+ AfterObjCDeclaration: false
+ AfterStruct: false
+ AfterUnion: false
+ AfterExternBlock: false
+ BeforeCatch: false
+ BeforeElse: false
+ IndentBraces: false
+ SplitEmptyFunction: true
+ SplitEmptyRecord: true
+ SplitEmptyNamespace: true
+BreakBeforeBinaryOperators: None
+BreakBeforeBraces: Custom
+BreakBeforeInheritanceComma: false
+BreakBeforeTernaryOperators: false
+BreakConstructorInitializersBeforeComma: false
+BreakConstructorInitializers: BeforeComma
+BreakAfterJavaFieldAnnotations: false
+BreakStringLiterals: false
+ColumnLimit: 80
+CommentPragmas: '^ IWYU pragma:'
+CompactNamespaces: false
+ConstructorInitializerAllOnOneLineOrOnePerLine: false
+ConstructorInitializerIndentWidth: 8
+ContinuationIndentWidth: 8
+Cpp11BracedListStyle: false
+DerivePointerAlignment: false
+DisableFormat: false
+ExperimentalAutoDetectBinPacking: false
+FixNamespaceComments: false
+
+# Taken from:
+# git grep -h '^#define [^[:space:]]*for_each[^[:space:]]*(' \
+# | sed "s,^#define \([^[:space:]]*for_each[^[:space:]]*\)(.*$, - '\1'," \
+# | LC_ALL=C sort -u
+ForEachMacros:
+ - 'cil_list_for_each'
+ - 'cil_stack_for_each'
+ - 'cil_stack_for_each_starting_at'
+ - 'ebitmap_for_each_bit'
+ - 'ebitmap_for_each_positive_bit'
+
+IncludeBlocks: Preserve
+IncludeCategories:
+ - Regex: '.*'
+ Priority: 1
+IncludeIsMainRegex: '(Test)?$'
+IndentCaseLabels: false
+IndentGotoLabels: false
+IndentPPDirectives: None
+IndentWidth: 8
+IndentWrappedFunctionNames: false
+JavaScriptQuotes: Leave
+JavaScriptWrapImports: true
+KeepEmptyLinesAtTheStartOfBlocks: false
+MacroBlockBegin: ''
+MacroBlockEnd: ''
+MaxEmptyLinesToKeep: 1
+NamespaceIndentation: None
+ObjCBinPackProtocolList: Auto
+ObjCBlockIndentWidth: 8
+ObjCSpaceAfterProperty: true
+ObjCSpaceBeforeProtocolList: true
+
+# Taken from git's rules
+PenaltyBreakAssignment: 10
+PenaltyBreakBeforeFirstCallParameter: 30
+PenaltyBreakComment: 10
+PenaltyBreakFirstLessLess: 0
+PenaltyBreakString: 10
+PenaltyExcessCharacter: 100
+PenaltyReturnTypeOnItsOwnLine: 60
+
+PointerAlignment: Right
+ReflowComments: false
+SortIncludes: false
+SortUsingDeclarations: false
+SpaceAfterCStyleCast: false
+SpaceAfterTemplateKeyword: true
+SpaceBeforeAssignmentOperators: true
+SpaceBeforeCtorInitializerColon: true
+SpaceBeforeInheritanceColon: true
+SpaceBeforeParens: ControlStatementsExceptForEachMacros
+SpaceBeforeRangeBasedForLoopColon: true
+SpaceInEmptyParentheses: false
+SpacesBeforeTrailingComments: 1
+SpacesInAngles: false
+SpacesInContainerLiterals: false
+SpacesInCStyleCastParentheses: false
+SpacesInParentheses: false
+SpacesInSquareBrackets: false
+Standard: Cpp03
+TabWidth: 8
+UseTab: Always
+...
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index c501cf84..7ec8cb0f 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -53,6 +53,8 @@ When preparing patches, please follow these guidelines:
- Separate large patches into logical patches
- Patch descriptions must end with your "Signed-off-by" line. This means your
code meets the Developer's certificate of origin, see below.
+- C code should be formatted using clang-format, using the .clang-format
+ configuration file at the root of this repository.
When adding new, large features or tools it is best to discuss the
design on the mailing list prior to submitting the patch.
--
2.50.1
^ permalink raw reply related [flat|nested] 22+ messages in thread
* Re: [RFC PATCH v2] treewide: add .clang-format configuration file
2025-09-28 22:48 ` [RFC PATCH v2] " Rahul Sandhu
@ 2025-10-06 16:52 ` Stephen Smalley
2025-10-07 6:35 ` Petr Lautrbach
2025-10-08 15:17 ` [RFC PATCH v2] " Kenton Groombridge
0 siblings, 2 replies; 22+ messages in thread
From: Stephen Smalley @ 2025-10-06 16:52 UTC (permalink / raw)
To: Rahul Sandhu; +Cc: selinux
On Sun, Sep 28, 2025 at 6:48 PM Rahul Sandhu <nvraxn@gmail.com> wrote:
>
> Currently only an RFC.
>
> Add the .clang-format configuration file, taken from the Linux kernel
> repository. We don't have any official style guidelines in tree at
> present, which makes it a bit unclear how to format C code for new
> contributors. As well as this, different parts of the codebase seem to
> been formatted with different styles on occasion, so using an automatic
> formatter should resolve this.
>
> .clang-format is also read by various editors and tooling for writing C
> code. It may also be worth adding an editorconfig file in the future as
> well?
Can't hurt.
> It may well also be worth adding a `format` target to the Makefiles, is
> that something that would be useful?
IMHO, yes.
>
> A few other things to consider to do in the future:
> 1. Reformat all existing code. I understand this is a big change, hence
> the RFC, but we may as well get all code formatted if we go down
> this route; afterall, it's not like this will cause any breaking
> changes.
Not opposed but will defer to the distro package maintainers on when
they want to apply such a change since it makes back-porting future
patches more painful for them.
> 2. Possibly add a CI target to check that all code is formatted as per
> the new clang-format configuration? The options `--dry-run` as well
> as `-Werror` can be passed to clang-format for this.
Sounds reasonable too.
>
> Comments/feedback appreciated, thanks.
No strong opinions; would be fine with any standardized coding style.
For comparison, selinux-testsuite has tools/check-syntax which can be
used to check or fix coding style problems for C and perl code, but
I'd be fine with using clang-format here as in the kernel.
> Signed-off-by: Rahul Sandhu <nvraxn@gmail.com>
> ---
> .clang-format | 130 ++++++++++++++++++++++++++++++++++++++++++++++++
> CONTRIBUTING.md | 2 +
> 2 files changed, 132 insertions(+)
> create mode 100644 .clang-format
>
> v2: remove linux kernel ForEachMacros and replace them with ours
>
> diff --git a/.clang-format b/.clang-format
> new file mode 100644
> index 00000000..35595d87
> --- /dev/null
> +++ b/.clang-format
> @@ -0,0 +1,130 @@
> +# SPDX-License-Identifier: GPL-2.0
> +#
> +# clang-format configuration file. Intended for clang-format >= 11.
> +#
> +# For more information, see:
> +#
> +# Documentation/dev-tools/clang-format.rst
> +# https://clang.llvm.org/docs/ClangFormat.html
> +# https://clang.llvm.org/docs/ClangFormatStyleOptions.html
> +#
> +---
> +AccessModifierOffset: -4
> +AlignAfterOpenBracket: Align
> +AlignConsecutiveAssignments: false
> +AlignConsecutiveDeclarations: false
> +AlignEscapedNewlines: Left
> +AlignOperands: true
> +AlignTrailingComments: false
> +AllowAllParametersOfDeclarationOnNextLine: false
> +AllowShortBlocksOnASingleLine: false
> +AllowShortCaseLabelsOnASingleLine: false
> +AllowShortFunctionsOnASingleLine: None
> +AllowShortIfStatementsOnASingleLine: false
> +AllowShortLoopsOnASingleLine: false
> +AlwaysBreakAfterDefinitionReturnType: None
> +AlwaysBreakAfterReturnType: None
> +AlwaysBreakBeforeMultilineStrings: false
> +AlwaysBreakTemplateDeclarations: false
> +BinPackArguments: true
> +BinPackParameters: true
> +BraceWrapping:
> + AfterClass: false
> + AfterControlStatement: false
> + AfterEnum: false
> + AfterFunction: true
> + AfterNamespace: true
> + AfterObjCDeclaration: false
> + AfterStruct: false
> + AfterUnion: false
> + AfterExternBlock: false
> + BeforeCatch: false
> + BeforeElse: false
> + IndentBraces: false
> + SplitEmptyFunction: true
> + SplitEmptyRecord: true
> + SplitEmptyNamespace: true
> +BreakBeforeBinaryOperators: None
> +BreakBeforeBraces: Custom
> +BreakBeforeInheritanceComma: false
> +BreakBeforeTernaryOperators: false
> +BreakConstructorInitializersBeforeComma: false
> +BreakConstructorInitializers: BeforeComma
> +BreakAfterJavaFieldAnnotations: false
> +BreakStringLiterals: false
> +ColumnLimit: 80
> +CommentPragmas: '^ IWYU pragma:'
> +CompactNamespaces: false
> +ConstructorInitializerAllOnOneLineOrOnePerLine: false
> +ConstructorInitializerIndentWidth: 8
> +ContinuationIndentWidth: 8
> +Cpp11BracedListStyle: false
> +DerivePointerAlignment: false
> +DisableFormat: false
> +ExperimentalAutoDetectBinPacking: false
> +FixNamespaceComments: false
> +
> +# Taken from:
> +# git grep -h '^#define [^[:space:]]*for_each[^[:space:]]*(' \
> +# | sed "s,^#define \([^[:space:]]*for_each[^[:space:]]*\)(.*$, - '\1'," \
> +# | LC_ALL=C sort -u
> +ForEachMacros:
> + - 'cil_list_for_each'
> + - 'cil_stack_for_each'
> + - 'cil_stack_for_each_starting_at'
> + - 'ebitmap_for_each_bit'
> + - 'ebitmap_for_each_positive_bit'
> +
> +IncludeBlocks: Preserve
> +IncludeCategories:
> + - Regex: '.*'
> + Priority: 1
> +IncludeIsMainRegex: '(Test)?$'
> +IndentCaseLabels: false
> +IndentGotoLabels: false
> +IndentPPDirectives: None
> +IndentWidth: 8
> +IndentWrappedFunctionNames: false
> +JavaScriptQuotes: Leave
> +JavaScriptWrapImports: true
> +KeepEmptyLinesAtTheStartOfBlocks: false
> +MacroBlockBegin: ''
> +MacroBlockEnd: ''
> +MaxEmptyLinesToKeep: 1
> +NamespaceIndentation: None
> +ObjCBinPackProtocolList: Auto
> +ObjCBlockIndentWidth: 8
> +ObjCSpaceAfterProperty: true
> +ObjCSpaceBeforeProtocolList: true
> +
> +# Taken from git's rules
> +PenaltyBreakAssignment: 10
> +PenaltyBreakBeforeFirstCallParameter: 30
> +PenaltyBreakComment: 10
> +PenaltyBreakFirstLessLess: 0
> +PenaltyBreakString: 10
> +PenaltyExcessCharacter: 100
> +PenaltyReturnTypeOnItsOwnLine: 60
> +
> +PointerAlignment: Right
> +ReflowComments: false
> +SortIncludes: false
> +SortUsingDeclarations: false
> +SpaceAfterCStyleCast: false
> +SpaceAfterTemplateKeyword: true
> +SpaceBeforeAssignmentOperators: true
> +SpaceBeforeCtorInitializerColon: true
> +SpaceBeforeInheritanceColon: true
> +SpaceBeforeParens: ControlStatementsExceptForEachMacros
> +SpaceBeforeRangeBasedForLoopColon: true
> +SpaceInEmptyParentheses: false
> +SpacesBeforeTrailingComments: 1
> +SpacesInAngles: false
> +SpacesInContainerLiterals: false
> +SpacesInCStyleCastParentheses: false
> +SpacesInParentheses: false
> +SpacesInSquareBrackets: false
> +Standard: Cpp03
> +TabWidth: 8
> +UseTab: Always
> +...
> diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
> index c501cf84..7ec8cb0f 100644
> --- a/CONTRIBUTING.md
> +++ b/CONTRIBUTING.md
> @@ -53,6 +53,8 @@ When preparing patches, please follow these guidelines:
> - Separate large patches into logical patches
> - Patch descriptions must end with your "Signed-off-by" line. This means your
> code meets the Developer's certificate of origin, see below.
> +- C code should be formatted using clang-format, using the .clang-format
> + configuration file at the root of this repository.
>
> When adding new, large features or tools it is best to discuss the
> design on the mailing list prior to submitting the patch.
> --
> 2.50.1
>
>
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [RFC PATCH v2] treewide: add .clang-format configuration file
2025-10-06 16:52 ` Stephen Smalley
@ 2025-10-07 6:35 ` Petr Lautrbach
2025-10-07 10:46 ` [PATCH v3] " Rahul Sandhu
2025-10-08 15:17 ` [RFC PATCH v2] " Kenton Groombridge
1 sibling, 1 reply; 22+ messages in thread
From: Petr Lautrbach @ 2025-10-07 6:35 UTC (permalink / raw)
To: Stephen Smalley, Rahul Sandhu; +Cc: selinux
Stephen Smalley <stephen.smalley.work@gmail.com> writes:
> On Sun, Sep 28, 2025 at 6:48 PM Rahul Sandhu <nvraxn@gmail.com> wrote:
>>
>> Currently only an RFC.
>>
>> Add the .clang-format configuration file, taken from the Linux kernel
>> repository. We don't have any official style guidelines in tree at
>> present, which makes it a bit unclear how to format C code for new
>> contributors. As well as this, different parts of the codebase seem to
>> been formatted with different styles on occasion, so using an automatic
>> formatter should resolve this.
>>
>> .clang-format is also read by various editors and tooling for writing C
>> code. It may also be worth adding an editorconfig file in the future as
>> well?
>
> Can't hurt.
>
>> It may well also be worth adding a `format` target to the Makefiles, is
>> that something that would be useful?
>
> IMHO, yes.
>
>>
>> A few other things to consider to do in the future:
>> 1. Reformat all existing code. I understand this is a big change, hence
>> the RFC, but we may as well get all code formatted if we go down
>> this route; afterall, it's not like this will cause any breaking
>> changes.
>
> Not opposed but will defer to the distro package maintainers on when
> they want to apply such a change since it makes back-porting future
> patches more painful for them.
As a Fedora and RHEL maintainer, this might be annoying in the short
term, but I see it as an improvement in the long term.
If it's well-documented, with configuration files and a helper script
for formatting/checking available, and CI is set up, I would not be
opposed to this.
>> 2. Possibly add a CI target to check that all code is formatted as per
>> the new clang-format configuration? The options `--dry-run` as well
>> as `-Werror` can be passed to clang-format for this.
>
> Sounds reasonable too.
>
>>
>> Comments/feedback appreciated, thanks.
>
> No strong opinions; would be fine with any standardized coding style.
> For comparison, selinux-testsuite has tools/check-syntax which can be
> used to check or fix coding style problems for C and perl code, but
> I'd be fine with using clang-format here as in the kernel.
>
>> Signed-off-by: Rahul Sandhu <nvraxn@gmail.com>
>> ---
>> .clang-format | 130 ++++++++++++++++++++++++++++++++++++++++++++++++
>> CONTRIBUTING.md | 2 +
>> 2 files changed, 132 insertions(+)
>> create mode 100644 .clang-format
>>
>> v2: remove linux kernel ForEachMacros and replace them with ours
>>
>> diff --git a/.clang-format b/.clang-format
>> new file mode 100644
>> index 00000000..35595d87
>> --- /dev/null
>> +++ b/.clang-format
>> @@ -0,0 +1,130 @@
>> +# SPDX-License-Identifier: GPL-2.0
>> +#
>> +# clang-format configuration file. Intended for clang-format >= 11.
>> +#
>> +# For more information, see:
>> +#
>> +# Documentation/dev-tools/clang-format.rst
>> +# https://clang.llvm.org/docs/ClangFormat.html
>> +# https://clang.llvm.org/docs/ClangFormatStyleOptions.html
>> +#
>> +---
>> +AccessModifierOffset: -4
>> +AlignAfterOpenBracket: Align
>> +AlignConsecutiveAssignments: false
>> +AlignConsecutiveDeclarations: false
>> +AlignEscapedNewlines: Left
>> +AlignOperands: true
>> +AlignTrailingComments: false
>> +AllowAllParametersOfDeclarationOnNextLine: false
>> +AllowShortBlocksOnASingleLine: false
>> +AllowShortCaseLabelsOnASingleLine: false
>> +AllowShortFunctionsOnASingleLine: None
>> +AllowShortIfStatementsOnASingleLine: false
>> +AllowShortLoopsOnASingleLine: false
>> +AlwaysBreakAfterDefinitionReturnType: None
>> +AlwaysBreakAfterReturnType: None
>> +AlwaysBreakBeforeMultilineStrings: false
>> +AlwaysBreakTemplateDeclarations: false
>> +BinPackArguments: true
>> +BinPackParameters: true
>> +BraceWrapping:
>> + AfterClass: false
>> + AfterControlStatement: false
>> + AfterEnum: false
>> + AfterFunction: true
>> + AfterNamespace: true
>> + AfterObjCDeclaration: false
>> + AfterStruct: false
>> + AfterUnion: false
>> + AfterExternBlock: false
>> + BeforeCatch: false
>> + BeforeElse: false
>> + IndentBraces: false
>> + SplitEmptyFunction: true
>> + SplitEmptyRecord: true
>> + SplitEmptyNamespace: true
>> +BreakBeforeBinaryOperators: None
>> +BreakBeforeBraces: Custom
>> +BreakBeforeInheritanceComma: false
>> +BreakBeforeTernaryOperators: false
>> +BreakConstructorInitializersBeforeComma: false
>> +BreakConstructorInitializers: BeforeComma
>> +BreakAfterJavaFieldAnnotations: false
>> +BreakStringLiterals: false
>> +ColumnLimit: 80
>> +CommentPragmas: '^ IWYU pragma:'
>> +CompactNamespaces: false
>> +ConstructorInitializerAllOnOneLineOrOnePerLine: false
>> +ConstructorInitializerIndentWidth: 8
>> +ContinuationIndentWidth: 8
>> +Cpp11BracedListStyle: false
>> +DerivePointerAlignment: false
>> +DisableFormat: false
>> +ExperimentalAutoDetectBinPacking: false
>> +FixNamespaceComments: false
>> +
>> +# Taken from:
>> +# git grep -h '^#define [^[:space:]]*for_each[^[:space:]]*(' \
>> +# | sed "s,^#define \([^[:space:]]*for_each[^[:space:]]*\)(.*$, - '\1'," \
>> +# | LC_ALL=C sort -u
>> +ForEachMacros:
>> + - 'cil_list_for_each'
>> + - 'cil_stack_for_each'
>> + - 'cil_stack_for_each_starting_at'
>> + - 'ebitmap_for_each_bit'
>> + - 'ebitmap_for_each_positive_bit'
>> +
>> +IncludeBlocks: Preserve
>> +IncludeCategories:
>> + - Regex: '.*'
>> + Priority: 1
>> +IncludeIsMainRegex: '(Test)?$'
>> +IndentCaseLabels: false
>> +IndentGotoLabels: false
>> +IndentPPDirectives: None
>> +IndentWidth: 8
>> +IndentWrappedFunctionNames: false
>> +JavaScriptQuotes: Leave
>> +JavaScriptWrapImports: true
>> +KeepEmptyLinesAtTheStartOfBlocks: false
>> +MacroBlockBegin: ''
>> +MacroBlockEnd: ''
>> +MaxEmptyLinesToKeep: 1
>> +NamespaceIndentation: None
>> +ObjCBinPackProtocolList: Auto
>> +ObjCBlockIndentWidth: 8
>> +ObjCSpaceAfterProperty: true
>> +ObjCSpaceBeforeProtocolList: true
>> +
>> +# Taken from git's rules
>> +PenaltyBreakAssignment: 10
>> +PenaltyBreakBeforeFirstCallParameter: 30
>> +PenaltyBreakComment: 10
>> +PenaltyBreakFirstLessLess: 0
>> +PenaltyBreakString: 10
>> +PenaltyExcessCharacter: 100
>> +PenaltyReturnTypeOnItsOwnLine: 60
>> +
>> +PointerAlignment: Right
>> +ReflowComments: false
>> +SortIncludes: false
>> +SortUsingDeclarations: false
>> +SpaceAfterCStyleCast: false
>> +SpaceAfterTemplateKeyword: true
>> +SpaceBeforeAssignmentOperators: true
>> +SpaceBeforeCtorInitializerColon: true
>> +SpaceBeforeInheritanceColon: true
>> +SpaceBeforeParens: ControlStatementsExceptForEachMacros
>> +SpaceBeforeRangeBasedForLoopColon: true
>> +SpaceInEmptyParentheses: false
>> +SpacesBeforeTrailingComments: 1
>> +SpacesInAngles: false
>> +SpacesInContainerLiterals: false
>> +SpacesInCStyleCastParentheses: false
>> +SpacesInParentheses: false
>> +SpacesInSquareBrackets: false
>> +Standard: Cpp03
>> +TabWidth: 8
>> +UseTab: Always
>> +...
>> diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
>> index c501cf84..7ec8cb0f 100644
>> --- a/CONTRIBUTING.md
>> +++ b/CONTRIBUTING.md
>> @@ -53,6 +53,8 @@ When preparing patches, please follow these guidelines:
>> - Separate large patches into logical patches
>> - Patch descriptions must end with your "Signed-off-by" line. This means your
>> code meets the Developer's certificate of origin, see below.
>> +- C code should be formatted using clang-format, using the .clang-format
>> + configuration file at the root of this repository.
>>
>> When adding new, large features or tools it is best to discuss the
>> design on the mailing list prior to submitting the patch.
>> --
>> 2.50.1
>>
>>
^ permalink raw reply [flat|nested] 22+ messages in thread
* [PATCH v3] treewide: add .clang-format configuration file
2025-10-07 6:35 ` Petr Lautrbach
@ 2025-10-07 10:46 ` Rahul Sandhu
2025-10-07 11:07 ` Rahul Sandhu
2025-10-07 13:21 ` Stephen Smalley
0 siblings, 2 replies; 22+ messages in thread
From: Rahul Sandhu @ 2025-10-07 10:46 UTC (permalink / raw)
To: lautrbach; +Cc: nvraxn, selinux, stephen.smalley.work
Currently only an RFC.
Add the .clang-format configuration file, taken from the Linux kernel
repository. We don't have any official style guidelines in tree at
present, which makes it a bit unclear how to format C code for new
contributors. As well as this, different parts of the codebase seem to
been formatted with different styles on occasion, so using an automatic
formatter should resolve this.
As well as this, replace all the existing indent targets with format
targets. Commands used to find and replace those targets:
git grep -l -E '(\.\./)*scripts/Lindent' | xargs sed -i -E 's@(\.\./)*scripts/Lindent@clang-format -i@g'
git grep -l 'indent' -- '*Makefile' | xargs sed -i 's/indent/format/g'
Also add some empty format targets to Makefiles that previously were
missing an indent target so that `make format` does not error.
A few other things to consider to do in the future:
1. Reformat all existing code. I understand this is a big change, hence
the RFC, but we may as well get all code formatted if we go down
this route; afterall, it's not like this will cause any breaking
changes.
2. Possibly add a CI target to check that all code is formatted as per
the new clang-format configuration? The options `--dry-run` as well
as `-Werror` can be passed to clang-format for this.
Comments/feedback appreciated, thanks.
Signed-off-by: Rahul Sandhu <nvraxn@gmail.com>
---
.clang-format | 130 +++++++++++++++++++++++
CONTRIBUTING.md | 2 +
Makefile | 2 +-
checkpolicy/Makefile | 4 +-
dbus/Makefile | 2 +
gui/Makefile | 2 +-
libselinux/Makefile | 2 +-
libselinux/include/Makefile | 4 +-
libselinux/man/Makefile | 2 +-
libselinux/src/Makefile | 4 +-
libselinux/utils/Makefile | 4 +-
libsemanage/Makefile | 2 +-
libsemanage/include/Makefile | 4 +-
libsemanage/src/Makefile | 4 +-
libsemanage/utils/Makefile | 2 +-
libsepol/Makefile | 2 +-
libsepol/include/Makefile | 4 +-
libsepol/src/Makefile | 4 +-
libsepol/utils/Makefile | 4 +-
mcstrans/Makefile | 2 +
policycoreutils/Makefile | 2 +-
policycoreutils/hll/Makefile | 2 +-
policycoreutils/hll/pp/Makefile | 4 +-
policycoreutils/load_policy/Makefile | 4 +-
policycoreutils/man/Makefile | 2 +
policycoreutils/newrole/Makefile | 4 +-
policycoreutils/po/Makefile | 2 +
policycoreutils/run_init/Makefile | 4 +-
policycoreutils/scripts/Makefile | 2 +-
policycoreutils/secon/Makefile | 4 +-
policycoreutils/semodule/Makefile | 4 +-
policycoreutils/sestatus/Makefile | 4 +-
policycoreutils/setfiles/Makefile | 4 +-
policycoreutils/setsebool/Makefile | 4 +-
policycoreutils/unsetfiles/Makefile | 4 +-
python/Makefile | 2 +-
python/audit2allow/Makefile | 4 +-
python/chcat/Makefile | 2 +-
python/po/Makefile | 2 +
python/semanage/Makefile | 2 +-
python/sepolgen/Makefile | 2 +-
python/sepolgen/src/Makefile | 2 +-
python/sepolicy/Makefile | 2 +
restorecond/Makefile | 4 +-
sandbox/Makefile | 4 +-
scripts/Lindent | 18 ----
secilc/Makefile | 2 +
semodule-utils/Makefile | 2 +-
semodule-utils/semodule_expand/Makefile | 4 +-
semodule-utils/semodule_link/Makefile | 4 +-
semodule-utils/semodule_package/Makefile | 4 +-
51 files changed, 212 insertions(+), 84 deletions(-)
create mode 100644 .clang-format
delete mode 100755 scripts/Lindent
v2: remove linux kernel ForEachMacros and replace them with ours
v3: replace the indent target with the new format target. also remove any
mention of `.editorconfig` from the commit message; those changes are
better suited for another patch (they're small and self-contained enough
that they're a smaller thing to merge).
diff --git a/.clang-format b/.clang-format
new file mode 100644
index 00000000..35595d87
--- /dev/null
+++ b/.clang-format
@@ -0,0 +1,130 @@
+# SPDX-License-Identifier: GPL-2.0
+#
+# clang-format configuration file. Intended for clang-format >= 11.
+#
+# For more information, see:
+#
+# Documentation/dev-tools/clang-format.rst
+# https://clang.llvm.org/docs/ClangFormat.html
+# https://clang.llvm.org/docs/ClangFormatStyleOptions.html
+#
+---
+AccessModifierOffset: -4
+AlignAfterOpenBracket: Align
+AlignConsecutiveAssignments: false
+AlignConsecutiveDeclarations: false
+AlignEscapedNewlines: Left
+AlignOperands: true
+AlignTrailingComments: false
+AllowAllParametersOfDeclarationOnNextLine: false
+AllowShortBlocksOnASingleLine: false
+AllowShortCaseLabelsOnASingleLine: false
+AllowShortFunctionsOnASingleLine: None
+AllowShortIfStatementsOnASingleLine: false
+AllowShortLoopsOnASingleLine: false
+AlwaysBreakAfterDefinitionReturnType: None
+AlwaysBreakAfterReturnType: None
+AlwaysBreakBeforeMultilineStrings: false
+AlwaysBreakTemplateDeclarations: false
+BinPackArguments: true
+BinPackParameters: true
+BraceWrapping:
+ AfterClass: false
+ AfterControlStatement: false
+ AfterEnum: false
+ AfterFunction: true
+ AfterNamespace: true
+ AfterObjCDeclaration: false
+ AfterStruct: false
+ AfterUnion: false
+ AfterExternBlock: false
+ BeforeCatch: false
+ BeforeElse: false
+ IndentBraces: false
+ SplitEmptyFunction: true
+ SplitEmptyRecord: true
+ SplitEmptyNamespace: true
+BreakBeforeBinaryOperators: None
+BreakBeforeBraces: Custom
+BreakBeforeInheritanceComma: false
+BreakBeforeTernaryOperators: false
+BreakConstructorInitializersBeforeComma: false
+BreakConstructorInitializers: BeforeComma
+BreakAfterJavaFieldAnnotations: false
+BreakStringLiterals: false
+ColumnLimit: 80
+CommentPragmas: '^ IWYU pragma:'
+CompactNamespaces: false
+ConstructorInitializerAllOnOneLineOrOnePerLine: false
+ConstructorInitializerIndentWidth: 8
+ContinuationIndentWidth: 8
+Cpp11BracedListStyle: false
+DerivePointerAlignment: false
+DisableFormat: false
+ExperimentalAutoDetectBinPacking: false
+FixNamespaceComments: false
+
+# Taken from:
+# git grep -h '^#define [^[:space:]]*for_each[^[:space:]]*(' \
+# | sed "s,^#define \([^[:space:]]*for_each[^[:space:]]*\)(.*$, - '\1'," \
+# | LC_ALL=C sort -u
+ForEachMacros:
+ - 'cil_list_for_each'
+ - 'cil_stack_for_each'
+ - 'cil_stack_for_each_starting_at'
+ - 'ebitmap_for_each_bit'
+ - 'ebitmap_for_each_positive_bit'
+
+IncludeBlocks: Preserve
+IncludeCategories:
+ - Regex: '.*'
+ Priority: 1
+IncludeIsMainRegex: '(Test)?$'
+IndentCaseLabels: false
+IndentGotoLabels: false
+IndentPPDirectives: None
+IndentWidth: 8
+IndentWrappedFunctionNames: false
+JavaScriptQuotes: Leave
+JavaScriptWrapImports: true
+KeepEmptyLinesAtTheStartOfBlocks: false
+MacroBlockBegin: ''
+MacroBlockEnd: ''
+MaxEmptyLinesToKeep: 1
+NamespaceIndentation: None
+ObjCBinPackProtocolList: Auto
+ObjCBlockIndentWidth: 8
+ObjCSpaceAfterProperty: true
+ObjCSpaceBeforeProtocolList: true
+
+# Taken from git's rules
+PenaltyBreakAssignment: 10
+PenaltyBreakBeforeFirstCallParameter: 30
+PenaltyBreakComment: 10
+PenaltyBreakFirstLessLess: 0
+PenaltyBreakString: 10
+PenaltyExcessCharacter: 100
+PenaltyReturnTypeOnItsOwnLine: 60
+
+PointerAlignment: Right
+ReflowComments: false
+SortIncludes: false
+SortUsingDeclarations: false
+SpaceAfterCStyleCast: false
+SpaceAfterTemplateKeyword: true
+SpaceBeforeAssignmentOperators: true
+SpaceBeforeCtorInitializerColon: true
+SpaceBeforeInheritanceColon: true
+SpaceBeforeParens: ControlStatementsExceptForEachMacros
+SpaceBeforeRangeBasedForLoopColon: true
+SpaceInEmptyParentheses: false
+SpacesBeforeTrailingComments: 1
+SpacesInAngles: false
+SpacesInContainerLiterals: false
+SpacesInCStyleCastParentheses: false
+SpacesInParentheses: false
+SpacesInSquareBrackets: false
+Standard: Cpp03
+TabWidth: 8
+UseTab: Always
+...
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index c501cf84..7ec8cb0f 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -53,6 +53,8 @@ When preparing patches, please follow these guidelines:
- Separate large patches into logical patches
- Patch descriptions must end with your "Signed-off-by" line. This means your
code meets the Developer's certificate of origin, see below.
+- C code should be formatted using clang-format, using the .clang-format
+ configuration file at the root of this repository.
When adding new, large features or tools it is best to discuss the
design on the mailing list prior to submitting the patch.
diff --git a/Makefile b/Makefile
index 2ffba8e9..db065aa4 100644
--- a/Makefile
+++ b/Makefile
@@ -36,7 +36,7 @@ ifneq ($(DESTDIR),)
export LIBSEPOLA
endif
-all install relabel clean test indent:
+all install relabel clean test format:
@for subdir in $(SUBDIRS); do \
(cd $$subdir && $(MAKE) $@) || exit 1; \
done
diff --git a/checkpolicy/Makefile b/checkpolicy/Makefile
index 6e8008e3..edc5a30e 100644
--- a/checkpolicy/Makefile
+++ b/checkpolicy/Makefile
@@ -78,5 +78,5 @@ clean:
-rm -f $(TARGETS) $(CHECKPOLOBJS) $(CHECKMODOBJS) y.tab.c y.tab.h lex.yy.c tests/testpol.conf tests/testpol.bin
$(MAKE) -C test clean
-indent:
- ../scripts/Lindent $(filter-out $(GENERATED),$(wildcard *.[ch]))
+format:
+ clang-format -i $(filter-out $(GENERATED),$(wildcard *.[ch]))
diff --git a/dbus/Makefile b/dbus/Makefile
index 53143aff..a6d77d6e 100644
--- a/dbus/Makefile
+++ b/dbus/Makefile
@@ -16,4 +16,6 @@ install:
relabel:
+format:
+
test:
diff --git a/gui/Makefile b/gui/Makefile
index b29610d4..9ffa3604 100644
--- a/gui/Makefile
+++ b/gui/Makefile
@@ -60,7 +60,7 @@ install: all
clean:
(cd po && $(MAKE) $@)
-indent:
+format:
relabel:
diff --git a/libselinux/Makefile b/libselinux/Makefile
index a50b6491..e863e2e5 100644
--- a/libselinux/Makefile
+++ b/libselinux/Makefile
@@ -50,7 +50,7 @@ COMPILER := clang
endif
export COMPILER
-all install relabel clean distclean indent:
+all install relabel clean distclean format:
@for subdir in $(SUBDIRS); do \
(cd $$subdir && $(MAKE) $@) || exit 1; \
done
diff --git a/libselinux/include/Makefile b/libselinux/include/Makefile
index 8ab9ce92..0ff28d1d 100644
--- a/libselinux/include/Makefile
+++ b/libselinux/include/Makefile
@@ -10,8 +10,8 @@ install: all
relabel:
-indent:
- ../../scripts/Lindent $(wildcard selinux/*.h)
+format:
+ clang-format -i $(wildcard selinux/*.h)
distclean clean:
-rm -f selinux/*~
diff --git a/libselinux/man/Makefile b/libselinux/man/Makefile
index fdc0825f..42b1662a 100644
--- a/libselinux/man/Makefile
+++ b/libselinux/man/Makefile
@@ -35,4 +35,4 @@ install: all
relabel:
-indent distclean clean:
+format distclean clean:
diff --git a/libselinux/src/Makefile b/libselinux/src/Makefile
index 261c22d4..55520025 100644
--- a/libselinux/src/Makefile
+++ b/libselinux/src/Makefile
@@ -223,7 +223,7 @@ clean: clean-pywrap clean-rubywrap
distclean: clean
rm -f $(GENERATED) $(SWIGFILES)
-indent:
- ../../scripts/Lindent $(filter-out $(GENERATED),$(wildcard *.[ch]))
+format:
+ clang-format -i $(filter-out $(GENERATED),$(wildcard *.[ch]))
.PHONY: all clean clean-pywrap clean-rubywrap pywrap rubywrap swigify install install-pywrap install-rubywrap distclean
diff --git a/libselinux/utils/Makefile b/libselinux/utils/Makefile
index 6b1dc7c9..5213de8e 100644
--- a/libselinux/utils/Makefile
+++ b/libselinux/utils/Makefile
@@ -72,8 +72,8 @@ clean:
distclean: clean
-indent:
- ../../scripts/Lindent $(wildcard *.[ch])
+format:
+ clang-format -i $(wildcard *.[ch])
relabel:
diff --git a/libsemanage/Makefile b/libsemanage/Makefile
index dbd240da..e363cdde 100644
--- a/libsemanage/Makefile
+++ b/libsemanage/Makefile
@@ -29,7 +29,7 @@ clean distclean:
$(MAKE) -C src $@
$(MAKE) -C tests $@
-indent:
+format:
$(MAKE) -C src $@
$(MAKE) -C include $@
diff --git a/libsemanage/include/Makefile b/libsemanage/include/Makefile
index 6e44a28a..b2c195c5 100644
--- a/libsemanage/include/Makefile
+++ b/libsemanage/include/Makefile
@@ -8,5 +8,5 @@ install: all
test -d $(DESTDIR)$(INCDIR) || install -m 755 -d $(DESTDIR)$(INCDIR)
install -m 644 $(wildcard semanage/*.h) $(DESTDIR)$(INCDIR)
-indent:
- ../../scripts/Lindent $(wildcard semanage/*.h)
+format:
+ clang-format -i $(wildcard semanage/*.h)
diff --git a/libsemanage/src/Makefile b/libsemanage/src/Makefile
index fa3449fb..f2d8e634 100644
--- a/libsemanage/src/Makefile
+++ b/libsemanage/src/Makefile
@@ -167,7 +167,7 @@ clean:
distclean: clean
rm -f $(GENERATED) $(SWIGFILES)
-indent:
- ../../scripts/Lindent $(filter-out $(GENERATED),$(wildcard *.[ch]))
+format:
+ clang-format -i $(filter-out $(GENERATED),$(wildcard *.[ch]))
.PHONY: all clean pywrap rubywrap swigify install install-pywrap install-rubywrap distclean
diff --git a/libsemanage/utils/Makefile b/libsemanage/utils/Makefile
index 5b8fbb6b..94d576d9 100644
--- a/libsemanage/utils/Makefile
+++ b/libsemanage/utils/Makefile
@@ -13,7 +13,7 @@ clean:
distclean: clean
-indent:
+format:
relabel:
diff --git a/libsepol/Makefile b/libsepol/Makefile
index 5b5d03e2..2af93ace 100644
--- a/libsepol/Makefile
+++ b/libsepol/Makefile
@@ -20,7 +20,7 @@ clean:
$(MAKE) -C utils clean
$(MAKE) -C tests clean
-indent:
+format:
$(MAKE) -C src $@
$(MAKE) -C include $@
$(MAKE) -C utils $@
diff --git a/libsepol/include/Makefile b/libsepol/include/Makefile
index 1ad4ecab..fa8a96d6 100644
--- a/libsepol/include/Makefile
+++ b/libsepol/include/Makefile
@@ -13,5 +13,5 @@ install: all
install -m 644 $(wildcard sepol/policydb/*.h) $(DESTDIR)$(INCDIR)/policydb
install -m 644 $(wildcard $(CILDIR)/include/cil/*.h) $(DESTDIR)$(INCDIR)/cil
-indent:
- ../../scripts/Lindent $(wildcard sepol/*.h)
+format:
+ clang-format -i $(wildcard sepol/*.h)
diff --git a/libsepol/src/Makefile b/libsepol/src/Makefile
index a1aed072..86404f4b 100644
--- a/libsepol/src/Makefile
+++ b/libsepol/src/Makefile
@@ -104,6 +104,6 @@ relabel:
clean:
-rm -f $(LIBPC) $(LIBMAP) $(OBJS) $(LOBJS) $(LIBA) $(LIBSO) $(TARGET) $(CIL_GENERATED)
-indent:
- ../../scripts/Lindent $(wildcard *.[ch])
+format:
+ clang-format -i $(wildcard *.[ch])
diff --git a/libsepol/utils/Makefile b/libsepol/utils/Makefile
index 31932c11..0824f64f 100644
--- a/libsepol/utils/Makefile
+++ b/libsepol/utils/Makefile
@@ -18,8 +18,8 @@ install: all
clean:
-rm -f $(TARGETS) *.o
-indent:
- ../../scripts/Lindent $(wildcard *.[ch])
+format:
+ clang-format -i $(wildcard *.[ch])
relabel:
diff --git a/mcstrans/Makefile b/mcstrans/Makefile
index b20279ab..28d8c7bc 100644
--- a/mcstrans/Makefile
+++ b/mcstrans/Makefile
@@ -21,4 +21,6 @@ clean:
relabel:
+format:
+
test:
diff --git a/policycoreutils/Makefile b/policycoreutils/Makefile
index 7c9706e3..212fbf22 100644
--- a/policycoreutils/Makefile
+++ b/policycoreutils/Makefile
@@ -6,7 +6,7 @@ LIBSELINUX_LDLIBS := $(shell PKG_CONFIG_PATH="$(PKG_CONFIG_PATH):../libselinux/s
LIBSEMANAGE_LDLIBS := $(shell PKG_CONFIG_PATH="$(PKG_CONFIG_PATH):../libsemanage/src" $(PKG_CONFIG) --libs libsemanage)
export LIBSELINUX_LDLIBS LIBSEMANAGE_LDLIBS
-all install relabel clean indent:
+all install relabel clean format:
@for subdir in $(SUBDIRS); do \
(cd $$subdir && $(MAKE) $@) || exit 1; \
done
diff --git a/policycoreutils/hll/Makefile b/policycoreutils/hll/Makefile
index fe720e57..fc3f54db 100644
--- a/policycoreutils/hll/Makefile
+++ b/policycoreutils/hll/Makefile
@@ -1,6 +1,6 @@
SUBDIRS = pp
-all install relabel clean indent:
+all install relabel clean format:
@for subdir in $(SUBDIRS); do \
(cd $$subdir && $(MAKE) $@) || exit 1; \
done
diff --git a/policycoreutils/hll/pp/Makefile b/policycoreutils/hll/pp/Makefile
index 3c9b0efc..2aed5ffa 100644
--- a/policycoreutils/hll/pp/Makefile
+++ b/policycoreutils/hll/pp/Makefile
@@ -26,5 +26,5 @@ relabel:
clean:
-rm -f pp $(PP_OBJS)
-indent:
- ../../scripts/Lindent $(wildcard *.[ch])
+format:
+ clang-format -i $(wildcard *.[ch])
diff --git a/policycoreutils/load_policy/Makefile b/policycoreutils/load_policy/Makefile
index c61fee70..0359719e 100644
--- a/policycoreutils/load_policy/Makefile
+++ b/policycoreutils/load_policy/Makefile
@@ -28,8 +28,8 @@ install: all
clean:
-rm -f $(TARGETS) *.o
-indent:
- ../../scripts/Lindent $(wildcard *.[ch])
+format:
+ clang-format -i $(wildcard *.[ch])
relabel:
/sbin/restorecon $(DESTDIR)$(SBINDIR)/load_policy
diff --git a/policycoreutils/man/Makefile b/policycoreutils/man/Makefile
index a4539f24..1f4ae9c7 100644
--- a/policycoreutils/man/Makefile
+++ b/policycoreutils/man/Makefile
@@ -19,3 +19,5 @@ install: all
done
relabel:
+
+format:
diff --git a/policycoreutils/newrole/Makefile b/policycoreutils/newrole/Makefile
index df64483f..6081da3f 100644
--- a/policycoreutils/newrole/Makefile
+++ b/policycoreutils/newrole/Makefile
@@ -87,8 +87,8 @@ endif
clean:
rm -f newrole *.o
-indent:
- ../../scripts/Lindent $(wildcard *.[ch])
+format:
+ clang-format -i $(wildcard *.[ch])
relabel: install
/sbin/restorecon $(DESTDIR)$(BINDIR)/newrole
diff --git a/policycoreutils/po/Makefile b/policycoreutils/po/Makefile
index 5ff92bff..14e711db 100644
--- a/policycoreutils/po/Makefile
+++ b/policycoreutils/po/Makefile
@@ -81,4 +81,6 @@ report:
relabel:
+format:
+
test:
diff --git a/policycoreutils/run_init/Makefile b/policycoreutils/run_init/Makefile
index c89fffb9..f22e6c24 100644
--- a/policycoreutils/run_init/Makefile
+++ b/policycoreutils/run_init/Makefile
@@ -53,8 +53,8 @@ endif
clean:
-rm -f $(TARGETS) *.o
-indent:
- ../../scripts/Lindent $(wildcard *.[ch])
+format:
+ clang-format -i $(wildcard *.[ch])
relabel: install
/sbin/restorecon $(DESTDIR)$(SBINDIR)/run_init $(DESTDIR)$(SBINDIR)/open_init_pty
diff --git a/policycoreutils/scripts/Makefile b/policycoreutils/scripts/Makefile
index 6d8196c6..01957b5e 100644
--- a/policycoreutils/scripts/Makefile
+++ b/policycoreutils/scripts/Makefile
@@ -21,6 +21,6 @@ install: all
clean:
-indent:
+format:
relabel:
diff --git a/policycoreutils/secon/Makefile b/policycoreutils/secon/Makefile
index c9296f19..ac978a1d 100644
--- a/policycoreutils/secon/Makefile
+++ b/policycoreutils/secon/Makefile
@@ -35,8 +35,8 @@ relabel:
clean:
rm -f *.o core* secon *~ *.bak
-indent:
- ../../scripts/Lindent $(wildcard *.[ch])
+format:
+ clang-format -i $(wildcard *.[ch])
bare: clean
diff --git a/policycoreutils/semodule/Makefile b/policycoreutils/semodule/Makefile
index 018ee2ca..372e8647 100644
--- a/policycoreutils/semodule/Makefile
+++ b/policycoreutils/semodule/Makefile
@@ -36,6 +36,6 @@ relabel:
clean:
-rm -f semodule *.o genhomedircon
-indent:
- ../../scripts/Lindent $(wildcard *.[ch])
+format:
+ clang-format -i $(wildcard *.[ch])
diff --git a/policycoreutils/sestatus/Makefile b/policycoreutils/sestatus/Makefile
index 1ce617c0..0f3c2b83 100644
--- a/policycoreutils/sestatus/Makefile
+++ b/policycoreutils/sestatus/Makefile
@@ -41,7 +41,7 @@ install: all
clean:
rm -f sestatus *.o
-indent:
- ../../scripts/Lindent $(wildcard *.[ch])
+format:
+ clang-format -i $(wildcard *.[ch])
relabel:
diff --git a/policycoreutils/setfiles/Makefile b/policycoreutils/setfiles/Makefile
index dab6313c..1029c4b7 100644
--- a/policycoreutils/setfiles/Makefile
+++ b/policycoreutils/setfiles/Makefile
@@ -43,8 +43,8 @@ install: all
clean:
rm -f setfiles restorecon restorecon_xattr *.o
-indent:
- ../../scripts/Lindent $(wildcard *.[ch])
+format:
+ clang-format -i $(wildcard *.[ch])
relabel: install
$(DESTDIR)$(SBINDIR)/restorecon $(DESTDIR)$(SBINDIR)/setfiles $(DESTDIR)$(SBINDIR)/restorecon_xattr
diff --git a/policycoreutils/setsebool/Makefile b/policycoreutils/setsebool/Makefile
index 87494c55..5283b788 100644
--- a/policycoreutils/setsebool/Makefile
+++ b/policycoreutils/setsebool/Makefile
@@ -36,6 +36,6 @@ relabel:
clean:
-rm -f setsebool *.o
-indent:
- ../../scripts/Lindent $(wildcard *.[ch])
+format:
+ clang-format -i $(wildcard *.[ch])
diff --git a/policycoreutils/unsetfiles/Makefile b/policycoreutils/unsetfiles/Makefile
index 9cb51494..714fa4dd 100644
--- a/policycoreutils/unsetfiles/Makefile
+++ b/policycoreutils/unsetfiles/Makefile
@@ -20,8 +20,8 @@ install: all
clean:
-rm -f unsetfiles *.o
-indent:
- ../../scripts/Lindent $(wildcard *.[ch])
+format:
+ clang-format -i $(wildcard *.[ch])
relabel: install
/sbin/restorecon $(DESTDIR)$(SBINDIR)/unsetfiles
diff --git a/python/Makefile b/python/Makefile
index 00312dbd..c4c31a17 100644
--- a/python/Makefile
+++ b/python/Makefile
@@ -1,6 +1,6 @@
SUBDIRS = sepolicy audit2allow semanage sepolgen chcat po
-all install relabel clean indent test:
+all install relabel clean format test:
@for subdir in $(SUBDIRS); do \
(cd $$subdir && $(MAKE) $@) || exit 1; \
done
diff --git a/python/audit2allow/Makefile b/python/audit2allow/Makefile
index 28b8f7f2..427007b6 100644
--- a/python/audit2allow/Makefile
+++ b/python/audit2allow/Makefile
@@ -51,7 +51,7 @@ install: all
clean:
rm -f *~ *.o sepolgen-ifgen-attr-helper test_dummy_policy
-indent:
- ../../scripts/Lindent $(wildcard *.[ch])
+format:
+ clang-format -i $(wildcard *.[ch])
relabel: ;
diff --git a/python/chcat/Makefile b/python/chcat/Makefile
index 7b3ee17f..376c1978 100644
--- a/python/chcat/Makefile
+++ b/python/chcat/Makefile
@@ -21,7 +21,7 @@ install: all
clean:
-indent:
+format:
relabel:
diff --git a/python/po/Makefile b/python/po/Makefile
index 3ff9a47d..ca62356f 100644
--- a/python/po/Makefile
+++ b/python/po/Makefile
@@ -82,4 +82,6 @@ report:
relabel:
+format:
+
test:
diff --git a/python/semanage/Makefile b/python/semanage/Makefile
index 628d135a..54fa8146 100644
--- a/python/semanage/Makefile
+++ b/python/semanage/Makefile
@@ -35,6 +35,6 @@ test:
@$(PYTHON) test-semanage.py -a
clean:
-indent:
+format:
relabel:
diff --git a/python/sepolgen/Makefile b/python/sepolgen/Makefile
index 3aed3304..a4a3b99e 100644
--- a/python/sepolgen/Makefile
+++ b/python/sepolgen/Makefile
@@ -11,7 +11,7 @@ clean:
rm -f *~ *.pyc
rm -f parser.out parsetab.py
-indent: ;
+format: ;
test:
$(MAKE) -C tests $@
diff --git a/python/sepolgen/src/Makefile b/python/sepolgen/src/Makefile
index 2815a13d..72e8b356 100644
--- a/python/sepolgen/src/Makefile
+++ b/python/sepolgen/src/Makefile
@@ -12,7 +12,7 @@ clean:
rm -f *~ *.pyc
rm -f parser.out parsetab.py
-indent: ;
+format: ;
test: ;
diff --git a/python/sepolicy/Makefile b/python/sepolicy/Makefile
index 1a26cfdc..8147d423 100644
--- a/python/sepolicy/Makefile
+++ b/python/sepolicy/Makefile
@@ -43,3 +43,5 @@ install:
install -m 644 $(BASHCOMPLETIONS) $(DESTDIR)$(BASHCOMPLETIONDIR)/sepolicy
relabel:
+
+format:
diff --git a/restorecond/Makefile b/restorecond/Makefile
index b8b86eb4..573535c6 100644
--- a/restorecond/Makefile
+++ b/restorecond/Makefile
@@ -59,7 +59,7 @@ relabel: install
clean:
-rm -f restorecond *.o *~
-indent:
- ../../scripts/Lindent $(wildcard *.[ch])
+format:
+ clang-format -i $(wildcard *.[ch])
test:
diff --git a/sandbox/Makefile b/sandbox/Makefile
index 0799ab7c..2737e532 100644
--- a/sandbox/Makefile
+++ b/sandbox/Makefile
@@ -50,7 +50,7 @@ clean:
-rm -f seunshare *.o *~
(cd po && $(MAKE) $@)
-indent:
- ../../scripts/Lindent $(wildcard *.[ch])
+format:
+ clang-format -i $(wildcard *.[ch])
relabel:
diff --git a/scripts/Lindent b/scripts/Lindent
deleted file mode 100755
index 9c4b3e2b..00000000
--- a/scripts/Lindent
+++ /dev/null
@@ -1,18 +0,0 @@
-#!/bin/sh
-PARAM="-npro -kr -i8 -ts8 -sob -l80 -ss -ncs -cp1"
-RES=`indent --version`
-V1=`echo $RES | cut -d' ' -f3 | cut -d'.' -f1`
-V2=`echo $RES | cut -d' ' -f3 | cut -d'.' -f2`
-V3=`echo $RES | cut -d' ' -f3 | cut -d'.' -f3`
-if [ $V1 -gt 2 ]; then
- PARAM="$PARAM -il0"
-elif [ $V1 -eq 2 ]; then
- if [ $V2 -gt 2 ]; then
- PARAM="$PARAM -il0";
- elif [ $V2 -eq 2 ]; then
- if [ $V3 -ge 10 ]; then
- PARAM="$PARAM -il0"
- fi
- fi
-fi
-indent $PARAM "$@"
diff --git a/secilc/Makefile b/secilc/Makefile
index ef7bc8cd..2518933f 100644
--- a/secilc/Makefile
+++ b/secilc/Makefile
@@ -87,4 +87,6 @@ clean:
relabel:
+format:
+
.PHONY: all clean test install doc relabel man
diff --git a/semodule-utils/Makefile b/semodule-utils/Makefile
index e0a65792..0ab7d0dc 100644
--- a/semodule-utils/Makefile
+++ b/semodule-utils/Makefile
@@ -1,6 +1,6 @@
SUBDIRS = semodule_package semodule_link semodule_expand
-all install relabel clean indent:
+all install relabel clean format:
@for subdir in $(SUBDIRS); do \
(cd $$subdir && $(MAKE) $@) || exit 1; \
done
diff --git a/semodule-utils/semodule_expand/Makefile b/semodule-utils/semodule_expand/Makefile
index ad776b15..1e5f836d 100644
--- a/semodule-utils/semodule_expand/Makefile
+++ b/semodule-utils/semodule_expand/Makefile
@@ -28,6 +28,6 @@ relabel:
clean:
-rm -f semodule_expand *.o
-indent:
- ../../scripts/Lindent $(wildcard *.[ch])
+format:
+ clang-format -i $(wildcard *.[ch])
diff --git a/semodule-utils/semodule_link/Makefile b/semodule-utils/semodule_link/Makefile
index 936d161c..6c603b7c 100644
--- a/semodule-utils/semodule_link/Makefile
+++ b/semodule-utils/semodule_link/Makefile
@@ -28,6 +28,6 @@ relabel:
clean:
-rm -f semodule_link *.o
-indent:
- ../../scripts/Lindent $(wildcard *.[ch])
+format:
+ clang-format -i $(wildcard *.[ch])
diff --git a/semodule-utils/semodule_package/Makefile b/semodule-utils/semodule_package/Makefile
index 6a289f73..c5823cc0 100644
--- a/semodule-utils/semodule_package/Makefile
+++ b/semodule-utils/semodule_package/Makefile
@@ -30,6 +30,6 @@ relabel:
clean:
-rm -f semodule_package semodule_unpackage *.o
-indent:
- ../../scripts/Lindent $(wildcard *.[ch])
+format:
+ clang-format -i $(wildcard *.[ch])
--
2.50.1
^ permalink raw reply related [flat|nested] 22+ messages in thread
* Re: [PATCH v3] treewide: add .clang-format configuration file
2025-10-07 10:46 ` [PATCH v3] " Rahul Sandhu
@ 2025-10-07 11:07 ` Rahul Sandhu
2025-10-07 13:24 ` Stephen Smalley
2025-10-07 13:21 ` Stephen Smalley
1 sibling, 1 reply; 22+ messages in thread
From: Rahul Sandhu @ 2025-10-07 11:07 UTC (permalink / raw)
To: nvraxn; +Cc: lautrbach, selinux, stephen.smalley.work
On Tue Oct 7, 2025 at 11:46 AM, Rahul Sandhu wrote:
>
>Currently only an RFC.
>
>Add the .clang-format configuration file, taken from the Linux kernel
>repository. We don't have any official style guidelines in tree at
>present, which makes it a bit unclear how to format C code for new
>contributors. As well as this, different parts of the codebase seem to
>been formatted with different styles on occasion, so using an automatic
>formatter should resolve this.
>
>As well as this, replace all the existing indent targets with format
>targets. Commands used to find and replace those targets:
>
>git grep -l -E '(\.\./)*scripts/Lindent' | xargs sed -i -E 's@(\.\./)*scripts/Lindent@clang-format -i@g'
>git grep -l 'indent' -- '*Makefile' | xargs sed -i 's/indent/format/g'
>
>Also add some empty format targets to Makefiles that previously were
>missing an indent target so that `make format` does not error.
>
>A few other things to consider to do in the future:
>1. Reformat all existing code. I understand this is a big change, hence
> the RFC, but we may as well get all code formatted if we go down
> this route; afterall, it's not like this will cause any breaking
> changes.
>2. Possibly add a CI target to check that all code is formatted as per
> the new clang-format configuration? The options `--dry-run` as well
> as `-Werror` can be passed to clang-format for this.
>
>Comments/feedback appreciated, thanks.
>
>Signed-off-by: Rahul Sandhu <nvraxn@gmail.com>
>---
> .clang-format | 130 +++++++++++++++++++++++
> CONTRIBUTING.md | 2 +
> Makefile | 2 +-
> checkpolicy/Makefile | 4 +-
> dbus/Makefile | 2 +
> gui/Makefile | 2 +-
> libselinux/Makefile | 2 +-
> libselinux/include/Makefile | 4 +-
> libselinux/man/Makefile | 2 +-
> libselinux/src/Makefile | 4 +-
> libselinux/utils/Makefile | 4 +-
> libsemanage/Makefile | 2 +-
> libsemanage/include/Makefile | 4 +-
> libsemanage/src/Makefile | 4 +-
> libsemanage/utils/Makefile | 2 +-
> libsepol/Makefile | 2 +-
> libsepol/include/Makefile | 4 +-
> libsepol/src/Makefile | 4 +-
> libsepol/utils/Makefile | 4 +-
> mcstrans/Makefile | 2 +
> policycoreutils/Makefile | 2 +-
> policycoreutils/hll/Makefile | 2 +-
> policycoreutils/hll/pp/Makefile | 4 +-
> policycoreutils/load_policy/Makefile | 4 +-
> policycoreutils/man/Makefile | 2 +
> policycoreutils/newrole/Makefile | 4 +-
> policycoreutils/po/Makefile | 2 +
> policycoreutils/run_init/Makefile | 4 +-
> policycoreutils/scripts/Makefile | 2 +-
> policycoreutils/secon/Makefile | 4 +-
> policycoreutils/semodule/Makefile | 4 +-
> policycoreutils/sestatus/Makefile | 4 +-
> policycoreutils/setfiles/Makefile | 4 +-
> policycoreutils/setsebool/Makefile | 4 +-
> policycoreutils/unsetfiles/Makefile | 4 +-
> python/Makefile | 2 +-
> python/audit2allow/Makefile | 4 +-
> python/chcat/Makefile | 2 +-
> python/po/Makefile | 2 +
> python/semanage/Makefile | 2 +-
> python/sepolgen/Makefile | 2 +-
> python/sepolgen/src/Makefile | 2 +-
> python/sepolicy/Makefile | 2 +
> restorecond/Makefile | 4 +-
> sandbox/Makefile | 4 +-
> scripts/Lindent | 18 ----
> secilc/Makefile | 2 +
> semodule-utils/Makefile | 2 +-
> semodule-utils/semodule_expand/Makefile | 4 +-
> semodule-utils/semodule_link/Makefile | 4 +-
> semodule-utils/semodule_package/Makefile | 4 +-
> 51 files changed, 212 insertions(+), 84 deletions(-)
> create mode 100644 .clang-format
> delete mode 100755 scripts/Lindent
>
>v2: remove linux kernel ForEachMacros and replace them with ours
>v3: replace the indent target with the new format target. also remove any
> mention of `.editorconfig` from the commit message; those changes are
> better suited for another patch (they're small and self-contained enough
> that they're a smaller thing to merge).
>
>diff --git a/.clang-format b/.clang-format
>new file mode 100644
>index 00000000..35595d87
>--- /dev/null
>+++ b/.clang-format
>@@ -0,0 +1,130 @@
>+# SPDX-License-Identifier: GPL-2.0
>+#
>+# clang-format configuration file. Intended for clang-format >= 11.
>+#
>+# For more information, see:
>+#
>+# Documentation/dev-tools/clang-format.rst
>+# https://clang.llvm.org/docs/ClangFormat.html
>+# https://clang.llvm.org/docs/ClangFormatStyleOptions.html
>+#
>+---
>+AccessModifierOffset: -4
>+AlignAfterOpenBracket: Align
>+AlignConsecutiveAssignments: false
>+AlignConsecutiveDeclarations: false
>+AlignEscapedNewlines: Left
>+AlignOperands: true
>+AlignTrailingComments: false
>+AllowAllParametersOfDeclarationOnNextLine: false
>+AllowShortBlocksOnASingleLine: false
>+AllowShortCaseLabelsOnASingleLine: false
>+AllowShortFunctionsOnASingleLine: None
>+AllowShortIfStatementsOnASingleLine: false
>+AllowShortLoopsOnASingleLine: false
>+AlwaysBreakAfterDefinitionReturnType: None
>+AlwaysBreakAfterReturnType: None
>+AlwaysBreakBeforeMultilineStrings: false
>+AlwaysBreakTemplateDeclarations: false
>+BinPackArguments: true
>+BinPackParameters: true
>+BraceWrapping:
>+ AfterClass: false
>+ AfterControlStatement: false
>+ AfterEnum: false
>+ AfterFunction: true
>+ AfterNamespace: true
>+ AfterObjCDeclaration: false
>+ AfterStruct: false
>+ AfterUnion: false
>+ AfterExternBlock: false
>+ BeforeCatch: false
>+ BeforeElse: false
>+ IndentBraces: false
>+ SplitEmptyFunction: true
>+ SplitEmptyRecord: true
>+ SplitEmptyNamespace: true
>+BreakBeforeBinaryOperators: None
>+BreakBeforeBraces: Custom
>+BreakBeforeInheritanceComma: false
>+BreakBeforeTernaryOperators: false
>+BreakConstructorInitializersBeforeComma: false
>+BreakConstructorInitializers: BeforeComma
>+BreakAfterJavaFieldAnnotations: false
>+BreakStringLiterals: false
>+ColumnLimit: 80
>+CommentPragmas: '^ IWYU pragma:'
>+CompactNamespaces: false
>+ConstructorInitializerAllOnOneLineOrOnePerLine: false
>+ConstructorInitializerIndentWidth: 8
>+ContinuationIndentWidth: 8
>+Cpp11BracedListStyle: false
>+DerivePointerAlignment: false
>+DisableFormat: false
>+ExperimentalAutoDetectBinPacking: false
>+FixNamespaceComments: false
>+
>+# Taken from:
>+# git grep -h '^#define [^[:space:]]*for_each[^[:space:]]*(' \
>+# | sed "s,^#define \([^[:space:]]*for_each[^[:space:]]*\)(.*$, - '\1'," \
>+# | LC_ALL=C sort -u
>+ForEachMacros:
>+ - 'cil_list_for_each'
>+ - 'cil_stack_for_each'
>+ - 'cil_stack_for_each_starting_at'
>+ - 'ebitmap_for_each_bit'
>+ - 'ebitmap_for_each_positive_bit'
>+
>+IncludeBlocks: Preserve
>+IncludeCategories:
>+ - Regex: '.*'
>+ Priority: 1
>+IncludeIsMainRegex: '(Test)?$'
>+IndentCaseLabels: false
>+IndentGotoLabels: false
>+IndentPPDirectives: None
>+IndentWidth: 8
>+IndentWrappedFunctionNames: false
>+JavaScriptQuotes: Leave
>+JavaScriptWrapImports: true
>+KeepEmptyLinesAtTheStartOfBlocks: false
>+MacroBlockBegin: ''
>+MacroBlockEnd: ''
>+MaxEmptyLinesToKeep: 1
>+NamespaceIndentation: None
>+ObjCBinPackProtocolList: Auto
>+ObjCBlockIndentWidth: 8
>+ObjCSpaceAfterProperty: true
>+ObjCSpaceBeforeProtocolList: true
>+
>+# Taken from git's rules
>+PenaltyBreakAssignment: 10
>+PenaltyBreakBeforeFirstCallParameter: 30
>+PenaltyBreakComment: 10
>+PenaltyBreakFirstLessLess: 0
>+PenaltyBreakString: 10
>+PenaltyExcessCharacter: 100
>+PenaltyReturnTypeOnItsOwnLine: 60
>+
>+PointerAlignment: Right
>+ReflowComments: false
>+SortIncludes: false
>+SortUsingDeclarations: false
>+SpaceAfterCStyleCast: false
>+SpaceAfterTemplateKeyword: true
>+SpaceBeforeAssignmentOperators: true
>+SpaceBeforeCtorInitializerColon: true
>+SpaceBeforeInheritanceColon: true
>+SpaceBeforeParens: ControlStatementsExceptForEachMacros
>+SpaceBeforeRangeBasedForLoopColon: true
>+SpaceInEmptyParentheses: false
>+SpacesBeforeTrailingComments: 1
>+SpacesInAngles: false
>+SpacesInContainerLiterals: false
>+SpacesInCStyleCastParentheses: false
>+SpacesInParentheses: false
>+SpacesInSquareBrackets: false
>+Standard: Cpp03
>+TabWidth: 8
>+UseTab: Always
>+...
>diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
>index c501cf84..7ec8cb0f 100644
>--- a/CONTRIBUTING.md
>+++ b/CONTRIBUTING.md
>@@ -53,6 +53,8 @@ When preparing patches, please follow these guidelines:
> - Separate large patches into logical patches
> - Patch descriptions must end with your "Signed-off-by" line. This means your
> code meets the Developer's certificate of origin, see below.
>+- C code should be formatted using clang-format, using the .clang-format
>+ configuration file at the root of this repository.
>
> When adding new, large features or tools it is best to discuss the
> design on the mailing list prior to submitting the patch.
>diff --git a/Makefile b/Makefile
>index 2ffba8e9..db065aa4 100644
>--- a/Makefile
>+++ b/Makefile
>@@ -36,7 +36,7 @@ ifneq ($(DESTDIR),)
> export LIBSEPOLA
> endif
>
>-all install relabel clean test indent:
>+all install relabel clean test format:
> @for subdir in $(SUBDIRS); do \
> (cd $$subdir && $(MAKE) $@) || exit 1; \
> done
>diff --git a/checkpolicy/Makefile b/checkpolicy/Makefile
>index 6e8008e3..edc5a30e 100644
>--- a/checkpolicy/Makefile
>+++ b/checkpolicy/Makefile
>@@ -78,5 +78,5 @@ clean:
> -rm -f $(TARGETS) $(CHECKPOLOBJS) $(CHECKMODOBJS) y.tab.c y.tab.h lex.yy.c tests/testpol.conf tests/testpol.bin
> $(MAKE) -C test clean
>
>-indent:
>- ../scripts/Lindent $(filter-out $(GENERATED),$(wildcard *.[ch]))
>+format:
>+ clang-format -i $(filter-out $(GENERATED),$(wildcard *.[ch]))
>diff --git a/dbus/Makefile b/dbus/Makefile
>index 53143aff..a6d77d6e 100644
>--- a/dbus/Makefile
>+++ b/dbus/Makefile
>@@ -16,4 +16,6 @@ install:
>
> relabel:
>
>+format:
>+
> test:
>diff --git a/gui/Makefile b/gui/Makefile
>index b29610d4..9ffa3604 100644
>--- a/gui/Makefile
>+++ b/gui/Makefile
>@@ -60,7 +60,7 @@ install: all
> clean:
> (cd po && $(MAKE) $@)
>
>-indent:
>+format:
>
> relabel:
>
>diff --git a/libselinux/Makefile b/libselinux/Makefile
>index a50b6491..e863e2e5 100644
>--- a/libselinux/Makefile
>+++ b/libselinux/Makefile
>@@ -50,7 +50,7 @@ COMPILER := clang
> endif
> export COMPILER
>
>-all install relabel clean distclean indent:
>+all install relabel clean distclean format:
> @for subdir in $(SUBDIRS); do \
> (cd $$subdir && $(MAKE) $@) || exit 1; \
> done
>diff --git a/libselinux/include/Makefile b/libselinux/include/Makefile
>index 8ab9ce92..0ff28d1d 100644
>--- a/libselinux/include/Makefile
>+++ b/libselinux/include/Makefile
>@@ -10,8 +10,8 @@ install: all
>
> relabel:
>
>-indent:
>- ../../scripts/Lindent $(wildcard selinux/*.h)
>+format:
>+ clang-format -i $(wildcard selinux/*.h)
>
> distclean clean:
> -rm -f selinux/*~
>diff --git a/libselinux/man/Makefile b/libselinux/man/Makefile
>index fdc0825f..42b1662a 100644
>--- a/libselinux/man/Makefile
>+++ b/libselinux/man/Makefile
>@@ -35,4 +35,4 @@ install: all
>
> relabel:
>
>-indent distclean clean:
>+format distclean clean:
>diff --git a/libselinux/src/Makefile b/libselinux/src/Makefile
>index 261c22d4..55520025 100644
>--- a/libselinux/src/Makefile
>+++ b/libselinux/src/Makefile
>@@ -223,7 +223,7 @@ clean: clean-pywrap clean-rubywrap
> distclean: clean
> rm -f $(GENERATED) $(SWIGFILES)
>
>-indent:
>- ../../scripts/Lindent $(filter-out $(GENERATED),$(wildcard *.[ch]))
>+format:
>+ clang-format -i $(filter-out $(GENERATED),$(wildcard *.[ch]))
>
> .PHONY: all clean clean-pywrap clean-rubywrap pywrap rubywrap swigify install install-pywrap install-rubywrap distclean
>diff --git a/libselinux/utils/Makefile b/libselinux/utils/Makefile
>index 6b1dc7c9..5213de8e 100644
>--- a/libselinux/utils/Makefile
>+++ b/libselinux/utils/Makefile
>@@ -72,8 +72,8 @@ clean:
>
> distclean: clean
>
>-indent:
>- ../../scripts/Lindent $(wildcard *.[ch])
>+format:
>+ clang-format -i $(wildcard *.[ch])
>
> relabel:
>
>diff --git a/libsemanage/Makefile b/libsemanage/Makefile
>index dbd240da..e363cdde 100644
>--- a/libsemanage/Makefile
>+++ b/libsemanage/Makefile
>@@ -29,7 +29,7 @@ clean distclean:
> $(MAKE) -C src $@
> $(MAKE) -C tests $@
>
>-indent:
>+format:
> $(MAKE) -C src $@
> $(MAKE) -C include $@
>
>diff --git a/libsemanage/include/Makefile b/libsemanage/include/Makefile
>index 6e44a28a..b2c195c5 100644
>--- a/libsemanage/include/Makefile
>+++ b/libsemanage/include/Makefile
>@@ -8,5 +8,5 @@ install: all
> test -d $(DESTDIR)$(INCDIR) || install -m 755 -d $(DESTDIR)$(INCDIR)
> install -m 644 $(wildcard semanage/*.h) $(DESTDIR)$(INCDIR)
>
>-indent:
>- ../../scripts/Lindent $(wildcard semanage/*.h)
>+format:
>+ clang-format -i $(wildcard semanage/*.h)
>diff --git a/libsemanage/src/Makefile b/libsemanage/src/Makefile
>index fa3449fb..f2d8e634 100644
>--- a/libsemanage/src/Makefile
>+++ b/libsemanage/src/Makefile
>@@ -167,7 +167,7 @@ clean:
> distclean: clean
> rm -f $(GENERATED) $(SWIGFILES)
>
>-indent:
>- ../../scripts/Lindent $(filter-out $(GENERATED),$(wildcard *.[ch]))
>+format:
>+ clang-format -i $(filter-out $(GENERATED),$(wildcard *.[ch]))
>
> .PHONY: all clean pywrap rubywrap swigify install install-pywrap install-rubywrap distclean
>diff --git a/libsemanage/utils/Makefile b/libsemanage/utils/Makefile
>index 5b8fbb6b..94d576d9 100644
>--- a/libsemanage/utils/Makefile
>+++ b/libsemanage/utils/Makefile
>@@ -13,7 +13,7 @@ clean:
>
> distclean: clean
>
>-indent:
>+format:
>
> relabel:
>
>diff --git a/libsepol/Makefile b/libsepol/Makefile
>index 5b5d03e2..2af93ace 100644
>--- a/libsepol/Makefile
>+++ b/libsepol/Makefile
>@@ -20,7 +20,7 @@ clean:
> $(MAKE) -C utils clean
> $(MAKE) -C tests clean
>
>-indent:
>+format:
> $(MAKE) -C src $@
> $(MAKE) -C include $@
> $(MAKE) -C utils $@
>diff --git a/libsepol/include/Makefile b/libsepol/include/Makefile
>index 1ad4ecab..fa8a96d6 100644
>--- a/libsepol/include/Makefile
>+++ b/libsepol/include/Makefile
>@@ -13,5 +13,5 @@ install: all
> install -m 644 $(wildcard sepol/policydb/*.h) $(DESTDIR)$(INCDIR)/policydb
> install -m 644 $(wildcard $(CILDIR)/include/cil/*.h) $(DESTDIR)$(INCDIR)/cil
>
>-indent:
>- ../../scripts/Lindent $(wildcard sepol/*.h)
>+format:
>+ clang-format -i $(wildcard sepol/*.h)
>diff --git a/libsepol/src/Makefile b/libsepol/src/Makefile
>index a1aed072..86404f4b 100644
>--- a/libsepol/src/Makefile
>+++ b/libsepol/src/Makefile
>@@ -104,6 +104,6 @@ relabel:
> clean:
> -rm -f $(LIBPC) $(LIBMAP) $(OBJS) $(LOBJS) $(LIBA) $(LIBSO) $(TARGET) $(CIL_GENERATED)
>
>-indent:
>- ../../scripts/Lindent $(wildcard *.[ch])
>+format:
>+ clang-format -i $(wildcard *.[ch])
>
>diff --git a/libsepol/utils/Makefile b/libsepol/utils/Makefile
>index 31932c11..0824f64f 100644
>--- a/libsepol/utils/Makefile
>+++ b/libsepol/utils/Makefile
>@@ -18,8 +18,8 @@ install: all
> clean:
> -rm -f $(TARGETS) *.o
>
>-indent:
>- ../../scripts/Lindent $(wildcard *.[ch])
>+format:
>+ clang-format -i $(wildcard *.[ch])
>
> relabel:
>
>diff --git a/mcstrans/Makefile b/mcstrans/Makefile
>index b20279ab..28d8c7bc 100644
>--- a/mcstrans/Makefile
>+++ b/mcstrans/Makefile
>@@ -21,4 +21,6 @@ clean:
>
> relabel:
>
>+format:
>+
> test:
>diff --git a/policycoreutils/Makefile b/policycoreutils/Makefile
>index 7c9706e3..212fbf22 100644
>--- a/policycoreutils/Makefile
>+++ b/policycoreutils/Makefile
>@@ -6,7 +6,7 @@ LIBSELINUX_LDLIBS := $(shell PKG_CONFIG_PATH="$(PKG_CONFIG_PATH):../libselinux/s
> LIBSEMANAGE_LDLIBS := $(shell PKG_CONFIG_PATH="$(PKG_CONFIG_PATH):../libsemanage/src" $(PKG_CONFIG) --libs libsemanage)
> export LIBSELINUX_LDLIBS LIBSEMANAGE_LDLIBS
>
>-all install relabel clean indent:
>+all install relabel clean format:
> @for subdir in $(SUBDIRS); do \
> (cd $$subdir && $(MAKE) $@) || exit 1; \
> done
>diff --git a/policycoreutils/hll/Makefile b/policycoreutils/hll/Makefile
>index fe720e57..fc3f54db 100644
>--- a/policycoreutils/hll/Makefile
>+++ b/policycoreutils/hll/Makefile
>@@ -1,6 +1,6 @@
> SUBDIRS = pp
>
>-all install relabel clean indent:
>+all install relabel clean format:
> @for subdir in $(SUBDIRS); do \
> (cd $$subdir && $(MAKE) $@) || exit 1; \
> done
>diff --git a/policycoreutils/hll/pp/Makefile b/policycoreutils/hll/pp/Makefile
>index 3c9b0efc..2aed5ffa 100644
>--- a/policycoreutils/hll/pp/Makefile
>+++ b/policycoreutils/hll/pp/Makefile
>@@ -26,5 +26,5 @@ relabel:
> clean:
> -rm -f pp $(PP_OBJS)
>
>-indent:
>- ../../scripts/Lindent $(wildcard *.[ch])
>+format:
>+ clang-format -i $(wildcard *.[ch])
>diff --git a/policycoreutils/load_policy/Makefile b/policycoreutils/load_policy/Makefile
>index c61fee70..0359719e 100644
>--- a/policycoreutils/load_policy/Makefile
>+++ b/policycoreutils/load_policy/Makefile
>@@ -28,8 +28,8 @@ install: all
> clean:
> -rm -f $(TARGETS) *.o
>
>-indent:
>- ../../scripts/Lindent $(wildcard *.[ch])
>+format:
>+ clang-format -i $(wildcard *.[ch])
>
> relabel:
> /sbin/restorecon $(DESTDIR)$(SBINDIR)/load_policy
>diff --git a/policycoreutils/man/Makefile b/policycoreutils/man/Makefile
>index a4539f24..1f4ae9c7 100644
>--- a/policycoreutils/man/Makefile
>+++ b/policycoreutils/man/Makefile
>@@ -19,3 +19,5 @@ install: all
> done
>
> relabel:
>+
>+format:
>diff --git a/policycoreutils/newrole/Makefile b/policycoreutils/newrole/Makefile
>index df64483f..6081da3f 100644
>--- a/policycoreutils/newrole/Makefile
>+++ b/policycoreutils/newrole/Makefile
>@@ -87,8 +87,8 @@ endif
> clean:
> rm -f newrole *.o
>
>-indent:
>- ../../scripts/Lindent $(wildcard *.[ch])
>+format:
>+ clang-format -i $(wildcard *.[ch])
>
> relabel: install
> /sbin/restorecon $(DESTDIR)$(BINDIR)/newrole
>diff --git a/policycoreutils/po/Makefile b/policycoreutils/po/Makefile
>index 5ff92bff..14e711db 100644
>--- a/policycoreutils/po/Makefile
>+++ b/policycoreutils/po/Makefile
>@@ -81,4 +81,6 @@ report:
>
> relabel:
>
>+format:
>+
> test:
>diff --git a/policycoreutils/run_init/Makefile b/policycoreutils/run_init/Makefile
>index c89fffb9..f22e6c24 100644
>--- a/policycoreutils/run_init/Makefile
>+++ b/policycoreutils/run_init/Makefile
>@@ -53,8 +53,8 @@ endif
> clean:
> -rm -f $(TARGETS) *.o
>
>-indent:
>- ../../scripts/Lindent $(wildcard *.[ch])
>+format:
>+ clang-format -i $(wildcard *.[ch])
>
> relabel: install
> /sbin/restorecon $(DESTDIR)$(SBINDIR)/run_init $(DESTDIR)$(SBINDIR)/open_init_pty
>diff --git a/policycoreutils/scripts/Makefile b/policycoreutils/scripts/Makefile
>index 6d8196c6..01957b5e 100644
>--- a/policycoreutils/scripts/Makefile
>+++ b/policycoreutils/scripts/Makefile
>@@ -21,6 +21,6 @@ install: all
>
> clean:
>
>-indent:
>+format:
>
> relabel:
>diff --git a/policycoreutils/secon/Makefile b/policycoreutils/secon/Makefile
>index c9296f19..ac978a1d 100644
>--- a/policycoreutils/secon/Makefile
>+++ b/policycoreutils/secon/Makefile
>@@ -35,8 +35,8 @@ relabel:
> clean:
> rm -f *.o core* secon *~ *.bak
>
>-indent:
>- ../../scripts/Lindent $(wildcard *.[ch])
>+format:
>+ clang-format -i $(wildcard *.[ch])
>
> bare: clean
>
>diff --git a/policycoreutils/semodule/Makefile b/policycoreutils/semodule/Makefile
>index 018ee2ca..372e8647 100644
>--- a/policycoreutils/semodule/Makefile
>+++ b/policycoreutils/semodule/Makefile
>@@ -36,6 +36,6 @@ relabel:
> clean:
> -rm -f semodule *.o genhomedircon
>
>-indent:
>- ../../scripts/Lindent $(wildcard *.[ch])
>+format:
>+ clang-format -i $(wildcard *.[ch])
>
>diff --git a/policycoreutils/sestatus/Makefile b/policycoreutils/sestatus/Makefile
>index 1ce617c0..0f3c2b83 100644
>--- a/policycoreutils/sestatus/Makefile
>+++ b/policycoreutils/sestatus/Makefile
>@@ -41,7 +41,7 @@ install: all
> clean:
> rm -f sestatus *.o
>
>-indent:
>- ../../scripts/Lindent $(wildcard *.[ch])
>+format:
>+ clang-format -i $(wildcard *.[ch])
>
> relabel:
>diff --git a/policycoreutils/setfiles/Makefile b/policycoreutils/setfiles/Makefile
>index dab6313c..1029c4b7 100644
>--- a/policycoreutils/setfiles/Makefile
>+++ b/policycoreutils/setfiles/Makefile
>@@ -43,8 +43,8 @@ install: all
> clean:
> rm -f setfiles restorecon restorecon_xattr *.o
>
>-indent:
>- ../../scripts/Lindent $(wildcard *.[ch])
>+format:
>+ clang-format -i $(wildcard *.[ch])
>
> relabel: install
> $(DESTDIR)$(SBINDIR)/restorecon $(DESTDIR)$(SBINDIR)/setfiles $(DESTDIR)$(SBINDIR)/restorecon_xattr
>diff --git a/policycoreutils/setsebool/Makefile b/policycoreutils/setsebool/Makefile
>index 87494c55..5283b788 100644
>--- a/policycoreutils/setsebool/Makefile
>+++ b/policycoreutils/setsebool/Makefile
>@@ -36,6 +36,6 @@ relabel:
> clean:
> -rm -f setsebool *.o
>
>-indent:
>- ../../scripts/Lindent $(wildcard *.[ch])
>+format:
>+ clang-format -i $(wildcard *.[ch])
>
>diff --git a/policycoreutils/unsetfiles/Makefile b/policycoreutils/unsetfiles/Makefile
>index 9cb51494..714fa4dd 100644
>--- a/policycoreutils/unsetfiles/Makefile
>+++ b/policycoreutils/unsetfiles/Makefile
>@@ -20,8 +20,8 @@ install: all
> clean:
> -rm -f unsetfiles *.o
>
>-indent:
>- ../../scripts/Lindent $(wildcard *.[ch])
>+format:
>+ clang-format -i $(wildcard *.[ch])
>
> relabel: install
> /sbin/restorecon $(DESTDIR)$(SBINDIR)/unsetfiles
>diff --git a/python/Makefile b/python/Makefile
>index 00312dbd..c4c31a17 100644
>--- a/python/Makefile
>+++ b/python/Makefile
>@@ -1,6 +1,6 @@
> SUBDIRS = sepolicy audit2allow semanage sepolgen chcat po
>
>-all install relabel clean indent test:
>+all install relabel clean format test:
> @for subdir in $(SUBDIRS); do \
> (cd $$subdir && $(MAKE) $@) || exit 1; \
> done
>diff --git a/python/audit2allow/Makefile b/python/audit2allow/Makefile
>index 28b8f7f2..427007b6 100644
>--- a/python/audit2allow/Makefile
>+++ b/python/audit2allow/Makefile
>@@ -51,7 +51,7 @@ install: all
> clean:
> rm -f *~ *.o sepolgen-ifgen-attr-helper test_dummy_policy
>
>-indent:
>- ../../scripts/Lindent $(wildcard *.[ch])
>+format:
>+ clang-format -i $(wildcard *.[ch])
>
> relabel: ;
>diff --git a/python/chcat/Makefile b/python/chcat/Makefile
>index 7b3ee17f..376c1978 100644
>--- a/python/chcat/Makefile
>+++ b/python/chcat/Makefile
>@@ -21,7 +21,7 @@ install: all
>
> clean:
>
>-indent:
>+format:
>
> relabel:
>
>diff --git a/python/po/Makefile b/python/po/Makefile
>index 3ff9a47d..ca62356f 100644
>--- a/python/po/Makefile
>+++ b/python/po/Makefile
>@@ -82,4 +82,6 @@ report:
>
> relabel:
>
>+format:
>+
> test:
>diff --git a/python/semanage/Makefile b/python/semanage/Makefile
>index 628d135a..54fa8146 100644
>--- a/python/semanage/Makefile
>+++ b/python/semanage/Makefile
>@@ -35,6 +35,6 @@ test:
> @$(PYTHON) test-semanage.py -a
> clean:
>
>-indent:
>+format:
>
> relabel:
>diff --git a/python/sepolgen/Makefile b/python/sepolgen/Makefile
>index 3aed3304..a4a3b99e 100644
>--- a/python/sepolgen/Makefile
>+++ b/python/sepolgen/Makefile
>@@ -11,7 +11,7 @@ clean:
> rm -f *~ *.pyc
> rm -f parser.out parsetab.py
>
>-indent: ;
>+format: ;
>
> test:
> $(MAKE) -C tests $@
>diff --git a/python/sepolgen/src/Makefile b/python/sepolgen/src/Makefile
>index 2815a13d..72e8b356 100644
>--- a/python/sepolgen/src/Makefile
>+++ b/python/sepolgen/src/Makefile
>@@ -12,7 +12,7 @@ clean:
> rm -f *~ *.pyc
> rm -f parser.out parsetab.py
>
>-indent: ;
>+format: ;
>
>
> test: ;
>diff --git a/python/sepolicy/Makefile b/python/sepolicy/Makefile
>index 1a26cfdc..8147d423 100644
>--- a/python/sepolicy/Makefile
>+++ b/python/sepolicy/Makefile
>@@ -43,3 +43,5 @@ install:
> install -m 644 $(BASHCOMPLETIONS) $(DESTDIR)$(BASHCOMPLETIONDIR)/sepolicy
>
> relabel:
>+
>+format:
>diff --git a/restorecond/Makefile b/restorecond/Makefile
>index b8b86eb4..573535c6 100644
>--- a/restorecond/Makefile
>+++ b/restorecond/Makefile
>@@ -59,7 +59,7 @@ relabel: install
> clean:
> -rm -f restorecond *.o *~
>
>-indent:
>- ../../scripts/Lindent $(wildcard *.[ch])
>+format:
>+ clang-format -i $(wildcard *.[ch])
>
> test:
>diff --git a/sandbox/Makefile b/sandbox/Makefile
>index 0799ab7c..2737e532 100644
>--- a/sandbox/Makefile
>+++ b/sandbox/Makefile
>@@ -50,7 +50,7 @@ clean:
> -rm -f seunshare *.o *~
> (cd po && $(MAKE) $@)
>
>-indent:
>- ../../scripts/Lindent $(wildcard *.[ch])
>+format:
>+ clang-format -i $(wildcard *.[ch])
>
> relabel:
>diff --git a/scripts/Lindent b/scripts/Lindent
>deleted file mode 100755
>index 9c4b3e2b..00000000
>--- a/scripts/Lindent
>+++ /dev/null
>@@ -1,18 +0,0 @@
>-#!/bin/sh
>-PARAM="-npro -kr -i8 -ts8 -sob -l80 -ss -ncs -cp1"
>-RES=`indent --version`
>-V1=`echo $RES | cut -d' ' -f3 | cut -d'.' -f1`
>-V2=`echo $RES | cut -d' ' -f3 | cut -d'.' -f2`
>-V3=`echo $RES | cut -d' ' -f3 | cut -d'.' -f3`
>-if [ $V1 -gt 2 ]; then
>- PARAM="$PARAM -il0"
>-elif [ $V1 -eq 2 ]; then
>- if [ $V2 -gt 2 ]; then
>- PARAM="$PARAM -il0";
>- elif [ $V2 -eq 2 ]; then
>- if [ $V3 -ge 10 ]; then
>- PARAM="$PARAM -il0"
>- fi
>- fi
>-fi
>-indent $PARAM "$@"
>diff --git a/secilc/Makefile b/secilc/Makefile
>index ef7bc8cd..2518933f 100644
>--- a/secilc/Makefile
>+++ b/secilc/Makefile
>@@ -87,4 +87,6 @@ clean:
>
> relabel:
>
>+format:
>+
> .PHONY: all clean test install doc relabel man
>diff --git a/semodule-utils/Makefile b/semodule-utils/Makefile
>index e0a65792..0ab7d0dc 100644
>--- a/semodule-utils/Makefile
>+++ b/semodule-utils/Makefile
>@@ -1,6 +1,6 @@
> SUBDIRS = semodule_package semodule_link semodule_expand
>
>-all install relabel clean indent:
>+all install relabel clean format:
> @for subdir in $(SUBDIRS); do \
> (cd $$subdir && $(MAKE) $@) || exit 1; \
> done
>diff --git a/semodule-utils/semodule_expand/Makefile b/semodule-utils/semodule_expand/Makefile
>index ad776b15..1e5f836d 100644
>--- a/semodule-utils/semodule_expand/Makefile
>+++ b/semodule-utils/semodule_expand/Makefile
>@@ -28,6 +28,6 @@ relabel:
> clean:
> -rm -f semodule_expand *.o
>
>-indent:
>- ../../scripts/Lindent $(wildcard *.[ch])
>+format:
>+ clang-format -i $(wildcard *.[ch])
>
>diff --git a/semodule-utils/semodule_link/Makefile b/semodule-utils/semodule_link/Makefile
>index 936d161c..6c603b7c 100644
>--- a/semodule-utils/semodule_link/Makefile
>+++ b/semodule-utils/semodule_link/Makefile
>@@ -28,6 +28,6 @@ relabel:
> clean:
> -rm -f semodule_link *.o
>
>-indent:
>- ../../scripts/Lindent $(wildcard *.[ch])
>+format:
>+ clang-format -i $(wildcard *.[ch])
>
>diff --git a/semodule-utils/semodule_package/Makefile b/semodule-utils/semodule_package/Makefile
>index 6a289f73..c5823cc0 100644
>--- a/semodule-utils/semodule_package/Makefile
>+++ b/semodule-utils/semodule_package/Makefile
>@@ -30,6 +30,6 @@ relabel:
> clean:
> -rm -f semodule_package semodule_unpackage *.o
>
>-indent:
>- ../../scripts/Lindent $(wildcard *.[ch])
>+format:
>+ clang-format -i $(wildcard *.[ch])
>
>--
>2.50.1
>
>
Oops, I forgot to send this as an RFC, apologies - it still is one! I'll
sent the next patch as an RFC again.
While we're still talking about code style/formatting, I think it also
would be nice to add some clarification about usage of braces. Right
now, the usage of bracing is somewhat mixed: there are many places where
one line statements don't have braces, and vice versa. It would be good
to decide what the style regarding braces would be here and add it to
the CONTRIBUTING guide.
Regarding my own personal opinion, I think it would be best off to have
braces surrounding all statements (if/for/while, etc). It adds
consistency to all of those kinds of statements, and it also helps avoid
bugs such as the infamous `goto fail;` vulnerability[1]. It's a fairly
small trade off for a bit of added safety. However, maintainer opinions
are of course very much welcome here.
Regards,
Rahul
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [PATCH v3] treewide: add .clang-format configuration file
2025-10-07 10:46 ` [PATCH v3] " Rahul Sandhu
2025-10-07 11:07 ` Rahul Sandhu
@ 2025-10-07 13:21 ` Stephen Smalley
2025-10-16 22:05 ` Rahul Sandhu
2025-10-16 22:08 ` [PATCH v3] " Rahul Sandhu
1 sibling, 2 replies; 22+ messages in thread
From: Stephen Smalley @ 2025-10-07 13:21 UTC (permalink / raw)
To: Rahul Sandhu; +Cc: lautrbach, selinux
On Tue, Oct 7, 2025 at 6:47 AM Rahul Sandhu <nvraxn@gmail.com> wrote:
>
> Currently only an RFC.
>
> Add the .clang-format configuration file, taken from the Linux kernel
> repository. We don't have any official style guidelines in tree at
> present, which makes it a bit unclear how to format C code for new
> contributors. As well as this, different parts of the codebase seem to
> been formatted with different styles on occasion, so using an automatic
> formatter should resolve this.
>
> As well as this, replace all the existing indent targets with format
> targets. Commands used to find and replace those targets:
>
> git grep -l -E '(\.\./)*scripts/Lindent' | xargs sed -i -E 's@(\.\./)*scripts/Lindent@clang-format -i@g'
> git grep -l 'indent' -- '*Makefile' | xargs sed -i 's/indent/format/g'
>
> Also add some empty format targets to Makefiles that previously were
> missing an indent target so that `make format` does not error.
>
> A few other things to consider to do in the future:
> 1. Reformat all existing code. I understand this is a big change, hence
> the RFC, but we may as well get all code formatted if we go down
> this route; afterall, it's not like this will cause any breaking
> changes.
> 2. Possibly add a CI target to check that all code is formatted as per
> the new clang-format configuration? The options `--dry-run` as well
> as `-Werror` can be passed to clang-format for this.
Yes please.
>
> Comments/feedback appreciated, thanks.
>
> Signed-off-by: Rahul Sandhu <nvraxn@gmail.com>
> ---
>
> v2: remove linux kernel ForEachMacros and replace them with ours
> v3: replace the indent target with the new format target. also remove any
> mention of `.editorconfig` from the commit message; those changes are
> better suited for another patch (they're small and self-contained enough
> that they're a smaller thing to merge).
>
>
> diff --git a/mcstrans/Makefile b/mcstrans/Makefile
> index b20279ab..28d8c7bc 100644
> --- a/mcstrans/Makefile
> +++ b/mcstrans/Makefile
> @@ -21,4 +21,6 @@ clean:
>
> relabel:
>
> +format:
> +
We should add targets for mcstrans/utils/*.c and mcstrans/src/*.[hc]
> diff --git a/secilc/Makefile b/secilc/Makefile
> index ef7bc8cd..2518933f 100644
> --- a/secilc/Makefile
> +++ b/secilc/Makefile
> @@ -87,4 +87,6 @@ clean:
>
> relabel:
>
> +format:
> +
Should add a target for secilc/*.c
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [PATCH v3] treewide: add .clang-format configuration file
2025-10-07 11:07 ` Rahul Sandhu
@ 2025-10-07 13:24 ` Stephen Smalley
0 siblings, 0 replies; 22+ messages in thread
From: Stephen Smalley @ 2025-10-07 13:24 UTC (permalink / raw)
To: Rahul Sandhu; +Cc: lautrbach, selinux
On Tue, Oct 7, 2025 at 7:07 AM Rahul Sandhu <nvraxn@gmail.com> wrote:
>
> On Tue Oct 7, 2025 at 11:46 AM, Rahul Sandhu wrote:
> >
> >Currently only an RFC.
> >
> >Add the .clang-format configuration file, taken from the Linux kernel
> >repository. We don't have any official style guidelines in tree at
> >present, which makes it a bit unclear how to format C code for new
> >contributors. As well as this, different parts of the codebase seem to
> >been formatted with different styles on occasion, so using an automatic
> >formatter should resolve this.
> >
> >As well as this, replace all the existing indent targets with format
> >targets. Commands used to find and replace those targets:
> >
> >git grep -l -E '(\.\./)*scripts/Lindent' | xargs sed -i -E 's@(\.\./)*scripts/Lindent@clang-format -i@g'
> >git grep -l 'indent' -- '*Makefile' | xargs sed -i 's/indent/format/g'
> >
> >Also add some empty format targets to Makefiles that previously were
> >missing an indent target so that `make format` does not error.
> >
> >A few other things to consider to do in the future:
> >1. Reformat all existing code. I understand this is a big change, hence
> > the RFC, but we may as well get all code formatted if we go down
> > this route; afterall, it's not like this will cause any breaking
> > changes.
> >2. Possibly add a CI target to check that all code is formatted as per
> > the new clang-format configuration? The options `--dry-run` as well
> > as `-Werror` can be passed to clang-format for this.
> >
> >Comments/feedback appreciated, thanks.
> >
> >Signed-off-by: Rahul Sandhu <nvraxn@gmail.com>
> >---
> Oops, I forgot to send this as an RFC, apologies - it still is one! I'll
> sent the next patch as an RFC again.
>
> While we're still talking about code style/formatting, I think it also
> would be nice to add some clarification about usage of braces. Right
> now, the usage of bracing is somewhat mixed: there are many places where
> one line statements don't have braces, and vice versa. It would be good
> to decide what the style regarding braces would be here and add it to
> the CONTRIBUTING guide.
>
> Regarding my own personal opinion, I think it would be best off to have
> braces surrounding all statements (if/for/while, etc). It adds
> consistency to all of those kinds of statements, and it also helps avoid
> bugs such as the infamous `goto fail;` vulnerability[1]. It's a fairly
> small trade off for a bit of added safety. However, maintainer opinions
> are of course very much welcome here.
I would tend to be consistent with the kernel CodingStyle i.e. no { }
for singe-line statements, but this is not a hill I will die on.
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [RFC PATCH v2] treewide: add .clang-format configuration file
2025-10-06 16:52 ` Stephen Smalley
2025-10-07 6:35 ` Petr Lautrbach
@ 2025-10-08 15:17 ` Kenton Groombridge
1 sibling, 0 replies; 22+ messages in thread
From: Kenton Groombridge @ 2025-10-08 15:17 UTC (permalink / raw)
To: Stephen Smalley; +Cc: Rahul Sandhu, selinux
[-- Attachment #1: Type: text/plain, Size: 7876 bytes --]
On 25/10/06 12:52PM, Stephen Smalley wrote:
> On Sun, Sep 28, 2025 at 6:48 PM Rahul Sandhu <nvraxn@gmail.com> wrote:
> >
> > Currently only an RFC.
> >
> > Add the .clang-format configuration file, taken from the Linux kernel
> > repository. We don't have any official style guidelines in tree at
> > present, which makes it a bit unclear how to format C code for new
> > contributors. As well as this, different parts of the codebase seem to
> > been formatted with different styles on occasion, so using an automatic
> > formatter should resolve this.
> >
> > .clang-format is also read by various editors and tooling for writing C
> > code. It may also be worth adding an editorconfig file in the future as
> > well?
>
> Can't hurt.
>
> > It may well also be worth adding a `format` target to the Makefiles, is
> > that something that would be useful?
>
> IMHO, yes.
>
> >
> > A few other things to consider to do in the future:
> > 1. Reformat all existing code. I understand this is a big change, hence
> > the RFC, but we may as well get all code formatted if we go down
> > this route; afterall, it's not like this will cause any breaking
> > changes.
>
> Not opposed but will defer to the distro package maintainers on when
> they want to apply such a change since it makes back-porting future
> patches more painful for them.
>
No strong opinions from Gentoo. We aren't carrying any patches for C
code for SELinux userspace.
All in all I think this is a good change.
> > 2. Possibly add a CI target to check that all code is formatted as per
> > the new clang-format configuration? The options `--dry-run` as well
> > as `-Werror` can be passed to clang-format for this.
>
> Sounds reasonable too.
>
> >
> > Comments/feedback appreciated, thanks.
>
> No strong opinions; would be fine with any standardized coding style.
> For comparison, selinux-testsuite has tools/check-syntax which can be
> used to check or fix coding style problems for C and perl code, but
> I'd be fine with using clang-format here as in the kernel.
>
> > Signed-off-by: Rahul Sandhu <nvraxn@gmail.com>
> > ---
> > .clang-format | 130 ++++++++++++++++++++++++++++++++++++++++++++++++
> > CONTRIBUTING.md | 2 +
> > 2 files changed, 132 insertions(+)
> > create mode 100644 .clang-format
> >
> > v2: remove linux kernel ForEachMacros and replace them with ours
> >
> > diff --git a/.clang-format b/.clang-format
> > new file mode 100644
> > index 00000000..35595d87
> > --- /dev/null
> > +++ b/.clang-format
> > @@ -0,0 +1,130 @@
> > +# SPDX-License-Identifier: GPL-2.0
> > +#
> > +# clang-format configuration file. Intended for clang-format >= 11.
> > +#
> > +# For more information, see:
> > +#
> > +# Documentation/dev-tools/clang-format.rst
> > +# https://clang.llvm.org/docs/ClangFormat.html
> > +# https://clang.llvm.org/docs/ClangFormatStyleOptions.html
> > +#
> > +---
> > +AccessModifierOffset: -4
> > +AlignAfterOpenBracket: Align
> > +AlignConsecutiveAssignments: false
> > +AlignConsecutiveDeclarations: false
> > +AlignEscapedNewlines: Left
> > +AlignOperands: true
> > +AlignTrailingComments: false
> > +AllowAllParametersOfDeclarationOnNextLine: false
> > +AllowShortBlocksOnASingleLine: false
> > +AllowShortCaseLabelsOnASingleLine: false
> > +AllowShortFunctionsOnASingleLine: None
> > +AllowShortIfStatementsOnASingleLine: false
> > +AllowShortLoopsOnASingleLine: false
> > +AlwaysBreakAfterDefinitionReturnType: None
> > +AlwaysBreakAfterReturnType: None
> > +AlwaysBreakBeforeMultilineStrings: false
> > +AlwaysBreakTemplateDeclarations: false
> > +BinPackArguments: true
> > +BinPackParameters: true
> > +BraceWrapping:
> > + AfterClass: false
> > + AfterControlStatement: false
> > + AfterEnum: false
> > + AfterFunction: true
> > + AfterNamespace: true
> > + AfterObjCDeclaration: false
> > + AfterStruct: false
> > + AfterUnion: false
> > + AfterExternBlock: false
> > + BeforeCatch: false
> > + BeforeElse: false
> > + IndentBraces: false
> > + SplitEmptyFunction: true
> > + SplitEmptyRecord: true
> > + SplitEmptyNamespace: true
> > +BreakBeforeBinaryOperators: None
> > +BreakBeforeBraces: Custom
> > +BreakBeforeInheritanceComma: false
> > +BreakBeforeTernaryOperators: false
> > +BreakConstructorInitializersBeforeComma: false
> > +BreakConstructorInitializers: BeforeComma
> > +BreakAfterJavaFieldAnnotations: false
> > +BreakStringLiterals: false
> > +ColumnLimit: 80
> > +CommentPragmas: '^ IWYU pragma:'
> > +CompactNamespaces: false
> > +ConstructorInitializerAllOnOneLineOrOnePerLine: false
> > +ConstructorInitializerIndentWidth: 8
> > +ContinuationIndentWidth: 8
> > +Cpp11BracedListStyle: false
> > +DerivePointerAlignment: false
> > +DisableFormat: false
> > +ExperimentalAutoDetectBinPacking: false
> > +FixNamespaceComments: false
> > +
> > +# Taken from:
> > +# git grep -h '^#define [^[:space:]]*for_each[^[:space:]]*(' \
> > +# | sed "s,^#define \([^[:space:]]*for_each[^[:space:]]*\)(.*$, - '\1'," \
> > +# | LC_ALL=C sort -u
> > +ForEachMacros:
> > + - 'cil_list_for_each'
> > + - 'cil_stack_for_each'
> > + - 'cil_stack_for_each_starting_at'
> > + - 'ebitmap_for_each_bit'
> > + - 'ebitmap_for_each_positive_bit'
> > +
> > +IncludeBlocks: Preserve
> > +IncludeCategories:
> > + - Regex: '.*'
> > + Priority: 1
> > +IncludeIsMainRegex: '(Test)?$'
> > +IndentCaseLabels: false
> > +IndentGotoLabels: false
> > +IndentPPDirectives: None
> > +IndentWidth: 8
> > +IndentWrappedFunctionNames: false
> > +JavaScriptQuotes: Leave
> > +JavaScriptWrapImports: true
> > +KeepEmptyLinesAtTheStartOfBlocks: false
> > +MacroBlockBegin: ''
> > +MacroBlockEnd: ''
> > +MaxEmptyLinesToKeep: 1
> > +NamespaceIndentation: None
> > +ObjCBinPackProtocolList: Auto
> > +ObjCBlockIndentWidth: 8
> > +ObjCSpaceAfterProperty: true
> > +ObjCSpaceBeforeProtocolList: true
> > +
> > +# Taken from git's rules
> > +PenaltyBreakAssignment: 10
> > +PenaltyBreakBeforeFirstCallParameter: 30
> > +PenaltyBreakComment: 10
> > +PenaltyBreakFirstLessLess: 0
> > +PenaltyBreakString: 10
> > +PenaltyExcessCharacter: 100
> > +PenaltyReturnTypeOnItsOwnLine: 60
> > +
> > +PointerAlignment: Right
> > +ReflowComments: false
> > +SortIncludes: false
> > +SortUsingDeclarations: false
> > +SpaceAfterCStyleCast: false
> > +SpaceAfterTemplateKeyword: true
> > +SpaceBeforeAssignmentOperators: true
> > +SpaceBeforeCtorInitializerColon: true
> > +SpaceBeforeInheritanceColon: true
> > +SpaceBeforeParens: ControlStatementsExceptForEachMacros
> > +SpaceBeforeRangeBasedForLoopColon: true
> > +SpaceInEmptyParentheses: false
> > +SpacesBeforeTrailingComments: 1
> > +SpacesInAngles: false
> > +SpacesInContainerLiterals: false
> > +SpacesInCStyleCastParentheses: false
> > +SpacesInParentheses: false
> > +SpacesInSquareBrackets: false
> > +Standard: Cpp03
> > +TabWidth: 8
> > +UseTab: Always
> > +...
> > diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
> > index c501cf84..7ec8cb0f 100644
> > --- a/CONTRIBUTING.md
> > +++ b/CONTRIBUTING.md
> > @@ -53,6 +53,8 @@ When preparing patches, please follow these guidelines:
> > - Separate large patches into logical patches
> > - Patch descriptions must end with your "Signed-off-by" line. This means your
> > code meets the Developer's certificate of origin, see below.
> > +- C code should be formatted using clang-format, using the .clang-format
> > + configuration file at the root of this repository.
> >
> > When adding new, large features or tools it is best to discuss the
> > design on the mailing list prior to submitting the patch.
> > --
> > 2.50.1
> >
> >
--
Kenton Groombridge
Gentoo Linux Developer, SELinux Project
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 963 bytes --]
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [PATCH v3] treewide: add .clang-format configuration file
2025-10-07 13:21 ` Stephen Smalley
@ 2025-10-16 22:05 ` Rahul Sandhu
2025-10-17 12:51 ` Stephen Smalley
2025-10-16 22:08 ` [PATCH v3] " Rahul Sandhu
1 sibling, 1 reply; 22+ messages in thread
From: Rahul Sandhu @ 2025-10-16 22:05 UTC (permalink / raw)
To: Stephen Smalley; +Cc: lautrbach, selinux
On Tue Oct 7, 2025 at 2:21 PM BST, Stephen Smalley wrote:
> On Tue, Oct 7, 2025 at 6:47 AM Rahul Sandhu <nvraxn@gmail.com> wrote:
>>
>> Currently only an RFC.
>>
>> Add the .clang-format configuration file, taken from the Linux kernel
>> repository. We don't have any official style guidelines in tree at
>> present, which makes it a bit unclear how to format C code for new
>> contributors. As well as this, different parts of the codebase seem to
>> been formatted with different styles on occasion, so using an automatic
>> formatter should resolve this.
>>
>> As well as this, replace all the existing indent targets with format
>> targets. Commands used to find and replace those targets:
>>
>> git grep -l -E '(\.\./)*scripts/Lindent' | xargs sed -i -E 's@(\.\./)*scripts/Lindent@clang-format -i@g'
>> git grep -l 'indent' -- '*Makefile' | xargs sed -i 's/indent/format/g'
>>
>> Also add some empty format targets to Makefiles that previously were
>> missing an indent target so that `make format` does not error.
>>
>> A few other things to consider to do in the future:
>> 1. Reformat all existing code. I understand this is a big change, hence
>> the RFC, but we may as well get all code formatted if we go down
>> this route; afterall, it's not like this will cause any breaking
>> changes.
>> 2. Possibly add a CI target to check that all code is formatted as per
>> the new clang-format configuration? The options `--dry-run` as well
>> as `-Werror` can be passed to clang-format for this.
>
> Yes please.
Should this be added in another patch? My concern is that CI will fail
should this be merged without formatting all code.
>
>>
>> Comments/feedback appreciated, thanks.
>>
>> Signed-off-by: Rahul Sandhu <nvraxn@gmail.com>
>> ---
>>
>> v2: remove linux kernel ForEachMacros and replace them with ours
>> v3: replace the indent target with the new format target. also remove any
>> mention of `.editorconfig` from the commit message; those changes are
>> better suited for another patch (they're small and self-contained enough
>> that they're a smaller thing to merge).
>>
>>
>
>> diff --git a/mcstrans/Makefile b/mcstrans/Makefile
>> index b20279ab..28d8c7bc 100644
>> --- a/mcstrans/Makefile
>> +++ b/mcstrans/Makefile
>> @@ -21,4 +21,6 @@ clean:
>>
>> relabel:
>>
>> +format:
>> +
>
> We should add targets for mcstrans/utils/*.c and mcstrans/src/*.[hc]
I wrote a simple check-format target in the Makefile:
# We shouldn't have any unformatted files in the repo without an explicit exception.
# Given that this is used with the `check-format` target, which does not modify any
# source files, merely checking if they're formatted properly, it's fine to rely on
# find to get all C source and header files.
CHECK_FORMAT_SOURCE_FILES := $(shell find $(SUBDIRS) -type f \( -name '*.c' -o -name '*.h' \))
check-format:
clang-format --dry-run -Werror $(CHECK_FORMAT_SOURCE_FILES)
However, after running `make format` and `make check-format`, I noticed
a whole load of failures caused by a load of other missing targets. I'm
thinking that it may just be better off using that same find command to
get all c sources and headers, and have a single, global format target.
Afterall, in pushed code after we've formatted it all, I don't see any
reason that some code should be left unformatted (especially as we have
things such as the clang-format off comments for specific sub-sections
of code), and while working locally if someone wishes to format only a
specific globbed set of files, something like this should work fine:
clang-format -i src/*.c
Thoughts? Suggestions?
>
>> diff --git a/secilc/Makefile b/secilc/Makefile
>> index ef7bc8cd..2518933f 100644
>> --- a/secilc/Makefile
>> +++ b/secilc/Makefile
>> @@ -87,4 +87,6 @@ clean:
>>
>> relabel:
>>
>> +format:
>> +
>
> Should add a target for secilc/*.c
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [PATCH v3] treewide: add .clang-format configuration file
2025-10-07 13:21 ` Stephen Smalley
2025-10-16 22:05 ` Rahul Sandhu
@ 2025-10-16 22:08 ` Rahul Sandhu
1 sibling, 0 replies; 22+ messages in thread
From: Rahul Sandhu @ 2025-10-16 22:08 UTC (permalink / raw)
To: stephen.smalley.work; +Cc: lautrbach, nvraxn, selinux
On Tue Oct 7, 2025 at 2:21 PM BST, Stephen Smalley wrote:
> On Tue, Oct 7, 2025 at 6:47 AM Rahul Sandhu <nvraxn@gmail.com> wrote:
>>
>> Currently only an RFC.
>>
>> Add the .clang-format configuration file, taken from the Linux kernel
>> repository. We don't have any official style guidelines in tree at
>> present, which makes it a bit unclear how to format C code for new
>> contributors. As well as this, different parts of the codebase seem to
>> been formatted with different styles on occasion, so using an automatic
>> formatter should resolve this.
>>
>> As well as this, replace all the existing indent targets with format
>> targets. Commands used to find and replace those targets:
>>
>> git grep -l -E '(\.\./)*scripts/Lindent' | xargs sed -i -E 's@(\.\./)*scripts/Lindent@clang-format -i@g'
>> git grep -l 'indent' -- '*Makefile' | xargs sed -i 's/indent/format/g'
>>
>> Also add some empty format targets to Makefiles that previously were
>> missing an indent target so that `make format` does not error.
>>
>> A few other things to consider to do in the future:
>> 1. Reformat all existing code. I understand this is a big change, hence
>> the RFC, but we may as well get all code formatted if we go down
>> this route; afterall, it's not like this will cause any breaking
>> changes.
>> 2. Possibly add a CI target to check that all code is formatted as per
>> the new clang-format configuration? The options `--dry-run` as well
>> as `-Werror` can be passed to clang-format for this.
>
> Yes please.
Should this be added in another patch? My concern is that CI will fail
should this be merged without formatting all code.
>
>>
>> Comments/feedback appreciated, thanks.
>>
>> Signed-off-by: Rahul Sandhu <nvraxn@gmail.com>
>> ---
>>
>> v2: remove linux kernel ForEachMacros and replace them with ours
>> v3: replace the indent target with the new format target. also remove any
>> mention of `.editorconfig` from the commit message; those changes are
>> better suited for another patch (they're small and self-contained enough
>> that they're a smaller thing to merge).
>>
>>
>
>> diff --git a/mcstrans/Makefile b/mcstrans/Makefile
>> index b20279ab..28d8c7bc 100644
>> --- a/mcstrans/Makefile
>> +++ b/mcstrans/Makefile
>> @@ -21,4 +21,6 @@ clean:
>>
>> relabel:
>>
>> +format:
>> +
>
> We should add targets for mcstrans/utils/*.c and mcstrans/src/*.[hc]
I wrote a simple check-format target in the Makefile:
# We shouldn't have any unformatted files in the repo without an explicit exception.
# Given that this is used with the `check-format` target, which does not modify any
# source files, merely checking if they're formatted properly, it's fine to rely on
# find to get all C source and header files.
CHECK_FORMAT_SOURCE_FILES := $(shell find $(SUBDIRS) -type f \( -name '*.c' -o -name '*.h' \))
check-format:
clang-format --dry-run -Werror $(CHECK_FORMAT_SOURCE_FILES)
However, after running `make format` and `make check-format`, I noticed
a whole load of failures caused by a load of other missing targets. I'm
thinking that it may just be better off using that same find command to
get all c sources and headers, and have a single, global format target.
Afterall, in pushed code after we've formatted it all, I don't see any
reason that some code should be left unformatted (especially as we have
things such as the clang-format off comments for specific sub-sections
of code), and while working locally if someone wishes to format only a
specific globbed set of files, something like this should work fine:
clang-format -i src/*.c
Thoughts? Suggestions?
>
>> diff --git a/secilc/Makefile b/secilc/Makefile
>> index ef7bc8cd..2518933f 100644
>> --- a/secilc/Makefile
>> +++ b/secilc/Makefile
>> @@ -87,4 +87,6 @@ clean:
>>
>> relabel:
>>
>> +format:
>> +
>
> Should add a target for secilc/*.c
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [PATCH v3] treewide: add .clang-format configuration file
2025-10-16 22:05 ` Rahul Sandhu
@ 2025-10-17 12:51 ` Stephen Smalley
2025-10-18 6:11 ` [RFC PATCH v4] " Rahul Sandhu
0 siblings, 1 reply; 22+ messages in thread
From: Stephen Smalley @ 2025-10-17 12:51 UTC (permalink / raw)
To: Rahul Sandhu; +Cc: lautrbach, selinux
On Thu, Oct 16, 2025 at 6:05 PM Rahul Sandhu <nvraxn@gmail.com> wrote:
>
> On Tue Oct 7, 2025 at 2:21 PM BST, Stephen Smalley wrote:
> > On Tue, Oct 7, 2025 at 6:47 AM Rahul Sandhu <nvraxn@gmail.com> wrote:
> >>
> >> Currently only an RFC.
> >>
> >> Add the .clang-format configuration file, taken from the Linux kernel
> >> repository. We don't have any official style guidelines in tree at
> >> present, which makes it a bit unclear how to format C code for new
> >> contributors. As well as this, different parts of the codebase seem to
> >> been formatted with different styles on occasion, so using an automatic
> >> formatter should resolve this.
> >>
> >> As well as this, replace all the existing indent targets with format
> >> targets. Commands used to find and replace those targets:
> >>
> >> git grep -l -E '(\.\./)*scripts/Lindent' | xargs sed -i -E 's@(\.\./)*scripts/Lindent@clang-format -i@g'
> >> git grep -l 'indent' -- '*Makefile' | xargs sed -i 's/indent/format/g'
> >>
> >> Also add some empty format targets to Makefiles that previously were
> >> missing an indent target so that `make format` does not error.
> >>
> >> A few other things to consider to do in the future:
> >> 1. Reformat all existing code. I understand this is a big change, hence
> >> the RFC, but we may as well get all code formatted if we go down
> >> this route; afterall, it's not like this will cause any breaking
> >> changes.
> >> 2. Possibly add a CI target to check that all code is formatted as per
> >> the new clang-format configuration? The options `--dry-run` as well
> >> as `-Werror` can be passed to clang-format for this.
> >
> > Yes please.
>
> Should this be added in another patch? My concern is that CI will fail
> should this be merged without formatting all code.
Yes, we can wait on it.
> >> diff --git a/mcstrans/Makefile b/mcstrans/Makefile
> >> index b20279ab..28d8c7bc 100644
> >> --- a/mcstrans/Makefile
> >> +++ b/mcstrans/Makefile
> >> @@ -21,4 +21,6 @@ clean:
> >>
> >> relabel:
> >>
> >> +format:
> >> +
> >
> > We should add targets for mcstrans/utils/*.c and mcstrans/src/*.[hc]
>
> I wrote a simple check-format target in the Makefile:
>
> # We shouldn't have any unformatted files in the repo without an explicit exception.
> # Given that this is used with the `check-format` target, which does not modify any
> # source files, merely checking if they're formatted properly, it's fine to rely on
> # find to get all C source and header files.
> CHECK_FORMAT_SOURCE_FILES := $(shell find $(SUBDIRS) -type f \( -name '*.c' -o -name '*.h' \))
>
> check-format:
> clang-format --dry-run -Werror $(CHECK_FORMAT_SOURCE_FILES)
>
> However, after running `make format` and `make check-format`, I noticed
> a whole load of failures caused by a load of other missing targets. I'm
> thinking that it may just be better off using that same find command to
> get all c sources and headers, and have a single, global format target.
> Afterall, in pushed code after we've formatted it all, I don't see any
> reason that some code should be left unformatted (especially as we have
> things such as the clang-format off comments for specific sub-sections
> of code), and while working locally if someone wishes to format only a
> specific globbed set of files, something like this should work fine:
> clang-format -i src/*.c
>
> Thoughts? Suggestions?
Only caveat is that the selinux userspace tree is released as separate
archives for each packaged component so downstream users might not
have the top-level Makefile.
But I'm fine either way.
^ permalink raw reply [flat|nested] 22+ messages in thread
* [RFC PATCH v4] treewide: add .clang-format configuration file
2025-10-17 12:51 ` Stephen Smalley
@ 2025-10-18 6:11 ` Rahul Sandhu
2025-10-20 13:23 ` Stephen Smalley
0 siblings, 1 reply; 22+ messages in thread
From: Rahul Sandhu @ 2025-10-18 6:11 UTC (permalink / raw)
To: stephen.smalley.work; +Cc: lautrbach, nvraxn, selinux
Currently only an RFC.
Add the .clang-format configuration file, taken from the Linux kernel
repository. We don't have any official style guidelines in tree at
present, which makes it a bit unclear how to format C code for new
contributors. As well as this, different parts of the codebase seem to
been formatted with different styles on occasion, so using an automatic
formatter should resolve this.
As well as this, replace all the existing indent targets with a single
toplevel `format` target. Managing all the source files to be formatted
is not pretty to maintain, and doesn't really give us much.
Also define a toplevel `check-format` target to verify that all code is
formatted properly. This only becomes useful in the future once we have
reformatted all existing code, but is wired up for now.
For the future:
1. Reformat all existing code. I understand this is a big change, hence
the RFC, but we may as well get all code formatted if we go down
this route; afterall, it's not like this will cause any breaking
changes.
2. Add a CI target to check that all code is formatted as per the new
clang-format configuration. The `check-format` target can be used
for this.
Signed-off-by: Rahul Sandhu <nvraxn@gmail.com>
---
.clang-format | 130 +++++++++++++++++++++++
CONTRIBUTING.md | 2 +
Makefile | 11 +-
checkpolicy/Makefile | 3 -
gui/Makefile | 2 -
libselinux/Makefile | 2 +-
libselinux/include/Makefile | 4 -
libselinux/man/Makefile | 2 +-
libselinux/src/Makefile | 3 -
libselinux/utils/Makefile | 4 -
libsemanage/Makefile | 4 -
libsemanage/include/Makefile | 3 -
libsemanage/src/Makefile | 3 -
libsemanage/utils/Makefile | 3 -
libsepol/Makefile | 6 --
libsepol/include/Makefile | 3 -
libsepol/src/Makefile | 4 -
libsepol/utils/Makefile | 4 -
mcstrans/src/Makefile | 1 -
mcstrans/utils/Makefile | 1 -
policycoreutils/Makefile | 2 +-
policycoreutils/hll/Makefile | 2 +-
policycoreutils/hll/pp/Makefile | 3 -
policycoreutils/load_policy/Makefile | 3 -
policycoreutils/man/Makefile | 2 -
policycoreutils/newrole/Makefile | 3 -
policycoreutils/run_init/Makefile | 3 -
policycoreutils/scripts/Makefile | 2 -
policycoreutils/secon/Makefile | 3 -
policycoreutils/semodule/Makefile | 4 -
policycoreutils/sestatus/Makefile | 3 -
policycoreutils/setfiles/Makefile | 3 -
policycoreutils/setsebool/Makefile | 4 -
policycoreutils/unsetfiles/Makefile | 3 -
python/Makefile | 2 +-
python/audit2allow/Makefile | 3 -
python/chcat/Makefile | 2 -
python/semanage/Makefile | 2 -
python/sepolgen/Makefile | 5 -
python/sepolgen/src/Makefile | 6 --
restorecond/Makefile | 3 -
sandbox/Makefile | 3 -
scripts/Lindent | 18 ----
semodule-utils/Makefile | 2 +-
semodule-utils/semodule_expand/Makefile | 4 -
semodule-utils/semodule_link/Makefile | 4 -
semodule-utils/semodule_package/Makefile | 4 -
47 files changed, 148 insertions(+), 145 deletions(-)
create mode 100644 .clang-format
delete mode 100755 scripts/Lindent
v2: remove linux kernel ForEachMacros and replace them with ours
v3: replace the indent target with the new format target. also remove any
mention of `.editorconfig` from the commit message; those changes are
better suited for another patch (they're small and self-contained enough
that they're a smaller thing to merge).
v4: drop the subdir format targets entirely, replacing with a single toplevel
format and check-format target.
diff --git a/.clang-format b/.clang-format
new file mode 100644
index 00000000..35595d87
--- /dev/null
+++ b/.clang-format
@@ -0,0 +1,130 @@
+# SPDX-License-Identifier: GPL-2.0
+#
+# clang-format configuration file. Intended for clang-format >= 11.
+#
+# For more information, see:
+#
+# Documentation/dev-tools/clang-format.rst
+# https://clang.llvm.org/docs/ClangFormat.html
+# https://clang.llvm.org/docs/ClangFormatStyleOptions.html
+#
+---
+AccessModifierOffset: -4
+AlignAfterOpenBracket: Align
+AlignConsecutiveAssignments: false
+AlignConsecutiveDeclarations: false
+AlignEscapedNewlines: Left
+AlignOperands: true
+AlignTrailingComments: false
+AllowAllParametersOfDeclarationOnNextLine: false
+AllowShortBlocksOnASingleLine: false
+AllowShortCaseLabelsOnASingleLine: false
+AllowShortFunctionsOnASingleLine: None
+AllowShortIfStatementsOnASingleLine: false
+AllowShortLoopsOnASingleLine: false
+AlwaysBreakAfterDefinitionReturnType: None
+AlwaysBreakAfterReturnType: None
+AlwaysBreakBeforeMultilineStrings: false
+AlwaysBreakTemplateDeclarations: false
+BinPackArguments: true
+BinPackParameters: true
+BraceWrapping:
+ AfterClass: false
+ AfterControlStatement: false
+ AfterEnum: false
+ AfterFunction: true
+ AfterNamespace: true
+ AfterObjCDeclaration: false
+ AfterStruct: false
+ AfterUnion: false
+ AfterExternBlock: false
+ BeforeCatch: false
+ BeforeElse: false
+ IndentBraces: false
+ SplitEmptyFunction: true
+ SplitEmptyRecord: true
+ SplitEmptyNamespace: true
+BreakBeforeBinaryOperators: None
+BreakBeforeBraces: Custom
+BreakBeforeInheritanceComma: false
+BreakBeforeTernaryOperators: false
+BreakConstructorInitializersBeforeComma: false
+BreakConstructorInitializers: BeforeComma
+BreakAfterJavaFieldAnnotations: false
+BreakStringLiterals: false
+ColumnLimit: 80
+CommentPragmas: '^ IWYU pragma:'
+CompactNamespaces: false
+ConstructorInitializerAllOnOneLineOrOnePerLine: false
+ConstructorInitializerIndentWidth: 8
+ContinuationIndentWidth: 8
+Cpp11BracedListStyle: false
+DerivePointerAlignment: false
+DisableFormat: false
+ExperimentalAutoDetectBinPacking: false
+FixNamespaceComments: false
+
+# Taken from:
+# git grep -h '^#define [^[:space:]]*for_each[^[:space:]]*(' \
+# | sed "s,^#define \([^[:space:]]*for_each[^[:space:]]*\)(.*$, - '\1'," \
+# | LC_ALL=C sort -u
+ForEachMacros:
+ - 'cil_list_for_each'
+ - 'cil_stack_for_each'
+ - 'cil_stack_for_each_starting_at'
+ - 'ebitmap_for_each_bit'
+ - 'ebitmap_for_each_positive_bit'
+
+IncludeBlocks: Preserve
+IncludeCategories:
+ - Regex: '.*'
+ Priority: 1
+IncludeIsMainRegex: '(Test)?$'
+IndentCaseLabels: false
+IndentGotoLabels: false
+IndentPPDirectives: None
+IndentWidth: 8
+IndentWrappedFunctionNames: false
+JavaScriptQuotes: Leave
+JavaScriptWrapImports: true
+KeepEmptyLinesAtTheStartOfBlocks: false
+MacroBlockBegin: ''
+MacroBlockEnd: ''
+MaxEmptyLinesToKeep: 1
+NamespaceIndentation: None
+ObjCBinPackProtocolList: Auto
+ObjCBlockIndentWidth: 8
+ObjCSpaceAfterProperty: true
+ObjCSpaceBeforeProtocolList: true
+
+# Taken from git's rules
+PenaltyBreakAssignment: 10
+PenaltyBreakBeforeFirstCallParameter: 30
+PenaltyBreakComment: 10
+PenaltyBreakFirstLessLess: 0
+PenaltyBreakString: 10
+PenaltyExcessCharacter: 100
+PenaltyReturnTypeOnItsOwnLine: 60
+
+PointerAlignment: Right
+ReflowComments: false
+SortIncludes: false
+SortUsingDeclarations: false
+SpaceAfterCStyleCast: false
+SpaceAfterTemplateKeyword: true
+SpaceBeforeAssignmentOperators: true
+SpaceBeforeCtorInitializerColon: true
+SpaceBeforeInheritanceColon: true
+SpaceBeforeParens: ControlStatementsExceptForEachMacros
+SpaceBeforeRangeBasedForLoopColon: true
+SpaceInEmptyParentheses: false
+SpacesBeforeTrailingComments: 1
+SpacesInAngles: false
+SpacesInContainerLiterals: false
+SpacesInCStyleCastParentheses: false
+SpacesInParentheses: false
+SpacesInSquareBrackets: false
+Standard: Cpp03
+TabWidth: 8
+UseTab: Always
+...
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index c501cf84..7ec8cb0f 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -53,6 +53,8 @@ When preparing patches, please follow these guidelines:
- Separate large patches into logical patches
- Patch descriptions must end with your "Signed-off-by" line. This means your
code meets the Developer's certificate of origin, see below.
+- C code should be formatted using clang-format, using the .clang-format
+ configuration file at the root of this repository.
When adding new, large features or tools it is best to discuss the
design on the mailing list prior to submitting the patch.
diff --git a/Makefile b/Makefile
index 2ffba8e9..972d5525 100644
--- a/Makefile
+++ b/Makefile
@@ -36,7 +36,7 @@ ifneq ($(DESTDIR),)
export LIBSEPOLA
endif
-all install relabel clean test indent:
+all install relabel clean test:
@for subdir in $(SUBDIRS); do \
(cd $$subdir && $(MAKE) $@) || exit 1; \
done
@@ -50,3 +50,12 @@ distclean:
@for subdir in $(DISTCLEANSUBDIRS); do \
(cd $$subdir && $(MAKE) $@) || exit 1; \
done
+
+# We shouldn't have any unformatted files in the repo without an explicit exception.
+FORMAT_SOURCE_FILES := $(shell find $(SUBDIRS) -type f \( -name '*.c' -o -name '*.h' \))
+
+format:
+ clang-format -i $(FORMAT_SOURCE_FILES)
+
+check-format:
+ clang-format --dry-run -Werror $(FORMAT_SOURCE_FILES)
diff --git a/checkpolicy/Makefile b/checkpolicy/Makefile
index 6e8008e3..0055f495 100644
--- a/checkpolicy/Makefile
+++ b/checkpolicy/Makefile
@@ -77,6 +77,3 @@ relabel: install
clean:
-rm -f $(TARGETS) $(CHECKPOLOBJS) $(CHECKMODOBJS) y.tab.c y.tab.h lex.yy.c tests/testpol.conf tests/testpol.bin
$(MAKE) -C test clean
-
-indent:
- ../scripts/Lindent $(filter-out $(GENERATED),$(wildcard *.[ch]))
diff --git a/gui/Makefile b/gui/Makefile
index b29610d4..b1a94224 100644
--- a/gui/Makefile
+++ b/gui/Makefile
@@ -60,8 +60,6 @@ install: all
clean:
(cd po && $(MAKE) $@)
-indent:
-
relabel:
test:
diff --git a/libselinux/Makefile b/libselinux/Makefile
index a50b6491..aeede2b5 100644
--- a/libselinux/Makefile
+++ b/libselinux/Makefile
@@ -50,7 +50,7 @@ COMPILER := clang
endif
export COMPILER
-all install relabel clean distclean indent:
+all install relabel clean distclean:
@for subdir in $(SUBDIRS); do \
(cd $$subdir && $(MAKE) $@) || exit 1; \
done
diff --git a/libselinux/include/Makefile b/libselinux/include/Makefile
index 8ab9ce92..a1e322ac 100644
--- a/libselinux/include/Makefile
+++ b/libselinux/include/Makefile
@@ -10,9 +10,5 @@ install: all
relabel:
-indent:
- ../../scripts/Lindent $(wildcard selinux/*.h)
-
distclean clean:
-rm -f selinux/*~
-
diff --git a/libselinux/man/Makefile b/libselinux/man/Makefile
index fdc0825f..42b1662a 100644
--- a/libselinux/man/Makefile
+++ b/libselinux/man/Makefile
@@ -35,4 +35,4 @@ install: all
relabel:
-indent distclean clean:
+format distclean clean:
diff --git a/libselinux/src/Makefile b/libselinux/src/Makefile
index 261c22d4..f7412cd1 100644
--- a/libselinux/src/Makefile
+++ b/libselinux/src/Makefile
@@ -223,7 +223,4 @@ clean: clean-pywrap clean-rubywrap
distclean: clean
rm -f $(GENERATED) $(SWIGFILES)
-indent:
- ../../scripts/Lindent $(filter-out $(GENERATED),$(wildcard *.[ch]))
-
.PHONY: all clean clean-pywrap clean-rubywrap pywrap rubywrap swigify install install-pywrap install-rubywrap distclean
diff --git a/libselinux/utils/Makefile b/libselinux/utils/Makefile
index 6b1dc7c9..20dc44eb 100644
--- a/libselinux/utils/Makefile
+++ b/libselinux/utils/Makefile
@@ -72,8 +72,4 @@ clean:
distclean: clean
-indent:
- ../../scripts/Lindent $(wildcard *.[ch])
-
relabel:
-
diff --git a/libsemanage/Makefile b/libsemanage/Makefile
index dbd240da..591ce5f2 100644
--- a/libsemanage/Makefile
+++ b/libsemanage/Makefile
@@ -29,9 +29,5 @@ clean distclean:
$(MAKE) -C src $@
$(MAKE) -C tests $@
-indent:
- $(MAKE) -C src $@
- $(MAKE) -C include $@
-
test: all
$(MAKE) -C tests test
diff --git a/libsemanage/include/Makefile b/libsemanage/include/Makefile
index 6e44a28a..b08e48a0 100644
--- a/libsemanage/include/Makefile
+++ b/libsemanage/include/Makefile
@@ -7,6 +7,3 @@ all:
install: all
test -d $(DESTDIR)$(INCDIR) || install -m 755 -d $(DESTDIR)$(INCDIR)
install -m 644 $(wildcard semanage/*.h) $(DESTDIR)$(INCDIR)
-
-indent:
- ../../scripts/Lindent $(wildcard semanage/*.h)
diff --git a/libsemanage/src/Makefile b/libsemanage/src/Makefile
index fa3449fb..8e025112 100644
--- a/libsemanage/src/Makefile
+++ b/libsemanage/src/Makefile
@@ -167,7 +167,4 @@ clean:
distclean: clean
rm -f $(GENERATED) $(SWIGFILES)
-indent:
- ../../scripts/Lindent $(filter-out $(GENERATED),$(wildcard *.[ch]))
-
.PHONY: all clean pywrap rubywrap swigify install install-pywrap install-rubywrap distclean
diff --git a/libsemanage/utils/Makefile b/libsemanage/utils/Makefile
index 5b8fbb6b..0f382934 100644
--- a/libsemanage/utils/Makefile
+++ b/libsemanage/utils/Makefile
@@ -13,7 +13,4 @@ clean:
distclean: clean
-indent:
-
relabel:
-
diff --git a/libsepol/Makefile b/libsepol/Makefile
index 5b5d03e2..223edcec 100644
--- a/libsepol/Makefile
+++ b/libsepol/Makefile
@@ -20,11 +20,5 @@ clean:
$(MAKE) -C utils clean
$(MAKE) -C tests clean
-indent:
- $(MAKE) -C src $@
- $(MAKE) -C include $@
- $(MAKE) -C utils $@
-
test:
$(MAKE) -C tests test
-
diff --git a/libsepol/include/Makefile b/libsepol/include/Makefile
index 1ad4ecab..f49b6e19 100644
--- a/libsepol/include/Makefile
+++ b/libsepol/include/Makefile
@@ -12,6 +12,3 @@ install: all
install -m 644 $(wildcard sepol/*.h) $(DESTDIR)$(INCDIR)
install -m 644 $(wildcard sepol/policydb/*.h) $(DESTDIR)$(INCDIR)/policydb
install -m 644 $(wildcard $(CILDIR)/include/cil/*.h) $(DESTDIR)$(INCDIR)/cil
-
-indent:
- ../../scripts/Lindent $(wildcard sepol/*.h)
diff --git a/libsepol/src/Makefile b/libsepol/src/Makefile
index 90aed394..bb2b7f5e 100644
--- a/libsepol/src/Makefile
+++ b/libsepol/src/Makefile
@@ -105,7 +105,3 @@ relabel:
clean:
-rm -f $(LIBPC) $(LIBMAP) $(OBJS) $(LOBJS) $(LIBA) $(LIBSO) $(TARGET) $(CIL_GENERATED)
-
-indent:
- ../../scripts/Lindent $(wildcard *.[ch])
-
diff --git a/libsepol/utils/Makefile b/libsepol/utils/Makefile
index 31932c11..a8bedf2e 100644
--- a/libsepol/utils/Makefile
+++ b/libsepol/utils/Makefile
@@ -18,8 +18,4 @@ install: all
clean:
-rm -f $(TARGETS) *.o
-indent:
- ../../scripts/Lindent $(wildcard *.[ch])
-
relabel:
-
diff --git a/mcstrans/src/Makefile b/mcstrans/src/Makefile
index 88487068..609b2d45 100644
--- a/mcstrans/src/Makefile
+++ b/mcstrans/src/Makefile
@@ -37,4 +37,3 @@ install: all
clean:
-rm -f $(OBJS) $(LOBJS) $(TARGET) $(PROG) $(PROG_OBJS) *~ \#*
-
diff --git a/mcstrans/utils/Makefile b/mcstrans/utils/Makefile
index 57a73932..1d70b4ed 100644
--- a/mcstrans/utils/Makefile
+++ b/mcstrans/utils/Makefile
@@ -36,4 +36,3 @@ clean:
rm -f $(TARGETS) *.o *~ \#*
relabel:
-
diff --git a/policycoreutils/Makefile b/policycoreutils/Makefile
index 7c9706e3..9186a9ef 100644
--- a/policycoreutils/Makefile
+++ b/policycoreutils/Makefile
@@ -6,7 +6,7 @@ LIBSELINUX_LDLIBS := $(shell PKG_CONFIG_PATH="$(PKG_CONFIG_PATH):../libselinux/s
LIBSEMANAGE_LDLIBS := $(shell PKG_CONFIG_PATH="$(PKG_CONFIG_PATH):../libsemanage/src" $(PKG_CONFIG) --libs libsemanage)
export LIBSELINUX_LDLIBS LIBSEMANAGE_LDLIBS
-all install relabel clean indent:
+all install relabel clean:
@for subdir in $(SUBDIRS); do \
(cd $$subdir && $(MAKE) $@) || exit 1; \
done
diff --git a/policycoreutils/hll/Makefile b/policycoreutils/hll/Makefile
index fe720e57..390f3a34 100644
--- a/policycoreutils/hll/Makefile
+++ b/policycoreutils/hll/Makefile
@@ -1,6 +1,6 @@
SUBDIRS = pp
-all install relabel clean indent:
+all install relabel clean:
@for subdir in $(SUBDIRS); do \
(cd $$subdir && $(MAKE) $@) || exit 1; \
done
diff --git a/policycoreutils/hll/pp/Makefile b/policycoreutils/hll/pp/Makefile
index 3c9b0efc..a0d475a3 100644
--- a/policycoreutils/hll/pp/Makefile
+++ b/policycoreutils/hll/pp/Makefile
@@ -25,6 +25,3 @@ relabel:
clean:
-rm -f pp $(PP_OBJS)
-
-indent:
- ../../scripts/Lindent $(wildcard *.[ch])
diff --git a/policycoreutils/load_policy/Makefile b/policycoreutils/load_policy/Makefile
index c61fee70..7754cadc 100644
--- a/policycoreutils/load_policy/Makefile
+++ b/policycoreutils/load_policy/Makefile
@@ -28,8 +28,5 @@ install: all
clean:
-rm -f $(TARGETS) *.o
-indent:
- ../../scripts/Lindent $(wildcard *.[ch])
-
relabel:
/sbin/restorecon $(DESTDIR)$(SBINDIR)/load_policy
diff --git a/policycoreutils/man/Makefile b/policycoreutils/man/Makefile
index a4539f24..2d5bc4b5 100644
--- a/policycoreutils/man/Makefile
+++ b/policycoreutils/man/Makefile
@@ -17,5 +17,3 @@ install: all
install -m 644 $${lang}/man5/*.5 $(DESTDIR)$(MANDIR)/$${lang}/man5 ; \
fi ; \
done
-
-relabel:
diff --git a/policycoreutils/newrole/Makefile b/policycoreutils/newrole/Makefile
index df64483f..fcd2661f 100644
--- a/policycoreutils/newrole/Makefile
+++ b/policycoreutils/newrole/Makefile
@@ -87,9 +87,6 @@ endif
clean:
rm -f newrole *.o
-indent:
- ../../scripts/Lindent $(wildcard *.[ch])
-
relabel: install
/sbin/restorecon $(DESTDIR)$(BINDIR)/newrole
diff --git a/policycoreutils/run_init/Makefile b/policycoreutils/run_init/Makefile
index c89fffb9..0e904dba 100644
--- a/policycoreutils/run_init/Makefile
+++ b/policycoreutils/run_init/Makefile
@@ -53,8 +53,5 @@ endif
clean:
-rm -f $(TARGETS) *.o
-indent:
- ../../scripts/Lindent $(wildcard *.[ch])
-
relabel: install
/sbin/restorecon $(DESTDIR)$(SBINDIR)/run_init $(DESTDIR)$(SBINDIR)/open_init_pty
diff --git a/policycoreutils/scripts/Makefile b/policycoreutils/scripts/Makefile
index 6d8196c6..1058bbab 100644
--- a/policycoreutils/scripts/Makefile
+++ b/policycoreutils/scripts/Makefile
@@ -21,6 +21,4 @@ install: all
clean:
-indent:
-
relabel:
diff --git a/policycoreutils/secon/Makefile b/policycoreutils/secon/Makefile
index c9296f19..b2f276f9 100644
--- a/policycoreutils/secon/Makefile
+++ b/policycoreutils/secon/Makefile
@@ -35,9 +35,6 @@ relabel:
clean:
rm -f *.o core* secon *~ *.bak
-indent:
- ../../scripts/Lindent $(wildcard *.[ch])
-
bare: clean
.PHONY: clean bare
diff --git a/policycoreutils/semodule/Makefile b/policycoreutils/semodule/Makefile
index 018ee2ca..47bde5f8 100644
--- a/policycoreutils/semodule/Makefile
+++ b/policycoreutils/semodule/Makefile
@@ -35,7 +35,3 @@ relabel:
clean:
-rm -f semodule *.o genhomedircon
-
-indent:
- ../../scripts/Lindent $(wildcard *.[ch])
-
diff --git a/policycoreutils/sestatus/Makefile b/policycoreutils/sestatus/Makefile
index 1ce617c0..70f46956 100644
--- a/policycoreutils/sestatus/Makefile
+++ b/policycoreutils/sestatus/Makefile
@@ -41,7 +41,4 @@ install: all
clean:
rm -f sestatus *.o
-indent:
- ../../scripts/Lindent $(wildcard *.[ch])
-
relabel:
diff --git a/policycoreutils/setfiles/Makefile b/policycoreutils/setfiles/Makefile
index dab6313c..aa3e80fc 100644
--- a/policycoreutils/setfiles/Makefile
+++ b/policycoreutils/setfiles/Makefile
@@ -43,8 +43,5 @@ install: all
clean:
rm -f setfiles restorecon restorecon_xattr *.o
-indent:
- ../../scripts/Lindent $(wildcard *.[ch])
-
relabel: install
$(DESTDIR)$(SBINDIR)/restorecon $(DESTDIR)$(SBINDIR)/setfiles $(DESTDIR)$(SBINDIR)/restorecon_xattr
diff --git a/policycoreutils/setsebool/Makefile b/policycoreutils/setsebool/Makefile
index 87494c55..360e0ea0 100644
--- a/policycoreutils/setsebool/Makefile
+++ b/policycoreutils/setsebool/Makefile
@@ -35,7 +35,3 @@ relabel:
clean:
-rm -f setsebool *.o
-
-indent:
- ../../scripts/Lindent $(wildcard *.[ch])
-
diff --git a/policycoreutils/unsetfiles/Makefile b/policycoreutils/unsetfiles/Makefile
index 9cb51494..8dbf85af 100644
--- a/policycoreutils/unsetfiles/Makefile
+++ b/policycoreutils/unsetfiles/Makefile
@@ -20,8 +20,5 @@ install: all
clean:
-rm -f unsetfiles *.o
-indent:
- ../../scripts/Lindent $(wildcard *.[ch])
-
relabel: install
/sbin/restorecon $(DESTDIR)$(SBINDIR)/unsetfiles
diff --git a/python/Makefile b/python/Makefile
index 00312dbd..c4c31a17 100644
--- a/python/Makefile
+++ b/python/Makefile
@@ -1,6 +1,6 @@
SUBDIRS = sepolicy audit2allow semanage sepolgen chcat po
-all install relabel clean indent test:
+all install relabel clean format test:
@for subdir in $(SUBDIRS); do \
(cd $$subdir && $(MAKE) $@) || exit 1; \
done
diff --git a/python/audit2allow/Makefile b/python/audit2allow/Makefile
index 28b8f7f2..90d10d1a 100644
--- a/python/audit2allow/Makefile
+++ b/python/audit2allow/Makefile
@@ -51,7 +51,4 @@ install: all
clean:
rm -f *~ *.o sepolgen-ifgen-attr-helper test_dummy_policy
-indent:
- ../../scripts/Lindent $(wildcard *.[ch])
-
relabel: ;
diff --git a/python/chcat/Makefile b/python/chcat/Makefile
index 7b3ee17f..334b749d 100644
--- a/python/chcat/Makefile
+++ b/python/chcat/Makefile
@@ -21,8 +21,6 @@ install: all
clean:
-indent:
-
relabel:
test:
diff --git a/python/semanage/Makefile b/python/semanage/Makefile
index 628d135a..51208d9e 100644
--- a/python/semanage/Makefile
+++ b/python/semanage/Makefile
@@ -35,6 +35,4 @@ test:
@$(PYTHON) test-semanage.py -a
clean:
-indent:
-
relabel:
diff --git a/python/sepolgen/Makefile b/python/sepolgen/Makefile
index 3aed3304..2ad7b13c 100644
--- a/python/sepolgen/Makefile
+++ b/python/sepolgen/Makefile
@@ -11,10 +11,5 @@ clean:
rm -f *~ *.pyc
rm -f parser.out parsetab.py
-indent: ;
-
test:
$(MAKE) -C tests $@
-
-
-
diff --git a/python/sepolgen/src/Makefile b/python/sepolgen/src/Makefile
index 2815a13d..a2456652 100644
--- a/python/sepolgen/src/Makefile
+++ b/python/sepolgen/src/Makefile
@@ -12,10 +12,4 @@ clean:
rm -f *~ *.pyc
rm -f parser.out parsetab.py
-indent: ;
-
-
test: ;
-
-
-
diff --git a/restorecond/Makefile b/restorecond/Makefile
index b8b86eb4..51eb7608 100644
--- a/restorecond/Makefile
+++ b/restorecond/Makefile
@@ -59,7 +59,4 @@ relabel: install
clean:
-rm -f restorecond *.o *~
-indent:
- ../../scripts/Lindent $(wildcard *.[ch])
-
test:
diff --git a/sandbox/Makefile b/sandbox/Makefile
index 0799ab7c..eaaad75c 100644
--- a/sandbox/Makefile
+++ b/sandbox/Makefile
@@ -50,7 +50,4 @@ clean:
-rm -f seunshare *.o *~
(cd po && $(MAKE) $@)
-indent:
- ../../scripts/Lindent $(wildcard *.[ch])
-
relabel:
diff --git a/scripts/Lindent b/scripts/Lindent
deleted file mode 100755
index 9c4b3e2b..00000000
--- a/scripts/Lindent
+++ /dev/null
@@ -1,18 +0,0 @@
-#!/bin/sh
-PARAM="-npro -kr -i8 -ts8 -sob -l80 -ss -ncs -cp1"
-RES=`indent --version`
-V1=`echo $RES | cut -d' ' -f3 | cut -d'.' -f1`
-V2=`echo $RES | cut -d' ' -f3 | cut -d'.' -f2`
-V3=`echo $RES | cut -d' ' -f3 | cut -d'.' -f3`
-if [ $V1 -gt 2 ]; then
- PARAM="$PARAM -il0"
-elif [ $V1 -eq 2 ]; then
- if [ $V2 -gt 2 ]; then
- PARAM="$PARAM -il0";
- elif [ $V2 -eq 2 ]; then
- if [ $V3 -ge 10 ]; then
- PARAM="$PARAM -il0"
- fi
- fi
-fi
-indent $PARAM "$@"
diff --git a/semodule-utils/Makefile b/semodule-utils/Makefile
index e0a65792..81c97af0 100644
--- a/semodule-utils/Makefile
+++ b/semodule-utils/Makefile
@@ -1,6 +1,6 @@
SUBDIRS = semodule_package semodule_link semodule_expand
-all install relabel clean indent:
+all install relabel clean:
@for subdir in $(SUBDIRS); do \
(cd $$subdir && $(MAKE) $@) || exit 1; \
done
diff --git a/semodule-utils/semodule_expand/Makefile b/semodule-utils/semodule_expand/Makefile
index ad776b15..72f09a46 100644
--- a/semodule-utils/semodule_expand/Makefile
+++ b/semodule-utils/semodule_expand/Makefile
@@ -27,7 +27,3 @@ relabel:
clean:
-rm -f semodule_expand *.o
-
-indent:
- ../../scripts/Lindent $(wildcard *.[ch])
-
diff --git a/semodule-utils/semodule_link/Makefile b/semodule-utils/semodule_link/Makefile
index 936d161c..83590c07 100644
--- a/semodule-utils/semodule_link/Makefile
+++ b/semodule-utils/semodule_link/Makefile
@@ -27,7 +27,3 @@ relabel:
clean:
-rm -f semodule_link *.o
-
-indent:
- ../../scripts/Lindent $(wildcard *.[ch])
-
diff --git a/semodule-utils/semodule_package/Makefile b/semodule-utils/semodule_package/Makefile
index 6a289f73..2465f987 100644
--- a/semodule-utils/semodule_package/Makefile
+++ b/semodule-utils/semodule_package/Makefile
@@ -29,7 +29,3 @@ relabel:
clean:
-rm -f semodule_package semodule_unpackage *.o
-
-indent:
- ../../scripts/Lindent $(wildcard *.[ch])
-
--
2.51.0
^ permalink raw reply related [flat|nested] 22+ messages in thread
* Re: [RFC PATCH v4] treewide: add .clang-format configuration file
2025-10-18 6:11 ` [RFC PATCH v4] " Rahul Sandhu
@ 2025-10-20 13:23 ` Stephen Smalley
2025-10-20 13:49 ` Stephen Smalley
0 siblings, 1 reply; 22+ messages in thread
From: Stephen Smalley @ 2025-10-20 13:23 UTC (permalink / raw)
To: Rahul Sandhu; +Cc: lautrbach, selinux
On Sat, Oct 18, 2025 at 2:11 AM Rahul Sandhu <nvraxn@gmail.com> wrote:
>
> Currently only an RFC.
>
> Add the .clang-format configuration file, taken from the Linux kernel
> repository. We don't have any official style guidelines in tree at
> present, which makes it a bit unclear how to format C code for new
> contributors. As well as this, different parts of the codebase seem to
> been formatted with different styles on occasion, so using an automatic
> formatter should resolve this.
>
> As well as this, replace all the existing indent targets with a single
> toplevel `format` target. Managing all the source files to be formatted
> is not pretty to maintain, and doesn't really give us much.
>
> Also define a toplevel `check-format` target to verify that all code is
> formatted properly. This only becomes useful in the future once we have
> reformatted all existing code, but is wired up for now.
>
> For the future:
> 1. Reformat all existing code. I understand this is a big change, hence
> the RFC, but we may as well get all code formatted if we go down
> this route; afterall, it's not like this will cause any breaking
> changes.
> 2. Add a CI target to check that all code is formatted as per the new
> clang-format configuration. The `check-format` target can be used
> for this.
>
> Signed-off-by: Rahul Sandhu <nvraxn@gmail.com>
LGTM but still posted as an RFC so will await a final non-RFC version.
Acked-by: Stephen Smalley <stephen.smalley.work@gmail.com>
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [RFC PATCH v4] treewide: add .clang-format configuration file
2025-10-20 13:23 ` Stephen Smalley
@ 2025-10-20 13:49 ` Stephen Smalley
2025-10-20 14:07 ` [PATCH v5] " Rahul Sandhu
0 siblings, 1 reply; 22+ messages in thread
From: Stephen Smalley @ 2025-10-20 13:49 UTC (permalink / raw)
To: Rahul Sandhu; +Cc: lautrbach, selinux
On Mon, Oct 20, 2025 at 9:23 AM Stephen Smalley
<stephen.smalley.work@gmail.com> wrote:
>
> On Sat, Oct 18, 2025 at 2:11 AM Rahul Sandhu <nvraxn@gmail.com> wrote:
> >
> > Currently only an RFC.
> >
> > Add the .clang-format configuration file, taken from the Linux kernel
> > repository. We don't have any official style guidelines in tree at
> > present, which makes it a bit unclear how to format C code for new
> > contributors. As well as this, different parts of the codebase seem to
> > been formatted with different styles on occasion, so using an automatic
> > formatter should resolve this.
> >
> > As well as this, replace all the existing indent targets with a single
> > toplevel `format` target. Managing all the source files to be formatted
> > is not pretty to maintain, and doesn't really give us much.
> >
> > Also define a toplevel `check-format` target to verify that all code is
> > formatted properly. This only becomes useful in the future once we have
> > reformatted all existing code, but is wired up for now.
> >
> > For the future:
> > 1. Reformat all existing code. I understand this is a big change, hence
> > the RFC, but we may as well get all code formatted if we go down
> > this route; afterall, it's not like this will cause any breaking
> > changes.
> > 2. Add a CI target to check that all code is formatted as per the new
> > clang-format configuration. The `check-format` target can be used
> > for this.
> >
> > Signed-off-by: Rahul Sandhu <nvraxn@gmail.com>
>
> LGTM but still posted as an RFC so will await a final non-RFC version.
>
> Acked-by: Stephen Smalley <stephen.smalley.work@gmail.com>
Ah, actually you seem to have accidentally deleted an empty relabel:
target from policycoreutils/man/Makefile, which breaks a make relabel
at top-level.
^ permalink raw reply [flat|nested] 22+ messages in thread
* [PATCH v5] treewide: add .clang-format configuration file
2025-10-20 13:49 ` Stephen Smalley
@ 2025-10-20 14:07 ` Rahul Sandhu
2025-10-20 14:09 ` [PATCH v6] " Rahul Sandhu
0 siblings, 1 reply; 22+ messages in thread
From: Rahul Sandhu @ 2025-10-20 14:07 UTC (permalink / raw)
To: stephen.smalley.work; +Cc: lautrbach, nvraxn, selinux
Currently only an RFC.
Add the .clang-format configuration file, taken from the Linux kernel
repository. We don't have any official style guidelines in tree at
present, which makes it a bit unclear how to format C code for new
contributors. As well as this, different parts of the codebase seem to
been formatted with different styles on occasion, so using an automatic
formatter should resolve this.
As well as this, replace all the existing indent targets with a single
toplevel `format` target. Managing all the source files to be formatted
is not pretty to maintain, and doesn't really give us much.
Also define a toplevel `check-format` target to verify that all code is
formatted properly. This only becomes useful in the future once we have
reformatted all existing code, but is wired up for now.
For the future:
1. Reformat all existing code. I understand this is a big change, hence
the RFC, but we may as well get all code formatted if we go down
this route; afterall, it's not like this will cause any breaking
changes.
2. Add a CI target to check that all code is formatted as per the new
clang-format configuration. The `check-format` target can be used
for this.
Signed-off-by: Rahul Sandhu <nvraxn@gmail.com>
---
.clang-format | 130 +++++++++++++++++++++++
CONTRIBUTING.md | 2 +
Makefile | 11 +-
checkpolicy/Makefile | 3 -
gui/Makefile | 2 -
libselinux/Makefile | 2 +-
libselinux/include/Makefile | 4 -
libselinux/man/Makefile | 2 +-
libselinux/src/Makefile | 3 -
libselinux/utils/Makefile | 4 -
libsemanage/Makefile | 4 -
libsemanage/include/Makefile | 3 -
libsemanage/src/Makefile | 3 -
libsemanage/utils/Makefile | 3 -
libsepol/Makefile | 6 --
libsepol/include/Makefile | 3 -
libsepol/src/Makefile | 4 -
libsepol/utils/Makefile | 4 -
mcstrans/src/Makefile | 1 -
mcstrans/utils/Makefile | 1 -
policycoreutils/Makefile | 2 +-
policycoreutils/hll/Makefile | 2 +-
policycoreutils/hll/pp/Makefile | 3 -
policycoreutils/load_policy/Makefile | 3 -
policycoreutils/newrole/Makefile | 3 -
policycoreutils/run_init/Makefile | 3 -
policycoreutils/scripts/Makefile | 2 -
policycoreutils/secon/Makefile | 3 -
policycoreutils/semodule/Makefile | 4 -
policycoreutils/sestatus/Makefile | 3 -
policycoreutils/setfiles/Makefile | 3 -
policycoreutils/setsebool/Makefile | 4 -
policycoreutils/unsetfiles/Makefile | 3 -
python/Makefile | 2 +-
python/audit2allow/Makefile | 3 -
python/chcat/Makefile | 2 -
python/semanage/Makefile | 2 -
python/sepolgen/Makefile | 5 -
python/sepolgen/src/Makefile | 6 --
restorecond/Makefile | 3 -
sandbox/Makefile | 3 -
scripts/Lindent | 18 ----
semodule-utils/Makefile | 2 +-
semodule-utils/semodule_expand/Makefile | 4 -
semodule-utils/semodule_link/Makefile | 4 -
semodule-utils/semodule_package/Makefile | 4 -
46 files changed, 148 insertions(+), 143 deletions(-)
create mode 100644 .clang-format
delete mode 100755 scripts/Lindent
v2: remove linux kernel ForEachMacros and replace them with ours
v3: replace the indent target with the new format target. also remove any
mention of `.editorconfig` from the commit message; those changes are
better suited for another patch (they're small and self-contained enough
that they're a smaller thing to merge).
v4: drop the subdir format targets entirely, replacing with a single toplevel
format and check-format target.
v5: add back relabel target accidently removed.
diff --git a/.clang-format b/.clang-format
new file mode 100644
index 00000000..35595d87
--- /dev/null
+++ b/.clang-format
@@ -0,0 +1,130 @@
+# SPDX-License-Identifier: GPL-2.0
+#
+# clang-format configuration file. Intended for clang-format >= 11.
+#
+# For more information, see:
+#
+# Documentation/dev-tools/clang-format.rst
+# https://clang.llvm.org/docs/ClangFormat.html
+# https://clang.llvm.org/docs/ClangFormatStyleOptions.html
+#
+---
+AccessModifierOffset: -4
+AlignAfterOpenBracket: Align
+AlignConsecutiveAssignments: false
+AlignConsecutiveDeclarations: false
+AlignEscapedNewlines: Left
+AlignOperands: true
+AlignTrailingComments: false
+AllowAllParametersOfDeclarationOnNextLine: false
+AllowShortBlocksOnASingleLine: false
+AllowShortCaseLabelsOnASingleLine: false
+AllowShortFunctionsOnASingleLine: None
+AllowShortIfStatementsOnASingleLine: false
+AllowShortLoopsOnASingleLine: false
+AlwaysBreakAfterDefinitionReturnType: None
+AlwaysBreakAfterReturnType: None
+AlwaysBreakBeforeMultilineStrings: false
+AlwaysBreakTemplateDeclarations: false
+BinPackArguments: true
+BinPackParameters: true
+BraceWrapping:
+ AfterClass: false
+ AfterControlStatement: false
+ AfterEnum: false
+ AfterFunction: true
+ AfterNamespace: true
+ AfterObjCDeclaration: false
+ AfterStruct: false
+ AfterUnion: false
+ AfterExternBlock: false
+ BeforeCatch: false
+ BeforeElse: false
+ IndentBraces: false
+ SplitEmptyFunction: true
+ SplitEmptyRecord: true
+ SplitEmptyNamespace: true
+BreakBeforeBinaryOperators: None
+BreakBeforeBraces: Custom
+BreakBeforeInheritanceComma: false
+BreakBeforeTernaryOperators: false
+BreakConstructorInitializersBeforeComma: false
+BreakConstructorInitializers: BeforeComma
+BreakAfterJavaFieldAnnotations: false
+BreakStringLiterals: false
+ColumnLimit: 80
+CommentPragmas: '^ IWYU pragma:'
+CompactNamespaces: false
+ConstructorInitializerAllOnOneLineOrOnePerLine: false
+ConstructorInitializerIndentWidth: 8
+ContinuationIndentWidth: 8
+Cpp11BracedListStyle: false
+DerivePointerAlignment: false
+DisableFormat: false
+ExperimentalAutoDetectBinPacking: false
+FixNamespaceComments: false
+
+# Taken from:
+# git grep -h '^#define [^[:space:]]*for_each[^[:space:]]*(' \
+# | sed "s,^#define \([^[:space:]]*for_each[^[:space:]]*\)(.*$, - '\1'," \
+# | LC_ALL=C sort -u
+ForEachMacros:
+ - 'cil_list_for_each'
+ - 'cil_stack_for_each'
+ - 'cil_stack_for_each_starting_at'
+ - 'ebitmap_for_each_bit'
+ - 'ebitmap_for_each_positive_bit'
+
+IncludeBlocks: Preserve
+IncludeCategories:
+ - Regex: '.*'
+ Priority: 1
+IncludeIsMainRegex: '(Test)?$'
+IndentCaseLabels: false
+IndentGotoLabels: false
+IndentPPDirectives: None
+IndentWidth: 8
+IndentWrappedFunctionNames: false
+JavaScriptQuotes: Leave
+JavaScriptWrapImports: true
+KeepEmptyLinesAtTheStartOfBlocks: false
+MacroBlockBegin: ''
+MacroBlockEnd: ''
+MaxEmptyLinesToKeep: 1
+NamespaceIndentation: None
+ObjCBinPackProtocolList: Auto
+ObjCBlockIndentWidth: 8
+ObjCSpaceAfterProperty: true
+ObjCSpaceBeforeProtocolList: true
+
+# Taken from git's rules
+PenaltyBreakAssignment: 10
+PenaltyBreakBeforeFirstCallParameter: 30
+PenaltyBreakComment: 10
+PenaltyBreakFirstLessLess: 0
+PenaltyBreakString: 10
+PenaltyExcessCharacter: 100
+PenaltyReturnTypeOnItsOwnLine: 60
+
+PointerAlignment: Right
+ReflowComments: false
+SortIncludes: false
+SortUsingDeclarations: false
+SpaceAfterCStyleCast: false
+SpaceAfterTemplateKeyword: true
+SpaceBeforeAssignmentOperators: true
+SpaceBeforeCtorInitializerColon: true
+SpaceBeforeInheritanceColon: true
+SpaceBeforeParens: ControlStatementsExceptForEachMacros
+SpaceBeforeRangeBasedForLoopColon: true
+SpaceInEmptyParentheses: false
+SpacesBeforeTrailingComments: 1
+SpacesInAngles: false
+SpacesInContainerLiterals: false
+SpacesInCStyleCastParentheses: false
+SpacesInParentheses: false
+SpacesInSquareBrackets: false
+Standard: Cpp03
+TabWidth: 8
+UseTab: Always
+...
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index c501cf84..7ec8cb0f 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -53,6 +53,8 @@ When preparing patches, please follow these guidelines:
- Separate large patches into logical patches
- Patch descriptions must end with your "Signed-off-by" line. This means your
code meets the Developer's certificate of origin, see below.
+- C code should be formatted using clang-format, using the .clang-format
+ configuration file at the root of this repository.
When adding new, large features or tools it is best to discuss the
design on the mailing list prior to submitting the patch.
diff --git a/Makefile b/Makefile
index 2ffba8e9..972d5525 100644
--- a/Makefile
+++ b/Makefile
@@ -36,7 +36,7 @@ ifneq ($(DESTDIR),)
export LIBSEPOLA
endif
-all install relabel clean test indent:
+all install relabel clean test:
@for subdir in $(SUBDIRS); do \
(cd $$subdir && $(MAKE) $@) || exit 1; \
done
@@ -50,3 +50,12 @@ distclean:
@for subdir in $(DISTCLEANSUBDIRS); do \
(cd $$subdir && $(MAKE) $@) || exit 1; \
done
+
+# We shouldn't have any unformatted files in the repo without an explicit exception.
+FORMAT_SOURCE_FILES := $(shell find $(SUBDIRS) -type f \( -name '*.c' -o -name '*.h' \))
+
+format:
+ clang-format -i $(FORMAT_SOURCE_FILES)
+
+check-format:
+ clang-format --dry-run -Werror $(FORMAT_SOURCE_FILES)
diff --git a/checkpolicy/Makefile b/checkpolicy/Makefile
index 6e8008e3..0055f495 100644
--- a/checkpolicy/Makefile
+++ b/checkpolicy/Makefile
@@ -77,6 +77,3 @@ relabel: install
clean:
-rm -f $(TARGETS) $(CHECKPOLOBJS) $(CHECKMODOBJS) y.tab.c y.tab.h lex.yy.c tests/testpol.conf tests/testpol.bin
$(MAKE) -C test clean
-
-indent:
- ../scripts/Lindent $(filter-out $(GENERATED),$(wildcard *.[ch]))
diff --git a/gui/Makefile b/gui/Makefile
index b29610d4..b1a94224 100644
--- a/gui/Makefile
+++ b/gui/Makefile
@@ -60,8 +60,6 @@ install: all
clean:
(cd po && $(MAKE) $@)
-indent:
-
relabel:
test:
diff --git a/libselinux/Makefile b/libselinux/Makefile
index a50b6491..aeede2b5 100644
--- a/libselinux/Makefile
+++ b/libselinux/Makefile
@@ -50,7 +50,7 @@ COMPILER := clang
endif
export COMPILER
-all install relabel clean distclean indent:
+all install relabel clean distclean:
@for subdir in $(SUBDIRS); do \
(cd $$subdir && $(MAKE) $@) || exit 1; \
done
diff --git a/libselinux/include/Makefile b/libselinux/include/Makefile
index 8ab9ce92..a1e322ac 100644
--- a/libselinux/include/Makefile
+++ b/libselinux/include/Makefile
@@ -10,9 +10,5 @@ install: all
relabel:
-indent:
- ../../scripts/Lindent $(wildcard selinux/*.h)
-
distclean clean:
-rm -f selinux/*~
-
diff --git a/libselinux/man/Makefile b/libselinux/man/Makefile
index fdc0825f..42b1662a 100644
--- a/libselinux/man/Makefile
+++ b/libselinux/man/Makefile
@@ -35,4 +35,4 @@ install: all
relabel:
-indent distclean clean:
+format distclean clean:
diff --git a/libselinux/src/Makefile b/libselinux/src/Makefile
index 261c22d4..f7412cd1 100644
--- a/libselinux/src/Makefile
+++ b/libselinux/src/Makefile
@@ -223,7 +223,4 @@ clean: clean-pywrap clean-rubywrap
distclean: clean
rm -f $(GENERATED) $(SWIGFILES)
-indent:
- ../../scripts/Lindent $(filter-out $(GENERATED),$(wildcard *.[ch]))
-
.PHONY: all clean clean-pywrap clean-rubywrap pywrap rubywrap swigify install install-pywrap install-rubywrap distclean
diff --git a/libselinux/utils/Makefile b/libselinux/utils/Makefile
index 6b1dc7c9..20dc44eb 100644
--- a/libselinux/utils/Makefile
+++ b/libselinux/utils/Makefile
@@ -72,8 +72,4 @@ clean:
distclean: clean
-indent:
- ../../scripts/Lindent $(wildcard *.[ch])
-
relabel:
-
diff --git a/libsemanage/Makefile b/libsemanage/Makefile
index dbd240da..591ce5f2 100644
--- a/libsemanage/Makefile
+++ b/libsemanage/Makefile
@@ -29,9 +29,5 @@ clean distclean:
$(MAKE) -C src $@
$(MAKE) -C tests $@
-indent:
- $(MAKE) -C src $@
- $(MAKE) -C include $@
-
test: all
$(MAKE) -C tests test
diff --git a/libsemanage/include/Makefile b/libsemanage/include/Makefile
index 6e44a28a..b08e48a0 100644
--- a/libsemanage/include/Makefile
+++ b/libsemanage/include/Makefile
@@ -7,6 +7,3 @@ all:
install: all
test -d $(DESTDIR)$(INCDIR) || install -m 755 -d $(DESTDIR)$(INCDIR)
install -m 644 $(wildcard semanage/*.h) $(DESTDIR)$(INCDIR)
-
-indent:
- ../../scripts/Lindent $(wildcard semanage/*.h)
diff --git a/libsemanage/src/Makefile b/libsemanage/src/Makefile
index fa3449fb..8e025112 100644
--- a/libsemanage/src/Makefile
+++ b/libsemanage/src/Makefile
@@ -167,7 +167,4 @@ clean:
distclean: clean
rm -f $(GENERATED) $(SWIGFILES)
-indent:
- ../../scripts/Lindent $(filter-out $(GENERATED),$(wildcard *.[ch]))
-
.PHONY: all clean pywrap rubywrap swigify install install-pywrap install-rubywrap distclean
diff --git a/libsemanage/utils/Makefile b/libsemanage/utils/Makefile
index 5b8fbb6b..0f382934 100644
--- a/libsemanage/utils/Makefile
+++ b/libsemanage/utils/Makefile
@@ -13,7 +13,4 @@ clean:
distclean: clean
-indent:
-
relabel:
-
diff --git a/libsepol/Makefile b/libsepol/Makefile
index 5b5d03e2..223edcec 100644
--- a/libsepol/Makefile
+++ b/libsepol/Makefile
@@ -20,11 +20,5 @@ clean:
$(MAKE) -C utils clean
$(MAKE) -C tests clean
-indent:
- $(MAKE) -C src $@
- $(MAKE) -C include $@
- $(MAKE) -C utils $@
-
test:
$(MAKE) -C tests test
-
diff --git a/libsepol/include/Makefile b/libsepol/include/Makefile
index 1ad4ecab..f49b6e19 100644
--- a/libsepol/include/Makefile
+++ b/libsepol/include/Makefile
@@ -12,6 +12,3 @@ install: all
install -m 644 $(wildcard sepol/*.h) $(DESTDIR)$(INCDIR)
install -m 644 $(wildcard sepol/policydb/*.h) $(DESTDIR)$(INCDIR)/policydb
install -m 644 $(wildcard $(CILDIR)/include/cil/*.h) $(DESTDIR)$(INCDIR)/cil
-
-indent:
- ../../scripts/Lindent $(wildcard sepol/*.h)
diff --git a/libsepol/src/Makefile b/libsepol/src/Makefile
index 90aed394..bb2b7f5e 100644
--- a/libsepol/src/Makefile
+++ b/libsepol/src/Makefile
@@ -105,7 +105,3 @@ relabel:
clean:
-rm -f $(LIBPC) $(LIBMAP) $(OBJS) $(LOBJS) $(LIBA) $(LIBSO) $(TARGET) $(CIL_GENERATED)
-
-indent:
- ../../scripts/Lindent $(wildcard *.[ch])
-
diff --git a/libsepol/utils/Makefile b/libsepol/utils/Makefile
index 31932c11..a8bedf2e 100644
--- a/libsepol/utils/Makefile
+++ b/libsepol/utils/Makefile
@@ -18,8 +18,4 @@ install: all
clean:
-rm -f $(TARGETS) *.o
-indent:
- ../../scripts/Lindent $(wildcard *.[ch])
-
relabel:
-
diff --git a/mcstrans/src/Makefile b/mcstrans/src/Makefile
index 88487068..609b2d45 100644
--- a/mcstrans/src/Makefile
+++ b/mcstrans/src/Makefile
@@ -37,4 +37,3 @@ install: all
clean:
-rm -f $(OBJS) $(LOBJS) $(TARGET) $(PROG) $(PROG_OBJS) *~ \#*
-
diff --git a/mcstrans/utils/Makefile b/mcstrans/utils/Makefile
index 57a73932..1d70b4ed 100644
--- a/mcstrans/utils/Makefile
+++ b/mcstrans/utils/Makefile
@@ -36,4 +36,3 @@ clean:
rm -f $(TARGETS) *.o *~ \#*
relabel:
-
diff --git a/policycoreutils/Makefile b/policycoreutils/Makefile
index 7c9706e3..9186a9ef 100644
--- a/policycoreutils/Makefile
+++ b/policycoreutils/Makefile
@@ -6,7 +6,7 @@ LIBSELINUX_LDLIBS := $(shell PKG_CONFIG_PATH="$(PKG_CONFIG_PATH):../libselinux/s
LIBSEMANAGE_LDLIBS := $(shell PKG_CONFIG_PATH="$(PKG_CONFIG_PATH):../libsemanage/src" $(PKG_CONFIG) --libs libsemanage)
export LIBSELINUX_LDLIBS LIBSEMANAGE_LDLIBS
-all install relabel clean indent:
+all install relabel clean:
@for subdir in $(SUBDIRS); do \
(cd $$subdir && $(MAKE) $@) || exit 1; \
done
diff --git a/policycoreutils/hll/Makefile b/policycoreutils/hll/Makefile
index fe720e57..390f3a34 100644
--- a/policycoreutils/hll/Makefile
+++ b/policycoreutils/hll/Makefile
@@ -1,6 +1,6 @@
SUBDIRS = pp
-all install relabel clean indent:
+all install relabel clean:
@for subdir in $(SUBDIRS); do \
(cd $$subdir && $(MAKE) $@) || exit 1; \
done
diff --git a/policycoreutils/hll/pp/Makefile b/policycoreutils/hll/pp/Makefile
index 3c9b0efc..a0d475a3 100644
--- a/policycoreutils/hll/pp/Makefile
+++ b/policycoreutils/hll/pp/Makefile
@@ -25,6 +25,3 @@ relabel:
clean:
-rm -f pp $(PP_OBJS)
-
-indent:
- ../../scripts/Lindent $(wildcard *.[ch])
diff --git a/policycoreutils/load_policy/Makefile b/policycoreutils/load_policy/Makefile
index c61fee70..7754cadc 100644
--- a/policycoreutils/load_policy/Makefile
+++ b/policycoreutils/load_policy/Makefile
@@ -28,8 +28,5 @@ install: all
clean:
-rm -f $(TARGETS) *.o
-indent:
- ../../scripts/Lindent $(wildcard *.[ch])
-
relabel:
/sbin/restorecon $(DESTDIR)$(SBINDIR)/load_policy
diff --git a/policycoreutils/newrole/Makefile b/policycoreutils/newrole/Makefile
index df64483f..fcd2661f 100644
--- a/policycoreutils/newrole/Makefile
+++ b/policycoreutils/newrole/Makefile
@@ -87,9 +87,6 @@ endif
clean:
rm -f newrole *.o
-indent:
- ../../scripts/Lindent $(wildcard *.[ch])
-
relabel: install
/sbin/restorecon $(DESTDIR)$(BINDIR)/newrole
diff --git a/policycoreutils/run_init/Makefile b/policycoreutils/run_init/Makefile
index c89fffb9..0e904dba 100644
--- a/policycoreutils/run_init/Makefile
+++ b/policycoreutils/run_init/Makefile
@@ -53,8 +53,5 @@ endif
clean:
-rm -f $(TARGETS) *.o
-indent:
- ../../scripts/Lindent $(wildcard *.[ch])
-
relabel: install
/sbin/restorecon $(DESTDIR)$(SBINDIR)/run_init $(DESTDIR)$(SBINDIR)/open_init_pty
diff --git a/policycoreutils/scripts/Makefile b/policycoreutils/scripts/Makefile
index 6d8196c6..1058bbab 100644
--- a/policycoreutils/scripts/Makefile
+++ b/policycoreutils/scripts/Makefile
@@ -21,6 +21,4 @@ install: all
clean:
-indent:
-
relabel:
diff --git a/policycoreutils/secon/Makefile b/policycoreutils/secon/Makefile
index c9296f19..b2f276f9 100644
--- a/policycoreutils/secon/Makefile
+++ b/policycoreutils/secon/Makefile
@@ -35,9 +35,6 @@ relabel:
clean:
rm -f *.o core* secon *~ *.bak
-indent:
- ../../scripts/Lindent $(wildcard *.[ch])
-
bare: clean
.PHONY: clean bare
diff --git a/policycoreutils/semodule/Makefile b/policycoreutils/semodule/Makefile
index 018ee2ca..47bde5f8 100644
--- a/policycoreutils/semodule/Makefile
+++ b/policycoreutils/semodule/Makefile
@@ -35,7 +35,3 @@ relabel:
clean:
-rm -f semodule *.o genhomedircon
-
-indent:
- ../../scripts/Lindent $(wildcard *.[ch])
-
diff --git a/policycoreutils/sestatus/Makefile b/policycoreutils/sestatus/Makefile
index 1ce617c0..70f46956 100644
--- a/policycoreutils/sestatus/Makefile
+++ b/policycoreutils/sestatus/Makefile
@@ -41,7 +41,4 @@ install: all
clean:
rm -f sestatus *.o
-indent:
- ../../scripts/Lindent $(wildcard *.[ch])
-
relabel:
diff --git a/policycoreutils/setfiles/Makefile b/policycoreutils/setfiles/Makefile
index dab6313c..aa3e80fc 100644
--- a/policycoreutils/setfiles/Makefile
+++ b/policycoreutils/setfiles/Makefile
@@ -43,8 +43,5 @@ install: all
clean:
rm -f setfiles restorecon restorecon_xattr *.o
-indent:
- ../../scripts/Lindent $(wildcard *.[ch])
-
relabel: install
$(DESTDIR)$(SBINDIR)/restorecon $(DESTDIR)$(SBINDIR)/setfiles $(DESTDIR)$(SBINDIR)/restorecon_xattr
diff --git a/policycoreutils/setsebool/Makefile b/policycoreutils/setsebool/Makefile
index 87494c55..360e0ea0 100644
--- a/policycoreutils/setsebool/Makefile
+++ b/policycoreutils/setsebool/Makefile
@@ -35,7 +35,3 @@ relabel:
clean:
-rm -f setsebool *.o
-
-indent:
- ../../scripts/Lindent $(wildcard *.[ch])
-
diff --git a/policycoreutils/unsetfiles/Makefile b/policycoreutils/unsetfiles/Makefile
index 9cb51494..8dbf85af 100644
--- a/policycoreutils/unsetfiles/Makefile
+++ b/policycoreutils/unsetfiles/Makefile
@@ -20,8 +20,5 @@ install: all
clean:
-rm -f unsetfiles *.o
-indent:
- ../../scripts/Lindent $(wildcard *.[ch])
-
relabel: install
/sbin/restorecon $(DESTDIR)$(SBINDIR)/unsetfiles
diff --git a/python/Makefile b/python/Makefile
index 00312dbd..c4c31a17 100644
--- a/python/Makefile
+++ b/python/Makefile
@@ -1,6 +1,6 @@
SUBDIRS = sepolicy audit2allow semanage sepolgen chcat po
-all install relabel clean indent test:
+all install relabel clean format test:
@for subdir in $(SUBDIRS); do \
(cd $$subdir && $(MAKE) $@) || exit 1; \
done
diff --git a/python/audit2allow/Makefile b/python/audit2allow/Makefile
index 28b8f7f2..90d10d1a 100644
--- a/python/audit2allow/Makefile
+++ b/python/audit2allow/Makefile
@@ -51,7 +51,4 @@ install: all
clean:
rm -f *~ *.o sepolgen-ifgen-attr-helper test_dummy_policy
-indent:
- ../../scripts/Lindent $(wildcard *.[ch])
-
relabel: ;
diff --git a/python/chcat/Makefile b/python/chcat/Makefile
index 7b3ee17f..334b749d 100644
--- a/python/chcat/Makefile
+++ b/python/chcat/Makefile
@@ -21,8 +21,6 @@ install: all
clean:
-indent:
-
relabel:
test:
diff --git a/python/semanage/Makefile b/python/semanage/Makefile
index 628d135a..51208d9e 100644
--- a/python/semanage/Makefile
+++ b/python/semanage/Makefile
@@ -35,6 +35,4 @@ test:
@$(PYTHON) test-semanage.py -a
clean:
-indent:
-
relabel:
diff --git a/python/sepolgen/Makefile b/python/sepolgen/Makefile
index 3aed3304..2ad7b13c 100644
--- a/python/sepolgen/Makefile
+++ b/python/sepolgen/Makefile
@@ -11,10 +11,5 @@ clean:
rm -f *~ *.pyc
rm -f parser.out parsetab.py
-indent: ;
-
test:
$(MAKE) -C tests $@
-
-
-
diff --git a/python/sepolgen/src/Makefile b/python/sepolgen/src/Makefile
index 2815a13d..a2456652 100644
--- a/python/sepolgen/src/Makefile
+++ b/python/sepolgen/src/Makefile
@@ -12,10 +12,4 @@ clean:
rm -f *~ *.pyc
rm -f parser.out parsetab.py
-indent: ;
-
-
test: ;
-
-
-
diff --git a/restorecond/Makefile b/restorecond/Makefile
index b8b86eb4..51eb7608 100644
--- a/restorecond/Makefile
+++ b/restorecond/Makefile
@@ -59,7 +59,4 @@ relabel: install
clean:
-rm -f restorecond *.o *~
-indent:
- ../../scripts/Lindent $(wildcard *.[ch])
-
test:
diff --git a/sandbox/Makefile b/sandbox/Makefile
index 0799ab7c..eaaad75c 100644
--- a/sandbox/Makefile
+++ b/sandbox/Makefile
@@ -50,7 +50,4 @@ clean:
-rm -f seunshare *.o *~
(cd po && $(MAKE) $@)
-indent:
- ../../scripts/Lindent $(wildcard *.[ch])
-
relabel:
diff --git a/scripts/Lindent b/scripts/Lindent
deleted file mode 100755
index 9c4b3e2b..00000000
--- a/scripts/Lindent
+++ /dev/null
@@ -1,18 +0,0 @@
-#!/bin/sh
-PARAM="-npro -kr -i8 -ts8 -sob -l80 -ss -ncs -cp1"
-RES=`indent --version`
-V1=`echo $RES | cut -d' ' -f3 | cut -d'.' -f1`
-V2=`echo $RES | cut -d' ' -f3 | cut -d'.' -f2`
-V3=`echo $RES | cut -d' ' -f3 | cut -d'.' -f3`
-if [ $V1 -gt 2 ]; then
- PARAM="$PARAM -il0"
-elif [ $V1 -eq 2 ]; then
- if [ $V2 -gt 2 ]; then
- PARAM="$PARAM -il0";
- elif [ $V2 -eq 2 ]; then
- if [ $V3 -ge 10 ]; then
- PARAM="$PARAM -il0"
- fi
- fi
-fi
-indent $PARAM "$@"
diff --git a/semodule-utils/Makefile b/semodule-utils/Makefile
index e0a65792..81c97af0 100644
--- a/semodule-utils/Makefile
+++ b/semodule-utils/Makefile
@@ -1,6 +1,6 @@
SUBDIRS = semodule_package semodule_link semodule_expand
-all install relabel clean indent:
+all install relabel clean:
@for subdir in $(SUBDIRS); do \
(cd $$subdir && $(MAKE) $@) || exit 1; \
done
diff --git a/semodule-utils/semodule_expand/Makefile b/semodule-utils/semodule_expand/Makefile
index ad776b15..72f09a46 100644
--- a/semodule-utils/semodule_expand/Makefile
+++ b/semodule-utils/semodule_expand/Makefile
@@ -27,7 +27,3 @@ relabel:
clean:
-rm -f semodule_expand *.o
-
-indent:
- ../../scripts/Lindent $(wildcard *.[ch])
-
diff --git a/semodule-utils/semodule_link/Makefile b/semodule-utils/semodule_link/Makefile
index 936d161c..83590c07 100644
--- a/semodule-utils/semodule_link/Makefile
+++ b/semodule-utils/semodule_link/Makefile
@@ -27,7 +27,3 @@ relabel:
clean:
-rm -f semodule_link *.o
-
-indent:
- ../../scripts/Lindent $(wildcard *.[ch])
-
diff --git a/semodule-utils/semodule_package/Makefile b/semodule-utils/semodule_package/Makefile
index 6a289f73..2465f987 100644
--- a/semodule-utils/semodule_package/Makefile
+++ b/semodule-utils/semodule_package/Makefile
@@ -29,7 +29,3 @@ relabel:
clean:
-rm -f semodule_package semodule_unpackage *.o
-
-indent:
- ../../scripts/Lindent $(wildcard *.[ch])
-
--
2.51.0
^ permalink raw reply related [flat|nested] 22+ messages in thread
* [PATCH v6] treewide: add .clang-format configuration file
2025-10-20 14:07 ` [PATCH v5] " Rahul Sandhu
@ 2025-10-20 14:09 ` Rahul Sandhu
2025-10-20 14:55 ` Stephen Smalley
0 siblings, 1 reply; 22+ messages in thread
From: Rahul Sandhu @ 2025-10-20 14:09 UTC (permalink / raw)
To: nvraxn; +Cc: lautrbach, selinux, stephen.smalley.work
Add the .clang-format configuration file, taken from the Linux kernel
repository. We don't have any official style guidelines in tree at
present, which makes it a bit unclear how to format C code for new
contributors. As well as this, different parts of the codebase seem to
been formatted with different styles on occasion, so using an automatic
formatter should resolve this.
As well as this, replace all the existing indent targets with a single
toplevel `format` target. Managing all the source files to be formatted
is not pretty to maintain, and doesn't really give us much.
Also define a toplevel `check-format` target to verify that all code is
formatted properly. This only becomes useful in the future once we have
reformatted all existing code, but is wired up for now.
For the future:
1. Reformat all existing code. I understand this is a big change, but
we may as well get all code formatted if we go down this route;
afterall, it's not like this will cause any breaking changes.
2. Add a CI target to check that all code is formatted as per the new
clang-format configuration. The `check-format` target can be used
for this.
Signed-off-by: Rahul Sandhu <nvraxn@gmail.com>
---
.clang-format | 130 +++++++++++++++++++++++
CONTRIBUTING.md | 2 +
Makefile | 11 +-
checkpolicy/Makefile | 3 -
gui/Makefile | 2 -
libselinux/Makefile | 2 +-
libselinux/include/Makefile | 4 -
libselinux/man/Makefile | 2 +-
libselinux/src/Makefile | 3 -
libselinux/utils/Makefile | 4 -
libsemanage/Makefile | 4 -
libsemanage/include/Makefile | 3 -
libsemanage/src/Makefile | 3 -
libsemanage/utils/Makefile | 3 -
libsepol/Makefile | 6 --
libsepol/include/Makefile | 3 -
libsepol/src/Makefile | 4 -
libsepol/utils/Makefile | 4 -
mcstrans/src/Makefile | 1 -
mcstrans/utils/Makefile | 1 -
policycoreutils/Makefile | 2 +-
policycoreutils/hll/Makefile | 2 +-
policycoreutils/hll/pp/Makefile | 3 -
policycoreutils/load_policy/Makefile | 3 -
policycoreutils/newrole/Makefile | 3 -
policycoreutils/run_init/Makefile | 3 -
policycoreutils/scripts/Makefile | 2 -
policycoreutils/secon/Makefile | 3 -
policycoreutils/semodule/Makefile | 4 -
policycoreutils/sestatus/Makefile | 3 -
policycoreutils/setfiles/Makefile | 3 -
policycoreutils/setsebool/Makefile | 4 -
policycoreutils/unsetfiles/Makefile | 3 -
python/Makefile | 2 +-
python/audit2allow/Makefile | 3 -
python/chcat/Makefile | 2 -
python/semanage/Makefile | 2 -
python/sepolgen/Makefile | 5 -
python/sepolgen/src/Makefile | 6 --
restorecond/Makefile | 3 -
sandbox/Makefile | 3 -
scripts/Lindent | 18 ----
semodule-utils/Makefile | 2 +-
semodule-utils/semodule_expand/Makefile | 4 -
semodule-utils/semodule_link/Makefile | 4 -
semodule-utils/semodule_package/Makefile | 4 -
46 files changed, 148 insertions(+), 143 deletions(-)
create mode 100644 .clang-format
delete mode 100755 scripts/Lindent
v2: remove linux kernel ForEachMacros and replace them with ours
v3: replace the indent target with the new format target. also remove any
mention of `.editorconfig` from the commit message; those changes are
better suited for another patch (they're small and self-contained enough
that they're a smaller thing to merge).
v4: drop the subdir format targets entirely, replacing with a single toplevel
format and check-format target.
v5: add back relabel target accidently removed.
v6: remove all references to being an RFC in the commit message.
diff --git a/.clang-format b/.clang-format
new file mode 100644
index 00000000..35595d87
--- /dev/null
+++ b/.clang-format
@@ -0,0 +1,130 @@
+# SPDX-License-Identifier: GPL-2.0
+#
+# clang-format configuration file. Intended for clang-format >= 11.
+#
+# For more information, see:
+#
+# Documentation/dev-tools/clang-format.rst
+# https://clang.llvm.org/docs/ClangFormat.html
+# https://clang.llvm.org/docs/ClangFormatStyleOptions.html
+#
+---
+AccessModifierOffset: -4
+AlignAfterOpenBracket: Align
+AlignConsecutiveAssignments: false
+AlignConsecutiveDeclarations: false
+AlignEscapedNewlines: Left
+AlignOperands: true
+AlignTrailingComments: false
+AllowAllParametersOfDeclarationOnNextLine: false
+AllowShortBlocksOnASingleLine: false
+AllowShortCaseLabelsOnASingleLine: false
+AllowShortFunctionsOnASingleLine: None
+AllowShortIfStatementsOnASingleLine: false
+AllowShortLoopsOnASingleLine: false
+AlwaysBreakAfterDefinitionReturnType: None
+AlwaysBreakAfterReturnType: None
+AlwaysBreakBeforeMultilineStrings: false
+AlwaysBreakTemplateDeclarations: false
+BinPackArguments: true
+BinPackParameters: true
+BraceWrapping:
+ AfterClass: false
+ AfterControlStatement: false
+ AfterEnum: false
+ AfterFunction: true
+ AfterNamespace: true
+ AfterObjCDeclaration: false
+ AfterStruct: false
+ AfterUnion: false
+ AfterExternBlock: false
+ BeforeCatch: false
+ BeforeElse: false
+ IndentBraces: false
+ SplitEmptyFunction: true
+ SplitEmptyRecord: true
+ SplitEmptyNamespace: true
+BreakBeforeBinaryOperators: None
+BreakBeforeBraces: Custom
+BreakBeforeInheritanceComma: false
+BreakBeforeTernaryOperators: false
+BreakConstructorInitializersBeforeComma: false
+BreakConstructorInitializers: BeforeComma
+BreakAfterJavaFieldAnnotations: false
+BreakStringLiterals: false
+ColumnLimit: 80
+CommentPragmas: '^ IWYU pragma:'
+CompactNamespaces: false
+ConstructorInitializerAllOnOneLineOrOnePerLine: false
+ConstructorInitializerIndentWidth: 8
+ContinuationIndentWidth: 8
+Cpp11BracedListStyle: false
+DerivePointerAlignment: false
+DisableFormat: false
+ExperimentalAutoDetectBinPacking: false
+FixNamespaceComments: false
+
+# Taken from:
+# git grep -h '^#define [^[:space:]]*for_each[^[:space:]]*(' \
+# | sed "s,^#define \([^[:space:]]*for_each[^[:space:]]*\)(.*$, - '\1'," \
+# | LC_ALL=C sort -u
+ForEachMacros:
+ - 'cil_list_for_each'
+ - 'cil_stack_for_each'
+ - 'cil_stack_for_each_starting_at'
+ - 'ebitmap_for_each_bit'
+ - 'ebitmap_for_each_positive_bit'
+
+IncludeBlocks: Preserve
+IncludeCategories:
+ - Regex: '.*'
+ Priority: 1
+IncludeIsMainRegex: '(Test)?$'
+IndentCaseLabels: false
+IndentGotoLabels: false
+IndentPPDirectives: None
+IndentWidth: 8
+IndentWrappedFunctionNames: false
+JavaScriptQuotes: Leave
+JavaScriptWrapImports: true
+KeepEmptyLinesAtTheStartOfBlocks: false
+MacroBlockBegin: ''
+MacroBlockEnd: ''
+MaxEmptyLinesToKeep: 1
+NamespaceIndentation: None
+ObjCBinPackProtocolList: Auto
+ObjCBlockIndentWidth: 8
+ObjCSpaceAfterProperty: true
+ObjCSpaceBeforeProtocolList: true
+
+# Taken from git's rules
+PenaltyBreakAssignment: 10
+PenaltyBreakBeforeFirstCallParameter: 30
+PenaltyBreakComment: 10
+PenaltyBreakFirstLessLess: 0
+PenaltyBreakString: 10
+PenaltyExcessCharacter: 100
+PenaltyReturnTypeOnItsOwnLine: 60
+
+PointerAlignment: Right
+ReflowComments: false
+SortIncludes: false
+SortUsingDeclarations: false
+SpaceAfterCStyleCast: false
+SpaceAfterTemplateKeyword: true
+SpaceBeforeAssignmentOperators: true
+SpaceBeforeCtorInitializerColon: true
+SpaceBeforeInheritanceColon: true
+SpaceBeforeParens: ControlStatementsExceptForEachMacros
+SpaceBeforeRangeBasedForLoopColon: true
+SpaceInEmptyParentheses: false
+SpacesBeforeTrailingComments: 1
+SpacesInAngles: false
+SpacesInContainerLiterals: false
+SpacesInCStyleCastParentheses: false
+SpacesInParentheses: false
+SpacesInSquareBrackets: false
+Standard: Cpp03
+TabWidth: 8
+UseTab: Always
+...
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index c501cf84..7ec8cb0f 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -53,6 +53,8 @@ When preparing patches, please follow these guidelines:
- Separate large patches into logical patches
- Patch descriptions must end with your "Signed-off-by" line. This means your
code meets the Developer's certificate of origin, see below.
+- C code should be formatted using clang-format, using the .clang-format
+ configuration file at the root of this repository.
When adding new, large features or tools it is best to discuss the
design on the mailing list prior to submitting the patch.
diff --git a/Makefile b/Makefile
index 2ffba8e9..972d5525 100644
--- a/Makefile
+++ b/Makefile
@@ -36,7 +36,7 @@ ifneq ($(DESTDIR),)
export LIBSEPOLA
endif
-all install relabel clean test indent:
+all install relabel clean test:
@for subdir in $(SUBDIRS); do \
(cd $$subdir && $(MAKE) $@) || exit 1; \
done
@@ -50,3 +50,12 @@ distclean:
@for subdir in $(DISTCLEANSUBDIRS); do \
(cd $$subdir && $(MAKE) $@) || exit 1; \
done
+
+# We shouldn't have any unformatted files in the repo without an explicit exception.
+FORMAT_SOURCE_FILES := $(shell find $(SUBDIRS) -type f \( -name '*.c' -o -name '*.h' \))
+
+format:
+ clang-format -i $(FORMAT_SOURCE_FILES)
+
+check-format:
+ clang-format --dry-run -Werror $(FORMAT_SOURCE_FILES)
diff --git a/checkpolicy/Makefile b/checkpolicy/Makefile
index 6e8008e3..0055f495 100644
--- a/checkpolicy/Makefile
+++ b/checkpolicy/Makefile
@@ -77,6 +77,3 @@ relabel: install
clean:
-rm -f $(TARGETS) $(CHECKPOLOBJS) $(CHECKMODOBJS) y.tab.c y.tab.h lex.yy.c tests/testpol.conf tests/testpol.bin
$(MAKE) -C test clean
-
-indent:
- ../scripts/Lindent $(filter-out $(GENERATED),$(wildcard *.[ch]))
diff --git a/gui/Makefile b/gui/Makefile
index b29610d4..b1a94224 100644
--- a/gui/Makefile
+++ b/gui/Makefile
@@ -60,8 +60,6 @@ install: all
clean:
(cd po && $(MAKE) $@)
-indent:
-
relabel:
test:
diff --git a/libselinux/Makefile b/libselinux/Makefile
index a50b6491..aeede2b5 100644
--- a/libselinux/Makefile
+++ b/libselinux/Makefile
@@ -50,7 +50,7 @@ COMPILER := clang
endif
export COMPILER
-all install relabel clean distclean indent:
+all install relabel clean distclean:
@for subdir in $(SUBDIRS); do \
(cd $$subdir && $(MAKE) $@) || exit 1; \
done
diff --git a/libselinux/include/Makefile b/libselinux/include/Makefile
index 8ab9ce92..a1e322ac 100644
--- a/libselinux/include/Makefile
+++ b/libselinux/include/Makefile
@@ -10,9 +10,5 @@ install: all
relabel:
-indent:
- ../../scripts/Lindent $(wildcard selinux/*.h)
-
distclean clean:
-rm -f selinux/*~
-
diff --git a/libselinux/man/Makefile b/libselinux/man/Makefile
index fdc0825f..42b1662a 100644
--- a/libselinux/man/Makefile
+++ b/libselinux/man/Makefile
@@ -35,4 +35,4 @@ install: all
relabel:
-indent distclean clean:
+format distclean clean:
diff --git a/libselinux/src/Makefile b/libselinux/src/Makefile
index 261c22d4..f7412cd1 100644
--- a/libselinux/src/Makefile
+++ b/libselinux/src/Makefile
@@ -223,7 +223,4 @@ clean: clean-pywrap clean-rubywrap
distclean: clean
rm -f $(GENERATED) $(SWIGFILES)
-indent:
- ../../scripts/Lindent $(filter-out $(GENERATED),$(wildcard *.[ch]))
-
.PHONY: all clean clean-pywrap clean-rubywrap pywrap rubywrap swigify install install-pywrap install-rubywrap distclean
diff --git a/libselinux/utils/Makefile b/libselinux/utils/Makefile
index 6b1dc7c9..20dc44eb 100644
--- a/libselinux/utils/Makefile
+++ b/libselinux/utils/Makefile
@@ -72,8 +72,4 @@ clean:
distclean: clean
-indent:
- ../../scripts/Lindent $(wildcard *.[ch])
-
relabel:
-
diff --git a/libsemanage/Makefile b/libsemanage/Makefile
index dbd240da..591ce5f2 100644
--- a/libsemanage/Makefile
+++ b/libsemanage/Makefile
@@ -29,9 +29,5 @@ clean distclean:
$(MAKE) -C src $@
$(MAKE) -C tests $@
-indent:
- $(MAKE) -C src $@
- $(MAKE) -C include $@
-
test: all
$(MAKE) -C tests test
diff --git a/libsemanage/include/Makefile b/libsemanage/include/Makefile
index 6e44a28a..b08e48a0 100644
--- a/libsemanage/include/Makefile
+++ b/libsemanage/include/Makefile
@@ -7,6 +7,3 @@ all:
install: all
test -d $(DESTDIR)$(INCDIR) || install -m 755 -d $(DESTDIR)$(INCDIR)
install -m 644 $(wildcard semanage/*.h) $(DESTDIR)$(INCDIR)
-
-indent:
- ../../scripts/Lindent $(wildcard semanage/*.h)
diff --git a/libsemanage/src/Makefile b/libsemanage/src/Makefile
index fa3449fb..8e025112 100644
--- a/libsemanage/src/Makefile
+++ b/libsemanage/src/Makefile
@@ -167,7 +167,4 @@ clean:
distclean: clean
rm -f $(GENERATED) $(SWIGFILES)
-indent:
- ../../scripts/Lindent $(filter-out $(GENERATED),$(wildcard *.[ch]))
-
.PHONY: all clean pywrap rubywrap swigify install install-pywrap install-rubywrap distclean
diff --git a/libsemanage/utils/Makefile b/libsemanage/utils/Makefile
index 5b8fbb6b..0f382934 100644
--- a/libsemanage/utils/Makefile
+++ b/libsemanage/utils/Makefile
@@ -13,7 +13,4 @@ clean:
distclean: clean
-indent:
-
relabel:
-
diff --git a/libsepol/Makefile b/libsepol/Makefile
index 5b5d03e2..223edcec 100644
--- a/libsepol/Makefile
+++ b/libsepol/Makefile
@@ -20,11 +20,5 @@ clean:
$(MAKE) -C utils clean
$(MAKE) -C tests clean
-indent:
- $(MAKE) -C src $@
- $(MAKE) -C include $@
- $(MAKE) -C utils $@
-
test:
$(MAKE) -C tests test
-
diff --git a/libsepol/include/Makefile b/libsepol/include/Makefile
index 1ad4ecab..f49b6e19 100644
--- a/libsepol/include/Makefile
+++ b/libsepol/include/Makefile
@@ -12,6 +12,3 @@ install: all
install -m 644 $(wildcard sepol/*.h) $(DESTDIR)$(INCDIR)
install -m 644 $(wildcard sepol/policydb/*.h) $(DESTDIR)$(INCDIR)/policydb
install -m 644 $(wildcard $(CILDIR)/include/cil/*.h) $(DESTDIR)$(INCDIR)/cil
-
-indent:
- ../../scripts/Lindent $(wildcard sepol/*.h)
diff --git a/libsepol/src/Makefile b/libsepol/src/Makefile
index 90aed394..bb2b7f5e 100644
--- a/libsepol/src/Makefile
+++ b/libsepol/src/Makefile
@@ -105,7 +105,3 @@ relabel:
clean:
-rm -f $(LIBPC) $(LIBMAP) $(OBJS) $(LOBJS) $(LIBA) $(LIBSO) $(TARGET) $(CIL_GENERATED)
-
-indent:
- ../../scripts/Lindent $(wildcard *.[ch])
-
diff --git a/libsepol/utils/Makefile b/libsepol/utils/Makefile
index 31932c11..a8bedf2e 100644
--- a/libsepol/utils/Makefile
+++ b/libsepol/utils/Makefile
@@ -18,8 +18,4 @@ install: all
clean:
-rm -f $(TARGETS) *.o
-indent:
- ../../scripts/Lindent $(wildcard *.[ch])
-
relabel:
-
diff --git a/mcstrans/src/Makefile b/mcstrans/src/Makefile
index 88487068..609b2d45 100644
--- a/mcstrans/src/Makefile
+++ b/mcstrans/src/Makefile
@@ -37,4 +37,3 @@ install: all
clean:
-rm -f $(OBJS) $(LOBJS) $(TARGET) $(PROG) $(PROG_OBJS) *~ \#*
-
diff --git a/mcstrans/utils/Makefile b/mcstrans/utils/Makefile
index 57a73932..1d70b4ed 100644
--- a/mcstrans/utils/Makefile
+++ b/mcstrans/utils/Makefile
@@ -36,4 +36,3 @@ clean:
rm -f $(TARGETS) *.o *~ \#*
relabel:
-
diff --git a/policycoreutils/Makefile b/policycoreutils/Makefile
index 7c9706e3..9186a9ef 100644
--- a/policycoreutils/Makefile
+++ b/policycoreutils/Makefile
@@ -6,7 +6,7 @@ LIBSELINUX_LDLIBS := $(shell PKG_CONFIG_PATH="$(PKG_CONFIG_PATH):../libselinux/s
LIBSEMANAGE_LDLIBS := $(shell PKG_CONFIG_PATH="$(PKG_CONFIG_PATH):../libsemanage/src" $(PKG_CONFIG) --libs libsemanage)
export LIBSELINUX_LDLIBS LIBSEMANAGE_LDLIBS
-all install relabel clean indent:
+all install relabel clean:
@for subdir in $(SUBDIRS); do \
(cd $$subdir && $(MAKE) $@) || exit 1; \
done
diff --git a/policycoreutils/hll/Makefile b/policycoreutils/hll/Makefile
index fe720e57..390f3a34 100644
--- a/policycoreutils/hll/Makefile
+++ b/policycoreutils/hll/Makefile
@@ -1,6 +1,6 @@
SUBDIRS = pp
-all install relabel clean indent:
+all install relabel clean:
@for subdir in $(SUBDIRS); do \
(cd $$subdir && $(MAKE) $@) || exit 1; \
done
diff --git a/policycoreutils/hll/pp/Makefile b/policycoreutils/hll/pp/Makefile
index 3c9b0efc..a0d475a3 100644
--- a/policycoreutils/hll/pp/Makefile
+++ b/policycoreutils/hll/pp/Makefile
@@ -25,6 +25,3 @@ relabel:
clean:
-rm -f pp $(PP_OBJS)
-
-indent:
- ../../scripts/Lindent $(wildcard *.[ch])
diff --git a/policycoreutils/load_policy/Makefile b/policycoreutils/load_policy/Makefile
index c61fee70..7754cadc 100644
--- a/policycoreutils/load_policy/Makefile
+++ b/policycoreutils/load_policy/Makefile
@@ -28,8 +28,5 @@ install: all
clean:
-rm -f $(TARGETS) *.o
-indent:
- ../../scripts/Lindent $(wildcard *.[ch])
-
relabel:
/sbin/restorecon $(DESTDIR)$(SBINDIR)/load_policy
diff --git a/policycoreutils/newrole/Makefile b/policycoreutils/newrole/Makefile
index df64483f..fcd2661f 100644
--- a/policycoreutils/newrole/Makefile
+++ b/policycoreutils/newrole/Makefile
@@ -87,9 +87,6 @@ endif
clean:
rm -f newrole *.o
-indent:
- ../../scripts/Lindent $(wildcard *.[ch])
-
relabel: install
/sbin/restorecon $(DESTDIR)$(BINDIR)/newrole
diff --git a/policycoreutils/run_init/Makefile b/policycoreutils/run_init/Makefile
index c89fffb9..0e904dba 100644
--- a/policycoreutils/run_init/Makefile
+++ b/policycoreutils/run_init/Makefile
@@ -53,8 +53,5 @@ endif
clean:
-rm -f $(TARGETS) *.o
-indent:
- ../../scripts/Lindent $(wildcard *.[ch])
-
relabel: install
/sbin/restorecon $(DESTDIR)$(SBINDIR)/run_init $(DESTDIR)$(SBINDIR)/open_init_pty
diff --git a/policycoreutils/scripts/Makefile b/policycoreutils/scripts/Makefile
index 6d8196c6..1058bbab 100644
--- a/policycoreutils/scripts/Makefile
+++ b/policycoreutils/scripts/Makefile
@@ -21,6 +21,4 @@ install: all
clean:
-indent:
-
relabel:
diff --git a/policycoreutils/secon/Makefile b/policycoreutils/secon/Makefile
index c9296f19..b2f276f9 100644
--- a/policycoreutils/secon/Makefile
+++ b/policycoreutils/secon/Makefile
@@ -35,9 +35,6 @@ relabel:
clean:
rm -f *.o core* secon *~ *.bak
-indent:
- ../../scripts/Lindent $(wildcard *.[ch])
-
bare: clean
.PHONY: clean bare
diff --git a/policycoreutils/semodule/Makefile b/policycoreutils/semodule/Makefile
index 018ee2ca..47bde5f8 100644
--- a/policycoreutils/semodule/Makefile
+++ b/policycoreutils/semodule/Makefile
@@ -35,7 +35,3 @@ relabel:
clean:
-rm -f semodule *.o genhomedircon
-
-indent:
- ../../scripts/Lindent $(wildcard *.[ch])
-
diff --git a/policycoreutils/sestatus/Makefile b/policycoreutils/sestatus/Makefile
index 1ce617c0..70f46956 100644
--- a/policycoreutils/sestatus/Makefile
+++ b/policycoreutils/sestatus/Makefile
@@ -41,7 +41,4 @@ install: all
clean:
rm -f sestatus *.o
-indent:
- ../../scripts/Lindent $(wildcard *.[ch])
-
relabel:
diff --git a/policycoreutils/setfiles/Makefile b/policycoreutils/setfiles/Makefile
index dab6313c..aa3e80fc 100644
--- a/policycoreutils/setfiles/Makefile
+++ b/policycoreutils/setfiles/Makefile
@@ -43,8 +43,5 @@ install: all
clean:
rm -f setfiles restorecon restorecon_xattr *.o
-indent:
- ../../scripts/Lindent $(wildcard *.[ch])
-
relabel: install
$(DESTDIR)$(SBINDIR)/restorecon $(DESTDIR)$(SBINDIR)/setfiles $(DESTDIR)$(SBINDIR)/restorecon_xattr
diff --git a/policycoreutils/setsebool/Makefile b/policycoreutils/setsebool/Makefile
index 87494c55..360e0ea0 100644
--- a/policycoreutils/setsebool/Makefile
+++ b/policycoreutils/setsebool/Makefile
@@ -35,7 +35,3 @@ relabel:
clean:
-rm -f setsebool *.o
-
-indent:
- ../../scripts/Lindent $(wildcard *.[ch])
-
diff --git a/policycoreutils/unsetfiles/Makefile b/policycoreutils/unsetfiles/Makefile
index 9cb51494..8dbf85af 100644
--- a/policycoreutils/unsetfiles/Makefile
+++ b/policycoreutils/unsetfiles/Makefile
@@ -20,8 +20,5 @@ install: all
clean:
-rm -f unsetfiles *.o
-indent:
- ../../scripts/Lindent $(wildcard *.[ch])
-
relabel: install
/sbin/restorecon $(DESTDIR)$(SBINDIR)/unsetfiles
diff --git a/python/Makefile b/python/Makefile
index 00312dbd..c4c31a17 100644
--- a/python/Makefile
+++ b/python/Makefile
@@ -1,6 +1,6 @@
SUBDIRS = sepolicy audit2allow semanage sepolgen chcat po
-all install relabel clean indent test:
+all install relabel clean format test:
@for subdir in $(SUBDIRS); do \
(cd $$subdir && $(MAKE) $@) || exit 1; \
done
diff --git a/python/audit2allow/Makefile b/python/audit2allow/Makefile
index 28b8f7f2..90d10d1a 100644
--- a/python/audit2allow/Makefile
+++ b/python/audit2allow/Makefile
@@ -51,7 +51,4 @@ install: all
clean:
rm -f *~ *.o sepolgen-ifgen-attr-helper test_dummy_policy
-indent:
- ../../scripts/Lindent $(wildcard *.[ch])
-
relabel: ;
diff --git a/python/chcat/Makefile b/python/chcat/Makefile
index 7b3ee17f..334b749d 100644
--- a/python/chcat/Makefile
+++ b/python/chcat/Makefile
@@ -21,8 +21,6 @@ install: all
clean:
-indent:
-
relabel:
test:
diff --git a/python/semanage/Makefile b/python/semanage/Makefile
index 628d135a..51208d9e 100644
--- a/python/semanage/Makefile
+++ b/python/semanage/Makefile
@@ -35,6 +35,4 @@ test:
@$(PYTHON) test-semanage.py -a
clean:
-indent:
-
relabel:
diff --git a/python/sepolgen/Makefile b/python/sepolgen/Makefile
index 3aed3304..2ad7b13c 100644
--- a/python/sepolgen/Makefile
+++ b/python/sepolgen/Makefile
@@ -11,10 +11,5 @@ clean:
rm -f *~ *.pyc
rm -f parser.out parsetab.py
-indent: ;
-
test:
$(MAKE) -C tests $@
-
-
-
diff --git a/python/sepolgen/src/Makefile b/python/sepolgen/src/Makefile
index 2815a13d..a2456652 100644
--- a/python/sepolgen/src/Makefile
+++ b/python/sepolgen/src/Makefile
@@ -12,10 +12,4 @@ clean:
rm -f *~ *.pyc
rm -f parser.out parsetab.py
-indent: ;
-
-
test: ;
-
-
-
diff --git a/restorecond/Makefile b/restorecond/Makefile
index b8b86eb4..51eb7608 100644
--- a/restorecond/Makefile
+++ b/restorecond/Makefile
@@ -59,7 +59,4 @@ relabel: install
clean:
-rm -f restorecond *.o *~
-indent:
- ../../scripts/Lindent $(wildcard *.[ch])
-
test:
diff --git a/sandbox/Makefile b/sandbox/Makefile
index 0799ab7c..eaaad75c 100644
--- a/sandbox/Makefile
+++ b/sandbox/Makefile
@@ -50,7 +50,4 @@ clean:
-rm -f seunshare *.o *~
(cd po && $(MAKE) $@)
-indent:
- ../../scripts/Lindent $(wildcard *.[ch])
-
relabel:
diff --git a/scripts/Lindent b/scripts/Lindent
deleted file mode 100755
index 9c4b3e2b..00000000
--- a/scripts/Lindent
+++ /dev/null
@@ -1,18 +0,0 @@
-#!/bin/sh
-PARAM="-npro -kr -i8 -ts8 -sob -l80 -ss -ncs -cp1"
-RES=`indent --version`
-V1=`echo $RES | cut -d' ' -f3 | cut -d'.' -f1`
-V2=`echo $RES | cut -d' ' -f3 | cut -d'.' -f2`
-V3=`echo $RES | cut -d' ' -f3 | cut -d'.' -f3`
-if [ $V1 -gt 2 ]; then
- PARAM="$PARAM -il0"
-elif [ $V1 -eq 2 ]; then
- if [ $V2 -gt 2 ]; then
- PARAM="$PARAM -il0";
- elif [ $V2 -eq 2 ]; then
- if [ $V3 -ge 10 ]; then
- PARAM="$PARAM -il0"
- fi
- fi
-fi
-indent $PARAM "$@"
diff --git a/semodule-utils/Makefile b/semodule-utils/Makefile
index e0a65792..81c97af0 100644
--- a/semodule-utils/Makefile
+++ b/semodule-utils/Makefile
@@ -1,6 +1,6 @@
SUBDIRS = semodule_package semodule_link semodule_expand
-all install relabel clean indent:
+all install relabel clean:
@for subdir in $(SUBDIRS); do \
(cd $$subdir && $(MAKE) $@) || exit 1; \
done
diff --git a/semodule-utils/semodule_expand/Makefile b/semodule-utils/semodule_expand/Makefile
index ad776b15..72f09a46 100644
--- a/semodule-utils/semodule_expand/Makefile
+++ b/semodule-utils/semodule_expand/Makefile
@@ -27,7 +27,3 @@ relabel:
clean:
-rm -f semodule_expand *.o
-
-indent:
- ../../scripts/Lindent $(wildcard *.[ch])
-
diff --git a/semodule-utils/semodule_link/Makefile b/semodule-utils/semodule_link/Makefile
index 936d161c..83590c07 100644
--- a/semodule-utils/semodule_link/Makefile
+++ b/semodule-utils/semodule_link/Makefile
@@ -27,7 +27,3 @@ relabel:
clean:
-rm -f semodule_link *.o
-
-indent:
- ../../scripts/Lindent $(wildcard *.[ch])
-
diff --git a/semodule-utils/semodule_package/Makefile b/semodule-utils/semodule_package/Makefile
index 6a289f73..2465f987 100644
--- a/semodule-utils/semodule_package/Makefile
+++ b/semodule-utils/semodule_package/Makefile
@@ -29,7 +29,3 @@ relabel:
clean:
-rm -f semodule_package semodule_unpackage *.o
-
-indent:
- ../../scripts/Lindent $(wildcard *.[ch])
-
--
2.51.0
^ permalink raw reply related [flat|nested] 22+ messages in thread
* Re: [PATCH v6] treewide: add .clang-format configuration file
2025-10-20 14:09 ` [PATCH v6] " Rahul Sandhu
@ 2025-10-20 14:55 ` Stephen Smalley
2025-10-20 16:18 ` When to apply `make format` to the entire tree Petr Lautrbach
2025-10-21 13:49 ` [PATCH v6] treewide: add .clang-format configuration file Stephen Smalley
0 siblings, 2 replies; 22+ messages in thread
From: Stephen Smalley @ 2025-10-20 14:55 UTC (permalink / raw)
To: Rahul Sandhu; +Cc: lautrbach, selinux
On Mon, Oct 20, 2025 at 10:09 AM Rahul Sandhu <nvraxn@gmail.com> wrote:
>
> Add the .clang-format configuration file, taken from the Linux kernel
> repository. We don't have any official style guidelines in tree at
> present, which makes it a bit unclear how to format C code for new
> contributors. As well as this, different parts of the codebase seem to
> been formatted with different styles on occasion, so using an automatic
> formatter should resolve this.
>
> As well as this, replace all the existing indent targets with a single
> toplevel `format` target. Managing all the source files to be formatted
> is not pretty to maintain, and doesn't really give us much.
>
> Also define a toplevel `check-format` target to verify that all code is
> formatted properly. This only becomes useful in the future once we have
> reformatted all existing code, but is wired up for now.
>
> For the future:
> 1. Reformat all existing code. I understand this is a big change, but
> we may as well get all code formatted if we go down this route;
> afterall, it's not like this will cause any breaking changes.
>
> 2. Add a CI target to check that all code is formatted as per the new
> clang-format configuration. The `check-format` target can be used
> for this.
>
> Signed-off-by: Rahul Sandhu <nvraxn@gmail.com>
Acked-by: Stephen Smalley <stephen.smalley.work@gmail.com>
Will defer to distro package maintainers to decide when to apply make
format to the entire tree. Common practice I think is to do it just
before or after a release.
> ---
> .clang-format | 130 +++++++++++++++++++++++
> CONTRIBUTING.md | 2 +
> Makefile | 11 +-
> checkpolicy/Makefile | 3 -
> gui/Makefile | 2 -
> libselinux/Makefile | 2 +-
> libselinux/include/Makefile | 4 -
> libselinux/man/Makefile | 2 +-
> libselinux/src/Makefile | 3 -
> libselinux/utils/Makefile | 4 -
> libsemanage/Makefile | 4 -
> libsemanage/include/Makefile | 3 -
> libsemanage/src/Makefile | 3 -
> libsemanage/utils/Makefile | 3 -
> libsepol/Makefile | 6 --
> libsepol/include/Makefile | 3 -
> libsepol/src/Makefile | 4 -
> libsepol/utils/Makefile | 4 -
> mcstrans/src/Makefile | 1 -
> mcstrans/utils/Makefile | 1 -
> policycoreutils/Makefile | 2 +-
> policycoreutils/hll/Makefile | 2 +-
> policycoreutils/hll/pp/Makefile | 3 -
> policycoreutils/load_policy/Makefile | 3 -
> policycoreutils/newrole/Makefile | 3 -
> policycoreutils/run_init/Makefile | 3 -
> policycoreutils/scripts/Makefile | 2 -
> policycoreutils/secon/Makefile | 3 -
> policycoreutils/semodule/Makefile | 4 -
> policycoreutils/sestatus/Makefile | 3 -
> policycoreutils/setfiles/Makefile | 3 -
> policycoreutils/setsebool/Makefile | 4 -
> policycoreutils/unsetfiles/Makefile | 3 -
> python/Makefile | 2 +-
> python/audit2allow/Makefile | 3 -
> python/chcat/Makefile | 2 -
> python/semanage/Makefile | 2 -
> python/sepolgen/Makefile | 5 -
> python/sepolgen/src/Makefile | 6 --
> restorecond/Makefile | 3 -
> sandbox/Makefile | 3 -
> scripts/Lindent | 18 ----
> semodule-utils/Makefile | 2 +-
> semodule-utils/semodule_expand/Makefile | 4 -
> semodule-utils/semodule_link/Makefile | 4 -
> semodule-utils/semodule_package/Makefile | 4 -
> 46 files changed, 148 insertions(+), 143 deletions(-)
> create mode 100644 .clang-format
> delete mode 100755 scripts/Lindent
>
> v2: remove linux kernel ForEachMacros and replace them with ours
> v3: replace the indent target with the new format target. also remove any
> mention of `.editorconfig` from the commit message; those changes are
> better suited for another patch (they're small and self-contained enough
> that they're a smaller thing to merge).
> v4: drop the subdir format targets entirely, replacing with a single toplevel
> format and check-format target.
> v5: add back relabel target accidently removed.
> v6: remove all references to being an RFC in the commit message.
>
> diff --git a/.clang-format b/.clang-format
> new file mode 100644
> index 00000000..35595d87
> --- /dev/null
> +++ b/.clang-format
> @@ -0,0 +1,130 @@
> +# SPDX-License-Identifier: GPL-2.0
> +#
> +# clang-format configuration file. Intended for clang-format >= 11.
> +#
> +# For more information, see:
> +#
> +# Documentation/dev-tools/clang-format.rst
> +# https://clang.llvm.org/docs/ClangFormat.html
> +# https://clang.llvm.org/docs/ClangFormatStyleOptions.html
> +#
> +---
> +AccessModifierOffset: -4
> +AlignAfterOpenBracket: Align
> +AlignConsecutiveAssignments: false
> +AlignConsecutiveDeclarations: false
> +AlignEscapedNewlines: Left
> +AlignOperands: true
> +AlignTrailingComments: false
> +AllowAllParametersOfDeclarationOnNextLine: false
> +AllowShortBlocksOnASingleLine: false
> +AllowShortCaseLabelsOnASingleLine: false
> +AllowShortFunctionsOnASingleLine: None
> +AllowShortIfStatementsOnASingleLine: false
> +AllowShortLoopsOnASingleLine: false
> +AlwaysBreakAfterDefinitionReturnType: None
> +AlwaysBreakAfterReturnType: None
> +AlwaysBreakBeforeMultilineStrings: false
> +AlwaysBreakTemplateDeclarations: false
> +BinPackArguments: true
> +BinPackParameters: true
> +BraceWrapping:
> + AfterClass: false
> + AfterControlStatement: false
> + AfterEnum: false
> + AfterFunction: true
> + AfterNamespace: true
> + AfterObjCDeclaration: false
> + AfterStruct: false
> + AfterUnion: false
> + AfterExternBlock: false
> + BeforeCatch: false
> + BeforeElse: false
> + IndentBraces: false
> + SplitEmptyFunction: true
> + SplitEmptyRecord: true
> + SplitEmptyNamespace: true
> +BreakBeforeBinaryOperators: None
> +BreakBeforeBraces: Custom
> +BreakBeforeInheritanceComma: false
> +BreakBeforeTernaryOperators: false
> +BreakConstructorInitializersBeforeComma: false
> +BreakConstructorInitializers: BeforeComma
> +BreakAfterJavaFieldAnnotations: false
> +BreakStringLiterals: false
> +ColumnLimit: 80
> +CommentPragmas: '^ IWYU pragma:'
> +CompactNamespaces: false
> +ConstructorInitializerAllOnOneLineOrOnePerLine: false
> +ConstructorInitializerIndentWidth: 8
> +ContinuationIndentWidth: 8
> +Cpp11BracedListStyle: false
> +DerivePointerAlignment: false
> +DisableFormat: false
> +ExperimentalAutoDetectBinPacking: false
> +FixNamespaceComments: false
> +
> +# Taken from:
> +# git grep -h '^#define [^[:space:]]*for_each[^[:space:]]*(' \
> +# | sed "s,^#define \([^[:space:]]*for_each[^[:space:]]*\)(.*$, - '\1'," \
> +# | LC_ALL=C sort -u
> +ForEachMacros:
> + - 'cil_list_for_each'
> + - 'cil_stack_for_each'
> + - 'cil_stack_for_each_starting_at'
> + - 'ebitmap_for_each_bit'
> + - 'ebitmap_for_each_positive_bit'
> +
> +IncludeBlocks: Preserve
> +IncludeCategories:
> + - Regex: '.*'
> + Priority: 1
> +IncludeIsMainRegex: '(Test)?$'
> +IndentCaseLabels: false
> +IndentGotoLabels: false
> +IndentPPDirectives: None
> +IndentWidth: 8
> +IndentWrappedFunctionNames: false
> +JavaScriptQuotes: Leave
> +JavaScriptWrapImports: true
> +KeepEmptyLinesAtTheStartOfBlocks: false
> +MacroBlockBegin: ''
> +MacroBlockEnd: ''
> +MaxEmptyLinesToKeep: 1
> +NamespaceIndentation: None
> +ObjCBinPackProtocolList: Auto
> +ObjCBlockIndentWidth: 8
> +ObjCSpaceAfterProperty: true
> +ObjCSpaceBeforeProtocolList: true
> +
> +# Taken from git's rules
> +PenaltyBreakAssignment: 10
> +PenaltyBreakBeforeFirstCallParameter: 30
> +PenaltyBreakComment: 10
> +PenaltyBreakFirstLessLess: 0
> +PenaltyBreakString: 10
> +PenaltyExcessCharacter: 100
> +PenaltyReturnTypeOnItsOwnLine: 60
> +
> +PointerAlignment: Right
> +ReflowComments: false
> +SortIncludes: false
> +SortUsingDeclarations: false
> +SpaceAfterCStyleCast: false
> +SpaceAfterTemplateKeyword: true
> +SpaceBeforeAssignmentOperators: true
> +SpaceBeforeCtorInitializerColon: true
> +SpaceBeforeInheritanceColon: true
> +SpaceBeforeParens: ControlStatementsExceptForEachMacros
> +SpaceBeforeRangeBasedForLoopColon: true
> +SpaceInEmptyParentheses: false
> +SpacesBeforeTrailingComments: 1
> +SpacesInAngles: false
> +SpacesInContainerLiterals: false
> +SpacesInCStyleCastParentheses: false
> +SpacesInParentheses: false
> +SpacesInSquareBrackets: false
> +Standard: Cpp03
> +TabWidth: 8
> +UseTab: Always
> +...
> diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
> index c501cf84..7ec8cb0f 100644
> --- a/CONTRIBUTING.md
> +++ b/CONTRIBUTING.md
> @@ -53,6 +53,8 @@ When preparing patches, please follow these guidelines:
> - Separate large patches into logical patches
> - Patch descriptions must end with your "Signed-off-by" line. This means your
> code meets the Developer's certificate of origin, see below.
> +- C code should be formatted using clang-format, using the .clang-format
> + configuration file at the root of this repository.
>
> When adding new, large features or tools it is best to discuss the
> design on the mailing list prior to submitting the patch.
> diff --git a/Makefile b/Makefile
> index 2ffba8e9..972d5525 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -36,7 +36,7 @@ ifneq ($(DESTDIR),)
> export LIBSEPOLA
> endif
>
> -all install relabel clean test indent:
> +all install relabel clean test:
> @for subdir in $(SUBDIRS); do \
> (cd $$subdir && $(MAKE) $@) || exit 1; \
> done
> @@ -50,3 +50,12 @@ distclean:
> @for subdir in $(DISTCLEANSUBDIRS); do \
> (cd $$subdir && $(MAKE) $@) || exit 1; \
> done
> +
> +# We shouldn't have any unformatted files in the repo without an explicit exception.
> +FORMAT_SOURCE_FILES := $(shell find $(SUBDIRS) -type f \( -name '*.c' -o -name '*.h' \))
> +
> +format:
> + clang-format -i $(FORMAT_SOURCE_FILES)
> +
> +check-format:
> + clang-format --dry-run -Werror $(FORMAT_SOURCE_FILES)
> diff --git a/checkpolicy/Makefile b/checkpolicy/Makefile
> index 6e8008e3..0055f495 100644
> --- a/checkpolicy/Makefile
> +++ b/checkpolicy/Makefile
> @@ -77,6 +77,3 @@ relabel: install
> clean:
> -rm -f $(TARGETS) $(CHECKPOLOBJS) $(CHECKMODOBJS) y.tab.c y.tab.h lex.yy.c tests/testpol.conf tests/testpol.bin
> $(MAKE) -C test clean
> -
> -indent:
> - ../scripts/Lindent $(filter-out $(GENERATED),$(wildcard *.[ch]))
> diff --git a/gui/Makefile b/gui/Makefile
> index b29610d4..b1a94224 100644
> --- a/gui/Makefile
> +++ b/gui/Makefile
> @@ -60,8 +60,6 @@ install: all
> clean:
> (cd po && $(MAKE) $@)
>
> -indent:
> -
> relabel:
>
> test:
> diff --git a/libselinux/Makefile b/libselinux/Makefile
> index a50b6491..aeede2b5 100644
> --- a/libselinux/Makefile
> +++ b/libselinux/Makefile
> @@ -50,7 +50,7 @@ COMPILER := clang
> endif
> export COMPILER
>
> -all install relabel clean distclean indent:
> +all install relabel clean distclean:
> @for subdir in $(SUBDIRS); do \
> (cd $$subdir && $(MAKE) $@) || exit 1; \
> done
> diff --git a/libselinux/include/Makefile b/libselinux/include/Makefile
> index 8ab9ce92..a1e322ac 100644
> --- a/libselinux/include/Makefile
> +++ b/libselinux/include/Makefile
> @@ -10,9 +10,5 @@ install: all
>
> relabel:
>
> -indent:
> - ../../scripts/Lindent $(wildcard selinux/*.h)
> -
> distclean clean:
> -rm -f selinux/*~
> -
> diff --git a/libselinux/man/Makefile b/libselinux/man/Makefile
> index fdc0825f..42b1662a 100644
> --- a/libselinux/man/Makefile
> +++ b/libselinux/man/Makefile
> @@ -35,4 +35,4 @@ install: all
>
> relabel:
>
> -indent distclean clean:
> +format distclean clean:
> diff --git a/libselinux/src/Makefile b/libselinux/src/Makefile
> index 261c22d4..f7412cd1 100644
> --- a/libselinux/src/Makefile
> +++ b/libselinux/src/Makefile
> @@ -223,7 +223,4 @@ clean: clean-pywrap clean-rubywrap
> distclean: clean
> rm -f $(GENERATED) $(SWIGFILES)
>
> -indent:
> - ../../scripts/Lindent $(filter-out $(GENERATED),$(wildcard *.[ch]))
> -
> .PHONY: all clean clean-pywrap clean-rubywrap pywrap rubywrap swigify install install-pywrap install-rubywrap distclean
> diff --git a/libselinux/utils/Makefile b/libselinux/utils/Makefile
> index 6b1dc7c9..20dc44eb 100644
> --- a/libselinux/utils/Makefile
> +++ b/libselinux/utils/Makefile
> @@ -72,8 +72,4 @@ clean:
>
> distclean: clean
>
> -indent:
> - ../../scripts/Lindent $(wildcard *.[ch])
> -
> relabel:
> -
> diff --git a/libsemanage/Makefile b/libsemanage/Makefile
> index dbd240da..591ce5f2 100644
> --- a/libsemanage/Makefile
> +++ b/libsemanage/Makefile
> @@ -29,9 +29,5 @@ clean distclean:
> $(MAKE) -C src $@
> $(MAKE) -C tests $@
>
> -indent:
> - $(MAKE) -C src $@
> - $(MAKE) -C include $@
> -
> test: all
> $(MAKE) -C tests test
> diff --git a/libsemanage/include/Makefile b/libsemanage/include/Makefile
> index 6e44a28a..b08e48a0 100644
> --- a/libsemanage/include/Makefile
> +++ b/libsemanage/include/Makefile
> @@ -7,6 +7,3 @@ all:
> install: all
> test -d $(DESTDIR)$(INCDIR) || install -m 755 -d $(DESTDIR)$(INCDIR)
> install -m 644 $(wildcard semanage/*.h) $(DESTDIR)$(INCDIR)
> -
> -indent:
> - ../../scripts/Lindent $(wildcard semanage/*.h)
> diff --git a/libsemanage/src/Makefile b/libsemanage/src/Makefile
> index fa3449fb..8e025112 100644
> --- a/libsemanage/src/Makefile
> +++ b/libsemanage/src/Makefile
> @@ -167,7 +167,4 @@ clean:
> distclean: clean
> rm -f $(GENERATED) $(SWIGFILES)
>
> -indent:
> - ../../scripts/Lindent $(filter-out $(GENERATED),$(wildcard *.[ch]))
> -
> .PHONY: all clean pywrap rubywrap swigify install install-pywrap install-rubywrap distclean
> diff --git a/libsemanage/utils/Makefile b/libsemanage/utils/Makefile
> index 5b8fbb6b..0f382934 100644
> --- a/libsemanage/utils/Makefile
> +++ b/libsemanage/utils/Makefile
> @@ -13,7 +13,4 @@ clean:
>
> distclean: clean
>
> -indent:
> -
> relabel:
> -
> diff --git a/libsepol/Makefile b/libsepol/Makefile
> index 5b5d03e2..223edcec 100644
> --- a/libsepol/Makefile
> +++ b/libsepol/Makefile
> @@ -20,11 +20,5 @@ clean:
> $(MAKE) -C utils clean
> $(MAKE) -C tests clean
>
> -indent:
> - $(MAKE) -C src $@
> - $(MAKE) -C include $@
> - $(MAKE) -C utils $@
> -
> test:
> $(MAKE) -C tests test
> -
> diff --git a/libsepol/include/Makefile b/libsepol/include/Makefile
> index 1ad4ecab..f49b6e19 100644
> --- a/libsepol/include/Makefile
> +++ b/libsepol/include/Makefile
> @@ -12,6 +12,3 @@ install: all
> install -m 644 $(wildcard sepol/*.h) $(DESTDIR)$(INCDIR)
> install -m 644 $(wildcard sepol/policydb/*.h) $(DESTDIR)$(INCDIR)/policydb
> install -m 644 $(wildcard $(CILDIR)/include/cil/*.h) $(DESTDIR)$(INCDIR)/cil
> -
> -indent:
> - ../../scripts/Lindent $(wildcard sepol/*.h)
> diff --git a/libsepol/src/Makefile b/libsepol/src/Makefile
> index 90aed394..bb2b7f5e 100644
> --- a/libsepol/src/Makefile
> +++ b/libsepol/src/Makefile
> @@ -105,7 +105,3 @@ relabel:
>
> clean:
> -rm -f $(LIBPC) $(LIBMAP) $(OBJS) $(LOBJS) $(LIBA) $(LIBSO) $(TARGET) $(CIL_GENERATED)
> -
> -indent:
> - ../../scripts/Lindent $(wildcard *.[ch])
> -
> diff --git a/libsepol/utils/Makefile b/libsepol/utils/Makefile
> index 31932c11..a8bedf2e 100644
> --- a/libsepol/utils/Makefile
> +++ b/libsepol/utils/Makefile
> @@ -18,8 +18,4 @@ install: all
> clean:
> -rm -f $(TARGETS) *.o
>
> -indent:
> - ../../scripts/Lindent $(wildcard *.[ch])
> -
> relabel:
> -
> diff --git a/mcstrans/src/Makefile b/mcstrans/src/Makefile
> index 88487068..609b2d45 100644
> --- a/mcstrans/src/Makefile
> +++ b/mcstrans/src/Makefile
> @@ -37,4 +37,3 @@ install: all
>
> clean:
> -rm -f $(OBJS) $(LOBJS) $(TARGET) $(PROG) $(PROG_OBJS) *~ \#*
> -
> diff --git a/mcstrans/utils/Makefile b/mcstrans/utils/Makefile
> index 57a73932..1d70b4ed 100644
> --- a/mcstrans/utils/Makefile
> +++ b/mcstrans/utils/Makefile
> @@ -36,4 +36,3 @@ clean:
> rm -f $(TARGETS) *.o *~ \#*
>
> relabel:
> -
> diff --git a/policycoreutils/Makefile b/policycoreutils/Makefile
> index 7c9706e3..9186a9ef 100644
> --- a/policycoreutils/Makefile
> +++ b/policycoreutils/Makefile
> @@ -6,7 +6,7 @@ LIBSELINUX_LDLIBS := $(shell PKG_CONFIG_PATH="$(PKG_CONFIG_PATH):../libselinux/s
> LIBSEMANAGE_LDLIBS := $(shell PKG_CONFIG_PATH="$(PKG_CONFIG_PATH):../libsemanage/src" $(PKG_CONFIG) --libs libsemanage)
> export LIBSELINUX_LDLIBS LIBSEMANAGE_LDLIBS
>
> -all install relabel clean indent:
> +all install relabel clean:
> @for subdir in $(SUBDIRS); do \
> (cd $$subdir && $(MAKE) $@) || exit 1; \
> done
> diff --git a/policycoreutils/hll/Makefile b/policycoreutils/hll/Makefile
> index fe720e57..390f3a34 100644
> --- a/policycoreutils/hll/Makefile
> +++ b/policycoreutils/hll/Makefile
> @@ -1,6 +1,6 @@
> SUBDIRS = pp
>
> -all install relabel clean indent:
> +all install relabel clean:
> @for subdir in $(SUBDIRS); do \
> (cd $$subdir && $(MAKE) $@) || exit 1; \
> done
> diff --git a/policycoreutils/hll/pp/Makefile b/policycoreutils/hll/pp/Makefile
> index 3c9b0efc..a0d475a3 100644
> --- a/policycoreutils/hll/pp/Makefile
> +++ b/policycoreutils/hll/pp/Makefile
> @@ -25,6 +25,3 @@ relabel:
>
> clean:
> -rm -f pp $(PP_OBJS)
> -
> -indent:
> - ../../scripts/Lindent $(wildcard *.[ch])
> diff --git a/policycoreutils/load_policy/Makefile b/policycoreutils/load_policy/Makefile
> index c61fee70..7754cadc 100644
> --- a/policycoreutils/load_policy/Makefile
> +++ b/policycoreutils/load_policy/Makefile
> @@ -28,8 +28,5 @@ install: all
> clean:
> -rm -f $(TARGETS) *.o
>
> -indent:
> - ../../scripts/Lindent $(wildcard *.[ch])
> -
> relabel:
> /sbin/restorecon $(DESTDIR)$(SBINDIR)/load_policy
> diff --git a/policycoreutils/newrole/Makefile b/policycoreutils/newrole/Makefile
> index df64483f..fcd2661f 100644
> --- a/policycoreutils/newrole/Makefile
> +++ b/policycoreutils/newrole/Makefile
> @@ -87,9 +87,6 @@ endif
> clean:
> rm -f newrole *.o
>
> -indent:
> - ../../scripts/Lindent $(wildcard *.[ch])
> -
> relabel: install
> /sbin/restorecon $(DESTDIR)$(BINDIR)/newrole
>
> diff --git a/policycoreutils/run_init/Makefile b/policycoreutils/run_init/Makefile
> index c89fffb9..0e904dba 100644
> --- a/policycoreutils/run_init/Makefile
> +++ b/policycoreutils/run_init/Makefile
> @@ -53,8 +53,5 @@ endif
> clean:
> -rm -f $(TARGETS) *.o
>
> -indent:
> - ../../scripts/Lindent $(wildcard *.[ch])
> -
> relabel: install
> /sbin/restorecon $(DESTDIR)$(SBINDIR)/run_init $(DESTDIR)$(SBINDIR)/open_init_pty
> diff --git a/policycoreutils/scripts/Makefile b/policycoreutils/scripts/Makefile
> index 6d8196c6..1058bbab 100644
> --- a/policycoreutils/scripts/Makefile
> +++ b/policycoreutils/scripts/Makefile
> @@ -21,6 +21,4 @@ install: all
>
> clean:
>
> -indent:
> -
> relabel:
> diff --git a/policycoreutils/secon/Makefile b/policycoreutils/secon/Makefile
> index c9296f19..b2f276f9 100644
> --- a/policycoreutils/secon/Makefile
> +++ b/policycoreutils/secon/Makefile
> @@ -35,9 +35,6 @@ relabel:
> clean:
> rm -f *.o core* secon *~ *.bak
>
> -indent:
> - ../../scripts/Lindent $(wildcard *.[ch])
> -
> bare: clean
>
> .PHONY: clean bare
> diff --git a/policycoreutils/semodule/Makefile b/policycoreutils/semodule/Makefile
> index 018ee2ca..47bde5f8 100644
> --- a/policycoreutils/semodule/Makefile
> +++ b/policycoreutils/semodule/Makefile
> @@ -35,7 +35,3 @@ relabel:
>
> clean:
> -rm -f semodule *.o genhomedircon
> -
> -indent:
> - ../../scripts/Lindent $(wildcard *.[ch])
> -
> diff --git a/policycoreutils/sestatus/Makefile b/policycoreutils/sestatus/Makefile
> index 1ce617c0..70f46956 100644
> --- a/policycoreutils/sestatus/Makefile
> +++ b/policycoreutils/sestatus/Makefile
> @@ -41,7 +41,4 @@ install: all
> clean:
> rm -f sestatus *.o
>
> -indent:
> - ../../scripts/Lindent $(wildcard *.[ch])
> -
> relabel:
> diff --git a/policycoreutils/setfiles/Makefile b/policycoreutils/setfiles/Makefile
> index dab6313c..aa3e80fc 100644
> --- a/policycoreutils/setfiles/Makefile
> +++ b/policycoreutils/setfiles/Makefile
> @@ -43,8 +43,5 @@ install: all
> clean:
> rm -f setfiles restorecon restorecon_xattr *.o
>
> -indent:
> - ../../scripts/Lindent $(wildcard *.[ch])
> -
> relabel: install
> $(DESTDIR)$(SBINDIR)/restorecon $(DESTDIR)$(SBINDIR)/setfiles $(DESTDIR)$(SBINDIR)/restorecon_xattr
> diff --git a/policycoreutils/setsebool/Makefile b/policycoreutils/setsebool/Makefile
> index 87494c55..360e0ea0 100644
> --- a/policycoreutils/setsebool/Makefile
> +++ b/policycoreutils/setsebool/Makefile
> @@ -35,7 +35,3 @@ relabel:
>
> clean:
> -rm -f setsebool *.o
> -
> -indent:
> - ../../scripts/Lindent $(wildcard *.[ch])
> -
> diff --git a/policycoreutils/unsetfiles/Makefile b/policycoreutils/unsetfiles/Makefile
> index 9cb51494..8dbf85af 100644
> --- a/policycoreutils/unsetfiles/Makefile
> +++ b/policycoreutils/unsetfiles/Makefile
> @@ -20,8 +20,5 @@ install: all
> clean:
> -rm -f unsetfiles *.o
>
> -indent:
> - ../../scripts/Lindent $(wildcard *.[ch])
> -
> relabel: install
> /sbin/restorecon $(DESTDIR)$(SBINDIR)/unsetfiles
> diff --git a/python/Makefile b/python/Makefile
> index 00312dbd..c4c31a17 100644
> --- a/python/Makefile
> +++ b/python/Makefile
> @@ -1,6 +1,6 @@
> SUBDIRS = sepolicy audit2allow semanage sepolgen chcat po
>
> -all install relabel clean indent test:
> +all install relabel clean format test:
> @for subdir in $(SUBDIRS); do \
> (cd $$subdir && $(MAKE) $@) || exit 1; \
> done
> diff --git a/python/audit2allow/Makefile b/python/audit2allow/Makefile
> index 28b8f7f2..90d10d1a 100644
> --- a/python/audit2allow/Makefile
> +++ b/python/audit2allow/Makefile
> @@ -51,7 +51,4 @@ install: all
> clean:
> rm -f *~ *.o sepolgen-ifgen-attr-helper test_dummy_policy
>
> -indent:
> - ../../scripts/Lindent $(wildcard *.[ch])
> -
> relabel: ;
> diff --git a/python/chcat/Makefile b/python/chcat/Makefile
> index 7b3ee17f..334b749d 100644
> --- a/python/chcat/Makefile
> +++ b/python/chcat/Makefile
> @@ -21,8 +21,6 @@ install: all
>
> clean:
>
> -indent:
> -
> relabel:
>
> test:
> diff --git a/python/semanage/Makefile b/python/semanage/Makefile
> index 628d135a..51208d9e 100644
> --- a/python/semanage/Makefile
> +++ b/python/semanage/Makefile
> @@ -35,6 +35,4 @@ test:
> @$(PYTHON) test-semanage.py -a
> clean:
>
> -indent:
> -
> relabel:
> diff --git a/python/sepolgen/Makefile b/python/sepolgen/Makefile
> index 3aed3304..2ad7b13c 100644
> --- a/python/sepolgen/Makefile
> +++ b/python/sepolgen/Makefile
> @@ -11,10 +11,5 @@ clean:
> rm -f *~ *.pyc
> rm -f parser.out parsetab.py
>
> -indent: ;
> -
> test:
> $(MAKE) -C tests $@
> -
> -
> -
> diff --git a/python/sepolgen/src/Makefile b/python/sepolgen/src/Makefile
> index 2815a13d..a2456652 100644
> --- a/python/sepolgen/src/Makefile
> +++ b/python/sepolgen/src/Makefile
> @@ -12,10 +12,4 @@ clean:
> rm -f *~ *.pyc
> rm -f parser.out parsetab.py
>
> -indent: ;
> -
> -
> test: ;
> -
> -
> -
> diff --git a/restorecond/Makefile b/restorecond/Makefile
> index b8b86eb4..51eb7608 100644
> --- a/restorecond/Makefile
> +++ b/restorecond/Makefile
> @@ -59,7 +59,4 @@ relabel: install
> clean:
> -rm -f restorecond *.o *~
>
> -indent:
> - ../../scripts/Lindent $(wildcard *.[ch])
> -
> test:
> diff --git a/sandbox/Makefile b/sandbox/Makefile
> index 0799ab7c..eaaad75c 100644
> --- a/sandbox/Makefile
> +++ b/sandbox/Makefile
> @@ -50,7 +50,4 @@ clean:
> -rm -f seunshare *.o *~
> (cd po && $(MAKE) $@)
>
> -indent:
> - ../../scripts/Lindent $(wildcard *.[ch])
> -
> relabel:
> diff --git a/scripts/Lindent b/scripts/Lindent
> deleted file mode 100755
> index 9c4b3e2b..00000000
> --- a/scripts/Lindent
> +++ /dev/null
> @@ -1,18 +0,0 @@
> -#!/bin/sh
> -PARAM="-npro -kr -i8 -ts8 -sob -l80 -ss -ncs -cp1"
> -RES=`indent --version`
> -V1=`echo $RES | cut -d' ' -f3 | cut -d'.' -f1`
> -V2=`echo $RES | cut -d' ' -f3 | cut -d'.' -f2`
> -V3=`echo $RES | cut -d' ' -f3 | cut -d'.' -f3`
> -if [ $V1 -gt 2 ]; then
> - PARAM="$PARAM -il0"
> -elif [ $V1 -eq 2 ]; then
> - if [ $V2 -gt 2 ]; then
> - PARAM="$PARAM -il0";
> - elif [ $V2 -eq 2 ]; then
> - if [ $V3 -ge 10 ]; then
> - PARAM="$PARAM -il0"
> - fi
> - fi
> -fi
> -indent $PARAM "$@"
> diff --git a/semodule-utils/Makefile b/semodule-utils/Makefile
> index e0a65792..81c97af0 100644
> --- a/semodule-utils/Makefile
> +++ b/semodule-utils/Makefile
> @@ -1,6 +1,6 @@
> SUBDIRS = semodule_package semodule_link semodule_expand
>
> -all install relabel clean indent:
> +all install relabel clean:
> @for subdir in $(SUBDIRS); do \
> (cd $$subdir && $(MAKE) $@) || exit 1; \
> done
> diff --git a/semodule-utils/semodule_expand/Makefile b/semodule-utils/semodule_expand/Makefile
> index ad776b15..72f09a46 100644
> --- a/semodule-utils/semodule_expand/Makefile
> +++ b/semodule-utils/semodule_expand/Makefile
> @@ -27,7 +27,3 @@ relabel:
>
> clean:
> -rm -f semodule_expand *.o
> -
> -indent:
> - ../../scripts/Lindent $(wildcard *.[ch])
> -
> diff --git a/semodule-utils/semodule_link/Makefile b/semodule-utils/semodule_link/Makefile
> index 936d161c..83590c07 100644
> --- a/semodule-utils/semodule_link/Makefile
> +++ b/semodule-utils/semodule_link/Makefile
> @@ -27,7 +27,3 @@ relabel:
>
> clean:
> -rm -f semodule_link *.o
> -
> -indent:
> - ../../scripts/Lindent $(wildcard *.[ch])
> -
> diff --git a/semodule-utils/semodule_package/Makefile b/semodule-utils/semodule_package/Makefile
> index 6a289f73..2465f987 100644
> --- a/semodule-utils/semodule_package/Makefile
> +++ b/semodule-utils/semodule_package/Makefile
> @@ -29,7 +29,3 @@ relabel:
>
> clean:
> -rm -f semodule_package semodule_unpackage *.o
> -
> -indent:
> - ../../scripts/Lindent $(wildcard *.[ch])
> -
> --
> 2.51.0
>
^ permalink raw reply [flat|nested] 22+ messages in thread
* When to apply `make format` to the entire tree
2025-10-20 14:55 ` Stephen Smalley
@ 2025-10-20 16:18 ` Petr Lautrbach
2025-10-20 16:26 ` Rahul Sandhu
2025-10-21 13:49 ` [PATCH v6] treewide: add .clang-format configuration file Stephen Smalley
1 sibling, 1 reply; 22+ messages in thread
From: Petr Lautrbach @ 2025-10-20 16:18 UTC (permalink / raw)
To: selinux; +Cc: Stephen Smalley, Rahul Sandhu
Stephen Smalley <stephen.smalley.work@gmail.com> writes:
> On Mon, Oct 20, 2025 at 10:09 AM Rahul Sandhu <nvraxn@gmail.com> wrote:
>>
>> Add the .clang-format configuration file, taken from the Linux kernel
>> repository. We don't have any official style guidelines in tree at
>> present, which makes it a bit unclear how to format C code for new
>> contributors. As well as this, different parts of the codebase seem to
>> been formatted with different styles on occasion, so using an automatic
>> formatter should resolve this.
>>
>> As well as this, replace all the existing indent targets with a single
>> toplevel `format` target. Managing all the source files to be formatted
>> is not pretty to maintain, and doesn't really give us much.
>>
>> Also define a toplevel `check-format` target to verify that all code is
>> formatted properly. This only becomes useful in the future once we have
>> reformatted all existing code, but is wired up for now.
>>
>> For the future:
>> 1. Reformat all existing code. I understand this is a big change, but
>> we may as well get all code formatted if we go down this route;
>> afterall, it's not like this will cause any breaking changes.
>>
>> 2. Add a CI target to check that all code is formatted as per the new
>> clang-format configuration. The `check-format` target can be used
>> for this.
>>
>> Signed-off-by: Rahul Sandhu <nvraxn@gmail.com>
>
> Acked-by: Stephen Smalley <stephen.smalley.work@gmail.com>
>
> Will defer to distro package maintainers to decide when to apply make
> format to the entire tree. Common practice I think is to do it just
> before or after a release.
For me, it's better do it before the release so I would not need to
backport the format patch together with some future change.
Petr
>> ---
>> .clang-format | 130 +++++++++++++++++++++++
>> CONTRIBUTING.md | 2 +
>> Makefile | 11 +-
>> checkpolicy/Makefile | 3 -
>> gui/Makefile | 2 -
>> libselinux/Makefile | 2 +-
>> libselinux/include/Makefile | 4 -
>> libselinux/man/Makefile | 2 +-
>> libselinux/src/Makefile | 3 -
>> libselinux/utils/Makefile | 4 -
>> libsemanage/Makefile | 4 -
>> libsemanage/include/Makefile | 3 -
>> libsemanage/src/Makefile | 3 -
>> libsemanage/utils/Makefile | 3 -
>> libsepol/Makefile | 6 --
>> libsepol/include/Makefile | 3 -
>> libsepol/src/Makefile | 4 -
>> libsepol/utils/Makefile | 4 -
>> mcstrans/src/Makefile | 1 -
>> mcstrans/utils/Makefile | 1 -
>> policycoreutils/Makefile | 2 +-
>> policycoreutils/hll/Makefile | 2 +-
>> policycoreutils/hll/pp/Makefile | 3 -
>> policycoreutils/load_policy/Makefile | 3 -
>> policycoreutils/newrole/Makefile | 3 -
>> policycoreutils/run_init/Makefile | 3 -
>> policycoreutils/scripts/Makefile | 2 -
>> policycoreutils/secon/Makefile | 3 -
>> policycoreutils/semodule/Makefile | 4 -
>> policycoreutils/sestatus/Makefile | 3 -
>> policycoreutils/setfiles/Makefile | 3 -
>> policycoreutils/setsebool/Makefile | 4 -
>> policycoreutils/unsetfiles/Makefile | 3 -
>> python/Makefile | 2 +-
>> python/audit2allow/Makefile | 3 -
>> python/chcat/Makefile | 2 -
>> python/semanage/Makefile | 2 -
>> python/sepolgen/Makefile | 5 -
>> python/sepolgen/src/Makefile | 6 --
>> restorecond/Makefile | 3 -
>> sandbox/Makefile | 3 -
>> scripts/Lindent | 18 ----
>> semodule-utils/Makefile | 2 +-
>> semodule-utils/semodule_expand/Makefile | 4 -
>> semodule-utils/semodule_link/Makefile | 4 -
>> semodule-utils/semodule_package/Makefile | 4 -
>> 46 files changed, 148 insertions(+), 143 deletions(-)
>> create mode 100644 .clang-format
>> delete mode 100755 scripts/Lindent
>>
>> v2: remove linux kernel ForEachMacros and replace them with ours
>> v3: replace the indent target with the new format target. also remove any
>> mention of `.editorconfig` from the commit message; those changes are
>> better suited for another patch (they're small and self-contained enough
>> that they're a smaller thing to merge).
>> v4: drop the subdir format targets entirely, replacing with a single toplevel
>> format and check-format target.
>> v5: add back relabel target accidently removed.
>> v6: remove all references to being an RFC in the commit message.
>>
>> diff --git a/.clang-format b/.clang-format
>> new file mode 100644
>> index 00000000..35595d87
>> --- /dev/null
>> +++ b/.clang-format
>> @@ -0,0 +1,130 @@
>> +# SPDX-License-Identifier: GPL-2.0
>> +#
>> +# clang-format configuration file. Intended for clang-format >= 11.
>> +#
>> +# For more information, see:
>> +#
>> +# Documentation/dev-tools/clang-format.rst
>> +# https://clang.llvm.org/docs/ClangFormat.html
>> +# https://clang.llvm.org/docs/ClangFormatStyleOptions.html
>> +#
>> +---
>> +AccessModifierOffset: -4
>> +AlignAfterOpenBracket: Align
>> +AlignConsecutiveAssignments: false
>> +AlignConsecutiveDeclarations: false
>> +AlignEscapedNewlines: Left
>> +AlignOperands: true
>> +AlignTrailingComments: false
>> +AllowAllParametersOfDeclarationOnNextLine: false
>> +AllowShortBlocksOnASingleLine: false
>> +AllowShortCaseLabelsOnASingleLine: false
>> +AllowShortFunctionsOnASingleLine: None
>> +AllowShortIfStatementsOnASingleLine: false
>> +AllowShortLoopsOnASingleLine: false
>> +AlwaysBreakAfterDefinitionReturnType: None
>> +AlwaysBreakAfterReturnType: None
>> +AlwaysBreakBeforeMultilineStrings: false
>> +AlwaysBreakTemplateDeclarations: false
>> +BinPackArguments: true
>> +BinPackParameters: true
>> +BraceWrapping:
>> + AfterClass: false
>> + AfterControlStatement: false
>> + AfterEnum: false
>> + AfterFunction: true
>> + AfterNamespace: true
>> + AfterObjCDeclaration: false
>> + AfterStruct: false
>> + AfterUnion: false
>> + AfterExternBlock: false
>> + BeforeCatch: false
>> + BeforeElse: false
>> + IndentBraces: false
>> + SplitEmptyFunction: true
>> + SplitEmptyRecord: true
>> + SplitEmptyNamespace: true
>> +BreakBeforeBinaryOperators: None
>> +BreakBeforeBraces: Custom
>> +BreakBeforeInheritanceComma: false
>> +BreakBeforeTernaryOperators: false
>> +BreakConstructorInitializersBeforeComma: false
>> +BreakConstructorInitializers: BeforeComma
>> +BreakAfterJavaFieldAnnotations: false
>> +BreakStringLiterals: false
>> +ColumnLimit: 80
>> +CommentPragmas: '^ IWYU pragma:'
>> +CompactNamespaces: false
>> +ConstructorInitializerAllOnOneLineOrOnePerLine: false
>> +ConstructorInitializerIndentWidth: 8
>> +ContinuationIndentWidth: 8
>> +Cpp11BracedListStyle: false
>> +DerivePointerAlignment: false
>> +DisableFormat: false
>> +ExperimentalAutoDetectBinPacking: false
>> +FixNamespaceComments: false
>> +
>> +# Taken from:
>> +# git grep -h '^#define [^[:space:]]*for_each[^[:space:]]*(' \
>> +# | sed "s,^#define \([^[:space:]]*for_each[^[:space:]]*\)(.*$, - '\1'," \
>> +# | LC_ALL=C sort -u
>> +ForEachMacros:
>> + - 'cil_list_for_each'
>> + - 'cil_stack_for_each'
>> + - 'cil_stack_for_each_starting_at'
>> + - 'ebitmap_for_each_bit'
>> + - 'ebitmap_for_each_positive_bit'
>> +
>> +IncludeBlocks: Preserve
>> +IncludeCategories:
>> + - Regex: '.*'
>> + Priority: 1
>> +IncludeIsMainRegex: '(Test)?$'
>> +IndentCaseLabels: false
>> +IndentGotoLabels: false
>> +IndentPPDirectives: None
>> +IndentWidth: 8
>> +IndentWrappedFunctionNames: false
>> +JavaScriptQuotes: Leave
>> +JavaScriptWrapImports: true
>> +KeepEmptyLinesAtTheStartOfBlocks: false
>> +MacroBlockBegin: ''
>> +MacroBlockEnd: ''
>> +MaxEmptyLinesToKeep: 1
>> +NamespaceIndentation: None
>> +ObjCBinPackProtocolList: Auto
>> +ObjCBlockIndentWidth: 8
>> +ObjCSpaceAfterProperty: true
>> +ObjCSpaceBeforeProtocolList: true
>> +
>> +# Taken from git's rules
>> +PenaltyBreakAssignment: 10
>> +PenaltyBreakBeforeFirstCallParameter: 30
>> +PenaltyBreakComment: 10
>> +PenaltyBreakFirstLessLess: 0
>> +PenaltyBreakString: 10
>> +PenaltyExcessCharacter: 100
>> +PenaltyReturnTypeOnItsOwnLine: 60
>> +
>> +PointerAlignment: Right
>> +ReflowComments: false
>> +SortIncludes: false
>> +SortUsingDeclarations: false
>> +SpaceAfterCStyleCast: false
>> +SpaceAfterTemplateKeyword: true
>> +SpaceBeforeAssignmentOperators: true
>> +SpaceBeforeCtorInitializerColon: true
>> +SpaceBeforeInheritanceColon: true
>> +SpaceBeforeParens: ControlStatementsExceptForEachMacros
>> +SpaceBeforeRangeBasedForLoopColon: true
>> +SpaceInEmptyParentheses: false
>> +SpacesBeforeTrailingComments: 1
>> +SpacesInAngles: false
>> +SpacesInContainerLiterals: false
>> +SpacesInCStyleCastParentheses: false
>> +SpacesInParentheses: false
>> +SpacesInSquareBrackets: false
>> +Standard: Cpp03
>> +TabWidth: 8
>> +UseTab: Always
>> +...
>> diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
>> index c501cf84..7ec8cb0f 100644
>> --- a/CONTRIBUTING.md
>> +++ b/CONTRIBUTING.md
>> @@ -53,6 +53,8 @@ When preparing patches, please follow these guidelines:
>> - Separate large patches into logical patches
>> - Patch descriptions must end with your "Signed-off-by" line. This means your
>> code meets the Developer's certificate of origin, see below.
>> +- C code should be formatted using clang-format, using the .clang-format
>> + configuration file at the root of this repository.
>>
>> When adding new, large features or tools it is best to discuss the
>> design on the mailing list prior to submitting the patch.
>> diff --git a/Makefile b/Makefile
>> index 2ffba8e9..972d5525 100644
>> --- a/Makefile
>> +++ b/Makefile
>> @@ -36,7 +36,7 @@ ifneq ($(DESTDIR),)
>> export LIBSEPOLA
>> endif
>>
>> -all install relabel clean test indent:
>> +all install relabel clean test:
>> @for subdir in $(SUBDIRS); do \
>> (cd $$subdir && $(MAKE) $@) || exit 1; \
>> done
>> @@ -50,3 +50,12 @@ distclean:
>> @for subdir in $(DISTCLEANSUBDIRS); do \
>> (cd $$subdir && $(MAKE) $@) || exit 1; \
>> done
>> +
>> +# We shouldn't have any unformatted files in the repo without an explicit exception.
>> +FORMAT_SOURCE_FILES := $(shell find $(SUBDIRS) -type f \( -name '*.c' -o -name '*.h' \))
>> +
>> +format:
>> + clang-format -i $(FORMAT_SOURCE_FILES)
>> +
>> +check-format:
>> + clang-format --dry-run -Werror $(FORMAT_SOURCE_FILES)
>> diff --git a/checkpolicy/Makefile b/checkpolicy/Makefile
>> index 6e8008e3..0055f495 100644
>> --- a/checkpolicy/Makefile
>> +++ b/checkpolicy/Makefile
>> @@ -77,6 +77,3 @@ relabel: install
>> clean:
>> -rm -f $(TARGETS) $(CHECKPOLOBJS) $(CHECKMODOBJS) y.tab.c y.tab.h lex.yy.c tests/testpol.conf tests/testpol.bin
>> $(MAKE) -C test clean
>> -
>> -indent:
>> - ../scripts/Lindent $(filter-out $(GENERATED),$(wildcard *.[ch]))
>> diff --git a/gui/Makefile b/gui/Makefile
>> index b29610d4..b1a94224 100644
>> --- a/gui/Makefile
>> +++ b/gui/Makefile
>> @@ -60,8 +60,6 @@ install: all
>> clean:
>> (cd po && $(MAKE) $@)
>>
>> -indent:
>> -
>> relabel:
>>
>> test:
>> diff --git a/libselinux/Makefile b/libselinux/Makefile
>> index a50b6491..aeede2b5 100644
>> --- a/libselinux/Makefile
>> +++ b/libselinux/Makefile
>> @@ -50,7 +50,7 @@ COMPILER := clang
>> endif
>> export COMPILER
>>
>> -all install relabel clean distclean indent:
>> +all install relabel clean distclean:
>> @for subdir in $(SUBDIRS); do \
>> (cd $$subdir && $(MAKE) $@) || exit 1; \
>> done
>> diff --git a/libselinux/include/Makefile b/libselinux/include/Makefile
>> index 8ab9ce92..a1e322ac 100644
>> --- a/libselinux/include/Makefile
>> +++ b/libselinux/include/Makefile
>> @@ -10,9 +10,5 @@ install: all
>>
>> relabel:
>>
>> -indent:
>> - ../../scripts/Lindent $(wildcard selinux/*.h)
>> -
>> distclean clean:
>> -rm -f selinux/*~
>> -
>> diff --git a/libselinux/man/Makefile b/libselinux/man/Makefile
>> index fdc0825f..42b1662a 100644
>> --- a/libselinux/man/Makefile
>> +++ b/libselinux/man/Makefile
>> @@ -35,4 +35,4 @@ install: all
>>
>> relabel:
>>
>> -indent distclean clean:
>> +format distclean clean:
>> diff --git a/libselinux/src/Makefile b/libselinux/src/Makefile
>> index 261c22d4..f7412cd1 100644
>> --- a/libselinux/src/Makefile
>> +++ b/libselinux/src/Makefile
>> @@ -223,7 +223,4 @@ clean: clean-pywrap clean-rubywrap
>> distclean: clean
>> rm -f $(GENERATED) $(SWIGFILES)
>>
>> -indent:
>> - ../../scripts/Lindent $(filter-out $(GENERATED),$(wildcard *.[ch]))
>> -
>> .PHONY: all clean clean-pywrap clean-rubywrap pywrap rubywrap swigify install install-pywrap install-rubywrap distclean
>> diff --git a/libselinux/utils/Makefile b/libselinux/utils/Makefile
>> index 6b1dc7c9..20dc44eb 100644
>> --- a/libselinux/utils/Makefile
>> +++ b/libselinux/utils/Makefile
>> @@ -72,8 +72,4 @@ clean:
>>
>> distclean: clean
>>
>> -indent:
>> - ../../scripts/Lindent $(wildcard *.[ch])
>> -
>> relabel:
>> -
>> diff --git a/libsemanage/Makefile b/libsemanage/Makefile
>> index dbd240da..591ce5f2 100644
>> --- a/libsemanage/Makefile
>> +++ b/libsemanage/Makefile
>> @@ -29,9 +29,5 @@ clean distclean:
>> $(MAKE) -C src $@
>> $(MAKE) -C tests $@
>>
>> -indent:
>> - $(MAKE) -C src $@
>> - $(MAKE) -C include $@
>> -
>> test: all
>> $(MAKE) -C tests test
>> diff --git a/libsemanage/include/Makefile b/libsemanage/include/Makefile
>> index 6e44a28a..b08e48a0 100644
>> --- a/libsemanage/include/Makefile
>> +++ b/libsemanage/include/Makefile
>> @@ -7,6 +7,3 @@ all:
>> install: all
>> test -d $(DESTDIR)$(INCDIR) || install -m 755 -d $(DESTDIR)$(INCDIR)
>> install -m 644 $(wildcard semanage/*.h) $(DESTDIR)$(INCDIR)
>> -
>> -indent:
>> - ../../scripts/Lindent $(wildcard semanage/*.h)
>> diff --git a/libsemanage/src/Makefile b/libsemanage/src/Makefile
>> index fa3449fb..8e025112 100644
>> --- a/libsemanage/src/Makefile
>> +++ b/libsemanage/src/Makefile
>> @@ -167,7 +167,4 @@ clean:
>> distclean: clean
>> rm -f $(GENERATED) $(SWIGFILES)
>>
>> -indent:
>> - ../../scripts/Lindent $(filter-out $(GENERATED),$(wildcard *.[ch]))
>> -
>> .PHONY: all clean pywrap rubywrap swigify install install-pywrap install-rubywrap distclean
>> diff --git a/libsemanage/utils/Makefile b/libsemanage/utils/Makefile
>> index 5b8fbb6b..0f382934 100644
>> --- a/libsemanage/utils/Makefile
>> +++ b/libsemanage/utils/Makefile
>> @@ -13,7 +13,4 @@ clean:
>>
>> distclean: clean
>>
>> -indent:
>> -
>> relabel:
>> -
>> diff --git a/libsepol/Makefile b/libsepol/Makefile
>> index 5b5d03e2..223edcec 100644
>> --- a/libsepol/Makefile
>> +++ b/libsepol/Makefile
>> @@ -20,11 +20,5 @@ clean:
>> $(MAKE) -C utils clean
>> $(MAKE) -C tests clean
>>
>> -indent:
>> - $(MAKE) -C src $@
>> - $(MAKE) -C include $@
>> - $(MAKE) -C utils $@
>> -
>> test:
>> $(MAKE) -C tests test
>> -
>> diff --git a/libsepol/include/Makefile b/libsepol/include/Makefile
>> index 1ad4ecab..f49b6e19 100644
>> --- a/libsepol/include/Makefile
>> +++ b/libsepol/include/Makefile
>> @@ -12,6 +12,3 @@ install: all
>> install -m 644 $(wildcard sepol/*.h) $(DESTDIR)$(INCDIR)
>> install -m 644 $(wildcard sepol/policydb/*.h) $(DESTDIR)$(INCDIR)/policydb
>> install -m 644 $(wildcard $(CILDIR)/include/cil/*.h) $(DESTDIR)$(INCDIR)/cil
>> -
>> -indent:
>> - ../../scripts/Lindent $(wildcard sepol/*.h)
>> diff --git a/libsepol/src/Makefile b/libsepol/src/Makefile
>> index 90aed394..bb2b7f5e 100644
>> --- a/libsepol/src/Makefile
>> +++ b/libsepol/src/Makefile
>> @@ -105,7 +105,3 @@ relabel:
>>
>> clean:
>> -rm -f $(LIBPC) $(LIBMAP) $(OBJS) $(LOBJS) $(LIBA) $(LIBSO) $(TARGET) $(CIL_GENERATED)
>> -
>> -indent:
>> - ../../scripts/Lindent $(wildcard *.[ch])
>> -
>> diff --git a/libsepol/utils/Makefile b/libsepol/utils/Makefile
>> index 31932c11..a8bedf2e 100644
>> --- a/libsepol/utils/Makefile
>> +++ b/libsepol/utils/Makefile
>> @@ -18,8 +18,4 @@ install: all
>> clean:
>> -rm -f $(TARGETS) *.o
>>
>> -indent:
>> - ../../scripts/Lindent $(wildcard *.[ch])
>> -
>> relabel:
>> -
>> diff --git a/mcstrans/src/Makefile b/mcstrans/src/Makefile
>> index 88487068..609b2d45 100644
>> --- a/mcstrans/src/Makefile
>> +++ b/mcstrans/src/Makefile
>> @@ -37,4 +37,3 @@ install: all
>>
>> clean:
>> -rm -f $(OBJS) $(LOBJS) $(TARGET) $(PROG) $(PROG_OBJS) *~ \#*
>> -
>> diff --git a/mcstrans/utils/Makefile b/mcstrans/utils/Makefile
>> index 57a73932..1d70b4ed 100644
>> --- a/mcstrans/utils/Makefile
>> +++ b/mcstrans/utils/Makefile
>> @@ -36,4 +36,3 @@ clean:
>> rm -f $(TARGETS) *.o *~ \#*
>>
>> relabel:
>> -
>> diff --git a/policycoreutils/Makefile b/policycoreutils/Makefile
>> index 7c9706e3..9186a9ef 100644
>> --- a/policycoreutils/Makefile
>> +++ b/policycoreutils/Makefile
>> @@ -6,7 +6,7 @@ LIBSELINUX_LDLIBS := $(shell PKG_CONFIG_PATH="$(PKG_CONFIG_PATH):../libselinux/s
>> LIBSEMANAGE_LDLIBS := $(shell PKG_CONFIG_PATH="$(PKG_CONFIG_PATH):../libsemanage/src" $(PKG_CONFIG) --libs libsemanage)
>> export LIBSELINUX_LDLIBS LIBSEMANAGE_LDLIBS
>>
>> -all install relabel clean indent:
>> +all install relabel clean:
>> @for subdir in $(SUBDIRS); do \
>> (cd $$subdir && $(MAKE) $@) || exit 1; \
>> done
>> diff --git a/policycoreutils/hll/Makefile b/policycoreutils/hll/Makefile
>> index fe720e57..390f3a34 100644
>> --- a/policycoreutils/hll/Makefile
>> +++ b/policycoreutils/hll/Makefile
>> @@ -1,6 +1,6 @@
>> SUBDIRS = pp
>>
>> -all install relabel clean indent:
>> +all install relabel clean:
>> @for subdir in $(SUBDIRS); do \
>> (cd $$subdir && $(MAKE) $@) || exit 1; \
>> done
>> diff --git a/policycoreutils/hll/pp/Makefile b/policycoreutils/hll/pp/Makefile
>> index 3c9b0efc..a0d475a3 100644
>> --- a/policycoreutils/hll/pp/Makefile
>> +++ b/policycoreutils/hll/pp/Makefile
>> @@ -25,6 +25,3 @@ relabel:
>>
>> clean:
>> -rm -f pp $(PP_OBJS)
>> -
>> -indent:
>> - ../../scripts/Lindent $(wildcard *.[ch])
>> diff --git a/policycoreutils/load_policy/Makefile b/policycoreutils/load_policy/Makefile
>> index c61fee70..7754cadc 100644
>> --- a/policycoreutils/load_policy/Makefile
>> +++ b/policycoreutils/load_policy/Makefile
>> @@ -28,8 +28,5 @@ install: all
>> clean:
>> -rm -f $(TARGETS) *.o
>>
>> -indent:
>> - ../../scripts/Lindent $(wildcard *.[ch])
>> -
>> relabel:
>> /sbin/restorecon $(DESTDIR)$(SBINDIR)/load_policy
>> diff --git a/policycoreutils/newrole/Makefile b/policycoreutils/newrole/Makefile
>> index df64483f..fcd2661f 100644
>> --- a/policycoreutils/newrole/Makefile
>> +++ b/policycoreutils/newrole/Makefile
>> @@ -87,9 +87,6 @@ endif
>> clean:
>> rm -f newrole *.o
>>
>> -indent:
>> - ../../scripts/Lindent $(wildcard *.[ch])
>> -
>> relabel: install
>> /sbin/restorecon $(DESTDIR)$(BINDIR)/newrole
>>
>> diff --git a/policycoreutils/run_init/Makefile b/policycoreutils/run_init/Makefile
>> index c89fffb9..0e904dba 100644
>> --- a/policycoreutils/run_init/Makefile
>> +++ b/policycoreutils/run_init/Makefile
>> @@ -53,8 +53,5 @@ endif
>> clean:
>> -rm -f $(TARGETS) *.o
>>
>> -indent:
>> - ../../scripts/Lindent $(wildcard *.[ch])
>> -
>> relabel: install
>> /sbin/restorecon $(DESTDIR)$(SBINDIR)/run_init $(DESTDIR)$(SBINDIR)/open_init_pty
>> diff --git a/policycoreutils/scripts/Makefile b/policycoreutils/scripts/Makefile
>> index 6d8196c6..1058bbab 100644
>> --- a/policycoreutils/scripts/Makefile
>> +++ b/policycoreutils/scripts/Makefile
>> @@ -21,6 +21,4 @@ install: all
>>
>> clean:
>>
>> -indent:
>> -
>> relabel:
>> diff --git a/policycoreutils/secon/Makefile b/policycoreutils/secon/Makefile
>> index c9296f19..b2f276f9 100644
>> --- a/policycoreutils/secon/Makefile
>> +++ b/policycoreutils/secon/Makefile
>> @@ -35,9 +35,6 @@ relabel:
>> clean:
>> rm -f *.o core* secon *~ *.bak
>>
>> -indent:
>> - ../../scripts/Lindent $(wildcard *.[ch])
>> -
>> bare: clean
>>
>> .PHONY: clean bare
>> diff --git a/policycoreutils/semodule/Makefile b/policycoreutils/semodule/Makefile
>> index 018ee2ca..47bde5f8 100644
>> --- a/policycoreutils/semodule/Makefile
>> +++ b/policycoreutils/semodule/Makefile
>> @@ -35,7 +35,3 @@ relabel:
>>
>> clean:
>> -rm -f semodule *.o genhomedircon
>> -
>> -indent:
>> - ../../scripts/Lindent $(wildcard *.[ch])
>> -
>> diff --git a/policycoreutils/sestatus/Makefile b/policycoreutils/sestatus/Makefile
>> index 1ce617c0..70f46956 100644
>> --- a/policycoreutils/sestatus/Makefile
>> +++ b/policycoreutils/sestatus/Makefile
>> @@ -41,7 +41,4 @@ install: all
>> clean:
>> rm -f sestatus *.o
>>
>> -indent:
>> - ../../scripts/Lindent $(wildcard *.[ch])
>> -
>> relabel:
>> diff --git a/policycoreutils/setfiles/Makefile b/policycoreutils/setfiles/Makefile
>> index dab6313c..aa3e80fc 100644
>> --- a/policycoreutils/setfiles/Makefile
>> +++ b/policycoreutils/setfiles/Makefile
>> @@ -43,8 +43,5 @@ install: all
>> clean:
>> rm -f setfiles restorecon restorecon_xattr *.o
>>
>> -indent:
>> - ../../scripts/Lindent $(wildcard *.[ch])
>> -
>> relabel: install
>> $(DESTDIR)$(SBINDIR)/restorecon $(DESTDIR)$(SBINDIR)/setfiles $(DESTDIR)$(SBINDIR)/restorecon_xattr
>> diff --git a/policycoreutils/setsebool/Makefile b/policycoreutils/setsebool/Makefile
>> index 87494c55..360e0ea0 100644
>> --- a/policycoreutils/setsebool/Makefile
>> +++ b/policycoreutils/setsebool/Makefile
>> @@ -35,7 +35,3 @@ relabel:
>>
>> clean:
>> -rm -f setsebool *.o
>> -
>> -indent:
>> - ../../scripts/Lindent $(wildcard *.[ch])
>> -
>> diff --git a/policycoreutils/unsetfiles/Makefile b/policycoreutils/unsetfiles/Makefile
>> index 9cb51494..8dbf85af 100644
>> --- a/policycoreutils/unsetfiles/Makefile
>> +++ b/policycoreutils/unsetfiles/Makefile
>> @@ -20,8 +20,5 @@ install: all
>> clean:
>> -rm -f unsetfiles *.o
>>
>> -indent:
>> - ../../scripts/Lindent $(wildcard *.[ch])
>> -
>> relabel: install
>> /sbin/restorecon $(DESTDIR)$(SBINDIR)/unsetfiles
>> diff --git a/python/Makefile b/python/Makefile
>> index 00312dbd..c4c31a17 100644
>> --- a/python/Makefile
>> +++ b/python/Makefile
>> @@ -1,6 +1,6 @@
>> SUBDIRS = sepolicy audit2allow semanage sepolgen chcat po
>>
>> -all install relabel clean indent test:
>> +all install relabel clean format test:
>> @for subdir in $(SUBDIRS); do \
>> (cd $$subdir && $(MAKE) $@) || exit 1; \
>> done
>> diff --git a/python/audit2allow/Makefile b/python/audit2allow/Makefile
>> index 28b8f7f2..90d10d1a 100644
>> --- a/python/audit2allow/Makefile
>> +++ b/python/audit2allow/Makefile
>> @@ -51,7 +51,4 @@ install: all
>> clean:
>> rm -f *~ *.o sepolgen-ifgen-attr-helper test_dummy_policy
>>
>> -indent:
>> - ../../scripts/Lindent $(wildcard *.[ch])
>> -
>> relabel: ;
>> diff --git a/python/chcat/Makefile b/python/chcat/Makefile
>> index 7b3ee17f..334b749d 100644
>> --- a/python/chcat/Makefile
>> +++ b/python/chcat/Makefile
>> @@ -21,8 +21,6 @@ install: all
>>
>> clean:
>>
>> -indent:
>> -
>> relabel:
>>
>> test:
>> diff --git a/python/semanage/Makefile b/python/semanage/Makefile
>> index 628d135a..51208d9e 100644
>> --- a/python/semanage/Makefile
>> +++ b/python/semanage/Makefile
>> @@ -35,6 +35,4 @@ test:
>> @$(PYTHON) test-semanage.py -a
>> clean:
>>
>> -indent:
>> -
>> relabel:
>> diff --git a/python/sepolgen/Makefile b/python/sepolgen/Makefile
>> index 3aed3304..2ad7b13c 100644
>> --- a/python/sepolgen/Makefile
>> +++ b/python/sepolgen/Makefile
>> @@ -11,10 +11,5 @@ clean:
>> rm -f *~ *.pyc
>> rm -f parser.out parsetab.py
>>
>> -indent: ;
>> -
>> test:
>> $(MAKE) -C tests $@
>> -
>> -
>> -
>> diff --git a/python/sepolgen/src/Makefile b/python/sepolgen/src/Makefile
>> index 2815a13d..a2456652 100644
>> --- a/python/sepolgen/src/Makefile
>> +++ b/python/sepolgen/src/Makefile
>> @@ -12,10 +12,4 @@ clean:
>> rm -f *~ *.pyc
>> rm -f parser.out parsetab.py
>>
>> -indent: ;
>> -
>> -
>> test: ;
>> -
>> -
>> -
>> diff --git a/restorecond/Makefile b/restorecond/Makefile
>> index b8b86eb4..51eb7608 100644
>> --- a/restorecond/Makefile
>> +++ b/restorecond/Makefile
>> @@ -59,7 +59,4 @@ relabel: install
>> clean:
>> -rm -f restorecond *.o *~
>>
>> -indent:
>> - ../../scripts/Lindent $(wildcard *.[ch])
>> -
>> test:
>> diff --git a/sandbox/Makefile b/sandbox/Makefile
>> index 0799ab7c..eaaad75c 100644
>> --- a/sandbox/Makefile
>> +++ b/sandbox/Makefile
>> @@ -50,7 +50,4 @@ clean:
>> -rm -f seunshare *.o *~
>> (cd po && $(MAKE) $@)
>>
>> -indent:
>> - ../../scripts/Lindent $(wildcard *.[ch])
>> -
>> relabel:
>> diff --git a/scripts/Lindent b/scripts/Lindent
>> deleted file mode 100755
>> index 9c4b3e2b..00000000
>> --- a/scripts/Lindent
>> +++ /dev/null
>> @@ -1,18 +0,0 @@
>> -#!/bin/sh
>> -PARAM="-npro -kr -i8 -ts8 -sob -l80 -ss -ncs -cp1"
>> -RES=`indent --version`
>> -V1=`echo $RES | cut -d' ' -f3 | cut -d'.' -f1`
>> -V2=`echo $RES | cut -d' ' -f3 | cut -d'.' -f2`
>> -V3=`echo $RES | cut -d' ' -f3 | cut -d'.' -f3`
>> -if [ $V1 -gt 2 ]; then
>> - PARAM="$PARAM -il0"
>> -elif [ $V1 -eq 2 ]; then
>> - if [ $V2 -gt 2 ]; then
>> - PARAM="$PARAM -il0";
>> - elif [ $V2 -eq 2 ]; then
>> - if [ $V3 -ge 10 ]; then
>> - PARAM="$PARAM -il0"
>> - fi
>> - fi
>> -fi
>> -indent $PARAM "$@"
>> diff --git a/semodule-utils/Makefile b/semodule-utils/Makefile
>> index e0a65792..81c97af0 100644
>> --- a/semodule-utils/Makefile
>> +++ b/semodule-utils/Makefile
>> @@ -1,6 +1,6 @@
>> SUBDIRS = semodule_package semodule_link semodule_expand
>>
>> -all install relabel clean indent:
>> +all install relabel clean:
>> @for subdir in $(SUBDIRS); do \
>> (cd $$subdir && $(MAKE) $@) || exit 1; \
>> done
>> diff --git a/semodule-utils/semodule_expand/Makefile b/semodule-utils/semodule_expand/Makefile
>> index ad776b15..72f09a46 100644
>> --- a/semodule-utils/semodule_expand/Makefile
>> +++ b/semodule-utils/semodule_expand/Makefile
>> @@ -27,7 +27,3 @@ relabel:
>>
>> clean:
>> -rm -f semodule_expand *.o
>> -
>> -indent:
>> - ../../scripts/Lindent $(wildcard *.[ch])
>> -
>> diff --git a/semodule-utils/semodule_link/Makefile b/semodule-utils/semodule_link/Makefile
>> index 936d161c..83590c07 100644
>> --- a/semodule-utils/semodule_link/Makefile
>> +++ b/semodule-utils/semodule_link/Makefile
>> @@ -27,7 +27,3 @@ relabel:
>>
>> clean:
>> -rm -f semodule_link *.o
>> -
>> -indent:
>> - ../../scripts/Lindent $(wildcard *.[ch])
>> -
>> diff --git a/semodule-utils/semodule_package/Makefile b/semodule-utils/semodule_package/Makefile
>> index 6a289f73..2465f987 100644
>> --- a/semodule-utils/semodule_package/Makefile
>> +++ b/semodule-utils/semodule_package/Makefile
>> @@ -29,7 +29,3 @@ relabel:
>>
>> clean:
>> -rm -f semodule_package semodule_unpackage *.o
>> -
>> -indent:
>> - ../../scripts/Lindent $(wildcard *.[ch])
>> -
>> --
>> 2.51.0
>>
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: When to apply `make format` to the entire tree
2025-10-20 16:18 ` When to apply `make format` to the entire tree Petr Lautrbach
@ 2025-10-20 16:26 ` Rahul Sandhu
2025-10-20 16:40 ` Stephen Smalley
0 siblings, 1 reply; 22+ messages in thread
From: Rahul Sandhu @ 2025-10-20 16:26 UTC (permalink / raw)
To: Petr Lautrbach, selinux; +Cc: Stephen Smalley
On Mon Oct 20, 2025 at 5:18 PM BST, Petr Lautrbach wrote:
> Stephen Smalley <stephen.smalley.work@gmail.com> writes:
>
>> On Mon, Oct 20, 2025 at 10:09 AM Rahul Sandhu <nvraxn@gmail.com> wrote:
>>>
>>> Add the .clang-format configuration file, taken from the Linux kernel
>>> repository. We don't have any official style guidelines in tree at
>>> present, which makes it a bit unclear how to format C code for new
>>> contributors. As well as this, different parts of the codebase seem to
>>> been formatted with different styles on occasion, so using an automatic
>>> formatter should resolve this.
>>>
>>> As well as this, replace all the existing indent targets with a single
>>> toplevel `format` target. Managing all the source files to be formatted
>>> is not pretty to maintain, and doesn't really give us much.
>>>
>>> Also define a toplevel `check-format` target to verify that all code is
>>> formatted properly. This only becomes useful in the future once we have
>>> reformatted all existing code, but is wired up for now.
>>>
>>> For the future:
>>> 1. Reformat all existing code. I understand this is a big change, but
>>> we may as well get all code formatted if we go down this route;
>>> afterall, it's not like this will cause any breaking changes.
>>>
>>> 2. Add a CI target to check that all code is formatted as per the new
>>> clang-format configuration. The `check-format` target can be used
>>> for this.
>>>
>>> Signed-off-by: Rahul Sandhu <nvraxn@gmail.com>
>>
>> Acked-by: Stephen Smalley <stephen.smalley.work@gmail.com>
>>
>> Will defer to distro package maintainers to decide when to apply make
>> format to the entire tree. Common practice I think is to do it just
>> before or after a release.
>
>
> For me, it's better do it before the release so I would not need to
> backport the format patch together with some future change.
Alright. I'll send a patch (non-rfc then) to format the code, and then
maybe just before the release someone can reply and I'll rebase it? I
also am happy to let a maintainer apply the patch instead (I mean it is
just one command) because of course the diff will be pretty huge, so it
is a real concern to make sure that the code is "untampered" with.
If that's the preferred route (I still think it is best regardless of
whoever sends the patch for people to check it locally by running `make
check-format` and committing it locally, and then diff'ing the patches
or something akin to that), I can simply send a patch hooking up CI and
updating the contribution guide telling people to format the code and
that can be applied after the format patch?
>
> Petr
>
>
>>> ---
>>> .clang-format | 130 +++++++++++++++++++++++
>>> CONTRIBUTING.md | 2 +
>>> Makefile | 11 +-
>>> checkpolicy/Makefile | 3 -
>>> gui/Makefile | 2 -
>>> libselinux/Makefile | 2 +-
>>> libselinux/include/Makefile | 4 -
>>> libselinux/man/Makefile | 2 +-
>>> libselinux/src/Makefile | 3 -
>>> libselinux/utils/Makefile | 4 -
>>> libsemanage/Makefile | 4 -
>>> libsemanage/include/Makefile | 3 -
>>> libsemanage/src/Makefile | 3 -
>>> libsemanage/utils/Makefile | 3 -
>>> libsepol/Makefile | 6 --
>>> libsepol/include/Makefile | 3 -
>>> libsepol/src/Makefile | 4 -
>>> libsepol/utils/Makefile | 4 -
>>> mcstrans/src/Makefile | 1 -
>>> mcstrans/utils/Makefile | 1 -
>>> policycoreutils/Makefile | 2 +-
>>> policycoreutils/hll/Makefile | 2 +-
>>> policycoreutils/hll/pp/Makefile | 3 -
>>> policycoreutils/load_policy/Makefile | 3 -
>>> policycoreutils/newrole/Makefile | 3 -
>>> policycoreutils/run_init/Makefile | 3 -
>>> policycoreutils/scripts/Makefile | 2 -
>>> policycoreutils/secon/Makefile | 3 -
>>> policycoreutils/semodule/Makefile | 4 -
>>> policycoreutils/sestatus/Makefile | 3 -
>>> policycoreutils/setfiles/Makefile | 3 -
>>> policycoreutils/setsebool/Makefile | 4 -
>>> policycoreutils/unsetfiles/Makefile | 3 -
>>> python/Makefile | 2 +-
>>> python/audit2allow/Makefile | 3 -
>>> python/chcat/Makefile | 2 -
>>> python/semanage/Makefile | 2 -
>>> python/sepolgen/Makefile | 5 -
>>> python/sepolgen/src/Makefile | 6 --
>>> restorecond/Makefile | 3 -
>>> sandbox/Makefile | 3 -
>>> scripts/Lindent | 18 ----
>>> semodule-utils/Makefile | 2 +-
>>> semodule-utils/semodule_expand/Makefile | 4 -
>>> semodule-utils/semodule_link/Makefile | 4 -
>>> semodule-utils/semodule_package/Makefile | 4 -
>>> 46 files changed, 148 insertions(+), 143 deletions(-)
>>> create mode 100644 .clang-format
>>> delete mode 100755 scripts/Lindent
>>>
>>> v2: remove linux kernel ForEachMacros and replace them with ours
>>> v3: replace the indent target with the new format target. also remove any
>>> mention of `.editorconfig` from the commit message; those changes are
>>> better suited for another patch (they're small and self-contained enough
>>> that they're a smaller thing to merge).
>>> v4: drop the subdir format targets entirely, replacing with a single toplevel
>>> format and check-format target.
>>> v5: add back relabel target accidently removed.
>>> v6: remove all references to being an RFC in the commit message.
>>>
>>> diff --git a/.clang-format b/.clang-format
>>> new file mode 100644
>>> index 00000000..35595d87
>>> --- /dev/null
>>> +++ b/.clang-format
>>> @@ -0,0 +1,130 @@
>>> +# SPDX-License-Identifier: GPL-2.0
>>> +#
>>> +# clang-format configuration file. Intended for clang-format >= 11.
>>> +#
>>> +# For more information, see:
>>> +#
>>> +# Documentation/dev-tools/clang-format.rst
>>> +# https://clang.llvm.org/docs/ClangFormat.html
>>> +# https://clang.llvm.org/docs/ClangFormatStyleOptions.html
>>> +#
>>> +---
>>> +AccessModifierOffset: -4
>>> +AlignAfterOpenBracket: Align
>>> +AlignConsecutiveAssignments: false
>>> +AlignConsecutiveDeclarations: false
>>> +AlignEscapedNewlines: Left
>>> +AlignOperands: true
>>> +AlignTrailingComments: false
>>> +AllowAllParametersOfDeclarationOnNextLine: false
>>> +AllowShortBlocksOnASingleLine: false
>>> +AllowShortCaseLabelsOnASingleLine: false
>>> +AllowShortFunctionsOnASingleLine: None
>>> +AllowShortIfStatementsOnASingleLine: false
>>> +AllowShortLoopsOnASingleLine: false
>>> +AlwaysBreakAfterDefinitionReturnType: None
>>> +AlwaysBreakAfterReturnType: None
>>> +AlwaysBreakBeforeMultilineStrings: false
>>> +AlwaysBreakTemplateDeclarations: false
>>> +BinPackArguments: true
>>> +BinPackParameters: true
>>> +BraceWrapping:
>>> + AfterClass: false
>>> + AfterControlStatement: false
>>> + AfterEnum: false
>>> + AfterFunction: true
>>> + AfterNamespace: true
>>> + AfterObjCDeclaration: false
>>> + AfterStruct: false
>>> + AfterUnion: false
>>> + AfterExternBlock: false
>>> + BeforeCatch: false
>>> + BeforeElse: false
>>> + IndentBraces: false
>>> + SplitEmptyFunction: true
>>> + SplitEmptyRecord: true
>>> + SplitEmptyNamespace: true
>>> +BreakBeforeBinaryOperators: None
>>> +BreakBeforeBraces: Custom
>>> +BreakBeforeInheritanceComma: false
>>> +BreakBeforeTernaryOperators: false
>>> +BreakConstructorInitializersBeforeComma: false
>>> +BreakConstructorInitializers: BeforeComma
>>> +BreakAfterJavaFieldAnnotations: false
>>> +BreakStringLiterals: false
>>> +ColumnLimit: 80
>>> +CommentPragmas: '^ IWYU pragma:'
>>> +CompactNamespaces: false
>>> +ConstructorInitializerAllOnOneLineOrOnePerLine: false
>>> +ConstructorInitializerIndentWidth: 8
>>> +ContinuationIndentWidth: 8
>>> +Cpp11BracedListStyle: false
>>> +DerivePointerAlignment: false
>>> +DisableFormat: false
>>> +ExperimentalAutoDetectBinPacking: false
>>> +FixNamespaceComments: false
>>> +
>>> +# Taken from:
>>> +# git grep -h '^#define [^[:space:]]*for_each[^[:space:]]*(' \
>>> +# | sed "s,^#define \([^[:space:]]*for_each[^[:space:]]*\)(.*$, - '\1'," \
>>> +# | LC_ALL=C sort -u
>>> +ForEachMacros:
>>> + - 'cil_list_for_each'
>>> + - 'cil_stack_for_each'
>>> + - 'cil_stack_for_each_starting_at'
>>> + - 'ebitmap_for_each_bit'
>>> + - 'ebitmap_for_each_positive_bit'
>>> +
>>> +IncludeBlocks: Preserve
>>> +IncludeCategories:
>>> + - Regex: '.*'
>>> + Priority: 1
>>> +IncludeIsMainRegex: '(Test)?$'
>>> +IndentCaseLabels: false
>>> +IndentGotoLabels: false
>>> +IndentPPDirectives: None
>>> +IndentWidth: 8
>>> +IndentWrappedFunctionNames: false
>>> +JavaScriptQuotes: Leave
>>> +JavaScriptWrapImports: true
>>> +KeepEmptyLinesAtTheStartOfBlocks: false
>>> +MacroBlockBegin: ''
>>> +MacroBlockEnd: ''
>>> +MaxEmptyLinesToKeep: 1
>>> +NamespaceIndentation: None
>>> +ObjCBinPackProtocolList: Auto
>>> +ObjCBlockIndentWidth: 8
>>> +ObjCSpaceAfterProperty: true
>>> +ObjCSpaceBeforeProtocolList: true
>>> +
>>> +# Taken from git's rules
>>> +PenaltyBreakAssignment: 10
>>> +PenaltyBreakBeforeFirstCallParameter: 30
>>> +PenaltyBreakComment: 10
>>> +PenaltyBreakFirstLessLess: 0
>>> +PenaltyBreakString: 10
>>> +PenaltyExcessCharacter: 100
>>> +PenaltyReturnTypeOnItsOwnLine: 60
>>> +
>>> +PointerAlignment: Right
>>> +ReflowComments: false
>>> +SortIncludes: false
>>> +SortUsingDeclarations: false
>>> +SpaceAfterCStyleCast: false
>>> +SpaceAfterTemplateKeyword: true
>>> +SpaceBeforeAssignmentOperators: true
>>> +SpaceBeforeCtorInitializerColon: true
>>> +SpaceBeforeInheritanceColon: true
>>> +SpaceBeforeParens: ControlStatementsExceptForEachMacros
>>> +SpaceBeforeRangeBasedForLoopColon: true
>>> +SpaceInEmptyParentheses: false
>>> +SpacesBeforeTrailingComments: 1
>>> +SpacesInAngles: false
>>> +SpacesInContainerLiterals: false
>>> +SpacesInCStyleCastParentheses: false
>>> +SpacesInParentheses: false
>>> +SpacesInSquareBrackets: false
>>> +Standard: Cpp03
>>> +TabWidth: 8
>>> +UseTab: Always
>>> +...
>>> diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
>>> index c501cf84..7ec8cb0f 100644
>>> --- a/CONTRIBUTING.md
>>> +++ b/CONTRIBUTING.md
>>> @@ -53,6 +53,8 @@ When preparing patches, please follow these guidelines:
>>> - Separate large patches into logical patches
>>> - Patch descriptions must end with your "Signed-off-by" line. This means your
>>> code meets the Developer's certificate of origin, see below.
>>> +- C code should be formatted using clang-format, using the .clang-format
>>> + configuration file at the root of this repository.
>>>
>>> When adding new, large features or tools it is best to discuss the
>>> design on the mailing list prior to submitting the patch.
>>> diff --git a/Makefile b/Makefile
>>> index 2ffba8e9..972d5525 100644
>>> --- a/Makefile
>>> +++ b/Makefile
>>> @@ -36,7 +36,7 @@ ifneq ($(DESTDIR),)
>>> export LIBSEPOLA
>>> endif
>>>
>>> -all install relabel clean test indent:
>>> +all install relabel clean test:
>>> @for subdir in $(SUBDIRS); do \
>>> (cd $$subdir && $(MAKE) $@) || exit 1; \
>>> done
>>> @@ -50,3 +50,12 @@ distclean:
>>> @for subdir in $(DISTCLEANSUBDIRS); do \
>>> (cd $$subdir && $(MAKE) $@) || exit 1; \
>>> done
>>> +
>>> +# We shouldn't have any unformatted files in the repo without an explicit exception.
>>> +FORMAT_SOURCE_FILES := $(shell find $(SUBDIRS) -type f \( -name '*.c' -o -name '*.h' \))
>>> +
>>> +format:
>>> + clang-format -i $(FORMAT_SOURCE_FILES)
>>> +
>>> +check-format:
>>> + clang-format --dry-run -Werror $(FORMAT_SOURCE_FILES)
>>> diff --git a/checkpolicy/Makefile b/checkpolicy/Makefile
>>> index 6e8008e3..0055f495 100644
>>> --- a/checkpolicy/Makefile
>>> +++ b/checkpolicy/Makefile
>>> @@ -77,6 +77,3 @@ relabel: install
>>> clean:
>>> -rm -f $(TARGETS) $(CHECKPOLOBJS) $(CHECKMODOBJS) y.tab.c y.tab.h lex.yy.c tests/testpol.conf tests/testpol.bin
>>> $(MAKE) -C test clean
>>> -
>>> -indent:
>>> - ../scripts/Lindent $(filter-out $(GENERATED),$(wildcard *.[ch]))
>>> diff --git a/gui/Makefile b/gui/Makefile
>>> index b29610d4..b1a94224 100644
>>> --- a/gui/Makefile
>>> +++ b/gui/Makefile
>>> @@ -60,8 +60,6 @@ install: all
>>> clean:
>>> (cd po && $(MAKE) $@)
>>>
>>> -indent:
>>> -
>>> relabel:
>>>
>>> test:
>>> diff --git a/libselinux/Makefile b/libselinux/Makefile
>>> index a50b6491..aeede2b5 100644
>>> --- a/libselinux/Makefile
>>> +++ b/libselinux/Makefile
>>> @@ -50,7 +50,7 @@ COMPILER := clang
>>> endif
>>> export COMPILER
>>>
>>> -all install relabel clean distclean indent:
>>> +all install relabel clean distclean:
>>> @for subdir in $(SUBDIRS); do \
>>> (cd $$subdir && $(MAKE) $@) || exit 1; \
>>> done
>>> diff --git a/libselinux/include/Makefile b/libselinux/include/Makefile
>>> index 8ab9ce92..a1e322ac 100644
>>> --- a/libselinux/include/Makefile
>>> +++ b/libselinux/include/Makefile
>>> @@ -10,9 +10,5 @@ install: all
>>>
>>> relabel:
>>>
>>> -indent:
>>> - ../../scripts/Lindent $(wildcard selinux/*.h)
>>> -
>>> distclean clean:
>>> -rm -f selinux/*~
>>> -
>>> diff --git a/libselinux/man/Makefile b/libselinux/man/Makefile
>>> index fdc0825f..42b1662a 100644
>>> --- a/libselinux/man/Makefile
>>> +++ b/libselinux/man/Makefile
>>> @@ -35,4 +35,4 @@ install: all
>>>
>>> relabel:
>>>
>>> -indent distclean clean:
>>> +format distclean clean:
>>> diff --git a/libselinux/src/Makefile b/libselinux/src/Makefile
>>> index 261c22d4..f7412cd1 100644
>>> --- a/libselinux/src/Makefile
>>> +++ b/libselinux/src/Makefile
>>> @@ -223,7 +223,4 @@ clean: clean-pywrap clean-rubywrap
>>> distclean: clean
>>> rm -f $(GENERATED) $(SWIGFILES)
>>>
>>> -indent:
>>> - ../../scripts/Lindent $(filter-out $(GENERATED),$(wildcard *.[ch]))
>>> -
>>> .PHONY: all clean clean-pywrap clean-rubywrap pywrap rubywrap swigify install install-pywrap install-rubywrap distclean
>>> diff --git a/libselinux/utils/Makefile b/libselinux/utils/Makefile
>>> index 6b1dc7c9..20dc44eb 100644
>>> --- a/libselinux/utils/Makefile
>>> +++ b/libselinux/utils/Makefile
>>> @@ -72,8 +72,4 @@ clean:
>>>
>>> distclean: clean
>>>
>>> -indent:
>>> - ../../scripts/Lindent $(wildcard *.[ch])
>>> -
>>> relabel:
>>> -
>>> diff --git a/libsemanage/Makefile b/libsemanage/Makefile
>>> index dbd240da..591ce5f2 100644
>>> --- a/libsemanage/Makefile
>>> +++ b/libsemanage/Makefile
>>> @@ -29,9 +29,5 @@ clean distclean:
>>> $(MAKE) -C src $@
>>> $(MAKE) -C tests $@
>>>
>>> -indent:
>>> - $(MAKE) -C src $@
>>> - $(MAKE) -C include $@
>>> -
>>> test: all
>>> $(MAKE) -C tests test
>>> diff --git a/libsemanage/include/Makefile b/libsemanage/include/Makefile
>>> index 6e44a28a..b08e48a0 100644
>>> --- a/libsemanage/include/Makefile
>>> +++ b/libsemanage/include/Makefile
>>> @@ -7,6 +7,3 @@ all:
>>> install: all
>>> test -d $(DESTDIR)$(INCDIR) || install -m 755 -d $(DESTDIR)$(INCDIR)
>>> install -m 644 $(wildcard semanage/*.h) $(DESTDIR)$(INCDIR)
>>> -
>>> -indent:
>>> - ../../scripts/Lindent $(wildcard semanage/*.h)
>>> diff --git a/libsemanage/src/Makefile b/libsemanage/src/Makefile
>>> index fa3449fb..8e025112 100644
>>> --- a/libsemanage/src/Makefile
>>> +++ b/libsemanage/src/Makefile
>>> @@ -167,7 +167,4 @@ clean:
>>> distclean: clean
>>> rm -f $(GENERATED) $(SWIGFILES)
>>>
>>> -indent:
>>> - ../../scripts/Lindent $(filter-out $(GENERATED),$(wildcard *.[ch]))
>>> -
>>> .PHONY: all clean pywrap rubywrap swigify install install-pywrap install-rubywrap distclean
>>> diff --git a/libsemanage/utils/Makefile b/libsemanage/utils/Makefile
>>> index 5b8fbb6b..0f382934 100644
>>> --- a/libsemanage/utils/Makefile
>>> +++ b/libsemanage/utils/Makefile
>>> @@ -13,7 +13,4 @@ clean:
>>>
>>> distclean: clean
>>>
>>> -indent:
>>> -
>>> relabel:
>>> -
>>> diff --git a/libsepol/Makefile b/libsepol/Makefile
>>> index 5b5d03e2..223edcec 100644
>>> --- a/libsepol/Makefile
>>> +++ b/libsepol/Makefile
>>> @@ -20,11 +20,5 @@ clean:
>>> $(MAKE) -C utils clean
>>> $(MAKE) -C tests clean
>>>
>>> -indent:
>>> - $(MAKE) -C src $@
>>> - $(MAKE) -C include $@
>>> - $(MAKE) -C utils $@
>>> -
>>> test:
>>> $(MAKE) -C tests test
>>> -
>>> diff --git a/libsepol/include/Makefile b/libsepol/include/Makefile
>>> index 1ad4ecab..f49b6e19 100644
>>> --- a/libsepol/include/Makefile
>>> +++ b/libsepol/include/Makefile
>>> @@ -12,6 +12,3 @@ install: all
>>> install -m 644 $(wildcard sepol/*.h) $(DESTDIR)$(INCDIR)
>>> install -m 644 $(wildcard sepol/policydb/*.h) $(DESTDIR)$(INCDIR)/policydb
>>> install -m 644 $(wildcard $(CILDIR)/include/cil/*.h) $(DESTDIR)$(INCDIR)/cil
>>> -
>>> -indent:
>>> - ../../scripts/Lindent $(wildcard sepol/*.h)
>>> diff --git a/libsepol/src/Makefile b/libsepol/src/Makefile
>>> index 90aed394..bb2b7f5e 100644
>>> --- a/libsepol/src/Makefile
>>> +++ b/libsepol/src/Makefile
>>> @@ -105,7 +105,3 @@ relabel:
>>>
>>> clean:
>>> -rm -f $(LIBPC) $(LIBMAP) $(OBJS) $(LOBJS) $(LIBA) $(LIBSO) $(TARGET) $(CIL_GENERATED)
>>> -
>>> -indent:
>>> - ../../scripts/Lindent $(wildcard *.[ch])
>>> -
>>> diff --git a/libsepol/utils/Makefile b/libsepol/utils/Makefile
>>> index 31932c11..a8bedf2e 100644
>>> --- a/libsepol/utils/Makefile
>>> +++ b/libsepol/utils/Makefile
>>> @@ -18,8 +18,4 @@ install: all
>>> clean:
>>> -rm -f $(TARGETS) *.o
>>>
>>> -indent:
>>> - ../../scripts/Lindent $(wildcard *.[ch])
>>> -
>>> relabel:
>>> -
>>> diff --git a/mcstrans/src/Makefile b/mcstrans/src/Makefile
>>> index 88487068..609b2d45 100644
>>> --- a/mcstrans/src/Makefile
>>> +++ b/mcstrans/src/Makefile
>>> @@ -37,4 +37,3 @@ install: all
>>>
>>> clean:
>>> -rm -f $(OBJS) $(LOBJS) $(TARGET) $(PROG) $(PROG_OBJS) *~ \#*
>>> -
>>> diff --git a/mcstrans/utils/Makefile b/mcstrans/utils/Makefile
>>> index 57a73932..1d70b4ed 100644
>>> --- a/mcstrans/utils/Makefile
>>> +++ b/mcstrans/utils/Makefile
>>> @@ -36,4 +36,3 @@ clean:
>>> rm -f $(TARGETS) *.o *~ \#*
>>>
>>> relabel:
>>> -
>>> diff --git a/policycoreutils/Makefile b/policycoreutils/Makefile
>>> index 7c9706e3..9186a9ef 100644
>>> --- a/policycoreutils/Makefile
>>> +++ b/policycoreutils/Makefile
>>> @@ -6,7 +6,7 @@ LIBSELINUX_LDLIBS := $(shell PKG_CONFIG_PATH="$(PKG_CONFIG_PATH):../libselinux/s
>>> LIBSEMANAGE_LDLIBS := $(shell PKG_CONFIG_PATH="$(PKG_CONFIG_PATH):../libsemanage/src" $(PKG_CONFIG) --libs libsemanage)
>>> export LIBSELINUX_LDLIBS LIBSEMANAGE_LDLIBS
>>>
>>> -all install relabel clean indent:
>>> +all install relabel clean:
>>> @for subdir in $(SUBDIRS); do \
>>> (cd $$subdir && $(MAKE) $@) || exit 1; \
>>> done
>>> diff --git a/policycoreutils/hll/Makefile b/policycoreutils/hll/Makefile
>>> index fe720e57..390f3a34 100644
>>> --- a/policycoreutils/hll/Makefile
>>> +++ b/policycoreutils/hll/Makefile
>>> @@ -1,6 +1,6 @@
>>> SUBDIRS = pp
>>>
>>> -all install relabel clean indent:
>>> +all install relabel clean:
>>> @for subdir in $(SUBDIRS); do \
>>> (cd $$subdir && $(MAKE) $@) || exit 1; \
>>> done
>>> diff --git a/policycoreutils/hll/pp/Makefile b/policycoreutils/hll/pp/Makefile
>>> index 3c9b0efc..a0d475a3 100644
>>> --- a/policycoreutils/hll/pp/Makefile
>>> +++ b/policycoreutils/hll/pp/Makefile
>>> @@ -25,6 +25,3 @@ relabel:
>>>
>>> clean:
>>> -rm -f pp $(PP_OBJS)
>>> -
>>> -indent:
>>> - ../../scripts/Lindent $(wildcard *.[ch])
>>> diff --git a/policycoreutils/load_policy/Makefile b/policycoreutils/load_policy/Makefile
>>> index c61fee70..7754cadc 100644
>>> --- a/policycoreutils/load_policy/Makefile
>>> +++ b/policycoreutils/load_policy/Makefile
>>> @@ -28,8 +28,5 @@ install: all
>>> clean:
>>> -rm -f $(TARGETS) *.o
>>>
>>> -indent:
>>> - ../../scripts/Lindent $(wildcard *.[ch])
>>> -
>>> relabel:
>>> /sbin/restorecon $(DESTDIR)$(SBINDIR)/load_policy
>>> diff --git a/policycoreutils/newrole/Makefile b/policycoreutils/newrole/Makefile
>>> index df64483f..fcd2661f 100644
>>> --- a/policycoreutils/newrole/Makefile
>>> +++ b/policycoreutils/newrole/Makefile
>>> @@ -87,9 +87,6 @@ endif
>>> clean:
>>> rm -f newrole *.o
>>>
>>> -indent:
>>> - ../../scripts/Lindent $(wildcard *.[ch])
>>> -
>>> relabel: install
>>> /sbin/restorecon $(DESTDIR)$(BINDIR)/newrole
>>>
>>> diff --git a/policycoreutils/run_init/Makefile b/policycoreutils/run_init/Makefile
>>> index c89fffb9..0e904dba 100644
>>> --- a/policycoreutils/run_init/Makefile
>>> +++ b/policycoreutils/run_init/Makefile
>>> @@ -53,8 +53,5 @@ endif
>>> clean:
>>> -rm -f $(TARGETS) *.o
>>>
>>> -indent:
>>> - ../../scripts/Lindent $(wildcard *.[ch])
>>> -
>>> relabel: install
>>> /sbin/restorecon $(DESTDIR)$(SBINDIR)/run_init $(DESTDIR)$(SBINDIR)/open_init_pty
>>> diff --git a/policycoreutils/scripts/Makefile b/policycoreutils/scripts/Makefile
>>> index 6d8196c6..1058bbab 100644
>>> --- a/policycoreutils/scripts/Makefile
>>> +++ b/policycoreutils/scripts/Makefile
>>> @@ -21,6 +21,4 @@ install: all
>>>
>>> clean:
>>>
>>> -indent:
>>> -
>>> relabel:
>>> diff --git a/policycoreutils/secon/Makefile b/policycoreutils/secon/Makefile
>>> index c9296f19..b2f276f9 100644
>>> --- a/policycoreutils/secon/Makefile
>>> +++ b/policycoreutils/secon/Makefile
>>> @@ -35,9 +35,6 @@ relabel:
>>> clean:
>>> rm -f *.o core* secon *~ *.bak
>>>
>>> -indent:
>>> - ../../scripts/Lindent $(wildcard *.[ch])
>>> -
>>> bare: clean
>>>
>>> .PHONY: clean bare
>>> diff --git a/policycoreutils/semodule/Makefile b/policycoreutils/semodule/Makefile
>>> index 018ee2ca..47bde5f8 100644
>>> --- a/policycoreutils/semodule/Makefile
>>> +++ b/policycoreutils/semodule/Makefile
>>> @@ -35,7 +35,3 @@ relabel:
>>>
>>> clean:
>>> -rm -f semodule *.o genhomedircon
>>> -
>>> -indent:
>>> - ../../scripts/Lindent $(wildcard *.[ch])
>>> -
>>> diff --git a/policycoreutils/sestatus/Makefile b/policycoreutils/sestatus/Makefile
>>> index 1ce617c0..70f46956 100644
>>> --- a/policycoreutils/sestatus/Makefile
>>> +++ b/policycoreutils/sestatus/Makefile
>>> @@ -41,7 +41,4 @@ install: all
>>> clean:
>>> rm -f sestatus *.o
>>>
>>> -indent:
>>> - ../../scripts/Lindent $(wildcard *.[ch])
>>> -
>>> relabel:
>>> diff --git a/policycoreutils/setfiles/Makefile b/policycoreutils/setfiles/Makefile
>>> index dab6313c..aa3e80fc 100644
>>> --- a/policycoreutils/setfiles/Makefile
>>> +++ b/policycoreutils/setfiles/Makefile
>>> @@ -43,8 +43,5 @@ install: all
>>> clean:
>>> rm -f setfiles restorecon restorecon_xattr *.o
>>>
>>> -indent:
>>> - ../../scripts/Lindent $(wildcard *.[ch])
>>> -
>>> relabel: install
>>> $(DESTDIR)$(SBINDIR)/restorecon $(DESTDIR)$(SBINDIR)/setfiles $(DESTDIR)$(SBINDIR)/restorecon_xattr
>>> diff --git a/policycoreutils/setsebool/Makefile b/policycoreutils/setsebool/Makefile
>>> index 87494c55..360e0ea0 100644
>>> --- a/policycoreutils/setsebool/Makefile
>>> +++ b/policycoreutils/setsebool/Makefile
>>> @@ -35,7 +35,3 @@ relabel:
>>>
>>> clean:
>>> -rm -f setsebool *.o
>>> -
>>> -indent:
>>> - ../../scripts/Lindent $(wildcard *.[ch])
>>> -
>>> diff --git a/policycoreutils/unsetfiles/Makefile b/policycoreutils/unsetfiles/Makefile
>>> index 9cb51494..8dbf85af 100644
>>> --- a/policycoreutils/unsetfiles/Makefile
>>> +++ b/policycoreutils/unsetfiles/Makefile
>>> @@ -20,8 +20,5 @@ install: all
>>> clean:
>>> -rm -f unsetfiles *.o
>>>
>>> -indent:
>>> - ../../scripts/Lindent $(wildcard *.[ch])
>>> -
>>> relabel: install
>>> /sbin/restorecon $(DESTDIR)$(SBINDIR)/unsetfiles
>>> diff --git a/python/Makefile b/python/Makefile
>>> index 00312dbd..c4c31a17 100644
>>> --- a/python/Makefile
>>> +++ b/python/Makefile
>>> @@ -1,6 +1,6 @@
>>> SUBDIRS = sepolicy audit2allow semanage sepolgen chcat po
>>>
>>> -all install relabel clean indent test:
>>> +all install relabel clean format test:
>>> @for subdir in $(SUBDIRS); do \
>>> (cd $$subdir && $(MAKE) $@) || exit 1; \
>>> done
>>> diff --git a/python/audit2allow/Makefile b/python/audit2allow/Makefile
>>> index 28b8f7f2..90d10d1a 100644
>>> --- a/python/audit2allow/Makefile
>>> +++ b/python/audit2allow/Makefile
>>> @@ -51,7 +51,4 @@ install: all
>>> clean:
>>> rm -f *~ *.o sepolgen-ifgen-attr-helper test_dummy_policy
>>>
>>> -indent:
>>> - ../../scripts/Lindent $(wildcard *.[ch])
>>> -
>>> relabel: ;
>>> diff --git a/python/chcat/Makefile b/python/chcat/Makefile
>>> index 7b3ee17f..334b749d 100644
>>> --- a/python/chcat/Makefile
>>> +++ b/python/chcat/Makefile
>>> @@ -21,8 +21,6 @@ install: all
>>>
>>> clean:
>>>
>>> -indent:
>>> -
>>> relabel:
>>>
>>> test:
>>> diff --git a/python/semanage/Makefile b/python/semanage/Makefile
>>> index 628d135a..51208d9e 100644
>>> --- a/python/semanage/Makefile
>>> +++ b/python/semanage/Makefile
>>> @@ -35,6 +35,4 @@ test:
>>> @$(PYTHON) test-semanage.py -a
>>> clean:
>>>
>>> -indent:
>>> -
>>> relabel:
>>> diff --git a/python/sepolgen/Makefile b/python/sepolgen/Makefile
>>> index 3aed3304..2ad7b13c 100644
>>> --- a/python/sepolgen/Makefile
>>> +++ b/python/sepolgen/Makefile
>>> @@ -11,10 +11,5 @@ clean:
>>> rm -f *~ *.pyc
>>> rm -f parser.out parsetab.py
>>>
>>> -indent: ;
>>> -
>>> test:
>>> $(MAKE) -C tests $@
>>> -
>>> -
>>> -
>>> diff --git a/python/sepolgen/src/Makefile b/python/sepolgen/src/Makefile
>>> index 2815a13d..a2456652 100644
>>> --- a/python/sepolgen/src/Makefile
>>> +++ b/python/sepolgen/src/Makefile
>>> @@ -12,10 +12,4 @@ clean:
>>> rm -f *~ *.pyc
>>> rm -f parser.out parsetab.py
>>>
>>> -indent: ;
>>> -
>>> -
>>> test: ;
>>> -
>>> -
>>> -
>>> diff --git a/restorecond/Makefile b/restorecond/Makefile
>>> index b8b86eb4..51eb7608 100644
>>> --- a/restorecond/Makefile
>>> +++ b/restorecond/Makefile
>>> @@ -59,7 +59,4 @@ relabel: install
>>> clean:
>>> -rm -f restorecond *.o *~
>>>
>>> -indent:
>>> - ../../scripts/Lindent $(wildcard *.[ch])
>>> -
>>> test:
>>> diff --git a/sandbox/Makefile b/sandbox/Makefile
>>> index 0799ab7c..eaaad75c 100644
>>> --- a/sandbox/Makefile
>>> +++ b/sandbox/Makefile
>>> @@ -50,7 +50,4 @@ clean:
>>> -rm -f seunshare *.o *~
>>> (cd po && $(MAKE) $@)
>>>
>>> -indent:
>>> - ../../scripts/Lindent $(wildcard *.[ch])
>>> -
>>> relabel:
>>> diff --git a/scripts/Lindent b/scripts/Lindent
>>> deleted file mode 100755
>>> index 9c4b3e2b..00000000
>>> --- a/scripts/Lindent
>>> +++ /dev/null
>>> @@ -1,18 +0,0 @@
>>> -#!/bin/sh
>>> -PARAM="-npro -kr -i8 -ts8 -sob -l80 -ss -ncs -cp1"
>>> -RES=`indent --version`
>>> -V1=`echo $RES | cut -d' ' -f3 | cut -d'.' -f1`
>>> -V2=`echo $RES | cut -d' ' -f3 | cut -d'.' -f2`
>>> -V3=`echo $RES | cut -d' ' -f3 | cut -d'.' -f3`
>>> -if [ $V1 -gt 2 ]; then
>>> - PARAM="$PARAM -il0"
>>> -elif [ $V1 -eq 2 ]; then
>>> - if [ $V2 -gt 2 ]; then
>>> - PARAM="$PARAM -il0";
>>> - elif [ $V2 -eq 2 ]; then
>>> - if [ $V3 -ge 10 ]; then
>>> - PARAM="$PARAM -il0"
>>> - fi
>>> - fi
>>> -fi
>>> -indent $PARAM "$@"
>>> diff --git a/semodule-utils/Makefile b/semodule-utils/Makefile
>>> index e0a65792..81c97af0 100644
>>> --- a/semodule-utils/Makefile
>>> +++ b/semodule-utils/Makefile
>>> @@ -1,6 +1,6 @@
>>> SUBDIRS = semodule_package semodule_link semodule_expand
>>>
>>> -all install relabel clean indent:
>>> +all install relabel clean:
>>> @for subdir in $(SUBDIRS); do \
>>> (cd $$subdir && $(MAKE) $@) || exit 1; \
>>> done
>>> diff --git a/semodule-utils/semodule_expand/Makefile b/semodule-utils/semodule_expand/Makefile
>>> index ad776b15..72f09a46 100644
>>> --- a/semodule-utils/semodule_expand/Makefile
>>> +++ b/semodule-utils/semodule_expand/Makefile
>>> @@ -27,7 +27,3 @@ relabel:
>>>
>>> clean:
>>> -rm -f semodule_expand *.o
>>> -
>>> -indent:
>>> - ../../scripts/Lindent $(wildcard *.[ch])
>>> -
>>> diff --git a/semodule-utils/semodule_link/Makefile b/semodule-utils/semodule_link/Makefile
>>> index 936d161c..83590c07 100644
>>> --- a/semodule-utils/semodule_link/Makefile
>>> +++ b/semodule-utils/semodule_link/Makefile
>>> @@ -27,7 +27,3 @@ relabel:
>>>
>>> clean:
>>> -rm -f semodule_link *.o
>>> -
>>> -indent:
>>> - ../../scripts/Lindent $(wildcard *.[ch])
>>> -
>>> diff --git a/semodule-utils/semodule_package/Makefile b/semodule-utils/semodule_package/Makefile
>>> index 6a289f73..2465f987 100644
>>> --- a/semodule-utils/semodule_package/Makefile
>>> +++ b/semodule-utils/semodule_package/Makefile
>>> @@ -29,7 +29,3 @@ relabel:
>>>
>>> clean:
>>> -rm -f semodule_package semodule_unpackage *.o
>>> -
>>> -indent:
>>> - ../../scripts/Lindent $(wildcard *.[ch])
>>> -
>>> --
>>> 2.51.0
>>>
Regards,
Rahul
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: When to apply `make format` to the entire tree
2025-10-20 16:26 ` Rahul Sandhu
@ 2025-10-20 16:40 ` Stephen Smalley
0 siblings, 0 replies; 22+ messages in thread
From: Stephen Smalley @ 2025-10-20 16:40 UTC (permalink / raw)
To: Rahul Sandhu; +Cc: Petr Lautrbach, selinux
On Mon, Oct 20, 2025 at 12:26 PM Rahul Sandhu <nvraxn@gmail.com> wrote:
>
> On Mon Oct 20, 2025 at 5:18 PM BST, Petr Lautrbach wrote:
> > Stephen Smalley <stephen.smalley.work@gmail.com> writes:
> >
> >> On Mon, Oct 20, 2025 at 10:09 AM Rahul Sandhu <nvraxn@gmail.com> wrote:
> >>>
> >>> Add the .clang-format configuration file, taken from the Linux kernel
> >>> repository. We don't have any official style guidelines in tree at
> >>> present, which makes it a bit unclear how to format C code for new
> >>> contributors. As well as this, different parts of the codebase seem to
> >>> been formatted with different styles on occasion, so using an automatic
> >>> formatter should resolve this.
> >>>
> >>> As well as this, replace all the existing indent targets with a single
> >>> toplevel `format` target. Managing all the source files to be formatted
> >>> is not pretty to maintain, and doesn't really give us much.
> >>>
> >>> Also define a toplevel `check-format` target to verify that all code is
> >>> formatted properly. This only becomes useful in the future once we have
> >>> reformatted all existing code, but is wired up for now.
> >>>
> >>> For the future:
> >>> 1. Reformat all existing code. I understand this is a big change, but
> >>> we may as well get all code formatted if we go down this route;
> >>> afterall, it's not like this will cause any breaking changes.
> >>>
> >>> 2. Add a CI target to check that all code is formatted as per the new
> >>> clang-format configuration. The `check-format` target can be used
> >>> for this.
> >>>
> >>> Signed-off-by: Rahul Sandhu <nvraxn@gmail.com>
> >>
> >> Acked-by: Stephen Smalley <stephen.smalley.work@gmail.com>
> >>
> >> Will defer to distro package maintainers to decide when to apply make
> >> format to the entire tree. Common practice I think is to do it just
> >> before or after a release.
> >
> >
> > For me, it's better do it before the release so I would not need to
> > backport the format patch together with some future change.
>
> Alright. I'll send a patch (non-rfc then) to format the code, and then
> maybe just before the release someone can reply and I'll rebase it? I
> also am happy to let a maintainer apply the patch instead (I mean it is
> just one command) because of course the diff will be pretty huge, so it
> is a real concern to make sure that the code is "untampered" with.
I don't think we need to send a patch to the mailing list for that,
just have whoever cuts the next release run make format and commit the
result before tagging.
> If that's the preferred route (I still think it is best regardless of
> whoever sends the patch for people to check it locally by running `make
> check-format` and committing it locally, and then diff'ing the patches
> or something akin to that), I can simply send a patch hooking up CI and
> updating the contribution guide telling people to format the code and
> that can be applied after the format patch?
Yes, that seems fine.
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [PATCH v6] treewide: add .clang-format configuration file
2025-10-20 14:55 ` Stephen Smalley
2025-10-20 16:18 ` When to apply `make format` to the entire tree Petr Lautrbach
@ 2025-10-21 13:49 ` Stephen Smalley
1 sibling, 0 replies; 22+ messages in thread
From: Stephen Smalley @ 2025-10-21 13:49 UTC (permalink / raw)
To: Rahul Sandhu; +Cc: lautrbach, selinux
On Mon, Oct 20, 2025 at 10:55 AM Stephen Smalley
<stephen.smalley.work@gmail.com> wrote:
>
> On Mon, Oct 20, 2025 at 10:09 AM Rahul Sandhu <nvraxn@gmail.com> wrote:
> >
> > Add the .clang-format configuration file, taken from the Linux kernel
> > repository. We don't have any official style guidelines in tree at
> > present, which makes it a bit unclear how to format C code for new
> > contributors. As well as this, different parts of the codebase seem to
> > been formatted with different styles on occasion, so using an automatic
> > formatter should resolve this.
> >
> > As well as this, replace all the existing indent targets with a single
> > toplevel `format` target. Managing all the source files to be formatted
> > is not pretty to maintain, and doesn't really give us much.
> >
> > Also define a toplevel `check-format` target to verify that all code is
> > formatted properly. This only becomes useful in the future once we have
> > reformatted all existing code, but is wired up for now.
> >
> > For the future:
> > 1. Reformat all existing code. I understand this is a big change, but
> > we may as well get all code formatted if we go down this route;
> > afterall, it's not like this will cause any breaking changes.
> >
> > 2. Add a CI target to check that all code is formatted as per the new
> > clang-format configuration. The `check-format` target can be used
> > for this.
> >
> > Signed-off-by: Rahul Sandhu <nvraxn@gmail.com>
>
> Acked-by: Stephen Smalley <stephen.smalley.work@gmail.com>
Thanks, merged this patch but as I noted, will defer to one of the
other maintainers to apply make format prior to making the next
release.
^ permalink raw reply [flat|nested] 22+ messages in thread
end of thread, other threads:[~2025-10-21 13:49 UTC | newest]
Thread overview: 22+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-28 22:39 [RFC PATCH] treewide: add .clang-format configuration file Rahul Sandhu
2025-09-28 22:48 ` [RFC PATCH v2] " Rahul Sandhu
2025-10-06 16:52 ` Stephen Smalley
2025-10-07 6:35 ` Petr Lautrbach
2025-10-07 10:46 ` [PATCH v3] " Rahul Sandhu
2025-10-07 11:07 ` Rahul Sandhu
2025-10-07 13:24 ` Stephen Smalley
2025-10-07 13:21 ` Stephen Smalley
2025-10-16 22:05 ` Rahul Sandhu
2025-10-17 12:51 ` Stephen Smalley
2025-10-18 6:11 ` [RFC PATCH v4] " Rahul Sandhu
2025-10-20 13:23 ` Stephen Smalley
2025-10-20 13:49 ` Stephen Smalley
2025-10-20 14:07 ` [PATCH v5] " Rahul Sandhu
2025-10-20 14:09 ` [PATCH v6] " Rahul Sandhu
2025-10-20 14:55 ` Stephen Smalley
2025-10-20 16:18 ` When to apply `make format` to the entire tree Petr Lautrbach
2025-10-20 16:26 ` Rahul Sandhu
2025-10-20 16:40 ` Stephen Smalley
2025-10-21 13:49 ` [PATCH v6] treewide: add .clang-format configuration file Stephen Smalley
2025-10-16 22:08 ` [PATCH v3] " Rahul Sandhu
2025-10-08 15:17 ` [RFC PATCH v2] " Kenton Groombridge
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.