Skip to content

Commit

Permalink
ansible: fix scripts for LinuxONE and SmartOS (#2569)
Browse files Browse the repository at this point in the history
Move non-package manager ccache tasks into partial tasks to
avoid the different platforms interfering which each other.
  • Loading branch information
richardlau committed Mar 15, 2021
1 parent 7034b89 commit f65a7e6
Show file tree
Hide file tree
Showing 7 changed files with 220 additions and 172 deletions.
125 changes: 0 additions & 125 deletions ansible/roles/baselayout/tasks/ccache.yml

This file was deleted.

51 changes: 9 additions & 42 deletions ansible/roles/baselayout/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,6 @@
- "{{ role_path }}/tasks/partials/repo/{{ os|stripversion }}.yml"
skip: true

- name: check for a recent enough ccache
when: os in ccache_no_binpkg or 'rhel7-s390x' in inventory_hostname
stat: path="{{ binary_dest }}"
register: has_ccache

- name: check for ccache aix
when: os|startswith("aix")
stat:
path: /opt/ccache-3.7.4/bin/ccache
register: has_ccache

- name: check for a recent enough git
when: os in git_no_binpkg
stat: path="{{ binary_dest }}"
Expand Down Expand Up @@ -107,20 +96,6 @@
- "{{ packages[os|stripversion]|default('[]') }}"
- "{{ common_packages|default('[]') }}"

- name: Check whether /etc/paths contains "/usr/local/opt/ccache/libexec" (macos)
when: os|startswith("macos")
command: grep -Fxq "/usr/local/opt/ccache/libexec" /etc/paths
register: ccache_mac
check_mode: no
ignore_errors: yes
changed_when: no

- name: add ccache to the path (macos)
when: os|startswith("macos") and ccache_mac.rc == 1
lineinfile: dest=/etc/paths
insertbefore=BOF
line='/usr/local/opt/ccache/libexec'

- name: centos7_ppc64 | update package alternatives
when: os == "centos7" and arch == "ppc64"
alternatives:
Expand Down Expand Up @@ -213,23 +188,15 @@
- curl_64

- name: run ccache installer
when: os == "rhel7" and arch == "s390x" and not has_ccache.stat.exists
include: ccache.yml
static: false
vars:
- version: 3.3.3

- name: run ccache installer
when: os in ccache_no_binpkg and not has_ccache.stat.exists
include: ccache.yml
static: false

- name: run ccache installer
when: os|startswith("aix") and not has_ccache.stat.exists
include: ccache.yml
static: false
vars:
- version: 3.7.4
include: "{{ ccache_include }}"
loop_control:
loop_var: ccache_include
with_first_found:
- files:
- "{{ role_path }}/tasks/partials/ccache/{{ os }}-{{ arch }}.yml"
- "{{ role_path }}/tasks/partials/ccache/{{ os }}.yml"
- "{{ role_path }}/tasks/partials/ccache/{{ os|stripversion }}.yml"
skip: true

- name: set up ntp
include: "{{ ntp_include }}"
Expand Down
70 changes: 70 additions & 0 deletions ansible/roles/baselayout/tasks/partials/ccache/aix.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
---
#
# Downloads and installs ccache
#

- name: "ccache : check for a recent enough ccache"
stat:
path: "/opt/ccache-3.7.4/bin/ccache"
register: has_ccache

- name: "ccache : fetch tarball - aix"
shell:
chdir: "/tmp"
cmd: "curl -L -o ccache-3.7.4.tar.gz https://github.com/ccache/ccache/releases/download/v3.7.4/ccache-3.7.4.tar.gz"
when: not has_ccache.stat.exists

- name: "ccache : extract tarball - aix"
shell:
chdir: "/tmp"
cmd: "/opt/freeware/bin/tar -xzf ccache-3.7.4.tar.gz"
when: not has_ccache.stat.exists

- name: "ccache : compile - aix"
shell:
chdir: "/tmp/ccache-3.7.4"
cmd: './configure CC="/opt/freeware/bin/gcc -maix64" && /opt/freeware/bin/gmake'
when: not has_ccache.stat.exists

- name: "ccache : install - create directory aix"
file:
path: /opt/ccache-3.7.4/{{ item.dest }}
state: directory
mode: '0755'
loop:
- { dest: bin }
- { dest: libexec }
when: not has_ccache.stat.exists

- name: "ccache : install - move file aix"
shell:
chdir: "/tmp"
cmd: "mv ccache-3.7.4/ccache /opt/ccache-3.7.4/bin"
when: not has_ccache.stat.exists

- name: "ccache : create symlinks - aix"
file:
src: /opt/ccache-3.7.4/bin/ccache
dest: /opt/ccache-3.7.4/libexec/{{ item.dest }}
owner: root
group: system
state: link
loop:
- { dest: gcc }
- { dest: g++ }
- { dest: gcov }
- { dest: cpp }
- { dest: c++ }
when: not has_ccache.stat.exists

- name: "ccache : cleanup - aix tarball"
file:
path: "/tmp/ccache-3.7.4.tar.gz"
state: absent
when: not has_ccache.stat.exists

- name: "ccache : cleanup - aix directory"
file:
path: /tmp/ccache-3.7.4
state: absent
when: not has_ccache.stat.exists
13 changes: 13 additions & 0 deletions ansible/roles/baselayout/tasks/partials/ccache/macos.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
- name: "ccache : check whether /etc/paths contains '/usr/local/opt/ccache/libexec' (macos)"
command: grep -Fxq "/usr/local/opt/ccache/libexec" /etc/paths
register: ccache_mac
check_mode: no
ignore_errors: yes
changed_when: no

- name: "ccache : add ccache to the path (macos)"
when: ccache_mac.rc == 1
lineinfile:
dest: "etc/paths"
insertbefore: BOF
line: "usr/local/opt/ccache/libexec"
63 changes: 63 additions & 0 deletions ansible/roles/baselayout/tasks/partials/ccache/rhel7-s390x.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
---
#
# Downloads and installs ccache
#

- name: "ccache : check for a recent enough ccache"
stat:
path: "/usr/local/bin/ccache"
register: has_ccache

- name: "ccache : fetch samba ccache HTML page"
# This depends on ansible being able to run curl locally, YMMV, if it doesn't
# work, try changing the local_action to a remote one:
# raw: curl -sL https://www.samba.org/ftp/ccache/
local_action: shell curl -sL https://www.samba.org/ftp/ccache/ | sed -n -e 's/.*"ccache-\([0-9.]*\).tar.gz".*/\1/p' | tail -1
register: ccache_html_content
when: not has_ccache.stat.exists

- name: "ccache : extract ccache latest version"
set_fact:
ccache_latest: "{{ ccache_html_content.stdout }}"
when: not has_ccache.stat.exists

- name: "ccache : download and extract"
unarchive:
dest: /tmp/
remote_src: yes
src: "https://www.samba.org/ftp/ccache/ccache-{{ ccache_latest }}.tar.gz"
register: new_archive
when: not has_ccache.stat.exists

- name: "ccache : prepare for compilation"
shell: ./configure -q
args:
chdir: "/tmp/ccache-{{ ccache_latest }}"
when: not has_ccache.stat.exists

- name: "ccache : compile"
make:
chdir: "tmp/ccache-{{ ccache_latest }}"
when: not has_ccache.stat.exists

- name: "ccache : install"
copy:
dest: "/usr/local/bin"
mode: 0755
remote_src: yes
src: "/tmp/ccache-{{ ccache_latest }}/ccache"
when: not has_ccache.stat.exists

- name: "ccache : create symlinks"
loop_control:
loop_var: destination
with_items: [ 'gcc', 'cc', 'g++', 'c++' ]
file:
dest: "/usr/local/bin/{{ destination }}"
src: /usr/local/bin/ccache
state: link
when: not has_ccache.stat.exists

- name: "ccache : cleanup"
file: path="/tmp/ccache-{{ ccache_latest }}" state=absent
when: not has_ccache.stat.exists

0 comments on commit f65a7e6

Please sign in to comment.