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 - name: install apt package
become: true
apt: apt:
name: gdb name: gdb
state: latest 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' - include_tasks: '{{ansible_os_family}}.yaml'
- name: create directory # gdb 11.1 introduced support for config files that respect the XDG base
file: # directory spec, handle the boths paths dependant on the gdb version install.
path: '{{item}}' - name: get installed version
state: directory command: gdb --version
with_items: register: gdb_version_output
- '{{config_dir}}' changed_when: false
- '{{state_dir}}'
- 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 - name: create config file
template: template:
src: gdbinit 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 # Enable saving command history
set history filename {{state_dir}}/history set history filename {{gdb_state_dir}}/history
set history save on set history save on