From 80ebc553eca19dafc64c47420cd49ddd506bc9b7 Mon Sep 17 00:00:00 2001 From: Shea Levy Date: Tue, 9 Aug 2016 06:24:19 -0400 Subject: [PATCH 1/3] nix-build: Port to c++ This was a dumb line-for-line rewrite, because nix build/nix run/etc. will replace it. --- .gitignore | 4 +- Makefile | 1 + scripts/local.mk | 2 - scripts/nix-build.in | 359 --------------------------- src/nix-build/local.mk | 9 + src/nix-build/nix-build.cc | 482 +++++++++++++++++++++++++++++++++++++ 6 files changed, 495 insertions(+), 362 deletions(-) delete mode 100755 scripts/nix-build.in create mode 100644 src/nix-build/local.mk create mode 100755 src/nix-build/nix-build.cc diff --git a/.gitignore b/.gitignore index a524e9b6a..2252e512a 100644 --- a/.gitignore +++ b/.gitignore @@ -40,7 +40,6 @@ Makefile.config /scripts/nix-prefetch-url /scripts/nix-install-package /scripts/nix-channel -/scripts/nix-build /scripts/nix-copy-closure /scripts/NixConfig.pm /scripts/NixManifest.pm @@ -77,6 +76,9 @@ Makefile.config # /src/download-via-ssh/ /src/download-via-ssh/download-via-ssh +# /src/nix-build/ +/src/nix-build/nix-build + # /tests/ /tests/test-tmp /tests/common.sh diff --git a/Makefile b/Makefile index 90dca473f..52286b1fa 100644 --- a/Makefile +++ b/Makefile @@ -12,6 +12,7 @@ makefiles = \ src/nix-daemon/local.mk \ src/nix-collect-garbage/local.mk \ src/nix-prefetch-url/local.mk \ + src/nix-build/local.mk \ perl/local.mk \ scripts/local.mk \ corepkgs/local.mk \ diff --git a/scripts/local.mk b/scripts/local.mk index edaf44cc4..142188ad5 100644 --- a/scripts/local.mk +++ b/scripts/local.mk @@ -1,5 +1,4 @@ nix_bin_scripts := \ - $(d)/nix-build \ $(d)/nix-channel \ $(d)/nix-copy-closure \ $(d)/nix-install-package \ @@ -26,6 +25,5 @@ $(eval $(call install-program-in, $(d)/build-remote.pl, $(libexecdir)/nix)) ifeq ($(OS), Darwin) $(eval $(call install-program-in, $(d)/resolve-system-dependencies.pl, $(libexecdir)/nix)) endif -$(eval $(call install-symlink, nix-build, $(bindir)/nix-shell)) clean-files += $(nix_bin_scripts) $(nix_noinst_scripts) diff --git a/scripts/nix-build.in b/scripts/nix-build.in deleted file mode 100755 index 2d45e37c5..000000000 --- a/scripts/nix-build.in +++ /dev/null @@ -1,359 +0,0 @@ -#! @perl@ -w @perlFlags@ - -use utf8; -use strict; -use Nix::Config; -use Nix::Store; -use Nix::Utils; -use File::Basename; -use Text::ParseWords; -use Cwd; - -binmode STDERR, ":encoding(utf8)"; - -my $dryRun = 0; -my $verbose = 0; -my $runEnv = $0 =~ /nix-shell$/; -my $pure = 0; -my $fromArgs = 0; -my $packages = 0; -my $interactive = 1; - -my @instArgs = (); -my @buildArgs = (); -my @exprs = (); - -my $shell = $ENV{SHELL} || "/bin/sh"; -my $envCommand = ""; # interactive shell -my @envExclude = (); - -my $myName = $runEnv ? "nix-shell" : "nix-build"; - -my $inShebang = 0; -my $script; -my @savedArgs; - -my $tmpDir = mkTempDir($myName); - -my $outLink = "./result"; -my $drvLink = "$tmpDir/derivation"; - -# Ensure that the $tmpDir is deleted. -$SIG{'INT'} = sub { exit 1 }; - - -# Heuristic to see if we're invoked as a shebang script, namely, if we -# have a single argument, it's the name of an executable file, and it -# starts with "#!". -if ($runEnv && defined $ARGV[0] && $ARGV[0] !~ /nix-shell/) { - $script = $ARGV[0]; - if (-f $script && -x $script) { - open SCRIPT, "<$script" or die "$0: cannot open ‘$script’: $!\n"; - my $first =