Set gdb config file based on installed version

This commit is contained in:
Kenneth Benzie 2022-11-06 19:38:43 +00:00
parent 08af0f00b6
commit bebe6de7cd
4 changed files with 40 additions and 13 deletions

View File

@ -1,5 +1,6 @@
---
- name: install apt package
become: true
apt:
name: gdb
state: latest

View File

@ -0,0 +1,11 @@
---
- set_fact:
gdb_config_dir: '{{ansible_env.HOME}}/.config/gdb'
- name: create config directory
file:
path: '{{gdb_config_dir}}'
state: directory
- set_fact:
gdb_config_file: '{{gdb_config_dir}}/gdbinit'

View File

@ -1,19 +1,34 @@
---
- set_fact:
config_dir: '{{ansible_env.HOME}}/.config/gdb'
state_dir: '{{ansible_env.HOME}}/.local/state/gdb'
- include_tasks: '{{ansible_os_family}}.yaml'
- name: create directory
file:
path: '{{item}}'
state: directory
with_items:
- '{{config_dir}}'
- '{{state_dir}}'
# gdb 11.1 introduced support for config files that respect the XDG base
# directory spec, handle the boths paths dependant on the gdb version install.
- name: get installed version
command: gdb --version
register: gdb_version_output
changed_when: false
- set_fact:
gdb_version: '{{gdb_version_output.stdout | regex_search("(\d+)\.(\d+)", "\1", "\2")}}'
- set_fact:
gdb_xdg_base_dir_check:
gdb_version[0] | int > 11 or (
gdb_version[0] | int == 11 and gdb_version[1] | int == 1
)
- set_fact:
gdb_config_file: '{{ansible_env.HOME}}/.gdbinit'
gdb_state_dir: '{{ansible_env.HOME}}/.local/state/gdb'
- when: gdb_xdg_base_dir_check
include_tasks: gdb-11.1-config.yaml
- name: create config file
template:
src: gdbinit
dest: '{{config_dir}}/gdbinit'
dest: '{{gdb_config_file}}'
- name: create state directory
file:
path: '{{gdb_state_dir}}'
state: directory

View File

@ -1,3 +1,3 @@
# Enable saving command history
set history filename {{state_dir}}/history
set history filename {{gdb_state_dir}}/history
set history save on