Skip to content

Commit

Permalink
Cache ccache folder in CI workspace (#2401)
Browse files Browse the repository at this point in the history
* Cache ccache folder in workspace
and move ccache_stats command into setup_workspace

* Store ccache logs in colcon build log path

* Updates to cache ccache folder in workspace
  • Loading branch information
ruffsl authored Jun 9, 2021
1 parent 8372aa6 commit d2cf200
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 30 deletions.
57 changes: 27 additions & 30 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,24 @@ version: 2.1

_commands:
common_commands: &common_commands
ccache_stats:
description: "CCache Stats"
parameters:
workspace:
type: string
when:
type: string
default: on_success
steps:
- run:
name: CCache Stats
working_directory: << parameters.workspace >>
command: |
ccache -s # show stats
ccache -z # zero stats
ccache -V # show version
ccache -p # show config
when: << parameters.when >>
restore_from_cache:
description: "Restore From Cache"
parameters:
Expand Down Expand Up @@ -45,6 +63,7 @@ _commands:
-{{ checksum \"<< parameters.workspace >>/lockfile.txt\" }}\
-{{ epoch }}"
paths:
- << parameters.path >>/.ccache
- << parameters.path >>/build
- << parameters.path >>/install
- << parameters.path >>/log
Expand Down Expand Up @@ -106,6 +125,9 @@ _commands:
- when:
condition: << parameters.build >>
steps:
- ccache_stats:
workspace: << parameters.workspace >>
when: always
- run:
name: Build Workspace | << parameters.workspace >>
working_directory: << parameters.workspace >>
Expand Down Expand Up @@ -158,6 +180,9 @@ _commands:
colcon build \
--packages-select ${BUILD_PACKAGES} \
--mixin << parameters.mixins >>
- ccache_stats:
workspace: << parameters.workspace >>
when: always
- save_to_cache:
key: << parameters.key >>
path: << parameters.workspace >>
Expand Down Expand Up @@ -268,7 +293,6 @@ _steps:
TZ=utc stat -c '%y' /ros_entrypoint.sh | \
(echo ros_entrypoint && cat) >> lockfile.txt
sha256sum $PWD/lockfile.txt >> lockfile.txt
mv ~/.ccache $CCACHE_DIR || true
rm -rf $OVERLAY_WS/*
on_checkout: &on_checkout
checkout:
Expand All @@ -292,18 +316,6 @@ _steps:
install_dependencies:
underlay: /opt/ros_ws
workspace: /opt/underlay_ws
restore_ccache: &restore_ccache
restore_from_cache:
key: ccache
workspace: /opt/underlay_ws
ccache_stats: &ccache_stats
run:
name: CCache Stats
command: |
ccache -s # show stats
ccache -z # zero stats
ccache -V # show version
ccache -p # show config
setup_underlay_workspace: &setup_underlay_workspace
setup_workspace: &setup_workspace_underlay
key: underlay_ws
Expand All @@ -328,15 +340,6 @@ _steps:
setup_workspace:
<<: *setup_workspace_overlay
build: false
store_ccache_logs: &store_ccache_logs
store_artifacts:
path: /tmp/ccache.log
save_ccache: &save_ccache
save_to_cache:
key: ccache
workspace: /opt/underlay_ws
path: /tmp/.ccache
when: always
test_overlay_workspace: &test_overlay_workspace
test_workspace:
key: overlay_ws
Expand Down Expand Up @@ -375,18 +378,12 @@ commands:
description: "Setup Dependencies"
steps:
- *install_underlay_dependencies
- *restore_ccache
- *ccache_stats
- *setup_underlay_workspace
- *ccache_stats
- *install_overlay_dependencies
build_source:
description: "Build Source"
steps:
- *setup_overlay_workspace
- *store_ccache_logs
- *ccache_stats
- *save_ccache
restore_build:
description: "Restore Build"
steps:
Expand Down Expand Up @@ -414,8 +411,8 @@ _environments:
UNDERLAY_WS: "/opt/underlay_ws"
OVERLAY_WS: "/opt/overlay_ws"
UNDERLAY_MIXINS: "release ccache"
CCACHE_DIR: "/tmp/.ccache"
CCACHE_LOGFILE: "/tmp/ccache.log"
CCACHE_DIR: ".ccache"
CCACHE_LOGFILE: "log/build/ccache.log"
CCACHE_MAXSIZE: "200M"
MAKEFLAGS: "-j 2 -l 2 "
COLCON_DEFAULTS_FILE: "/tmp/defaults.yaml"
Expand Down
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ RUN . /opt/ros/$ROS_DISTRO/setup.sh && \
COPY --from=cacher $UNDERLAY_WS ./
ARG UNDERLAY_MIXINS="release ccache"
ARG FAIL_ON_BUILD_FAILURE=True
ARG CCACHE_DIR=".ccache"
RUN . /opt/ros/$ROS_DISTRO/setup.sh && \
colcon cache lock && \
colcon build \
Expand Down

0 comments on commit d2cf200

Please sign in to comment.