diff --git a/nox/review.py b/nox/review.py index 0d31db9..8bd9375 100644 --- a/nox/review.py +++ b/nox/review.py @@ -11,17 +11,21 @@ from .nixpkgs_repo import get_repo, packages, packages_for_sha -def get_build_command(args, attrs, path): +def get_build_command(args): """ Get the appropriate command to use to build the given attributes """ command = ['nix-build'] command += args - for a in attrs: - command.append('-A') - command.append(a) - command.append(path) + command.append("-E") + command.append("-") + return command +def get_build_expr(attrs, path): + """ Get the appropriate expression to use to build the given attributes """ + return "with import {} {{}}; [ {} ]".format(path, ' '.join(attrs)) + + def build_in_path(args, attrs, path, dry_run=False): """Build the given package attributes in the given nixpkgs path""" if not attrs: @@ -33,15 +37,19 @@ def build_in_path(args, attrs, path, dry_run=False): click.echo('Building in {}: {}'.format(click.style(result_dir, bold=True), click.style(' '.join(attrs), bold=True))) - command = get_build_command(args, attrs, canonical_path) + expr = get_build_expr(attrs, canonical_path) + command = get_build_command(args) - click.echo('Invoking {}'.format(' '.join(command))) + click.echo('Invoking {} with expression {}'.format(' '.join(command), expr)) if dry_run: return try: - subprocess.check_call(command, cwd=result_dir) + with tempfile.SpooledTemporaryFile() as expr_f: + expr_f.write(expr.encode('utf-8')) + expr_f.seek(0) + subprocess.check_call(command, cwd=result_dir, stdin=expr_f) except subprocess.CalledProcessError: click.secho('The invocation of "{}" failed'.format(' '.join(command)), fg='red') sys.exit(1) diff --git a/nox/tests/test_review.py b/nox/tests/test_review.py index b7f3042..ccb7405 100644 --- a/nox/tests/test_review.py +++ b/nox/tests/test_review.py @@ -5,12 +5,17 @@ class TestReview(unittest.TestCase): def test_get_build_command(self): - result = review.get_build_command([], ["nox"], ".") - self.assertEqual(["nix-build", "-A", "nox", "."], result) + result = review.get_build_command([]) + self.assertEqual(["nix-build", "-E", "-"], result) + + def test_get_build_expr(self): + result = review.get_build_expr(["nox"], "./.") + self.assertEqual("with import ./. {}; [ nox ]", result) def test_build_in_path(self): # Just do a dry run to make sure there aren't any exceptions self.assertIs(None, review.build_in_path([], ["nox"], ".", dry_run=True)) + self.assertIs(None, review.build_in_path([], ["nox"], "./.", dry_run=True)) def test_differences(self): # Tuples of , ,