Skip to content

Instantly share code, notes, and snippets.

@ellispritchard
Last active August 29, 2015 14:01
Show Gist options
  • Save ellispritchard/497881acf4d1c6daa483 to your computer and use it in GitHub Desktop.
Save ellispritchard/497881acf4d1c6daa483 to your computer and use it in GitHub Desktop.
sym-link target directories to /run for faster builds

sym-link target directories to /run for faster builds

Just run this in your parent project directory (or anywhere below), it finds pom.xml files and sym-links target directories in those directories.

Run as root:

sudo runtargets.py

Caveats

  • deletes existing target directory
  • needs to be re-run after re-boot (since /run is in RAM)
  • mvn clean will destroy the links (re-run the script, don't clean!)
  • uses RAM instead of disk, so may not be great you've not got much memory installed.
#!/usr/bin/python
import os
import shutil
top=os.getcwd()
for root, dirs, files in os.walk(top):
if "target" in dirs:
dirs.remove('target')
if "src" in dirs:
dirs.remove('src')
if "pom.xml" in files:
print "project root:",root
projectname = os.path.basename(root)
targetdir = os.path.join(root,"target")
print "project:",projectname
print "targetdir:",targetdir
if os.path.lexists(targetdir):
print "target exists; removing"
if os.path.islink(targetdir):
print "removing existing link"
os.remove(targetdir)
else:
print "removing target"
shutil.rmtree(targetdir)
runtargetdir = os.path.join("/run/build/",projectname)
print "runtargetdir:",runtargetdir
if not os.path.exists(runtargetdir):
print "making",runtargetdir
os.makedirs(runtargetdir)
fstat = os.stat(root)
os.chown(runtargetdir,fstat.st_uid,fstat.st_gid)
os.symlink(runtargetdir,targetdir)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment