git diff 2483c3fa520a09c0f3071b2a1a4aadc47c1551cf snapcraft/commands/build.py snapcraft/common.py
diff --git a/snapcraft/commands/build.py b/snapcraft/commands/build.py
index fed5828..a82a7e6 100644
--- a/snapcraft/commands/build.py
+++ b/snapcraft/commands/build.py
@@ -23,6 +23,9 @@ Usage:
build [options] [PART ...]
Options:
+ -j [<threads>] multi threaded build for plugins that support it;
+ use 0 for cpu-count+1 [default: 0]
+ -V verbose built for plugins that support it.
-h --help show this help message and exit.
"""
@@ -30,10 +33,14 @@ Options:
from docopt import docopt
from snapcraft import lifecycle
+from snapcraft import common
def main(argv=None):
argv = argv if argv else []
args = docopt(__doc__, argv=argv)
+ common.set_build_threads(int(args['-j']))
+ common.set_verbose(args['-V'])
+
lifecycle.execute('build', args['PART'])
diff --git a/snapcraft/common.py b/snapcraft/common.py
index fcbeb9d..63a3ee4 100644
--- a/snapcraft/common.py
+++ b/snapcraft/common.py
@@ -20,6 +20,7 @@ import os
import subprocess
import tempfile
import urllib
+import multiprocessing
SNAPCRAFT_FILES = ['snapcraft.yaml', 'parts', 'stage', 'snap']
@@ -30,7 +31,8 @@ _DEFAULT_SCHEMADIR = '/usr/share/snapcraft/schema'
_schemadir = _DEFAULT_SCHEMADIR
_arch = None
_arch_triplet = None
-
+j_count = 0
+verbose = False
env = []
@@ -117,6 +130,26 @@ def reset_env():
env = []
+def set_build_threads(j):
+ global j_count
+ j_count = j
+
+
+def get_build_threads():
+ if j_count <= 0:
+ return multiprocessing.cpu_count() + 1
+ return j_count
+
+
+def set_verbose(v):
+ global verbose
+ verbose = v
+
+
+def get_verbose():
+ return verbose
+
+
def replace_in_file(directory, file_pattern, search_pattern, replacement):
"""Searches and replaces patterns that match a file pattern.
:param str directory: The directory to look for files.