Skip to content

Commit

Permalink
SConstruct: automate choice of -j<n> (Spot got a new cpu )
Browse files Browse the repository at this point in the history
  • Loading branch information
SeeSpotRun committed Nov 5, 2017
1 parent 7b93e80 commit dcf23a0
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 5 deletions.
33 changes: 33 additions & 0 deletions SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,39 @@ SConsEnvironment.InstallPerm = InstallPerm
# Your extra checks here
env = conf.Finish()

def get_cpu_count():
# priority: environ('NUM_CPU'), else try to read actual cpu count, else fallback
fallback = 4

if 'NUM_CPU' in os.environ:
return int(os.environ.get('NUM_CPU'))

# try multiprocessing.cpu_count() (Python 2.6+)
try:
import multiprocessing
return multiprocessing.cpu_count()
except (ImportError, NotImplementedError):
pass

# try psutil.cpu_count()
try:
import psutil
return psutil.cpu_count()
except (ImportError, AttributeError):
pass

# default value
return fallback


# set number of parallel jobs during build
# note: while not particularly intuitive or obvious from the documentation,
# SetOption() will *not* over-ride commandline option passed by `scons -j<n>`
# or `scons --jobs=<n>`
SetOption('num_jobs', get_cpu_count())

print "Running with --jobs=" + repr(GetOption('num_jobs'))

library = SConscript('lib/SConscript')
programs = SConscript('src/SConscript', exports='library')
env.Default(library)
Expand Down
4 changes: 2 additions & 2 deletions docs/install.rst
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,9 @@ build the software from the potentially unstable ``develop`` branch:
$ git clone -b develop https://github.com/sahib/rmlint.git
$ cd rmlint/
$ scons config # Look what features scons would compile
$ scons DEBUG=1 -j4 # Optional, build locally.
$ scons DEBUG=1 # Optional, build locally.
# Install (and build if necessary). For releases you can omit DEBUG=1
$ sudo scons DEBUG=1 -j4 --prefix=/usr install
$ sudo scons DEBUG=1 --prefix=/usr install
Done!

Expand Down
2 changes: 1 addition & 1 deletion pkg/arch/PKGBUILD
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pkgver() {

build() {
cd "${srcdir}/${pkgname}"
scons -j4 DEBUG=1 --prefix=${pkgdir}/usr --actual-prefix=/usr
scons DEBUG=1 --prefix=${pkgdir}/usr --actual-prefix=/usr
}

package() {
Expand Down
4 changes: 2 additions & 2 deletions pkg/fedora/rmlint.spec
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ especially an extremely fast tool to remove duplicates from your filesystem.
%prep
%autosetup -c rmlint-%{version}

%build scons config; scons -j4 --prefix=%{buildroot}/usr --actual-prefix=/usr --libdir=lib64
%build scons config; scons --prefix=%{buildroot}/usr --actual-prefix=/usr --libdir=lib64

%install

# Build rmlint, install it into BUILDROOT/<name>-<version>/,
# but take care rmlint thinks it's installed to /usr (--actual_prefix)
scons install -j4 --prefix=%{buildroot}/usr --actual-prefix=/usr --libdir=lib64
scons install --prefix=%{buildroot}/usr --actual-prefix=/usr --libdir=lib64

# Find all rmlint.mo files and put them in rmlint.lang
%find_lang %{name}
Expand Down

0 comments on commit dcf23a0

Please sign in to comment.