1 # Unlinks a directory (given as the first argument), and re-creates that
2 # directory as an actual directory. Then descends into the directory of
3 # the same name in the origin (arg_2/arg_3) and symlinks the contents of
4 # that directory into the passed end-location.
5 unlinkDirReSymlinkContents
() {
8 local contentsLocation
="$3"
10 unlink
$dirToUnlink/$contentsLocation
11 mkdir
-p $dirToUnlink/$contentsLocation
12 for f
in $origin/$contentsLocation/*; do
13 ln -s -t "$dirToUnlink/$contentsLocation" "$f"
17 # Using unlinkDirReSymlinkContents, un-symlinks directories down to
18 # $out/share/octave, and then creates the octave_packages directory.
19 createOctavePackagesPath
() {
23 if [ -L "$out/share" ]; then
24 unlinkDirReSymlinkContents
"$desiredOut" "$origin" "share"
27 if [ -L "$out/share/octave" ]; then
28 unlinkDirReSymlinkContents
"$desiredOut" "$origin" "share/octave"
31 # Now that octave_packages has a path rather than symlinks, create the
32 # octave_packages directory for installed packages.
33 mkdir
-p "$desiredOut/share/octave/octave_packages"
36 # First, descends down to $out/share/octave/site/m/startup/octaverc, and
37 # copies that start-up file. Once done, it performs a `chmod` to allow
38 # writing. Lastly, it `echo`s the location of the locally installed packages
39 # to the startup file, allowing octave to discover installed packages.
43 local octaveSite
="share/octave/site"
44 local octaveSiteM
="$octaveSite/m"
45 local octaveSiteStartup
="$octaveSiteM/startup"
46 local siteOctavercStartup
="$octaveSiteStartup/octaverc"
48 unlinkDirReSymlinkContents
"$desiredOut" "$origin" "$octaveSite"
49 unlinkDirReSymlinkContents
"$desiredOut" "$origin" "$octaveSiteM"
50 unlinkDirReSymlinkContents
"$desiredOut" "$origin" "$octaveSiteStartup"
52 unlink
"$out/$siteOctavercStartup"
53 cp "$origin/$siteOctavercStartup" "$desiredOut/$siteOctavercStartup"
54 chmod u
+w
"$desiredOut/$siteOctavercStartup"
55 echo "pkg local_list $out/.octave_packages" >> "$desiredOut/$siteOctavercStartup"
58 # Wrapper function for wrapOctaveProgramsIn. Takes one argument, a
59 # space-delimited string of packages' paths that will be installed.
60 wrapOctavePrograms
() {
61 wrapOctaveProgramsIn
"$out/bin" "$out" "$@"
64 # Wraps all octave programs in $out/bin with all the propagated inputs that
65 # a particular package requires. $1 is the directory to look for binaries in
66 # to wrap. $2 is the path to the octave ENVIRONMENT. $3 is the space-delimited
68 wrapOctaveProgramsIn
() {
74 buildOctavePath
"$octavePath" "$pkgs"
76 # Find all regular files in the output directory that are executable.
77 if [ -d "$dir" ]; then
78 find "$dir" -type f
-perm -0100 -print0 |
while read -d "" f
; do
79 echo "wrapping \`$f'..."
80 local -a wrap_args
=("$f"
81 --prefix PATH
':' "$program_PATH"
83 local -a wrapProgramArgs
=("${wrap_args[@]}")
84 wrapProgram
"${wrapProgramArgs[@]}"
89 # Build the PATH environment variable by walking through the closure of
90 # dependencies. Starts by constructing the `program_PATH` variable with the
91 # environment's path, then adding the original octave's location, and marking
92 # them in `octavePathsSeen`.
97 local pathsToSearch
="$octavePath $packages"
99 # Create an empty table of Octave paths.
100 declare -A octavePathsSeen
=()
102 octavePathsSeen
["$out"]=1
103 octavePathsSeen
["@octave@"]=1
104 addToSearchPath program_PATH
"$out/bin"
105 addToSearchPath program_PATH
"@octave@/bin"
106 echo "program_PATH to change to is: $program_PATH"
107 for path
in $pathsToSearch; do
108 echo "Recurse to propagated-build-input: $path"
109 _addToOctavePath
$path
113 # Adds the bin directories to the program_PATH variable.
114 # Recurses on any paths declared in `propagated-build-inputs`, while avoiding
115 # duplicating paths by flagging the directires it has seen in `octavePathsSeen`.
118 # Stop if we've already visited this path.
119 if [ -n "${octavePathsSeen[$dir]}" ]; then return; fi
120 octavePathsSeen
[$dir]=1
121 # addToSearchPath is defined in stdenv/generic/setup.sh. It has the effect
122 # of calling `export X=$dir/...:$X`.
123 addToSearchPath program_PATH
$dir/bin
125 # Inspect the propagated inputs (if they exist) and recur on them.
126 local prop
="$dir/nix-support/propagated-build-inputs"
127 if [ -e $prop ]; then
128 for new_path
in $
(cat $prop); do
129 _addToOctavePath
$new_path