-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Compile zulu source and package files
A number of changes made to the way Zulu and its packages are loaded in order to dramatically increase startup performance. * Source is now moved into `src` directory, and the script `build.zsh` has been added to the repository, which concatenates all the source files into a single script with comments removed for speed. * The `self-update` command has been modified to run the `build.zsh` script once it has finished downloading updates. * Adds a new `compile` command, which runs `zcompile` on the Zulu core, all files in `~/.zulu/{bin,share,init}`, the completion cache and the following files in the user's `$ZDOTDIR`: * `.zlogin` * `.zshenv` * `.zprofile` * `.zshrc` * `.zlogout` The end result is a massive increase in startup speed. * `zulu compile` is run in the background to compile sources on startup. A new `--no-compile` option has been added to `zulu init` to avoid this.
- Loading branch information
Showing
26 changed files
with
162 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Ignore files generated by nested Zulu install | ||
tests/_support/.config/* | ||
tests/_support/.zulu/* | ||
tests/_support/zulu-install.zsh | ||
|
||
# Ignore output | ||
tests/_output/* | ||
!tests/_output/.gitkeep | ||
|
||
/zulu | ||
*.zwc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
files: ./tests/commands/**/* | ||
run: zunit "%file%" | ||
--- | ||
files: ./src/**/*.zsh | ||
run: ./build.zsh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#!/usr/bin/env zsh | ||
|
||
# Clear the file to start with | ||
cat /dev/null > zulu | ||
|
||
# Start with the shebang | ||
echo "#!/usr/bin/env zsh\n" >> zulu | ||
|
||
# We need to do some fancy globbing | ||
setopt EXTENDED_GLOB | ||
|
||
# Print each of the source files into the target, removing any comments | ||
# and blank lines from the compiled executable | ||
cat src/**/(^zulu).zsh | grep -v -E '^(\s*#.*[^"]|\s*)$' >> zulu | ||
|
||
# Print the main command last | ||
cat src/zulu.zsh | grep -v -E '^(\s*#.*[^"]|\s*)$' >> zulu | ||
|
||
# Make sure the file is executable | ||
chmod u+x zulu | ||
|
||
# Let the user know we're finished | ||
echo "\033[0;32m✔\033[0;m zulu built successfully" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
#!/usr/bin/env zsh | ||
|
||
### | ||
# Print usage information | ||
### | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
#!/usr/bin/env zsh | ||
|
||
### | ||
# Output usage information and exit | ||
### | ||
function _zulu_compile_usage() { | ||
echo '\033[0;32mUsage:\033[0;m' | ||
echo ' zulu_compile [options]' | ||
} | ||
|
||
### | ||
# Resolve symbolic links to a file, a compare it's last-modified date | ||
# with the compiled version, recompiling if needed | ||
### | ||
function _zulu_compile_if_needed() { | ||
local file="$1" follow_symlinks | ||
|
||
zparseopts -D \ | ||
f=follow_symlinks -follow-symlinks=follow_symlinks | ||
|
||
# We can't compile files that do not exist | ||
[[ ! -e $file ]] && return | ||
|
||
# Resolve symlinks if necessary | ||
[[ -n $follow_symlinks && -L $file ]] && file=$(readlink $file) | ||
|
||
# Check if the file is newer than it's compiled version, | ||
# and recompile if necessary | ||
if [[ -s ${file} && ( ! -s ${file}.zwc || ${file} -nt ${file}.zwc) ]]; then | ||
zcompile ${file} | ||
fi | ||
} | ||
|
||
### | ||
# The main zulu_compile process | ||
### | ||
(( $+functions[_zulu_compile] )) || function _zulu_compile() { | ||
local base=${ZULU_DIR:-"${ZDOTDIR:-$HOME}/.zulu"} | ||
local config=${ZULU_CONFIG_DIR:-"${ZDOTDIR:-$HOME}/.config/zulu"} | ||
local help version | ||
|
||
zparseopts -D \ | ||
h=help -help=help | ||
|
||
if [[ -n $help ]]; then | ||
_zulu_compile_usage | ||
exit | ||
fi | ||
|
||
setopt EXTENDED_GLOB | ||
# A list of glob paths pointing to files to be compiled | ||
local -a compile_targets; compile_targets=( | ||
# Zulu's core | ||
${base}/core/zulu | ||
|
||
# Files linked by packages | ||
${base}/share/**/*^(*.zwc)(#q@) | ||
${base}/bin/**/*^(*.zwc)(#q@) | ||
|
||
# Completion dump | ||
${ZDOTDIR:-${HOME}}/.zcomp^(*.zwc)(.) | ||
|
||
# User env files | ||
${ZDOTDIR:-${HOME}}/.zshenv | ||
${ZDOTDIR:-${HOME}}/.zlogin | ||
${ZDOTDIR:-${HOME}}/.zprofile | ||
${ZDOTDIR:-${HOME}}/.zshrc | ||
${ZDOTDIR:-${HOME}}/.zlogout | ||
) | ||
|
||
# A second list of compile targets. These files have their symlinks resolved | ||
# before they are sourced, so we need to follow the symlink before compiling, | ||
# to ensure the compiled version is picked up | ||
local -a linked_compile_targets; linked_compile_targets=( | ||
# Initialisation scripts for packages | ||
${base}/init/**/*^(*.zwc)(#q@) | ||
) | ||
|
||
# Loop through each of the files marked for compilation, and compile | ||
# them if necessary | ||
for file in ${(@f)compile_targets}; do | ||
_zulu_compile_if_needed $file | ||
done | ||
|
||
# Loop through each of the files marked for compilation, follow their | ||
# symlinks, and compile them if necessary | ||
for file in ${(@f)linked_compile_targets}; do | ||
_zulu_compile_if_needed --follow-symlinks $file | ||
done | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
#!/usr/bin/env zsh | ||
|
||
### | ||
# Output usage information | ||
### | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
#!/usr/bin/env zsh | ||
|
||
### | ||
# Output usage information | ||
### | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
#!/usr/bin/env zsh | ||
|
||
### | ||
# Output usage information | ||
### | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
#!/usr/bin/env zsh | ||
|
||
### | ||
# Print usage information | ||
### | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
#!/usr/bin/env zsh | ||
|
||
### | ||
# Output usage information | ||
### | ||
|
Oops, something went wrong.