2. Introduction
• Key feature of SONiC build
• Plug-and-play of a module
• Inter-module dependency through .deb packages
• What’s missing in SONiC?
• No incremental build support ( Any change in source will trigger rebuild from scatch)
• Long time to build
• DPKG caching framework provides an infrastructure to cache the SONiC module/target/docker
.deb files into a local cache
• Module/Target Dependency file tracking
• Inter-module dependency
• Environment variable changes
• Two-level caching support
• Support for true incremental build
• Overall build time reduction
3. SONiC Build Framework
• Each module compiles the
source code and generates the
.deb package
• Main .deb package and zero or
more derived packages
• Clean compilation( no incremental
support)
• From the .deb packages
• sonic-<image>.bin
• docker-<image(s)>.gz
SONiC Build Module(s)
(e.g. linux, libnl ,etc.)
Compile and build .deb
Build Artifacts
target/debs/module(s).deb
Docker Images
target/docker-images(s).gz
SONiC Image
target/sonic-<vendor.bin>
4. SONiC Build Organization
1. SONiC repo
• Source code is part of repo
• Build and generate the .deb package
2. Non-SONiC repo
• Download the source file
• Apply the patch files
• Build and generate the .deb package
3. Non-source files
• Download the .deb file directly from web or remote server
5. SONiC DPKG Caching Framework
SONiC Build
Module(s)
(e.g. linux, libnl, etc.)
Compile and build .deb
Build Artifacts
target/debs/module(s).deb
Docker Images
target/docker-images(s).gz
SONiC Image
target/sonic-<vendor.bin>
Module(s) .deb Cache
Cache framework
Module(s) dependency files
6. Git Database Commands
• To get the SHA value of a file: hash-object
# git hash-object slave.mk some-new-file.txt
ef2de5371650c4460dea3ad3887a4d6d57cbc845
e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
• To get all the files in a module: ls-files
# git ls-files -cms src/bash
100644 9395dcd541987faae588462a63d06c303b11cebe 0 src/bash/Makefile
100644 253475b21878b3373c21f9ec7ba6ad14c220cbdd 0 src/bash/patch/series
100644 2a19c9e70d3c38572f81a7c62cb722e5c80f939c 0 src/bash/patch/readline.patch
• To get the modified files in a module: status
# git status -s src/bash
M src/bash/Makefile
7. Dependency Tracking
Dependencies > Target deb
Common Dependencies
( rules/config , slave.mk, rules/functions )
ENV Flags
(SONIC_DEBUGGING_ON, SONIC_PROFILING_ON , etc.)
Load deb from cache
Not modified
Compile and build deb
Modifed
Dependency SHA
Module Dependencies
( Makefile, debian/rules, srcs, patch files, etc.)
DPKG Cache
8. Derived .deb(s)
Dependency Generation
• Use git ls-files command to get
the list of files for a module
• Add package specific
dependency files .mk, .dep, etc. <target> ( Eg: bash)
rules/<target>.dep
rules/<target>.mk
target/debs/stretch/<target>.deb
target/debs/stretch/<target>.deb .dep
target/debs/stretch/<target>.deb .dep.sha
11. Cache File Tracking
The cache file is a compressed TAR ball of a module's target DEB file and its derived-target DEB files.
The cache filename is constructed as follows:
FORMAT:
<module deb filename>-<24 byte SHA hash>-<24 byte SHA hash>.tgz
Eg:
linux-headers-4.9.0-9-2-common_4.9.168-1+deb9u3_all.deb-fa16f47c0b63fa16f47c0b63-fd21bb776fa16f47c0b6.tgz
<24-byte SHA value> - derived from the following:
DEPENDS, RDEPENDS, WHEEL_DEPENDS, PYTHON_DEBS, PYTHON_WHEELS
DBG_DEPENDS, DBG_IMAGE_PACKAGES, LOAD_DOCKERS
<24-byte SHA value> - derived from either of the following:
GIT_COMMIT_SHA - SHA value of the last git commit ID if it is a submodule
GIT_CONTENT_SHA - SHA value is generated from the content of the target dependency
12. Support for Environmental Flags
• Support for Environment flags
• SONIC_DEBUGGING_ON = y
• SONIC_PROFILING_ON = y
• Etc.
• Support for inter-module dependency changes
• If Module B depends on Module A, any changes to module A will:
• Skip cache loading for module A and B, and
• Rebuild modules A and B
13. Module Makefile
• Module Makefile/Makefile.am
• Must specify source files explicitly in Makefile
• SRCS = $(wildcard *.c) Not OK
• SRCS = src1.c src2.c src3.c OK
14. Cache Hierarchy
• Two-level cache hierarchy:
• Global Caching
• Committed changes
• Module files are not modified
• Cache location:
• Outside of sonic-buildimage folder
• Local Caching
• Local changes prior to commit (doesn’t change the global cache - Development)
• Module files are modified
• Dependent target(s) updated
• Cache location:
• sonic-buildimage/target/cache
15. Cache Disable
• Global
• rules/config file:
• SONIC_DPKG_CACHE_METHOD=none
• Build environment:
• make SONIC_DPKG_CACHE_METHOD=none
• Per-module
• rules/<target>.dep file:
• $(TARGET)_CACHE_MODE := none
• To force a rebuild
• Rebuild cache with latest changes:
• make SONIC_DPKG_CACHE_METHOD=rebuild
• Use when the source is modified outside the sonic ‘git repo’
16. Cache Location
• Can choose where to locate the DPKG cache:
• Local tmp storage
• /tmp/dpkg_cache
• Local disk storage
• /dpkg_cache
• NFS mount
• /mnt/dpkg_cache
• Cache size
• 3G (All the .debs)
• Incremental
17. Cache Cleanup
• Recently used cache files are updated with newer timestamp.
• The DPKG framework automatically touch the used cache files to current
timestamp.
• touch /<cache_path>/<cache_file>.tgz
• Least-recently-used cache file cleanup command:
• find <cache_path> -name “*.tgz” ! -mtime -7 –exec rm {} ;
• Where:
-mtime n => Files were modified within last n*24 hours .
-mtime -7 => means ( -7 * 24 ) => Files were modified within last 7 days
! -mtime -7 => Files were modified 7 days ago