HACK in a Speedy Access Workspace
If you have a large multi-gigabyte codebase spread out through multiple git projects it can take a long time branch off a clean workspace. Hacksaw is a tool that lets you split off a clean workspace in seconds. It does so by only copying git projects that you explicitly select to be edited. All other projects are read-only bind mounts. This lets you build without cloning the full codebase to a new location!
Lets look at some performance numbers for creating a hacksaw workspace using as a codebase the AOSP master branch as of 2020-8-4. The machine used was a c2-standard-60 Google Cloud Platform VM with 60 vCPUs and 240 GiB of RAM. Each action was performed at least 10 times then averaged out.
Create a new Hacksaw workspace
Remove a Hacksaw workspace with no edits or build artifacts.
Create a new Hacksaw workspace and edit build/make project.
Create a new Hacksaw workspace and edit frameworks/base project.
As you can see, the time it takes to set up a new hacksaw workspace is proportional to the git projects checked out for editing. Contrast that with how long it takes to create a workspace using a full repo sync with a local mirror.
Create a new full repo workspace using a fresh local mirror
Remove a full repo workspace with no build artifacts
$ mkdir ~/aosp $ cd ~/aosp $ repo init -u https://android.googlesource.com/platform/manifest ... $ repo sync --quiet --current-branch --no-tags --no-clone-bundle --jobs=$(nproc) ... $ hacksaw codebase add aosp ~/aosp Added codebase aosp $ hacksaw codebase default aosp Default codebase set to aosp $ hacksaw workspace new big-feature Composing................................................................. .......................................................................... .......................................................................... .......................................................................... .......................................................................... .......................................................................... .......................................................................... .......................................................................... .......................................................................... .......................................................................... .......................................................................... ........................................... Workspace composed Created big-feature at ~/hacksaw/big-feature $ hacksaw edit ~/hacksaw/big-feature/tools/treble Created branch big-feature on project ~/hacksaw/big-feature/tools/treble $ hacksaw workspace new quick-fix Composing................................................................. .......................................................................... .......................................................................... .......................................................................... .......................................................................... .......................................................................... .......................................................................... .......................................................................... .......................................................................... .......................................................................... .......................................................................... ........................................... Workspace composed Created big-feature at ~/hacksaw/quick-fix $ hacksaw edit ~/hacksaw/quick-fix/tools/treble Created branch quick-fix on project ~/hacksaw/quick-fix/tools/treble
Building hacksaw requires golang to be installed. To install the hacksaw client run the following:
go get android.googlesource.com/platform/tools/treble.git/hacksaw/cmd/hacksaw
This will install hacksaw to ~/go/bin/hacksaw. You may choose to copy that to a location in your path. For example:
sudo cp ~/go/bin/hacksaw /usr/local/bin sudo chmod 755 /usr/local/bin/hacksaw
Hacksaw creates bind mounts for all git projects in a codebase. It then copies everything else. Make sure you remove all build artifacts from a codebase before create a workspace, otherwise it may spend a long time copying them.
Commands that mount and unmount will require sudo. That includes commands like
hacksaw workspace new
hacksaw edit
hacksaw workspace remove
Other commmands like hacksaw workspace list
or hacksaw add codebase
do not mount or unmount so do not require sudo.
If you would like to avoid using sudo you may install hacksawd as explained below.
Hacksawd is a privileged system daemon whose only job is to manage bind mounts. The provided install script will install to your system
go get android.googlesource.com/platform/tools/treble.git/hacksaw/cmd/hacksawd sudo cp ~/go/bin/hacksawd /usr/local/bin sudo chmod 755 /usr/local/bin/hacksawd sudo ~/go/src/android.googlesource.com/platform/tools/treble.git/hacksaw/scripts/install-service.sh
The installation scripts creates a new “hacksaw” group and adds you to it. You will need to log out and log back in for the group changes to take effect. After that you should be able to run any hacksaw command without sudo.
If you wish to uninstall the service then run:
sudo ~/go/src/android.googlesource.com/platform/tools/treble.git/hacksaw/scripts/uninstall-service.sh sudo rm /usr/local/bin/hacksawd
You sync your codebases using repo sync
. All updates will be propagated to workspaces. Except for projects that you are currently editing. Those will require you to git pull
manually in the workspace project.
Hacksaw uses read-only bind mounts to create project references from a workspace to a codebase. When you mark a project for editing then its read-only bind mount gets replaced by a writable Git worktree.
repo start
and repo upload
. So at the moment you can only upload to Gerrit using git push.You can ask hacksaw-users@googlegroups.com by joining the group.