├── .github └── workflows │ └── main.yaml ├── .gitignore ├── CHANGELOG.md ├── LICENSE ├── Makefile ├── README.md ├── appveyor.yml ├── bin └── swiftenv ├── completions ├── swiftenv.bash ├── swiftenv.fish └── swiftenv.zsh ├── docs ├── Makefile ├── _static │ └── swiftenv.png ├── _templates │ └── sidebar_intro.html ├── building-swift.md ├── changelog.md ├── commands.md ├── conf.py ├── getting-started.md ├── index.rst ├── install.sh ├── installation.md ├── integrations │ ├── heroku.md │ └── travis-ci.md └── sphinxcontrib_rawfiles.py ├── libexec ├── swiftenv ├── swiftenv---version ├── swiftenv-build ├── swiftenv-commands ├── swiftenv-completions ├── swiftenv-exec ├── swiftenv-global ├── swiftenv-help ├── swiftenv-init ├── swiftenv-install ├── swiftenv-local ├── swiftenv-prefix ├── swiftenv-rehash ├── swiftenv-uninstall ├── swiftenv-version ├── swiftenv-version-file ├── swiftenv-version-name ├── swiftenv-version-origin ├── swiftenv-versions └── swiftenv-which ├── share ├── man │ └── man1 │ │ ├── swiftenv-install.1 │ │ └── swiftenv.1 ├── swiftenv-build │ ├── 2.2 │ ├── 2.2-dev │ ├── 2.2.1 │ ├── 3.0 │ ├── 3.0-dev │ ├── 3.0.1 │ ├── 3.0.2 │ ├── 3.1 │ ├── 3.1-dev │ ├── 3.1.1 │ ├── 4.0 │ ├── 4.0-dev │ ├── 4.0.2 │ ├── 4.0.3 │ ├── 4.1 │ ├── 4.1-dev │ ├── 4.2-dev │ └── 5.0-dev └── swiftenv-install │ ├── 4.1.3 │ ├── 4.2.4 │ ├── 5.0 │ ├── 5.0.1 │ ├── 5.0.2 │ ├── 5.0.3 │ ├── 5.1 │ ├── 5.2 │ ├── 5.2.1 │ └── 5.2.2 └── test ├── exec.bats ├── global.bats ├── helpers.bash ├── init.bats ├── install.bats ├── integration └── install.bats ├── local.bats ├── prefix.bats ├── swiftenv.bats ├── version.bats ├── versions.bats └── which.bats /.github/workflows/main.yaml: -------------------------------------------------------------------------------- 1 | on: push 2 | jobs: 3 | test: 4 | strategy: 5 | matrix: 6 | platform: [ubuntu-latest, macos-latest, windows-latest] 7 | runs-on: ${{ matrix.platform }} 8 | steps: 9 | - uses: actions/checkout@v2 10 | - run: make test 11 | 12 | test-integration: 13 | strategy: 14 | matrix: 15 | platform: [ubuntu-latest] 16 | runs-on: ${{ matrix.platform }} 17 | steps: 18 | - uses: actions/checkout@v2 19 | - run: make test-integration 20 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /shims/ 2 | /versions/ 3 | /version 4 | /bats/ 5 | 6 | /docs/_build/ 7 | /docs/_build_html/ 8 | 9 | share/swiftenv-install/*.json 10 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | ## 1.5.0 4 | 5 | ### Enhancements 6 | 7 | - Fetching a list of versions that can be installed (`swiftenv install --list`) 8 | will now fetch an updated list of versions. 9 | 10 | ### Bug Fixes 11 | 12 | - Prevent `swiftenv install` picking up on unrelated `$URL` environment 13 | variables. 14 | [#170](https://github.com/kylef/swiftenv/issues/170) 15 | 16 | 17 | ## 1.4.0 18 | 19 | ### Enhancements 20 | 21 | - You can now instruct `swiftenv install` to both locally and globally set the 22 | installed swift version. `--set-local` and `--set-global` respectively will 23 | set the current Swift version. 24 | 25 | The default behaviour will set the global version by default when `swiftenv 26 | install` was provided an explicit version. When installing with the 27 | `SWIFT_VERSION` environment value or the `.swift-version` file present, then 28 | the default behaviour is to not set the global or local version. 29 | 30 | - When installing Swift from binary, swiftenv will now detect Ubuntu-based 31 | Linux distributions such as Elementary OS and use the appropriate binary 32 | image from swift.org. 33 | 34 | - On macOS, `swiftenv install` now accepts `--user` command which allows you to 35 | install Swift into your home directory instead of requiring root. 36 | 37 | ### Bug Fixes 38 | 39 | - On macOS, `swiftenv uninstall` would fail to uninstall some installed binary 40 | toolchains due to `-RELEASE` being after the version in some paths that was 41 | unexpected. 42 | 43 | - When using `swiftenv uninstall`, the command would fail if there was no 44 | global set version of swift. The command can now handle missing global 45 | version. 46 | 47 | 48 | ## 1.3.0 49 | 50 | ### Enhancements 51 | 52 | - New `--verify` option to swiftenv install to verify binary snapshots using 53 | GPG. This option expects that GPG is setup and configured to accept the Swift 54 | master keys. Verify can be forced with the environment variable 55 | `SWIFTENV_VERIFY`. 56 | - Added local cache for Swift binaries for 3.0.2, 3.1, 3.1.1. 57 | - `swiftenv install` will now resume any failed downloads instead of restarting 58 | the download process when restarting an install. 59 | - `swiftenv install --verbose` will now include verbose build output while 60 | compiling swift. 61 | - Adds build instructions for Swift 3.0, 3.0.1, 3.0.2, 3.1, 3.1.1, 3.0-dev, 62 | 3.1-dev and 4.0-dev. 63 | - When building Swift from source, swiftenv will download tarballs instead of 64 | git cloning the repository resulting in faster download speed. 65 | - Adds support for Fish 2.6. 66 | 67 | ## 1.2.1 68 | 69 | ### Enhancements 70 | 71 | - Adds usage and summaries when using `swiftenv --help` with a subcommand. 72 | - Adds a manpage for `swiftenv` and `swiftenv-install`. 73 | 74 | ```shell 75 | $ man swiftenv 76 | $ man swiftenv-install 77 | ``` 78 | 79 | ### Bug Fixes 80 | 81 | - Fixes detecting Swift release toolchains on macOS. 82 | - Fixes an issue where `swiftenv install` wouldn't emit an error if it 83 | couldn't find instructions to install the given version. 84 | 85 | 86 | ## 1.2.0 87 | 88 | ### Enhancements 89 | 90 | - Only create shims for `swift*` and `lldb*` binaries found within Xcode 91 | installs. Before we created shims for all executable tools found in Xcode 92 | and created shims for tools like ctags, cc, clang, etc. 93 | - Adds support for installing binary GM releases. 94 | 95 | ### Bug Fixes 96 | 97 | - Expose not found errors when using `swiftenv exec` against unknown commands. 98 | - Swift preview versions such as `3.0-preview-1` will be detected as binary 99 | versions when using `swiftenv install`. 100 | 101 | 102 | ## 1.1.0 103 | 104 | ### Enhancements 105 | 106 | - Add a `--skip-existing`/`-s` flag to `swiftenv install` to skip installation 107 | if version is already installed. 108 | - Adds support for Swift toolchains installed into 109 | `~/Library/Developer/Toolchains/` on OS X. 110 | 111 | 112 | ## 1.0.2 113 | 114 | ### Bug Fixes 115 | 116 | - Adds support for installing preview snapshots such as 117 | `3.0-preview-1-SNAPSHOT-2016-05-31-a`. 118 | - `swiftenv init` will now cause a rehash if the version of swiftenv has 119 | changed. 120 | 121 | 122 | ## 1.0.1 123 | 124 | ### Enhancements 125 | 126 | - Added `swiftenv install --list-snapshots` which shows you a list of 127 | snapshots for your platform. 128 | 129 | ### Bug Fixes 130 | 131 | - Adds support for building Swift 2.2.1 from source, and installing 2.2.1 132 | development snapshots. 133 | - `swiftenv uninstall` will now uninstall Swift toolchains on OS X. 134 | - `swiftenv uninstall` will now inform you if you're trying to uninstall 135 | a version of Swift bundled with Xcode. 136 | 137 | 138 | ## 1.0.0 139 | 140 | ### Enhancements 141 | 142 | - Supports installing final Swift releases such as `2.2`. 143 | 144 | ### Bug Fixes 145 | 146 | - Swift toolchains 'latest' version is no longer shown in `swiftenv versions` 147 | on OS X. 148 | - Fixes a problem where `swiftenv install` on Linux will incorrectly 149 | determine URL for the Swift binaries. 150 | - Adds a `--verbose` mode to `swiftenv versions` to show where the version was 151 | installed. 152 | 153 | 154 | ## 0.5.0 155 | 156 | ### Enhancements 157 | 158 | - The `swift-` prefix for versions is now optional. 159 | - `swiftenv install` now has a `--list` option: 160 | 161 | ```shell 162 | $ swiftenv install --list 163 | ``` 164 | 165 | - `swiftenv install` is capable of building Swift `2.2-dev` from source. 166 | - `swiftenv install` now takes URLs to a Swift binary package. 167 | - `swiftenv install` was updated to use the new binary swift.org release URLs. 168 | 169 | ### Bug Fixes 170 | 171 | - Fixes an issue where using shims would suppress error messages when the 172 | configured version was not installed. 173 | - Allows the completion to work when using swiftenv installed from Homebrew. 174 | 175 | ## 0.4.0 176 | 177 | ### Enhancements 178 | 179 | - Adds support for command and argument completions. 180 | 181 | ## 0.3.2 182 | 183 | ### Bug Fixes 184 | 185 | - Performance improvement when running on OS X. In previous versions, during 186 | initialisation swiftenv with rehash the environment, unfortunately once we 187 | added support for Xcode's Swift there was a huge negative performance impact 188 | due to Xcode tools taking large amount of time due to the underlying commands 189 | being tremendously slow. 190 | 191 | ## 0.3.1 192 | 193 | ### Bug Fixes 194 | 195 | - Improved error reporting when trying to install a non-existent Swift version. 196 | - When a shim command isn't found in version, search PATH too. This fixes a 197 | problem when using swiftenv on OS X with Xcode installed while your Swift 198 | version is configured to a snapshot from swift.org. 199 | 200 | ## 0.3.0 201 | 202 | ### Enhancements 203 | 204 | - `swiftenv install` can now install Swift on OS X. 205 | 206 | ## 0.2.1 207 | 208 | ### Bug Fixes 209 | 210 | * Fixes an issue when installing via Homebrew and the `$SWIFTENV_ROOT` 211 | directory didn't exist. 212 | 213 | ## 0.2.0 214 | 215 | ### Enhancements 216 | 217 | * Adds support for versions of Swift included in Xcode. 218 | * Added `swiftenv --help`. 219 | 220 | ## 0.1.0 221 | 222 | Initial release. 223 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2015 - 2016, Kyle Fuller 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | * Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation 12 | and/or other materials provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 18 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: test 2 | test: bats 3 | @PATH="$$PWD/bats/bin:$$PWD/bin:$$PATH" bats test 4 | 5 | .PHONY: test-integration 6 | test-integration: bats 7 | @PATH="$$PWD/bats/bin:$$PWD/bin:$$PWD/shims:$$PATH" SWIFTENV_ROOT="$$PWD" bats test/integration 8 | 9 | bats: 10 | git clone --depth 1 https://github.com/sstephenson/bats.git 11 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Swift Version Manager 2 | 3 | swiftenv allows you to easily install, and switch between multiple versions of Swift. 4 | 5 | This project was heavily inspired by [pyenv](https://github.com/yyuu/pyenv). 6 | 7 | ![swiftenv screenshot](docs/_static/swiftenv.png) 8 | 9 | swiftenv allows you to: 10 | 11 | - Change the **global Swift version**, per user. 12 | - Set a **per-project Swift version**. 13 | - Allows you to **override the Swift version** with an environmental variable. 14 | 15 | ## The User Guide 16 | 17 | - [Installation](https://swiftenv.fuller.li/en/latest/installation.html) 18 | - [Getting Started](https://swiftenv.fuller.li/en/latest/getting-started.html) 19 | - [Command Reference](https://swiftenv.fuller.li/en/latest/commands.html) 20 | - [`version`](https://swiftenv.fuller.li/en/latest/commands.html#version) 21 | - [`versions`](https://swiftenv.fuller.li/en/latest/commands.html#versions) 22 | - [`global`](https://swiftenv.fuller.li/en/latest/commands.html#global) 23 | - [`local`](https://swiftenv.fuller.li/en/latest/commands.html#local) 24 | - [`install`](https://swiftenv.fuller.li/en/latest/commands.html#install) 25 | - [`uninstall`](https://swiftenv.fuller.li/en/latest/commands.html#uninstall) 26 | - [`which`](https://swiftenv.fuller.li/en/latest/commands.html#which) 27 | - Integrations 28 | - [Heroku](https://swiftenv.fuller.li/en/latest/integrations/heroku.html) 29 | - [Travis CI](https://swiftenv.fuller.li/en/latest/integrations/travis-ci.html) 30 | -------------------------------------------------------------------------------- /appveyor.yml: -------------------------------------------------------------------------------- 1 | environment: 2 | PATH: '%APPVEYOR_BUILD_FOLDER%\bin;%APPVEYOR_BUILD_FOLDER%\bats\bin;C:\cygwin\bin;%PATH%' 3 | 4 | install: 5 | - git clone --depth 1 https://github.com/sstephenson/bats.git 6 | 7 | build: false 8 | 9 | test_script: 10 | - bash -lc 'bats /cygdrive/c/projects/swiftenv/test' 11 | -------------------------------------------------------------------------------- /bin/swiftenv: -------------------------------------------------------------------------------- 1 | ../libexec/swiftenv -------------------------------------------------------------------------------- /completions/swiftenv.bash: -------------------------------------------------------------------------------- 1 | _swiftenv() { 2 | COMPREPLY=() 3 | local word="${COMP_WORDS[COMP_CWORD]}" 4 | 5 | if [ "$COMP_CWORD" -eq 1 ]; then 6 | COMPREPLY=( $(compgen -W "$(swiftenv commands)" -- "$word") ) 7 | else 8 | local words=("${COMP_WORDS[@]}") 9 | unset words[0] 10 | unset words[$COMP_CWORD] 11 | local completions=$(swiftenv completions "${words[@]}") 12 | COMPREPLY=( $(compgen -W "$completions" -- "$word") ) 13 | fi 14 | } 15 | 16 | complete -F _swiftenv swiftenv 17 | -------------------------------------------------------------------------------- /completions/swiftenv.fish: -------------------------------------------------------------------------------- 1 | function __fish_swiftenv_needs_command 2 | set cmd (commandline -opc) 3 | if [ (count $cmd) -eq 1 -a $cmd[1] = 'swiftenv' ] 4 | return 0 5 | end 6 | return 1 7 | end 8 | 9 | function __fish_swiftenv_using_command 10 | set cmd (commandline -opc) 11 | if [ (count $cmd) -gt 1 ] 12 | if [ $argv[1] = $cmd[2] ] 13 | return 0 14 | end 15 | end 16 | return 1 17 | end 18 | 19 | complete -f -c swiftenv -n '__fish_swiftenv_needs_command' -a '(swiftenv commands)' 20 | for cmd in (swiftenv commands) 21 | complete -f -c swiftenv -n "__fish_swiftenv_using_command $cmd" -a "(swiftenv completions $cmd)" 22 | end 23 | -------------------------------------------------------------------------------- /completions/swiftenv.zsh: -------------------------------------------------------------------------------- 1 | if [[ ! -o interactive ]]; then 2 | return 3 | fi 4 | 5 | compctl -K _swiftenv swiftenv 6 | 7 | _swiftenv() { 8 | local words completions 9 | read -cA words 10 | 11 | if [ "${#words}" -eq 2 ]; then 12 | completions="$(swiftenv commands)" 13 | else 14 | completions="$(swiftenv completions ${words[2,-2]})" 15 | fi 16 | 17 | reply=(${(ps:\n:)completions}) 18 | } 19 | -------------------------------------------------------------------------------- /docs/Makefile: -------------------------------------------------------------------------------- 1 | # Makefile for Sphinx documentation 2 | # 3 | 4 | # You can set these variables from the command line. 5 | SPHINXOPTS = 6 | SPHINXBUILD = sphinx-build 7 | PAPER = 8 | BUILDDIR = _build 9 | 10 | # User-friendly check for sphinx-build 11 | ifeq ($(shell which $(SPHINXBUILD) >/dev/null 2>&1; echo $$?), 1) 12 | $(error The '$(SPHINXBUILD)' command was not found. Make sure you have Sphinx installed, then set the SPHINXBUILD environment variable to point to the full path of the '$(SPHINXBUILD)' executable. Alternatively you can add the directory with the executable to your PATH. If you don't have Sphinx installed, grab it from http://sphinx-doc.org/) 13 | endif 14 | 15 | # Internal variables. 16 | PAPEROPT_a4 = -D latex_paper_size=a4 17 | PAPEROPT_letter = -D latex_paper_size=letter 18 | ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . 19 | # the i18n builder cannot share the environment and doctrees with the others 20 | I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . 21 | 22 | .PHONY: help 23 | help: 24 | @echo "Please use \`make ' where is one of" 25 | @echo " html to make standalone HTML files" 26 | @echo " dirhtml to make HTML files named index.html in directories" 27 | @echo " singlehtml to make a single large HTML file" 28 | @echo " pickle to make pickle files" 29 | @echo " json to make JSON files" 30 | @echo " htmlhelp to make HTML files and a HTML help project" 31 | @echo " qthelp to make HTML files and a qthelp project" 32 | @echo " applehelp to make an Apple Help Book" 33 | @echo " devhelp to make HTML files and a Devhelp project" 34 | @echo " epub to make an epub" 35 | @echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter" 36 | @echo " latexpdf to make LaTeX files and run them through pdflatex" 37 | @echo " latexpdfja to make LaTeX files and run them through platex/dvipdfmx" 38 | @echo " text to make text files" 39 | @echo " man to make manual pages" 40 | @echo " texinfo to make Texinfo files" 41 | @echo " info to make Texinfo files and run them through makeinfo" 42 | @echo " gettext to make PO message catalogs" 43 | @echo " changes to make an overview of all changed/added/deprecated items" 44 | @echo " xml to make Docutils-native XML files" 45 | @echo " pseudoxml to make pseudoxml-XML files for display purposes" 46 | @echo " linkcheck to check all external links for integrity" 47 | 48 | .PHONY: clean 49 | clean: 50 | rm -rf $(BUILDDIR)/* 51 | 52 | .PHONY: html 53 | html: 54 | $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html 55 | @echo 56 | @echo "Build finished. The HTML pages are in $(BUILDDIR)/html." 57 | 58 | .PHONY: dirhtml 59 | dirhtml: 60 | $(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml 61 | @echo 62 | @echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml." 63 | 64 | .PHONY: singlehtml 65 | singlehtml: 66 | $(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml 67 | @echo 68 | @echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml." 69 | 70 | .PHONY: pickle 71 | pickle: 72 | $(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle 73 | @echo 74 | @echo "Build finished; now you can process the pickle files." 75 | 76 | .PHONY: json 77 | json: 78 | $(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json 79 | @echo 80 | @echo "Build finished; now you can process the JSON files." 81 | 82 | .PHONY: htmlhelp 83 | htmlhelp: 84 | $(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp 85 | @echo 86 | @echo "Build finished; now you can run HTML Help Workshop with the" \ 87 | ".hhp project file in $(BUILDDIR)/htmlhelp." 88 | 89 | .PHONY: qthelp 90 | qthelp: 91 | $(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp 92 | @echo 93 | @echo "Build finished; now you can run "qcollectiongenerator" with the" \ 94 | ".qhcp project file in $(BUILDDIR)/qthelp, like this:" 95 | @echo "# qcollectiongenerator $(BUILDDIR)/qthelp/swiftenv.qhcp" 96 | @echo "To view the help file:" 97 | @echo "# assistant -collectionFile $(BUILDDIR)/qthelp/swiftenv.qhc" 98 | 99 | .PHONY: applehelp 100 | applehelp: 101 | $(SPHINXBUILD) -b applehelp $(ALLSPHINXOPTS) $(BUILDDIR)/applehelp 102 | @echo 103 | @echo "Build finished. The help book is in $(BUILDDIR)/applehelp." 104 | @echo "N.B. You won't be able to view it unless you put it in" \ 105 | "~/Library/Documentation/Help or install it in your application" \ 106 | "bundle." 107 | 108 | .PHONY: devhelp 109 | devhelp: 110 | $(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp 111 | @echo 112 | @echo "Build finished." 113 | @echo "To view the help file:" 114 | @echo "# mkdir -p $$HOME/.local/share/devhelp/swiftenv" 115 | @echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/swiftenv" 116 | @echo "# devhelp" 117 | 118 | .PHONY: epub 119 | epub: 120 | $(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub 121 | @echo 122 | @echo "Build finished. The epub file is in $(BUILDDIR)/epub." 123 | 124 | .PHONY: latex 125 | latex: 126 | $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex 127 | @echo 128 | @echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex." 129 | @echo "Run \`make' in that directory to run these through (pdf)latex" \ 130 | "(use \`make latexpdf' here to do that automatically)." 131 | 132 | .PHONY: latexpdf 133 | latexpdf: 134 | $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex 135 | @echo "Running LaTeX files through pdflatex..." 136 | $(MAKE) -C $(BUILDDIR)/latex all-pdf 137 | @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." 138 | 139 | .PHONY: latexpdfja 140 | latexpdfja: 141 | $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex 142 | @echo "Running LaTeX files through platex and dvipdfmx..." 143 | $(MAKE) -C $(BUILDDIR)/latex all-pdf-ja 144 | @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." 145 | 146 | .PHONY: text 147 | text: 148 | $(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text 149 | @echo 150 | @echo "Build finished. The text files are in $(BUILDDIR)/text." 151 | 152 | .PHONY: man 153 | man: 154 | $(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man 155 | @echo 156 | @echo "Build finished. The manual pages are in $(BUILDDIR)/man." 157 | 158 | .PHONY: texinfo 159 | texinfo: 160 | $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo 161 | @echo 162 | @echo "Build finished. The Texinfo files are in $(BUILDDIR)/texinfo." 163 | @echo "Run \`make' in that directory to run these through makeinfo" \ 164 | "(use \`make info' here to do that automatically)." 165 | 166 | .PHONY: info 167 | info: 168 | $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo 169 | @echo "Running Texinfo files through makeinfo..." 170 | make -C $(BUILDDIR)/texinfo info 171 | @echo "makeinfo finished; the Info files are in $(BUILDDIR)/texinfo." 172 | 173 | .PHONY: gettext 174 | gettext: 175 | $(SPHINXBUILD) -b gettext $(I18NSPHINXOPTS) $(BUILDDIR)/locale 176 | @echo 177 | @echo "Build finished. The message catalogs are in $(BUILDDIR)/locale." 178 | 179 | .PHONY: changes 180 | changes: 181 | $(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes 182 | @echo 183 | @echo "The overview file is in $(BUILDDIR)/changes." 184 | 185 | .PHONY: linkcheck 186 | linkcheck: 187 | $(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck 188 | @echo 189 | @echo "Link check complete; look for any errors in the above output " \ 190 | "or in $(BUILDDIR)/linkcheck/output.txt." 191 | 192 | .PHONY: xml 193 | xml: 194 | $(SPHINXBUILD) -b xml $(ALLSPHINXOPTS) $(BUILDDIR)/xml 195 | @echo 196 | @echo "Build finished. The XML files are in $(BUILDDIR)/xml." 197 | 198 | .PHONY: pseudoxml 199 | pseudoxml: 200 | $(SPHINXBUILD) -b pseudoxml $(ALLSPHINXOPTS) $(BUILDDIR)/pseudoxml 201 | @echo 202 | @echo "Build finished. The pseudo-XML files are in $(BUILDDIR)/pseudoxml." 203 | -------------------------------------------------------------------------------- /docs/_static/swiftenv.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kylef/swiftenv/eaadbe0fa1589b158563e71c224d6e6b53643236/docs/_static/swiftenv.png -------------------------------------------------------------------------------- /docs/_templates/sidebar_intro.html: -------------------------------------------------------------------------------- 1 |

swiftenv

2 | 3 |

4 | 8 |

9 | 10 |

swiftenv allows you to easily install, and switch between multiple versions of Swift.

11 | 12 | 24 | 25 |

Other Projects

26 | 27 |

More Kyle Fuller projects:

28 | 34 | -------------------------------------------------------------------------------- /docs/building-swift.md: -------------------------------------------------------------------------------- 1 | # Building Swift from Source 2 | 3 | `swiftenv install` can install Swift from source. 4 | 5 | Listing available versions. 6 | 7 | ```shell 8 | $ swiftenv install --list 9 | 2.2 10 | 2.2-dev 11 | 3.0-dev 12 | ``` 13 | 14 | **NOTE**: *Swift 2.2 does not include the Swift Package Manager.* 15 | 16 | ```shell 17 | $ swiftenv install 2.2 18 | ``` 19 | 20 | By default, Swift will download from an Apple binary release available from 21 | swift.org. However you can use `--build` to force building the version. 22 | 23 | ```shell 24 | $ swiftenv install 2.2 --build 25 | ``` 26 | 27 | ## Platforms 28 | 29 | Below you can find a list of specific dependencies for each platform. 30 | 31 | ### macOS 32 | 33 | You will need to install the latest version of Xcode along with cmake 34 | and ninja build to build Swift on macOS. 35 | 36 | #### Via Homebrew 37 | 38 | ```shell 39 | $ brew install cmake ninja 40 | ``` 41 | 42 | #### Via Mac Ports 43 | 44 | ```shell 45 | $ sudo port install cmake ninja 46 | ``` 47 | 48 | ### Arch Linux 49 | 50 | You will need to install the following dependencies for Arch Linux: 51 | 52 | ```shell 53 | $ pacman -S perl libbsd icu git libedit python2 clang cmake ninja 54 | ``` 55 | 56 | ### Ubuntu 57 | 58 | You will need to install the following dependencies on Ubuntu: 59 | 60 | ```shell 61 | $ sudo apt-get install git cmake ninja-build clang python uuid-dev libicu-dev icu-devtools libbsd-dev libedit-dev libxml2-dev libsqlite3-dev swig libpython-dev libncurses5-dev pkg-config 62 | ``` 63 | 64 | If you are building on Ubuntu 14.04 LTS, you'll need to upgrade your clang 65 | compiler for C++14 support and create a symlink: 66 | 67 | ```shell 68 | $ sudo apt-get install clang-3.6 69 | $ sudo update-alternatives --install /usr/bin/clang clang /usr/bin/clang-3.6 100 70 | $ sudo update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-3.6 100 71 | ``` 72 | 73 | ### FreeBSD 74 | 75 | You will need to install the following dependencies on FreeBSD: 76 | 77 | ```shell 78 | $ pkg install binutils git python ninja cmake pkgconf e2fsprogs-libuuid 79 | ``` 80 | 81 | ### Your platform here 82 | 83 | If you have successfully build Swift via swiftenv on other platforms, feel free 84 | to [update this list with a pull request](https://github.com/kylef/swiftenv/blob/master/docs/building-swift.md). 85 | -------------------------------------------------------------------------------- /docs/changelog.md: -------------------------------------------------------------------------------- 1 | ../CHANGELOG.md -------------------------------------------------------------------------------- /docs/commands.md: -------------------------------------------------------------------------------- 1 | # Command Reference 2 | 3 | ## `version` 4 | 5 | Displays the current active Swift version and why it was chosen. 6 | 7 | ```shell 8 | $ swiftenv version 9 | 2.2 (set by /home/kyle/.swiftenv/version) 10 | ``` 11 | 12 | ## `versions` 13 | 14 | Lists all installed Swift versions, showing an asterisk next to the currently 15 | active version. 16 | 17 | ```shell 18 | $ swiftenv versions 19 | 2.1.1 20 | * 2.2 (set by /home/kyle/.swiftenv/version) 21 | DEVELOPMENT-SNAPSHOT-2016-03-01-a 22 | ``` 23 | 24 | ## `global` 25 | 26 | Sets the global version of Swift to be used by writing to the 27 | `~/.swiftenv/version` file. This version can be overridden by 28 | application-specific `.swift-version` file, or by setting the `SWIFT_VERSION` 29 | environment variable. 30 | 31 | ```shell 32 | $ swiftenv global 2.2 33 | $ swiftenv global 34 | 2.2 35 | ``` 36 | 37 | ## `local` 38 | 39 | Sets the local application-specific Swift version by writing the version to a 40 | `.swift-version` file in the current directory. This version overrides the 41 | global version and can also be overridden further by the `SWIFT_VERSION` 42 | environment variable. 43 | 44 | ### Setting a local Swift version 45 | 46 | ```shell 47 | $ swiftenv local 3.1.1 48 | ``` 49 | 50 | Setting the local swift version will write the version to the `.swift-version` 51 | file in the current working directory. 52 | 53 | ### Checking the local Swift version 54 | 55 | ```shell 56 | $ swiftenv local 57 | 3.1.1 58 | ``` 59 | 60 | ## `install` 61 | 62 | Installs a version of Swift. This supports both binary releases provided by 63 | Apple, along with all open source Swift releases. 64 | 65 | You may use `--build` or `--no-build` to force a building from source, or 66 | installing from a binary release. Otherwise swiftenv will prefer installing 67 | from a binary release if available. 68 | 69 | Please see [Building Swift from source](/building-swift.html) for more information. 70 | 71 | ```shell 72 | $ swiftenv install 2.2 73 | ``` 74 | 75 | You may also install from a user supplied URLs to a Swift Binary package URL from [Swift Snapshots](https://swift.org/download/#latest-development-snapshots) as a parameter 76 | 77 | ### Installing Swift from a URL 78 | 79 | You may pass a URL of a binary Swift release directly to swiftenv install. 80 | 81 | ```shell 82 | $ swiftenv install https://swift.org/builds/development/xcode/swift-DEVELOPMENT-SNAPSHOT-2016-03-01-a/swift-DEVELOPMENT-SNAPSHOT-2016-03-01-a-osx.pkg 83 | Downloading https://swift.org/builds/development/xcode/swift-DEVELOPMENT-SNAPSHOT-2016-03-01-a/swift-DEVELOPMENT-SNAPSHOT-2016-03-01-a-osx.pkg 84 | ``` 85 | 86 | ### Custom Installation 87 | 88 | You may also manually install Swift and make it accessible to swiftenv. Custom 89 | Swift installations can either be placed in a directory using the correct 90 | version number at `~/.swiftenv/versions/VERSION`, or can be symbolic 91 | linked into the version directory. 92 | 93 | It is expected that all dependencies are already installed for running Swift, 94 | please consult the [Swift website](https://swift.org/download/) for more 95 | information. 96 | 97 | **NOTE**: *After manually installing a version of Swift, it's recommended that 98 | you run `swiftenv rehash` to update the shims.* 99 | 100 | ### Verifying Linux Binary Packages 101 | 102 | When downloading a pre-built binary package, swiftenv can also download the corresponding signature and verify it with gpg. This option assumes gpg is installed on the system, and the [Swift public keys](https://swift.org/download/#active-signing-keys) already exist on the public gpg keyring. If verification fails, the version will not be installed. Signatures are currently only checked in this way for Linux builds. 103 | 104 | ```shell 105 | $ swiftenv install 2.2 --verify 106 | ``` 107 | 108 | ## `uninstall` 109 | 110 | Uninstalls a specific Swift version. 111 | 112 | ```shell 113 | $ swiftenv uninstall 2.2 114 | ``` 115 | 116 | ## `rehash` 117 | 118 | Installs shims for the Swift binaries. This command should be ran after you 119 | manually install new versions of Swift. 120 | 121 | ```shell 122 | $ swiftenv rehash 123 | ``` 124 | 125 | ## `which` 126 | 127 | Displays the full path to the executable that would be invoked for the selected 128 | version for the given command. 129 | 130 | ```shell 131 | $ swiftenv which swift 132 | /home/kyle/.swiftenv/versions/2.2/usr/bin/swift 133 | 134 | $ swiftenv which lldb 135 | /home/kyle/.swiftenv/versions/2.2/usr/bin/lldb 136 | ``` 137 | -------------------------------------------------------------------------------- /docs/conf.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | import sys 4 | import os 5 | 6 | from recommonmark.parser import CommonMarkParser 7 | 8 | # -- General configuration ------------------------------------------------ 9 | 10 | # If your documentation needs a minimal Sphinx version, state it here. 11 | #needs_sphinx = '1.0' 12 | 13 | # Add any Sphinx extension module names here, as strings. They can be 14 | # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom 15 | # ones. 16 | sys.path += ['.'] 17 | extensions = [ 18 | 'sphinxcontrib_rawfiles', 19 | ] 20 | rawfiles = ['install.sh'] 21 | 22 | # Add any paths that contain templates here, relative to this directory. 23 | templates_path = ['_templates'] 24 | 25 | source_parsers = { 26 | '.md': CommonMarkParser, 27 | } 28 | 29 | source_suffix = ['.rst', '.md'] 30 | 31 | # The encoding of source files. 32 | #source_encoding = 'utf-8-sig' 33 | 34 | # The master toctree document. 35 | master_doc = 'index' 36 | 37 | # General information about the project. 38 | project = u'swiftenv' 39 | copyright = u'2018, Kyle Fuller' 40 | author = u'Kyle Fuller' 41 | 42 | # The version info for the project you're documenting, acts as replacement for 43 | # |version| and |release|, also used in various other places throughout the 44 | # built documents. 45 | # 46 | # The short X.Y version. 47 | version = u'1.5' 48 | # The full version, including alpha/beta/rc tags. 49 | release = u'1.5.0' 50 | 51 | # The language for content autogenerated by Sphinx. Refer to documentation 52 | # for a list of supported languages. 53 | # 54 | # This is also used if you do content translation via gettext catalogs. 55 | # Usually you set "language" from the command line for these cases. 56 | language = None 57 | 58 | # There are two options for replacing |today|: either, you set today to some 59 | # non-false value, then it is used: 60 | #today = '' 61 | # Else, today_fmt is used as the format for a strftime call. 62 | #today_fmt = '%B %d, %Y' 63 | 64 | # List of patterns, relative to source directory, that match files and 65 | # directories to ignore when looking for source files. 66 | exclude_patterns = ['_build'] 67 | 68 | # The reST default role (used for this markup: `text`) to use for all 69 | # documents. 70 | #default_role = None 71 | 72 | # If true, '()' will be appended to :func: etc. cross-reference text. 73 | #add_function_parentheses = True 74 | 75 | # If true, the current module name will be prepended to all description 76 | # unit titles (such as .. function::). 77 | #add_module_names = True 78 | 79 | # If true, sectionauthor and moduleauthor directives will be shown in the 80 | # output. They are ignored by default. 81 | #show_authors = False 82 | 83 | # The name of the Pygments (syntax highlighting) style to use. 84 | pygments_style = 'sphinx' 85 | 86 | # A list of ignored prefixes for module index sorting. 87 | #modindex_common_prefix = [] 88 | 89 | # If true, keep warnings as "system message" paragraphs in the built documents. 90 | #keep_warnings = False 91 | 92 | # If true, `todo` and `todoList` produce output, else they produce nothing. 93 | todo_include_todos = False 94 | 95 | 96 | # -- Options for HTML output ---------------------------------------------- 97 | 98 | # The theme to use for HTML and HTML Help pages. See the documentation for 99 | # a list of builtin themes. 100 | html_theme = 'alabaster' 101 | 102 | # Theme options are theme-specific and customize the look and feel of a theme 103 | # further. For a list of options available for each theme, see the 104 | # documentation. 105 | #html_theme_options = {} 106 | 107 | # Add any paths that contain custom themes here, relative to this directory. 108 | #html_theme_path = [] 109 | 110 | # The name for this set of Sphinx documents. If None, it defaults to 111 | # " v documentation". 112 | #html_title = None 113 | 114 | # A shorter title for the navigation bar. Default is the same as html_title. 115 | #html_short_title = None 116 | 117 | # The name of an image file (relative to this directory) to place at the top 118 | # of the sidebar. 119 | #html_logo = None 120 | 121 | # The name of an image file (within the static path) to use as favicon of the 122 | # docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 123 | # pixels large. 124 | #html_favicon = None 125 | 126 | # Add any paths that contain custom static files (such as style sheets) here, 127 | # relative to this directory. They are copied after the builtin static files, 128 | # so a file named "default.css" will overwrite the builtin "default.css". 129 | html_static_path = ['_static'] 130 | 131 | # Add any extra paths that contain custom files (such as robots.txt or 132 | # .htaccess) here, relative to this directory. These files are copied 133 | # directly to the root of the documentation. 134 | #html_extra_path = [] 135 | 136 | # If not '', a 'Last updated on:' timestamp is inserted at every page bottom, 137 | # using the given strftime format. 138 | #html_last_updated_fmt = '%b %d, %Y' 139 | 140 | # If true, SmartyPants will be used to convert quotes and dashes to 141 | # typographically correct entities. 142 | #html_use_smartypants = True 143 | 144 | # Custom sidebar templates, maps document names to template names. 145 | html_sidebars = { 146 | 'index': ['sidebar_intro.html', 'searchbox.html'], 147 | '**': ['sidebar_intro.html', 'localtoc.html', 'relations.html', 'searchbox.html'], 148 | } 149 | 150 | # Additional templates that should be rendered to pages, maps page names to 151 | # template names. 152 | #html_additional_pages = {} 153 | 154 | # If false, no module index is generated. 155 | #html_domain_indices = True 156 | 157 | # If false, no index is generated. 158 | #html_use_index = True 159 | 160 | # If true, the index is split into individual pages for each letter. 161 | #html_split_index = False 162 | 163 | html_show_sourcelink = False 164 | html_show_sphinx = False 165 | html_show_copyright = True 166 | 167 | # If true, an OpenSearch description file will be output, and all pages will 168 | # contain a tag referring to it. The value of this option must be the 169 | # base URL from which the finished HTML is served. 170 | #html_use_opensearch = '' 171 | 172 | # This is the file name suffix for HTML files (e.g. ".xhtml"). 173 | #html_file_suffix = None 174 | 175 | # Language to be used for generating the HTML full-text search index. 176 | # Sphinx supports the following languages: 177 | # 'da', 'de', 'en', 'es', 'fi', 'fr', 'hu', 'it', 'ja' 178 | # 'nl', 'no', 'pt', 'ro', 'ru', 'sv', 'tr' 179 | #html_search_language = 'en' 180 | 181 | # A dictionary with options for the search language support, empty by default. 182 | # Now only 'ja' uses this config value 183 | #html_search_options = {'type': 'default'} 184 | 185 | # The name of a javascript file (relative to the configuration directory) that 186 | # implements a search results scorer. If empty, the default will be used. 187 | #html_search_scorer = 'scorer.js' 188 | 189 | # Output file base name for HTML help builder. 190 | htmlhelp_basename = 'swiftenvdoc' 191 | 192 | # -- Options for LaTeX output --------------------------------------------- 193 | 194 | latex_elements = { 195 | # The paper size ('letterpaper' or 'a4paper'). 196 | #'papersize': 'letterpaper', 197 | 198 | # The font size ('10pt', '11pt' or '12pt'). 199 | #'pointsize': '10pt', 200 | 201 | # Additional stuff for the LaTeX preamble. 202 | #'preamble': '', 203 | 204 | # Latex figure (float) alignment 205 | #'figure_align': 'htbp', 206 | } 207 | 208 | # Grouping the document tree into LaTeX files. List of tuples 209 | # (source start file, target name, title, 210 | # author, documentclass [howto, manual, or own class]). 211 | latex_documents = [ 212 | (master_doc, 'swiftenv.tex', u'swiftenv Documentation', 213 | u'Kyle Fuller', 'manual'), 214 | ] 215 | 216 | # The name of an image file (relative to this directory) to place at the top of 217 | # the title page. 218 | #latex_logo = None 219 | 220 | # For "manual" documents, if this is true, then toplevel headings are parts, 221 | # not chapters. 222 | #latex_use_parts = False 223 | 224 | # If true, show page references after internal links. 225 | #latex_show_pagerefs = False 226 | 227 | # If true, show URL addresses after external links. 228 | #latex_show_urls = False 229 | 230 | # Documents to append as an appendix to all manuals. 231 | #latex_appendices = [] 232 | 233 | # If false, no module index is generated. 234 | #latex_domain_indices = True 235 | 236 | 237 | # -- Options for manual page output --------------------------------------- 238 | 239 | # One entry per manual page. List of tuples 240 | # (source start file, name, description, authors, manual section). 241 | man_pages = [ 242 | (master_doc, 'swiftenv', u'swiftenv Documentation', 243 | [author], 1) 244 | ] 245 | 246 | # If true, show URL addresses after external links. 247 | #man_show_urls = False 248 | 249 | 250 | # -- Options for Texinfo output ------------------------------------------- 251 | 252 | # Grouping the document tree into Texinfo files. List of tuples 253 | # (source start file, target name, title, author, 254 | # dir menu entry, description, category) 255 | texinfo_documents = [ 256 | (master_doc, 'swiftenv', u'swiftenv Documentation', 257 | author, 'swiftenv', 'One line description of project.', 258 | 'Miscellaneous'), 259 | ] 260 | 261 | # Documents to append as an appendix to all manuals. 262 | #texinfo_appendices = [] 263 | 264 | # If false, no module index is generated. 265 | #texinfo_domain_indices = True 266 | 267 | # How to display URL addresses: 'footnote', 'no', or 'inline'. 268 | #texinfo_show_urls = 'footnote' 269 | 270 | # If true, do not generate a @detailmenu in the "Top" node's menu. 271 | #texinfo_no_detailmenu = False 272 | -------------------------------------------------------------------------------- /docs/getting-started.md: -------------------------------------------------------------------------------- 1 | # Getting Started 2 | 3 | Once you've [installed](installation.html) swiftenv you can get started by 4 | checking which existing versions of Swift you have installed. 5 | 6 | ```shell 7 | $ swiftenv versions 8 | 2.2.1 9 | 2.3 10 | * 3.0 (set by /Users/kyle/.swiftenv/version) 11 | ``` 12 | 13 | **NOTE**: *swiftenv will automatically pick up any versions of Swift installed on 14 | macOS by Xcode or Swift toolchains.* 15 | 16 | ## Installing Swift 17 | 18 | You can install swift using `swiftenv install`. 19 | 20 | ```shell 21 | $ swiftenv install 3.0 22 | ``` 23 | 24 | ### Listing all versions 25 | 26 | You can list all versions of Swift: 27 | 28 | ```shell 29 | $ swiftenv install --list 30 | ``` 31 | 32 | You can also list all binary snapshots of Swift that you can install. 33 | 34 | ```shell 35 | $ swiftenv install --list-snapshots 36 | ``` 37 | 38 | ## Switching Swift Versions 39 | 40 | swiftenv allows you to switch between the installed Swift versions either 41 | globally or locally. You can configure a global Swift version that is used 42 | by default unless overridden. 43 | 44 | ### Global Version 45 | 46 | You can check the current global Swift version using `swiftenv global`. 47 | 48 | ```shell 49 | $ swiftenv global 50 | 3.0 51 | ``` 52 | 53 | To change the global version: 54 | 55 | ```shell 56 | $ swiftenv global 2.2.1 57 | ``` 58 | 59 | ### Local Version 60 | 61 | You can override the global version within any project using a 62 | `.swift-version` file. A Swift version file will indicate the version 63 | to be used. 64 | 65 | Setting the local Swift version: 66 | 67 | ```shell 68 | $ swiftenv local 3.0 69 | ``` 70 | 71 | Now, when you're inside the current directory, the Swift version will be 72 | automatically changed to the local version. 73 | 74 | ```shell 75 | $ swiftenv version 76 | 2.2.1 (set by /Users/kyle/Projects/kylef/Curassow/.swift-version) 77 | ``` 78 | 79 | When you switch to another directory without a `.swift-version` file, the 80 | global version will be used. 81 | 82 | ```shell 83 | $ swiftenv version 84 | 3.0 (set by /Users/kyle/.swiftenv/version) 85 | ``` 86 | -------------------------------------------------------------------------------- /docs/index.rst: -------------------------------------------------------------------------------- 1 | swiftenv: Swift Version Manager 2 | =============================== 3 | 4 | swiftenv allows you to easily install, and switch between multiple 5 | versions of Swift. 6 | 7 | .. image:: _static/swiftenv.png 8 | 9 | swiftenv allows you to: 10 | 11 | - Change the **global Swift version**, per user. 12 | - Set a **per-project Swift version**. 13 | - Allows you to **override the Swift version** with an environmental variable. 14 | 15 | The User Guide 16 | -------------- 17 | 18 | .. toctree:: 19 | :maxdepth: 2 20 | 21 | installation 22 | getting-started 23 | building-swift 24 | commands 25 | changelog 26 | 27 | Integrations 28 | ~~~~~~~~~~~~ 29 | 30 | .. toctree:: 31 | :maxdepth: 1 32 | 33 | integrations/heroku 34 | integrations/travis-ci 35 | integrations/cocoapods 36 | -------------------------------------------------------------------------------- /docs/install.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Automatically installs swiftenv and run's swiftenv install. 4 | # This script was designed for usage in CI systems. 5 | 6 | git clone --depth 1 https://github.com/kylef/swiftenv.git ~/.swiftenv 7 | export SWIFTENV_ROOT="$HOME/.swiftenv" 8 | export PATH="$SWIFTENV_ROOT/bin:$SWIFTENV_ROOT/shims:$PATH" 9 | 10 | if [ -f ".swift-version" ] || [ -n "$SWIFT_VERSION" ]; then 11 | swiftenv install -s 12 | else 13 | swiftenv rehash 14 | fi 15 | -------------------------------------------------------------------------------- /docs/installation.md: -------------------------------------------------------------------------------- 1 | # Installation 2 | 3 | **NOTE**: If you're on macOS, consider [installing with Homebrew](#via-homebrew). 4 | 5 | ### Via a Git clone 6 | 7 | 1. Check out swiftenv, we recommend `~/.swiftenv` (but it can be installed elsewhere as long as you set `SWIFTENV_ROOT`). 8 | 9 | ```shell 10 | $ git clone https://github.com/kylef/swiftenv.git ~/.swiftenv 11 | ``` 12 | 13 | 2. Configure environment. 14 | 15 | For Bash: 16 | 17 | ```shell 18 | $ echo 'export SWIFTENV_ROOT="$HOME/.swiftenv"' >> ~/.bash_profile 19 | $ echo 'export PATH="$SWIFTENV_ROOT/bin:$PATH"' >> ~/.bash_profile 20 | $ echo 'eval "$(swiftenv init -)"' >> ~/.bash_profile 21 | ``` 22 | 23 | **NOTE**: *On some platforms, you may need to modify `~/.bashrc` instead of `~/.bash_profile`.* 24 | 25 | For ZSH: 26 | 27 | ```shell 28 | $ echo 'export SWIFTENV_ROOT="$HOME/.swiftenv"' >> ~/.zshenv 29 | $ echo 'export PATH="$SWIFTENV_ROOT/bin:$PATH"' >> ~/.zshenv 30 | $ echo 'eval "$(swiftenv init -)"' >> ~/.zshenv 31 | ``` 32 | 33 | For Fish: 34 | 35 | ```shell 36 | $ echo 'set -gx SWIFTENV_ROOT "$HOME/.swiftenv"' >> ~/.config/fish/config.fish 37 | $ echo 'set -gx PATH "$SWIFTENV_ROOT/bin" $PATH' >> ~/.config/fish/config.fish 38 | $ echo 'if which swiftenv > /dev/null; status --is-interactive; and source (swiftenv init -|psub); end' >> ~/.config/fish/config.fish 39 | ``` 40 | 41 | For other shells, please [open an issue](https://github.com/kylef/swiftenv/issues/new) and we will visit adding support. 42 | 43 | 3. Restart your shell so the changes take effect. 44 | 45 | ## Via Homebrew 46 | 47 | You can install swiftenv using the [Homebrew](http://brew.sh/) package manager 48 | on macOS. 49 | 50 | 1. Install swiftenv 51 | 52 | ```shell 53 | $ brew install kylef/formulae/swiftenv 54 | ``` 55 | 56 | 2. Then configure the shims and completions by adding the following to your profile. 57 | 58 | For Bash: 59 | 60 | ```shell 61 | $ echo 'if which swiftenv > /dev/null; then eval "$(swiftenv init -)"; fi' >> ~/.bash_profile 62 | ``` 63 | 64 | **NOTE**: *On some platforms, you may need to modify `~/.bashrc` instead of `~/.bash_profile`.* 65 | 66 | For ZSH: 67 | 68 | ```shell 69 | $ echo 'if which swiftenv > /dev/null; then eval "$(swiftenv init -)"; fi' >> ~/.zshrc 70 | ``` 71 | 72 | For Fish: 73 | 74 | ```shell 75 | $ echo 'if which swiftenv > /dev/null; status --is-interactive; and source (swiftenv init -|psub); end' >> ~/.config/fish/config.fish 76 | ``` 77 | 78 | ## Uninstalling swiftenv 79 | 80 | 1. Remove swiftenv from any `.bash_profile`, `.bashrc`, `.zshrc`, `fish.config` that you've added during installation. 81 | 82 | 2. Remove `SWIFTENV_ROOT` aka, `~/.swiftenv`. 83 | 84 | ```shell 85 | $ rm -fr ~/.swiftenv 86 | ``` 87 | 88 | 3. Uninstall any swiftenv packages (brew uninstall, pacman, etc). 89 | -------------------------------------------------------------------------------- /docs/integrations/heroku.md: -------------------------------------------------------------------------------- 1 | # Heroku 2 | 3 | The [Swift buildpack for Heroku](https://github.com/kylef/heroku-buildpack-swift) 4 | automatically makes use of swiftenv and will automatically install the local 5 | version of Swift you've specified in your `.swift-version` file. 6 | 7 | ## Usage 8 | 9 | Example usage: 10 | 11 | ```shell 12 | $ ls 13 | Procfile Package.swift Sources .swift-version 14 | 15 | $ heroku create --buildpack https://github.com/kylef/heroku-buildpack-swift.git 16 | 17 | $ git push heroku master 18 | remote: -----> Swift app detected 19 | remote: -----> Installing Swift DEVELOPMENT-SNAPSHOT-2016-02-08-a 20 | remote: -----> Installing clang-3.7.0 21 | remote: -----> Building Package 22 | remote: -----> Copying binaries to 'bin' 23 | ``` 24 | 25 | You can also add it to upcoming builds of an existing application: 26 | 27 | ```shell 28 | $ heroku buildpacks:set https://github.com/kylef/heroku-buildpack-swift.git 29 | ``` 30 | 31 | The buildpack will detect your app as Swift if it has a `Package.swift` file in 32 | the root. 33 | 34 | ### Procfile 35 | 36 | Using the Procfile, you can set the process to run for your web server. Any 37 | binaries built from your Swift source using swift package manager will 38 | be placed in your $PATH. 39 | 40 | ```swift 41 | web: HelloWorld --workers 3 --bind 0.0.0.0:$PORT 42 | ``` 43 | -------------------------------------------------------------------------------- /docs/integrations/travis-ci.md: -------------------------------------------------------------------------------- 1 | # Travis CI 2 | 3 | You can use swiftenv to both install Swift, and to manage multiple 4 | versions of Swift on [Travis CI](https://travis-ci.com/). 5 | 6 | Using the [following `install` phase](https://swiftenv.fuller.li/install.sh), you can install both swiftenv and the 7 | Swift version found in the `.swift-version` file or the `SWIFT_VERSION` 8 | environment variable. 9 | 10 | ```yaml 11 | install: 12 | - eval "$(curl -sL https://swiftenv.fuller.li/install.sh)" 13 | ``` 14 | 15 | ## Operating Systems 16 | 17 | ### macOS 18 | 19 | For macOS support on Travis, you will need to enable a version of Xcode which 20 | contains a support for the desired Swift version. See [Swift Documentation for 21 | Requirements on Apple 22 | platforms](https://swift.org/download/#requirements-for-tools). 23 | 24 | For example, Swift 5.1 requires macOS 10.14.6 and Xcode 11 or later: 25 | 26 | ```yaml 27 | osx_image: xcode11.3 28 | ``` 29 | 30 | ### Linux 31 | 32 | For Linux, Travis needs to be configured to use a compatible version of Ubuntu 33 | and the surrounding tools. 34 | 35 | Modern versions of Swift provided binary releases for Ubuntu 18.04 (also known 36 | as bionic). Use the `dist` key in Travis CI to enable the [Ubuntu 18.04 bionic 37 | runtime](https://docs.travis-ci.com/user/reference/bionic/). 38 | 39 | ```yaml 40 | language: generic 41 | sudo: required 42 | dist: bionic 43 | ``` 44 | 45 | ### Multi-OS 46 | 47 | swiftenv can be used on both macOS and Linux, you can use Travis 48 | [multiple operating system](https://docs.travis-ci.com/user/multi-os/) 49 | support by adding both platforms to the `os` key: 50 | 51 | ```yaml 52 | os: 53 | - linux 54 | - osx 55 | ``` 56 | 57 | You can mix this together with the above steps required for macOS and 58 | Linux to have a complete `.travis.yml` file as follows: 59 | 60 | ```yaml 61 | os: 62 | - linux 63 | - osx 64 | language: generic 65 | sudo: required 66 | dist: buster 67 | osx_image: xcode11.3 68 | install: 69 | - eval "$(curl -sL https://swiftenv.fuller.li/install.sh)" 70 | script: 71 | - swift build 72 | ``` 73 | 74 | ## Testing against multiple Swift versions 75 | 76 | You can use build matrix on Travis CI to set the `SWIFT_VERSION` environment 77 | variable to different values. Travis will now run against multiple 78 | versions of Swift. 79 | 80 | ```yaml 81 | env: 82 | - SWIFT_VERSION=4.2 83 | - SWIFT_VERSION=5.2.1 84 | ``` 85 | -------------------------------------------------------------------------------- /docs/sphinxcontrib_rawfiles.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | import os 3 | import shutil 4 | 5 | def on_html_collect_pages(app): 6 | for f in app.builder.config.rawfiles: 7 | src = os.path.join(app.srcdir, f) 8 | dst = os.path.join(app.builder.outdir, f) 9 | if os.path.isfile(src): 10 | shutil.copy(src, dst) 11 | else: 12 | shutil.copytree(src, dst) 13 | 14 | return () 15 | 16 | def setup(app): 17 | app.add_config_value('rawfiles', [], 'html') 18 | app.connect("html-collect-pages", on_html_collect_pages) 19 | -------------------------------------------------------------------------------- /libexec/swiftenv: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Usage: swiftenv [--version] 3 | 4 | set -e 5 | 6 | if [ -z "$SWIFTENV_ROOT" ]; then 7 | if [[ -n "${XDG_DATA_HOME}" ]] && [[ ! -d "${HOME}"/.swiftenv ]]; then 8 | SWIFTENV_ROOT="${XDG_DATA_HOME}"/swiftenv 9 | else 10 | SWIFTENV_ROOT="${HOME}"/.swiftenv 11 | fi 12 | fi 13 | if [ ! -d "$SWIFTENV_ROOT" ]; then 14 | mkdir -p "${SWIFTENV_ROOT}" 15 | fi 16 | export SWIFTENV_ROOT 17 | 18 | find_source_path() { 19 | cd "$(dirname "${BASH_SOURCE[0]}")" 20 | cd "$(dirname "$(readlink "${BASH_SOURCE[0]}")")" 21 | echo "$PWD/.." 22 | } 23 | 24 | export SWIFTENV_SOURCE_PATH="$(find_source_path)" 25 | export PATH="$SWIFTENV_SOURCE_PATH/libexec:$PATH" 26 | 27 | show_help=false 28 | 29 | for arg in "$@"; do 30 | case "$arg" in 31 | -h | --help ) 32 | show_help=true 33 | ;; 34 | 35 | -* ) 36 | # Ignore options and flags 37 | ;; 38 | 39 | * ) 40 | if [ -z "$command" ]; then 41 | command=$arg 42 | fi 43 | ;; 44 | esac 45 | done 46 | 47 | if [ -z "$SWIFTENV_SHIM" ]; then 48 | if $show_help; then 49 | swiftenv-help "$command" 50 | exit 51 | fi 52 | fi 53 | 54 | command="$1" 55 | case "$command" in 56 | "" ) 57 | swiftenv-help 58 | exit 1 59 | ;; 60 | 61 | -v | --version ) 62 | exec swiftenv---version 63 | exit 64 | ;; 65 | 66 | * ) 67 | command_path="$(command -v "swiftenv-$command" || true)" 68 | if ! [ -n "$command_path" ]; then 69 | echo "no such command \`$command'" 70 | exit 1 71 | fi 72 | 73 | shift 1 74 | exec "$command_path" "$@" 75 | ;; 76 | esac 77 | -------------------------------------------------------------------------------- /libexec/swiftenv---version: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | echo "swiftenv 1.5.0" 4 | -------------------------------------------------------------------------------- /libexec/swiftenv-build: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Summary: Build swift from source 3 | # Usage: swiftenv-build [--definitions] [--clean] [--no-clean] 4 | 5 | set -E 6 | 7 | exec 3<&2 # preserve original stderr at fd 3 8 | 9 | # fetch_git repository-name branch [destination] 10 | fetch_git() { 11 | if ! type git &>/dev/null; then 12 | echo "error: please install \`git\` and try again." >& 2 13 | exit 1 14 | fi 15 | 16 | if [ -d "$3" ]; then 17 | echo "Found "$3", skipping download" 18 | else 19 | echo "Downloading $1 ($2) from git" 20 | git clone --depth 1 --branch "$2" "https://github.com/apple/$1.git" "$3" >&4 2>&1 21 | fi 22 | } 23 | 24 | # fetch_git repository-name release [destination] 25 | fetch_github_release() { 26 | if [ -d "$3" ]; then 27 | echo "Found "$3", skipping download" 28 | else 29 | echo "Downloading $1 ($2)" 30 | curl -Lo "$1-$2.tar.gz" "https://github.com/apple/$1/archive/$2.tar.gz" 31 | 32 | mkdir "$3" 33 | tar xzf "$1-$2.tar.gz" --strip-components 1 -C "$3" 34 | fi 35 | } 36 | 37 | build_swift() { 38 | if ! type pod2man &>/dev/null && [[ -x "/usr/bin/core_perl/pod2man" ]]; then 39 | # On Arch linux, pod2man is in /usr/bin/core_perl 40 | export PATH="/usr/bin/core_perl:$PATH" 41 | fi 42 | 43 | if type python2 &>/dev/null; then 44 | # When python2 exists, link python to python2 45 | 46 | if ! [[ -x "$TMP/bin/python" ]]; then 47 | mkdir -p "$TMP/bin" 48 | ln -s "$(which python2)" "$TMP/bin/python" 49 | fi 50 | 51 | export PATH="$TMP/bin:$PATH" 52 | fi 53 | 54 | cd swift 55 | echo "Building Swift" 56 | echo "This may take a very long time..." 57 | 58 | ./utils/build-script -R -- --install-prefix="$destination" >&4 2>&1 59 | cd "$TMP" 60 | } 61 | 62 | install_swift() { 63 | mkdir -p "$destination/usr/bin" 64 | cp "$TMP/build/Ninja-ReleaseAssert/"swift-*/bin/swift{,-demangle} "$destination/usr/bin" 65 | } 66 | 67 | build_failed() { 68 | { echo "Building Swift failed" 69 | echo "Check out the logfile for more information: $LOG_PATH" 70 | echo "You can inspect or delete the working tree at: $TMP" 71 | rm -fr "$destination" 72 | } >&2 73 | exit 1 74 | } 75 | 76 | list_definitions() { 77 | ls "$SWIFTENV_SOURCE_PATH/share/swiftenv-build" | sort_versions | uniq 78 | } 79 | 80 | sort_versions() { 81 | sed 'h; s/[+-]/./g; s/.p\([[:digit:]]\)/.z\1/; s/$/.z/; G; s/\n/ /' | \ 82 | LC_ALL=C sort -t. -k 1,1 -k 2,2n -k 3,3n -k 4,4n -k 5,5n | awk '{print $2}' 83 | } 84 | 85 | clean=true 86 | definitions=false 87 | unset VERBOSE 88 | 89 | for args in "$@"; do 90 | if [ "$args" = "--no-clean" ]; then 91 | clean=false 92 | elif [ "$args" = "--clean" ]; then 93 | rehash=true 94 | elif [ "$args" = "--definitions" ]; then 95 | definitions=true 96 | elif [ "$args" = "--verbose" ]; then 97 | VERBOSE=true 98 | elif [ -z "$package" ]; then 99 | package="$args" 100 | elif [ -z "$destination" ]; then 101 | destination="$args" 102 | else 103 | echo "Unknown argument: $args" 104 | exit 1 105 | fi 106 | 107 | shift 108 | done 109 | 110 | if $definitions; then 111 | list_definitions 112 | exit 0 113 | fi 114 | 115 | if [ -z "$destination" ]; then 116 | echo "Usage: swiftenv build " 117 | exit 1 118 | fi 119 | 120 | if [ -d "$destination" ]; then 121 | echo "$destination already exists." 122 | exit 1 123 | fi 124 | 125 | PACKAGE_DEFINITION="$SWIFTENV_SOURCE_PATH/share/swiftenv-build/$package" 126 | if ! [ -r "$PACKAGE_DEFINITION" ]; then 127 | echo "Package definition not found for $package" 128 | exit 1 129 | fi 130 | 131 | # Swift build takes up a lot of room and unfortunately 132 | # had issues where I've ran out of space in /tmp while building 133 | TMP="$SWIFTENV_ROOT/tmp/swiftenv-build-$package" 134 | 135 | mkdir -p "$TMP" 136 | cd "$TMP" 137 | 138 | SEED="$(date "+%Y%m%d%H%M%S").$$" 139 | LOG_PATH="$TMP/swiftenv-build.$SEED.log" 140 | 141 | exec 4<> "$LOG_PATH" # open the log file at fd 4 142 | if [ -n "$VERBOSE" ]; then 143 | tail -f "$LOG_PATH" & 144 | TAIL_PID=$! 145 | trap "kill $TAIL_PID" SIGINT SIGTERM EXIT 146 | fi 147 | 148 | mkdir -p "$destination" 149 | trap build_failed ERR 150 | source "$PACKAGE_DEFINITION" 151 | install_swift 152 | 153 | if $clean; then 154 | rm -fr $TMP 155 | fi 156 | -------------------------------------------------------------------------------- /libexec/swiftenv-commands: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Summary: List all available commands 3 | 4 | set -e 5 | 6 | IFS=: paths=($PATH) 7 | 8 | shopt -s nullglob 9 | 10 | { for path in "${paths[@]}"; do 11 | for command in "$path/swiftenv-"*; do 12 | command="${command##*swiftenv-}" 13 | echo $command 14 | done 15 | done 16 | } | sort -u 17 | -------------------------------------------------------------------------------- /libexec/swiftenv-completions: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Usage: swiftenv completions 3 | 4 | set -e 5 | 6 | COMMAND="$1" 7 | if [ -z "$COMMAND" ]; then 8 | echo "Usage: swiftenv completions " >&2 9 | exit 1 10 | fi 11 | 12 | if [ "$COMMAND" = "--complete" ]; then 13 | exec swiftenv-commands 14 | fi 15 | 16 | COMMAND_PATH="$(command -v "swiftenv-$COMMAND")" 17 | if grep -iE "^(# completes)$" "$COMMAND_PATH" >/dev/null; then 18 | shift 19 | exec "$COMMAND_PATH" --complete "$@" 20 | fi 21 | -------------------------------------------------------------------------------- /libexec/swiftenv-exec: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Usage: swiftenv exec 3 | 4 | set -e 5 | 6 | SHIM="" 7 | if [ "$1" = "--shim" ]; then 8 | SHIM="--shim" 9 | shift 1 10 | fi 11 | 12 | COMMAND=$1 13 | 14 | if [ -z "$COMMAND" ] ; then 15 | swiftenv-help --usage exec 16 | exit 1 17 | fi 18 | 19 | COMMAND_PATH="$(swiftenv-which $SHIM $COMMAND || true)" 20 | COMMAND_BIN_PATH="${COMMAND_PATH%/*}" 21 | 22 | shift 1 23 | 24 | if [[ -z "$COMMAND_PATH" ]]; then 25 | echo "no such command: $COMMAND" 26 | exit 127 27 | fi 28 | 29 | VERSION=$(swiftenv-version-name) 30 | if [ "$VERSION" != "system" ]; then 31 | export PATH="$COMMAND_BIN_PATH:$PATH" 32 | fi 33 | exec -a "$COMMAND" "$COMMAND_PATH" "$@" 34 | -------------------------------------------------------------------------------- /libexec/swiftenv-global: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Usage: swiftenv global [] 3 | # Summary: Set or show the global Swift version 4 | # completes 5 | 6 | set -e 7 | 8 | if [ "$1" = "--complete" ]; then 9 | echo "system" 10 | exec swiftenv-versions --bare 11 | fi 12 | 13 | VERSION=$1 14 | VERSION_FILE="$SWIFTENV_ROOT/version" 15 | 16 | version_exists() { 17 | local version="$1" 18 | [ -d "$SWIFTENV_ROOT/versions/$version" ] || [ -d "/Library/Developer/Toolchains/$version.xctoolchain" ] 19 | } 20 | 21 | if [ -z "$VERSION" ]; then 22 | if [ -f "$VERSION_FILE" ]; then 23 | cat "$VERSION_FILE" 24 | else 25 | echo "swiftenv: version is not set" 26 | exit 1 27 | fi 28 | elif swiftenv-prefix "$VERSION" >/dev/null || [ "$VERSION" == "system" ]; then 29 | echo "$VERSION" > "$VERSION_FILE" 30 | else 31 | echo "swiftenv: version \`$VERSION' is not installed" 32 | exit 1 33 | fi 34 | -------------------------------------------------------------------------------- /libexec/swiftenv-help: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Usage: swiftenv help [--usage] [] 3 | 4 | print_usage() { 5 | local command 6 | local command_path 7 | local usage 8 | 9 | command="$1" 10 | command_path="$2" 11 | 12 | usage=$(cat "$command_path" | grep "^\# Usage:" | sed 's/# //') 13 | 14 | if [ -n "$usage" ]; then 15 | echo $usage 16 | else 17 | echo "Usage: swiftenv $command" 18 | fi 19 | } 20 | 21 | print_summary() { 22 | local command 23 | local command_path 24 | local summary 25 | 26 | command="$1" 27 | command_path="$2" 28 | 29 | summary=$(cat "$command_path" | grep "^\# Summary:" | sed 's/# Summary: //') 30 | 31 | if [ -n "$summary" ]; then 32 | echo 33 | echo $summary 34 | fi 35 | } 36 | 37 | swiftenv_help() { 38 | print_usage "swiftenv" "$(which swiftenv)" 39 | echo 40 | echo " version Displays the current active Swift version" 41 | echo " versions Lists all installed Swift versions" 42 | echo " global Sets the global version of Swift" 43 | echo " local Sets the local application-specific version of Swift" 44 | echo " install Installs a version of Swift" 45 | echo " uninstall Uninstalls a specific Swift version" 46 | echo " rehash Installs shims for Swift binaries" 47 | echo 48 | echo "Visit https://swiftenv.fuller.li for more info." 49 | } 50 | 51 | print_man() { 52 | local command 53 | command=$1 54 | 55 | if man -w "swiftenv-$command" >/dev/null 2>/dev/null; then 56 | man "swiftenv-$command" 57 | exit 58 | fi 59 | } 60 | 61 | usage=false 62 | if [ "$1" == "--usage" ]; then 63 | shift 1 64 | usage=true 65 | fi 66 | 67 | if [ -z "$1" ] || [ "$1" == "swiftenv" ]; then 68 | swiftenv_help 69 | else 70 | command="$1" 71 | command_path="$(command -v "swiftenv-$command" || true)" 72 | 73 | if ! [ -n "$command_path" ]; then 74 | echo "swiftenv: no such command '$command'" 75 | exit 1 76 | fi 77 | 78 | if ! $usage; then 79 | print_man "$command" 80 | fi 81 | 82 | print_usage "$command" "$command_path" 83 | 84 | if ! $usage; then 85 | print_summary "$command" "$command_path" 86 | fi 87 | fi 88 | -------------------------------------------------------------------------------- /libexec/swiftenv-init: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Usage: swiftenv init [-] [--[no-]rehash] 3 | # completes 4 | 5 | set -e 6 | 7 | if [ "$1" = "--complete" ]; then 8 | echo "-" 9 | echo "--no-rehash" 10 | echo "--rehash" 11 | echo "bash" 12 | echo "zsh" 13 | echo "fish" 14 | exit 15 | fi 16 | 17 | print="" 18 | 19 | rehash=true 20 | 21 | if [ -r "$SWIFTENV_ROOT/shims" ] && [[ "$(uname)" == "Darwin" ]]; then 22 | # Rehash takes a long time on Darwin due to mdfind 23 | 24 | if [ -r "$SWIFTENV_ROOT/shims/.version" ] && [ "$(cat "$SWIFTENV_ROOT/shims/.version")" == "$(swiftenv --version)" ]; then 25 | rehash=false 26 | fi 27 | fi 28 | 29 | for args in "$@" 30 | do 31 | if [ "$args" = "-" ]; then 32 | print=1 33 | shift 34 | fi 35 | 36 | if [ "$args" = "--rehash" ]; then 37 | rehash=true 38 | shift 39 | fi 40 | 41 | if [ "$args" = "--no-rehash" ]; then 42 | rehash=false 43 | shift 44 | fi 45 | done 46 | 47 | shell="$1" 48 | if [ -z "$shell" ]; then 49 | shell="$(ps c -p "$PPID" -o 'ucomm=' 2>/dev/null || true)" 50 | shell="${shell##-}" 51 | shell="${shell%% *}" 52 | shell="${shell:-$SHELL}" 53 | shell="${shell##*/}" 54 | fi 55 | 56 | if [ -z "$print" ]; then 57 | case "$shell" in 58 | bash ) 59 | if [ -f "${HOME}/.bashrc" ] && [ ! -f "${HOME}/.bash_profile" ]; then 60 | profile='~/.bashrc' 61 | else 62 | profile='~/.bash_profile' 63 | fi 64 | ;; 65 | zsh ) 66 | profile='~/.zshrc' 67 | ;; 68 | fish ) 69 | profile='~/.config/fish/config.fish' 70 | ;; 71 | * ) 72 | profile='your profile' 73 | esac 74 | 75 | { 76 | echo "# Load swiftenv automatically by appending" 77 | echo "# the following to your $profile:" 78 | echo 79 | 80 | case "$shell" in 81 | fish ) 82 | echo 'status --is-interactive; and source (swiftenv init -|psub)' 83 | ;; 84 | * ) 85 | echo 'eval "$(swiftenv init -)"' 86 | ;; 87 | esac 88 | echo 89 | 90 | exit 1 91 | } >&2 92 | 93 | exit 1 94 | fi 95 | 96 | mkdir -p "$SWIFTENV_ROOT/"{shims,versions} 97 | case "$shell" in 98 | fish ) 99 | echo "set -gx PATH '${SWIFTENV_ROOT}/shims' \$PATH" 100 | ;; 101 | * ) 102 | echo 'export PATH="'${SWIFTENV_ROOT}'/shims:${PATH}"' 103 | ;; 104 | esac 105 | 106 | if $rehash; then 107 | echo 'command swiftenv rehash 2>/dev/null' 108 | fi 109 | 110 | source_root="${0%/*}/.." 111 | completion="$source_root/completions/swiftenv.${shell}" 112 | if [ -r "$completion" ]; then 113 | echo "source '$completion'" 114 | fi 115 | -------------------------------------------------------------------------------- /libexec/swiftenv-install: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Usage: swiftenv install 3 | # completes 4 | 5 | set -e 6 | 7 | # Check if the given version is already installed 8 | check_installed() { 9 | local VERSION 10 | VERSION="$1" 11 | 12 | local PREFIX 13 | PREFIX="$(swiftenv-prefix "$VERSION" || true)" 14 | if [ -d "$PREFIX" ]; then 15 | echo "$VERSION is already installed." 16 | 17 | if [ -n "$SKIP_EXISTING" ]; then 18 | update_version_files 19 | exit 0 20 | fi 21 | 22 | exit 1 23 | fi 24 | } 25 | 26 | update_version_files() { 27 | if ([ "$set_global" == "auto" ] && [ "$set_local" == "false" ]); then 28 | swiftenv-global "$VERSION" 29 | elif ([ "$set_global" == "true" ]); then 30 | swiftenv-global "$VERSION" 31 | fi 32 | 33 | if [ "$set_local" == "true" ]; then 34 | swiftenv-local "$VERSION" 35 | fi 36 | } 37 | 38 | get_os_release() { 39 | test -e /etc/os-release && os_release='/etc/os-release' || os_release='/usr/lib/os-release' 40 | . "${os_release}" 41 | 42 | if [ "$ID" = "amzn" ]; then 43 | echo "amazonlinux$VERSION_ID" 44 | else 45 | echo $ID$VERSION_ID 46 | fi 47 | } 48 | 49 | get_platform() { 50 | if [ -n "$SWIFTENV_PLATFORM" ]; then 51 | echo "$SWIFTENV_PLATFORM" 52 | return 53 | fi 54 | 55 | if [ -n "$PLATFORM" ]; then 56 | echo "$PLATFORM" 57 | return 58 | fi 59 | 60 | case $(uname) in 61 | 'Linux' ) 62 | get_os_release 63 | ;; 64 | 'Darwin' ) 65 | echo "osx" 66 | ;; 67 | 'MINGW64_NT-10.0'* ) 68 | echo "windows10" 69 | ;; 70 | * ) 71 | echo "unsupported-platform" 72 | ;; 73 | esac 74 | } 75 | 76 | install_binary() { 77 | local VERSION 78 | local URL 79 | VERSION="$1" 80 | URL="$2" 81 | 82 | if [[ "$URL" = *".pkg" ]]; then 83 | if [ "$(uname)" != "Darwin" ]; then 84 | echo "Cannot install .pkg from $URL on non macOS platform $(uname)." 85 | exit 1 86 | fi 87 | 88 | install_pkg_binary "$URL" 89 | elif [[ "$URL" = *".tar.gz" ]]; then 90 | install_tar_binary "$VERSION" "$URL" 91 | elif [[ "$URL" = *".exe" ]]; then 92 | install_exe_binary "$URL" 93 | else 94 | echo "swiftenv does not know how to install $URL. Only tar.gz and pkg files are supported." 95 | exit 1 96 | fi 97 | } 98 | 99 | download() { 100 | local URL 101 | local FILE 102 | URL=$1 103 | FILE=$2 104 | if ! [ -r "$FILE" ]; then 105 | curl -C - -Lo "$FILE.download" "$URL" 106 | mv "$FILE.download" "$FILE" 107 | fi 108 | } 109 | 110 | # Install a tarball binary from the supplied URL 111 | install_tar_binary() { 112 | local VERSION 113 | local URL 114 | VERSION="$1" 115 | URL="$2" 116 | 117 | INSTALL_TMP="$TMPDIR/swiftenv-$VERSION-$USER" 118 | 119 | mkdir -p "$INSTALL_TMP" 120 | 121 | echo "Downloading $URL" 122 | 123 | pushd "$INSTALL_TMP" 124 | download "$URL" "swift-$VERSION.tar.gz" 125 | 126 | if $verify; then 127 | curl -o "swift-$VERSION.sig" "$URL.sig" 128 | gpg --verify "swift-$VERSION.sig" "swift-$VERSION.tar.gz" 129 | fi 130 | 131 | tar xzf "swift-$VERSION.tar.gz" 132 | popd 133 | 134 | DESTINATION="$SWIFTENV_ROOT/versions/$VERSION" 135 | # Some archives don't have an enclosing directory so check "usr" exists first 136 | if [ -d "$INSTALL_TMP/usr" ]; then 137 | mkdir -p "$DESTINATION" 138 | mv "$INSTALL_TMP/usr" "$DESTINATION" 139 | else 140 | mv "$INSTALL_TMP/swift-$VERSION_RELEASE"*/ "$DESTINATION" 141 | fi 142 | 143 | if $clean; then 144 | rm -fr "$INSTALL_TMP" 145 | fi 146 | } 147 | 148 | # Installs an `.pkg` binary from the supplied URL 149 | install_pkg_binary() { 150 | local URL 151 | URL="$1" 152 | PKG="$TMPDIR/swiftenv-$VERSION-$USER.pkg" 153 | 154 | download "$URL" "$PKG" 155 | 156 | if $user; then 157 | installer -pkg "$PKG" -target CurrentUserHomeDirectory 158 | else 159 | sudo installer -pkg "$PKG" -target LocalSystem 160 | fi 161 | 162 | if $clean; then 163 | rm -fr "$PKG" 164 | fi 165 | } 166 | 167 | install_exe_binary() { 168 | local URL 169 | URL="$1" 170 | 171 | #powershell -Command {Install-Binary -Url "$URL" -Name "installer.exe" -ArgumentList ("-q")} 172 | echo "swiftenv does not yet support installing on Windows" 173 | exit 1 174 | } 175 | 176 | # Install the given version from source 177 | install_source() { 178 | VERSION="$1" 179 | 180 | OPTIONS="" 181 | 182 | if $clean; then 183 | OPTIONS="--clean" 184 | else 185 | OPTIONS="--no-clean" 186 | fi 187 | 188 | if $verbose; then 189 | OPTIONS="$OPTIONS --verbose" 190 | fi 191 | 192 | swiftenv-build $OPTIONS "$VERSION" "$SWIFTENV_ROOT/versions/$VERSION" 193 | } 194 | 195 | build_version() { 196 | if [ -n "$url" ]; then 197 | echo 'The given URL must be to a binary version of Swift, you cannot use the `--build` option with a URL.' 198 | exit 1 199 | fi 200 | 201 | if [ -r "$SWIFTENV_SOURCE_PATH/share/swiftenv-build/$VERSION" ]; then 202 | vlog "Building $VERSION from source..." 203 | install_source "$VERSION" 204 | echo "$VERSION has been installed." 205 | swiftenv-rehash 206 | swiftenv-global "${VERSION##swift-}" 207 | exit 0 208 | fi 209 | 210 | echo "We don't have build instructions for $VERSION." 211 | exit 1 212 | } 213 | 214 | find_binary_url_from_api() { 215 | platform=$(get_platform) 216 | vlog "Checking for a URL for Swift $VERSION on $platform." 217 | 218 | extension="tar.gz" 219 | platform_directory="${platform/.}" 220 | 221 | if [ "$platform" == "osx" ]; then 222 | extension="pkg" 223 | platform_directory="xcode" 224 | elif [ "$platform" == "windows10" ]; then 225 | platform_directory=windows10 226 | platform=windows10 227 | extension=exe 228 | fi 229 | 230 | architecture="" 231 | if [ "$platform" != "osx" ] || [ "$platform" != "windows10" ]; then 232 | # macOS uses dual architecture binaries 233 | # FIXME windows10 - no support just yet 234 | 235 | if command -v "lscpu" >/dev/null 2>&1; then 236 | cpu_arch=$(LC_ALL=C lscpu | grep Architecture | cut -d ":" -f2 | tr -d " ") 237 | if [ "$cpu_arch" != "x86_64" ]; then 238 | architecture="-$cpu_arch" 239 | platform_directory+="-$cpu_arch" 240 | fi 241 | fi 242 | fi 243 | 244 | case "$VERSION" in 245 | *'-DEVELOPMENT-SNAPSHOT'* ) 246 | VERSION_NUMBER=$(echo "$VERSION" | cut -d "-" -f1) 247 | url="https://download.swift.org/swift-$VERSION_NUMBER-branch/$platform_directory/swift-$VERSION/swift-$VERSION-$platform$architecture.$extension" ;; 248 | "DEVELOPMENT-SNAPSHOT"* ) 249 | url="https://download.swift.org/development/$platform_directory/swift-$VERSION/swift-$VERSION-$platform$architecture.$extension" ;; 250 | * ) 251 | url="https://download.swift.org/swift-$VERSION-release/$platform_directory/swift-$VERSION-RELEASE/swift-$VERSION-RELEASE-$platform$architecture.$extension" ;; 252 | esac 253 | 254 | vlog "Trying URL: $url" 255 | } 256 | 257 | sort_versions() { 258 | sed 'h; s/[+-]/./g; s/.p\([[:digit:]]\)/.z\1/; s/$/.z/; G; s/\n/ /' | \ 259 | LC_ALL=C sort -t. -k 1,1 -k 2,2n -k 3,3n -k 4,4n -k 5,5n | awk '{print $2}' 260 | } 261 | 262 | get_version_list() { 263 | platform="$(get_platform)" 264 | 265 | if $snapshots; then 266 | curl -H 'Accept: text/plain' "https://swiftenv-api.fuller.li/versions?snapshot=true&platform=$platform" 267 | exit 268 | fi 269 | 270 | CACHE_DIR="${XDG_CACHE_HOME:-$HOME/.cache}/swiftenv" 271 | CACHE_FILE="$CACHE_DIR/versions-${platform}.txt" 272 | 273 | if $refresh; then 274 | vlog "Updating version cache" 275 | # FIXME: Add support for architecture to swiftenv api 276 | mkdir -p $CACHE_DIR 277 | curl -s -H 'Accept: text/plain' "https://swiftenv-api.fuller.li/versions?platform=$platform" > "$CACHE_FILE" 278 | fi 279 | 280 | if [ -r "$CACHE_FILE" ] && [ $build != "true" ]; then 281 | cat "$CACHE_FILE" 282 | else 283 | swiftenv-build --definitions 284 | fi 285 | 286 | exit 287 | } 288 | 289 | clean=true 290 | list=false 291 | refresh=true 292 | snapshots=false 293 | build=auto 294 | verbose=false 295 | verify=false 296 | set_global=auto 297 | set_local=false 298 | completes=false 299 | user=true 300 | 301 | if [ "$(uname)" == "Darwin" ]; then 302 | user=false 303 | fi 304 | 305 | if [ -n "$SWIFTENV_VERIFY" ] && [ "$SWIFTENV_VERIFY" != "false" ]; then 306 | verify=true 307 | fi 308 | 309 | unset SKIP_EXISTING 310 | 311 | for args in "$@"; do 312 | if [ "$args" = "--no-clean" ]; then 313 | clean=false 314 | elif [ "$args" = "--clean" ]; then 315 | clean=true 316 | elif [ "$args" = "--list" ] || [ "$args" = "-l" ]; then 317 | list=true 318 | elif [ "$args" = "--list-snapshots" ]; then 319 | list=true 320 | snapshots=true 321 | elif [ "$args" = "--refresh" ]; then 322 | refresh=true 323 | elif [ "$args" = "--no-refresh" ]; then 324 | refresh=false 325 | elif [ "$args" = "--complete" ]; then 326 | refresh=false 327 | completes=true 328 | elif [ "$args" = "--build" ]; then 329 | build=true 330 | elif [ "$args" = "--no-build" ]; then 331 | build=false 332 | elif [ "$args" = "--skip-existing" ] || [ "$args" = "-s" ]; then 333 | SKIP_EXISTING=true 334 | elif [ "$args" = "--verbose" ]; then 335 | verbose=true 336 | elif [ "$args" = "--no-verbose" ]; then 337 | verbose=false 338 | elif [ "$args" = "--verify" ]; then 339 | verify=true 340 | elif [ "$args" = "--no-verify" ]; then 341 | verify=false 342 | elif [ "$args" = "--no-set-global" ]; then 343 | set_global=false 344 | elif [ "$args" = "--no-set-local" ]; then 345 | set_local=false 346 | elif [ "$args" = "--set-global" ]; then 347 | set_global=true 348 | elif [ "$args" = "--set-local" ]; then 349 | set_local=true 350 | elif [ "$args" = "--user" ]; then 351 | user=true 352 | elif [ "$args" = "--no-user" ]; then 353 | user=false 354 | else 355 | VERSION="$args" 356 | fi 357 | 358 | shift 359 | done 360 | 361 | vlog() { 362 | if $verbose; then 363 | echo "$1" 364 | fi 365 | } 366 | 367 | if $completes; then 368 | echo "--list" 369 | echo "--list-snapshots" 370 | echo "--refresh" 371 | echo "--no-refresh" 372 | echo "--verbose" 373 | echo "--no-verbose" 374 | echo "--verify" 375 | echo "--no-verify" 376 | echo "--clean" 377 | echo "--no-clean" 378 | echo "--set-global" 379 | echo "--no-set-global" 380 | echo "--set-local" 381 | echo "--no-set-local" 382 | echo "--user" 383 | echo "--no-user" 384 | get_version_list 385 | exit 386 | fi 387 | 388 | if $list; then 389 | get_version_list 390 | fi 391 | 392 | mkdir -p "$SWIFTENV_ROOT/versions" 393 | if [ -z "$VERSION" ] ; then 394 | VERSION="$(swiftenv-version-name --dont-check)" 395 | 396 | if [ "$set_global" == "auto" ]; then 397 | set_global=false 398 | fi 399 | 400 | if [ "$VERSION" == "system" ]; then 401 | echo "Usage: swiftenv install " 402 | exit 1 403 | fi 404 | fi 405 | 406 | if [ -z "$TMPDIR" ] ; then 407 | export TMPDIR=/tmp 408 | fi 409 | 410 | if [[ "$VERSION" == "https://"* ]]; then 411 | url="$VERSION" 412 | VERSION="${url##*/}" 413 | VERSION="${VERSION%-*}" 414 | fi 415 | 416 | VERSION="${VERSION##swift-}" 417 | 418 | check_installed "$VERSION" 419 | 420 | if ! $user; then 421 | if [ "$(uname)" != "Darwin" ]; then 422 | echo "--no-user installation is only supported on macOS." 423 | exit 1 424 | fi 425 | fi 426 | 427 | # Install Binary 428 | if ([ "$build" == "auto" ] || [ "$build" == "false" ]); then 429 | if [ -z "$url" ]; then 430 | find_binary_url_from_api 431 | fi 432 | 433 | # verify URL points to valid file 434 | status_code=$(curl -I -s -o /dev/null -w "%{http_code}" $url || true) 435 | if [ "$status_code" == "404" ]; then 436 | unset url 437 | fi 438 | 439 | if [ "$url" ]; then 440 | install_binary "$VERSION" "$url" 441 | elif [ "$build" == "false" ]; then 442 | echo "Could not find a binary release of $VERSION." 443 | exit 1 444 | elif [ "$build" == "auto" ]; then 445 | build="true" 446 | fi 447 | fi 448 | 449 | 450 | # Install Source 451 | if [ "$build" == "true" ]; then 452 | build_version 453 | fi 454 | 455 | echo "$VERSION has been installed." 456 | swiftenv-rehash 457 | 458 | update_version_files 459 | -------------------------------------------------------------------------------- /libexec/swiftenv-local: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Usage: swiftenv local [] 3 | # Summary: Set or show the local Swift version 4 | # completes 5 | 6 | set -e 7 | 8 | if [ "$1" = "--complete" ]; then 9 | echo "--unset" 10 | echo "system" 11 | exec swiftenv-versions --bare 12 | fi 13 | 14 | VERSION=$1 15 | VERSION_FILE=".swift-version" 16 | 17 | if [ "$VERSION" = "--unset" ]; then 18 | rm -f $VERSION_FILE 19 | elif [ -z "$VERSION" ]; then 20 | if [ -f "$VERSION_FILE" ]; then 21 | cat "$VERSION_FILE" 22 | else 23 | echo "swiftenv: version is not set" 24 | exit 1 25 | fi 26 | elif swiftenv-prefix "$VERSION" >/dev/null || [ "$VERSION" == "system" ]; then 27 | echo "$VERSION" > "$VERSION_FILE" 28 | else 29 | echo "swiftenv: version \`$VERSION' is not installed" 30 | exit 1 31 | fi 32 | -------------------------------------------------------------------------------- /libexec/swiftenv-prefix: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Summary: Display the path for a Swift version 3 | 4 | set -e 5 | 6 | if [ -z "$1" ]; then 7 | SWIFT_VERSION="$(swiftenv-version-name)" 8 | else 9 | SWIFT_VERSION="$1" 10 | fi 11 | 12 | if [ "$SWIFT_VERSION" == "system" ]; then 13 | echo "/usr/bin" 14 | exit 15 | fi 16 | 17 | if [ -d "$SWIFTENV_ROOT/versions/$SWIFT_VERSION" ]; then 18 | echo "$SWIFTENV_ROOT/versions/$SWIFT_VERSION" 19 | exit 20 | fi 21 | 22 | if [ -d "$SWIFTENV_ROOT/versions/swift-$SWIFT_VERSION" ]; then 23 | echo "$SWIFTENV_ROOT/versions/swift-$SWIFT_VERSION" 24 | exit 25 | fi 26 | 27 | # OS X Swift Toolchain 28 | 29 | check_toolchain() { 30 | local TOOLCHAIN_DIR 31 | TOOLCHAIN_DIR=$1 32 | 33 | if [ -d "$TOOLCHAIN_DIR/swift-$SWIFT_VERSION-RELEASE.xctoolchain" ]; then 34 | echo "$TOOLCHAIN_DIR/swift-$SWIFT_VERSION-RELEASE.xctoolchain" 35 | exit 36 | fi 37 | 38 | if [ -d "$TOOLCHAIN_DIR/swift-$SWIFT_VERSION.xctoolchain" ]; then 39 | echo "$TOOLCHAIN_DIR/swift-$SWIFT_VERSION.xctoolchain" 40 | exit 41 | fi 42 | } 43 | 44 | check_toolchain "$HOME/Library/Developer/Toolchains" 45 | check_toolchain "/Library/Developer/Toolchains" 46 | 47 | # OS X Xcode Swift's 48 | if command -v "mdfind" >/dev/null 2>&1; then 49 | XCODES="$(mdfind "kMDItemCFBundleIdentifier == 'com.apple.dt.Xcode'" 2>/dev/null)" 50 | for xcode in $XCODES; do 51 | if [ -d "$xcode" ]; then 52 | version_line="$(env DEVELOPER_DIR="$xcode" xcrun swift --version 2>/dev/null | head -n1)" 53 | version="swift-$(echo "$version_line" | cut -d " " -f 4)" 54 | if [ "$version" == "$SWIFT_VERSION" ] || [ "$version" == "swift-$SWIFT_VERSION" ]; then 55 | echo "$xcode/Contents/Developer/Toolchains/XcodeDefault.xctoolchain" 56 | exit 57 | fi 58 | fi 59 | done 60 | fi 61 | 62 | echo "$SWIFT_VERSION is not installed" 63 | exit 1 64 | -------------------------------------------------------------------------------- /libexec/swiftenv-rehash: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Usage: Rehash swiftenv shims 3 | 4 | set -e 5 | 6 | SHIM_PATH=$SWIFTENV_ROOT/shims 7 | 8 | mkdir -p "$SHIM_PATH" 9 | 10 | list_executable_names_toolchains() { 11 | TOOLCHAINS_DIR="$1" 12 | 13 | if [ -d "$TOOLCHAINS_DIR" ]; then 14 | for path in "$TOOLCHAINS_DIR"/*.xctoolchain; do 15 | if [ -d "$path" ]; then 16 | for file in "$path/usr/bin/"*; do 17 | echo "${file##*/}" 18 | done 19 | fi 20 | done 21 | fi 22 | } 23 | 24 | list_executable_names_xcodes() { 25 | if command -v "mdfind" >/dev/null 2>&1; then 26 | XCODES="$(mdfind "kMDItemCFBundleIdentifier == 'com.apple.dt.Xcode'" 2>/dev/null)" 27 | for xcode in $XCODES; do 28 | TOOLCHAIN_DIR="$xcode/Contents/Developer/Toolchains/XcodeDefault.xctoolchain" 29 | if [ -d "$TOOLCHAIN_DIR" ]; then 30 | for file in "$TOOLCHAIN_DIR/usr/bin/"*; do 31 | executable="${file##*/}" 32 | if [[ "$executable" == "swift"* ]] || [[ "$executable" == "lldb"* ]]; then 33 | echo "$executable" 34 | fi 35 | done 36 | fi 37 | done 38 | fi 39 | } 40 | 41 | # List all basenames of executables for every installed Swift version 42 | list_executable_names() { 43 | VERSIONS_DIR="$SWIFTENV_ROOT/versions/$version" 44 | 45 | for path in "$VERSIONS_DIR"/*; do 46 | if [ -d "$path/usr/bin" ]; then 47 | for file in "$path/usr/bin"/*; do 48 | echo "${file##*/}" 49 | done 50 | fi 51 | done 52 | 53 | # OS X Swift Toolchains 54 | list_executable_names_toolchains "/Library/Developer/Toolchains" 55 | list_executable_names_toolchains "$HOME/Library/Developer/Toolchains" 56 | 57 | # Xcode installs 58 | list_executable_names_xcodes 59 | } 60 | 61 | remove_stale_shims() { 62 | local shim 63 | for shim in "$SHIM_PATH"/*; do 64 | if [[ "$registered_shims" != *" ${shim##*/} "* ]]; then 65 | rm -f "$shim" 66 | fi 67 | done 68 | } 69 | 70 | create_shims() { 71 | local shim 72 | for shim in $registered_shims; do 73 | create_shim "$shim" 74 | done 75 | } 76 | 77 | create_shim() { 78 | cat > "$SHIM_PATH/$1" < "$SHIM_PATH/.version" 91 | -------------------------------------------------------------------------------- /libexec/swiftenv-uninstall: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Usage: swiftenv uninstall 3 | # Summary: Uninstalls a Swift version 4 | # completes 5 | 6 | set -e 7 | 8 | if [ "$1" = "--complete" ]; then 9 | exec swiftenv-versions --bare 10 | fi 11 | 12 | VERSION=$1 13 | if [ -z "$VERSION" ] ; then 14 | echo "Usage: swiftenv uninstall " 15 | exit 1 16 | fi 17 | 18 | if [ "$VERSION" == "system" ]; then 19 | echo "$VERSION is uninstallable." 20 | exit 1 21 | fi 22 | 23 | if [ -d "$SWIFTENV_ROOT/versions/$VERSION" ]; then 24 | VERSION_DIRECTORY="$SWIFTENV_ROOT/versions/$VERSION" 25 | elif [ -d "$SWIFTENV_ROOT/versions/swift-$VERSION" ]; then 26 | VERSION_DIRECTORY="$SWIFTENV_ROOT/versions/swift-$VERSION" 27 | elif [ -d "/Library/Developer/Toolchains/swift-$VERSION.xctoolchain" ]; then 28 | VERSION_DIRECTORY="/Library/Developer/Toolchains/swift-$VERSION.xctoolchain" 29 | elif [ -d "$HOME/Library/Developer/Toolchains/swift-$VERSION.xctoolchain" ]; then 30 | VERSION_DIRECTORY="$HOME/Library/Developer/Toolchains/swift-$VERSION.xctoolchain" 31 | elif [ -d "/Library/Developer/Toolchains/swift-$VERSION-RELEASE.xctoolchain" ]; then 32 | VERSION_DIRECTORY="/Library/Developer/Toolchains/swift-$VERSION-RELEASE.xctoolchain" 33 | elif [ -d "$HOME/Library/Developer/Toolchains/swift-$VERSION-RELEASE.xctoolchain" ]; then 34 | VERSION_DIRECTORY="$HOME/Library/Developer/Toolchains/swift-$VERSION-RELEASE.xctoolchain" 35 | else 36 | 37 | # Xcode installs 38 | if command -v "mdfind" >/dev/null 2>&1; then 39 | XCODES="$(mdfind "kMDItemCFBundleIdentifier == 'com.apple.dt.Xcode'" 2>/dev/null)" 40 | for xcode in $XCODES; do 41 | if [ -d "$xcode" ]; then 42 | version_line="$(env DEVELOPER_DIR="$xcode" xcrun swift --version | head -n1)" 43 | xversion="$(echo "$version_line" | cut -d " " -f 4)" 44 | if [ "$xversion" == "$VERSION" ]; then 45 | echo "Cannot uninstall $VERSION from swiftenv." 46 | echo "You can uninstall $VERSION by uninstalling Xcode ($xcode)." 47 | exit 1 48 | fi 49 | fi 50 | done 51 | fi 52 | 53 | echo "$VERSION is not installed." 54 | exit 1 55 | fi 56 | 57 | 58 | if [ -r "$SWIFTENV_ROOT/version" ]; then 59 | CURRENT_VERSION=$(cat "$SWIFTENV_ROOT/version") 60 | 61 | if [ "$VERSION" == "$CURRENT_VERSION" ]; then 62 | rm -f "$SWIFTENV_ROOT/version" 63 | fi 64 | fi 65 | 66 | if [[ "$VERSION_DIRECTORY" == "/Library/Developer/Toolchains/"* ]]; then 67 | if [ "$(readlink /Library/Developer/Toolchains/swift-latest.xctoolchain)" == "$VERSION_DIRECTORY" ]; then 68 | sudo rm -fr /Library/Developer/Toolchains/swift-latest.xctoolchain 69 | fi 70 | 71 | sudo rm -fr "$VERSION_DIRECTORY" 72 | else 73 | rm -fr "$VERSION_DIRECTORY" 74 | fi 75 | 76 | swiftenv rehash 77 | -------------------------------------------------------------------------------- /libexec/swiftenv-version: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Summary: Show the current selected Swift version and how it was selected. 3 | 4 | set -e 5 | 6 | VERSION="$(swiftenv-version-name)" 7 | ORIGIN="$(swiftenv-version-origin)" 8 | 9 | echo "$VERSION (set by $ORIGIN)" 10 | -------------------------------------------------------------------------------- /libexec/swiftenv-version-file: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Find the file that sets the current swift version 3 | 4 | find_local_version_file() { 5 | local root="$1" 6 | while true; do 7 | [[ "$root" =~ ^//[^/]*$ ]] && break 8 | if [ -e "${root}/.swift-version" ]; then 9 | echo "${root}/.swift-version" 10 | exit 11 | fi 12 | [ -n "$root" ] || break 13 | root="${root%/*}" 14 | done 15 | } 16 | 17 | find_local_version_file "$PWD" 18 | echo "$SWIFTENV_ROOT/version" 19 | -------------------------------------------------------------------------------- /libexec/swiftenv-version-name: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -e 4 | 5 | if [ -z "$SWIFT_VERSION" ]; then 6 | SWIFT_VERSION_FILE=$(swiftenv-version-file) 7 | if [ "$SWIFT_VERSION_FILE" == "$SWIFTENV_ROOT/version" ] && ! [[ -f "$SWIFT_VERSION_FILE" ]]; then 8 | echo "system" 9 | exit 10 | fi 11 | 12 | SWIFT_VERSION=$(cat "$SWIFT_VERSION_FILE") 13 | fi 14 | 15 | if $DONT_CHECK || swiftenv-prefix "$SWIFT_VERSION" >/dev/null || [ "$SWIFT_VERSION" == "system" ]; then 16 | echo "${SWIFT_VERSION##swift-}" 17 | else 18 | >&2 echo "swiftenv: version \`$SWIFT_VERSION' is not installed" 19 | exit 1 20 | fi 21 | -------------------------------------------------------------------------------- /libexec/swiftenv-version-origin: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Usage: Find the reason the current swift version is set (either filename or environ) 3 | 4 | set -e 5 | 6 | if [ -n "$SWIFT_VERSION" ]; then 7 | echo "SWIFT_VERSION environment variable" 8 | else 9 | swiftenv-version-file 10 | fi 11 | -------------------------------------------------------------------------------- /libexec/swiftenv-versions: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Usage: List all Swift versions available to swiftenv 3 | 4 | set -e 5 | 6 | unset bare 7 | unset verbose 8 | for arg; do 9 | case "$arg" in 10 | --bare ) bare=1 ;; 11 | --verbose ) verbose=1 ;; 12 | esac 13 | done 14 | 15 | CURRENT_VERSION=$(swiftenv-version-name || true) 16 | 17 | printed=" " 18 | print_version() { 19 | # Don't print if we've already printed it 20 | if [[ "$printed" != *" $1 "* ]]; then 21 | local version 22 | version="${1##swift-}" 23 | if [ -n "$bare" ]; then 24 | echo "$version" 25 | elif [ "$version" == "$CURRENT_VERSION" ]; then 26 | if [ -n "$verbose" ]; then 27 | echo "* $version [from $2] (set by $(swiftenv-version-origin))" 28 | else 29 | echo "* $version (set by $(swiftenv-version-origin))" 30 | fi 31 | elif [ -n "$verbose" ]; then 32 | echo " $version [from $2]" 33 | else 34 | echo " $version" 35 | fi 36 | 37 | printed="$printed$1 " 38 | fi 39 | } 40 | 41 | VERSIONS_DIR="$SWIFTENV_ROOT/versions" 42 | 43 | if [ "$CURRENT_VERSION" == "system" ]; then 44 | echo "* system" 45 | fi 46 | 47 | # Installed into ~/.swiftenv/versions 48 | for path in "$VERSIONS_DIR"/*; do 49 | if [ -d "$path" ]; then 50 | print_version "${path##*/}" "swiftenv" 51 | fi 52 | done 53 | 54 | # Swift toolchains on OS X 55 | 56 | check_toolchains() { 57 | TOOLCHAIN_DIR="$1" 58 | 59 | if [ -d "$TOOLCHAIN_DIR" ]; then 60 | for path in "$TOOLCHAIN_DIR"/*; do 61 | if [[ "$path" == *".xctoolchain" ]] && [ -d "$path" ]; then 62 | version="$(basename ${path##*/} .xctoolchain)" 63 | if [ "$version" != "swift-latest" ]; then 64 | print_version "${version%-RELEASE}" "toolchain" 65 | fi 66 | fi 67 | done 68 | fi 69 | } 70 | 71 | check_toolchains "/Library/Developer/Toolchains" 72 | check_toolchains "$HOME/Library/Developer/Toolchains" 73 | 74 | # Xcode installs 75 | if command -v "mdfind" >/dev/null 2>&1; then 76 | XCODES="$(mdfind "kMDItemCFBundleIdentifier == 'com.apple.dt.Xcode'" 2>/dev/null)" 77 | for xcode in $XCODES; do 78 | if [ -d "$xcode" ]; then 79 | version_line="$(env DEVELOPER_DIR="$xcode" xcrun swift --version | head -n1)" 80 | version="swift-$(echo "$version_line" | cut -d " " -f 4)" 81 | print_version "$version" "xcode $xcode" 82 | fi 83 | done 84 | fi 85 | -------------------------------------------------------------------------------- /libexec/swiftenv-which: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Usage: swiftenv which 3 | 4 | set -e 5 | 6 | SHIM=false 7 | if [ "$1" = "--shim" ]; then 8 | SHIM=true 9 | shift 10 | fi 11 | 12 | COMMAND=$1 13 | 14 | if [ -z "$COMMAND" ] ; then 15 | swiftenv-help --usage which 16 | exit 1 17 | fi 18 | 19 | VERSION="$(swiftenv-version-name)" 20 | if [ "$VERSION" == "system" ]; then 21 | env PATH=/usr/bin:/bin which $COMMAND 22 | exit 23 | elif swiftenv-prefix "$VERSION" >/dev/null; then 24 | COMMAND_PATH="$(swiftenv-prefix)/usr/bin" 25 | else 26 | >&2 echo "swiftenv: version \`$VERSION' (set by $(swiftenv-version-origin)) is not installed" 27 | exit 1 28 | fi 29 | 30 | if [ -x "$COMMAND_PATH/$COMMAND" ]; then 31 | echo "$COMMAND_PATH/$COMMAND" 32 | else 33 | if $SHIM; then 34 | env PATH=/usr/bin:/bin which $COMMAND 35 | else 36 | exit 127 37 | fi 38 | fi 39 | -------------------------------------------------------------------------------- /share/man/man1/swiftenv-install.1: -------------------------------------------------------------------------------- 1 | .TH SWIFTENV\-INSTALL 1 2 | 3 | .SH NAME 4 | swiftenv-install \- Install a version of Swift 5 | 6 | .SH SYNOPSIS 7 | swiftenv install [\-\-verbose] [\-\-list] [\-\-list-snapshots] [\-\-no\-refresh] [\-\-[no\-]build] [\-\-[no\-]set\-global] [\-\-[no\-]set\-local] [--no-clean] [\-\-[no\-]user] 8 | 9 | .SH DESCRIPTION 10 | 11 | Installs a version of Swift. 12 | 13 | .SH OPTIONS 14 | 15 | \-\-verbose 16 | 17 | .RS 18 | Shows additional debugging information. 19 | .RE 20 | 21 | \-l/\-\-list 22 | 23 | .RS 24 | Lists all the Swift releases that can be installed. 25 | .RE 26 | 27 | \-\-refresh 28 | 29 | .RS 30 | On by default. 31 | When used in conjunction with \-\-list, fetches an updated information. 32 | .RE 33 | 34 | \-\-no\-refresh 35 | 36 | .RS 37 | Force using local version information with \-\-list. 38 | .RE 39 | 40 | \-\-list-snapshots 41 | 42 | .RS 43 | Lists all the Swift snapshot releases that can be installed. 44 | .RE 45 | 46 | \-\-build 47 | 48 | .RS 49 | Forces installation only from source. 50 | .RE 51 | 52 | \-\-no\-build 53 | 54 | .RS 55 | Forces installation only from binary releases of Swift. 56 | .RE 57 | 58 | \-\-no\-clean 59 | 60 | .RS 61 | Leaves the build directory intact for inspection and debugging. 62 | .RE 63 | 64 | \-\-verify\ 65 | 66 | .RS 67 | When downloading a pre-packaged tarball, also downloads the corresponding signature and verifies it with gpg. Assumes the keys already exist on the public gpg keyring. If verification fails, the version will not be installed. Signatures are only published for Linux tarballs, and not macOS packages. 68 | .RE 69 | 70 | \-\-set\-global 71 | 72 | .RS 73 | Set the installed version globally. 74 | .RE 75 | 76 | \-\-no\-set\-global 77 | 78 | .RS 79 | Don't set the installed version globally. 80 | .RE 81 | 82 | \-\-set\-local 83 | 84 | .RS 85 | Set the installed version in the local .swift-version file. 86 | .RE 87 | 88 | 89 | \-\-no\-set\-local 90 | 91 | .RS 92 | Don't set the installed version locally. 93 | .RE 94 | 95 | 96 | \-\-user 97 | 98 | .RS 99 | Install to the swiftenv user install directory for your platform. Typically ~/.swiftenv/versions 100 | .RE 101 | 102 | 103 | \-\-no\-user 104 | 105 | .RS 106 | Install to the swiftenv system install directory for your platform. On macOS this is in /Library 107 | .RE 108 | -------------------------------------------------------------------------------- /share/man/man1/swiftenv.1: -------------------------------------------------------------------------------- 1 | .TH SWIFTENV 1 2 | 3 | .SH NAME 4 | swiftenv \- Swift Version Manager 5 | 6 | .SH SYNOPSIS 7 | swiftenv [\-\-help] [\-\-version] 8 | 9 | .SH DESCRIPTION 10 | 11 | swiftenv allows you to easily install, and switch between multiple versions of 12 | Swift. 13 | 14 | swiftenv allows you to: 15 | 16 | \- Change the \fBglobal Swift version\fR, per user. 17 | 18 | \- Set a \fBper-project Swift version\fR. 19 | 20 | \- Allows you to \fBoverride the Swift version\fR with an environmental variable. 21 | 22 | .SH OPTIONS 23 | 24 | \-\-version 25 | 26 | .RS 27 | Prints the version of Swiftenv. 28 | .RE 29 | 30 | \-\-help 31 | 32 | .RS 33 | Prints the synopsis and a list of the most commonly used commands. 34 | .RE 35 | 36 | .SH COMMANDS 37 | 38 | \fBversion\fR 39 | 40 | .RS 41 | Displays the current active Swift version and why it was chosen. 42 | .RE 43 | 44 | \fBversions\fR 45 | 46 | .RS 47 | Lists all installed Swift versions, showing an asterisk next to the currently active version. 48 | .RE 49 | 50 | \fBglobal\fR [version] 51 | 52 | .RS 53 | Sets the global version of Swift 54 | .RE 55 | 56 | \fBlocal\fR [version] 57 | 58 | .RS 59 | Sets the local application-specific version of Swift 60 | .RE 61 | 62 | \fBinstall\fR 63 | 64 | .RS 65 | Installs a version of Swift 66 | .RE 67 | 68 | \fBuninstall\fR 69 | 70 | .RS 71 | Uninstalls a specific Swift version. 72 | .RE 73 | 74 | \fBrehash\fR 75 | 76 | .RS 77 | Installs shims for the Swift binaries. This command should be ran after you manually install new versions of Swift. 78 | .RE 79 | 80 | \fBwhich\fR 81 | 82 | .RS 83 | Displays the full path to the executable that would be invoked for the selected version for the given command. 84 | .RE 85 | -------------------------------------------------------------------------------- /share/swiftenv-build/2.2: -------------------------------------------------------------------------------- 1 | TAG="swift-2.2-RELEASE" 2 | fetch_github_release swift $TAG swift 3 | fetch_github_release swift-llvm $TAG llvm 4 | fetch_github_release swift-clang $TAG clang 5 | fetch_github_release swift-lldb $TAG lldb 6 | fetch_github_release swift-cmark $TAG cmark 7 | build_swift 8 | -------------------------------------------------------------------------------- /share/swiftenv-build/2.2-dev: -------------------------------------------------------------------------------- 1 | BRANCH="swift-2.2-branch" 2 | fetch_git swift $BRANCH swift 3 | fetch_git swift-llvm $BRANCH llvm 4 | fetch_git swift-clang $BRANCH clang 5 | fetch_git swift-lldb $BRANCH lldb 6 | fetch_git swift-cmark $BRANCH cmark 7 | build_swift 8 | -------------------------------------------------------------------------------- /share/swiftenv-build/2.2.1: -------------------------------------------------------------------------------- 1 | TAG="swift-2.2.1-RELEASE" 2 | fetch_github_release swift $TAG swift 3 | fetch_github_release swift-llvm $TAG llvm 4 | fetch_github_release swift-clang $TAG clang 5 | fetch_github_release swift-lldb $TAG lldb 6 | fetch_github_release swift-cmark $TAG cmark 7 | build_swift 8 | -------------------------------------------------------------------------------- /share/swiftenv-build/3.0: -------------------------------------------------------------------------------- 1 | TAG="swift-3.0-RELEASE" 2 | fetch_github_release swift $TAG swift 3 | fetch_github_release swift-llvm $TAG llvm 4 | fetch_github_release swift-clang $TAG clang 5 | fetch_github_release swift-lldb $TAG lldb 6 | fetch_github_release swift-cmark $TAG cmark 7 | fetch_github_release swift-llbuild $TAG llbuild 8 | fetch_github_release swift-package-manager $TAG swiftpm 9 | fetch_github_release swift-compiler-rt $TAG compiler-rt 10 | fetch_github_release swift-corelibs-xctest $TAG swift-corelibs-xctest 11 | fetch_github_release swift-corelibs-foundation $TAG swift-corelibs-foundation 12 | fetch_github_release swift-corelibs-libdispatch $TAG swift-corelibs-libdispatch 13 | build_swift 14 | -------------------------------------------------------------------------------- /share/swiftenv-build/3.0-dev: -------------------------------------------------------------------------------- 1 | BRANCH="swift-3.0-branch" 2 | fetch_git swift $BRANCH swift 3 | fetch_git swift-llvm $BRANCH llvm 4 | fetch_git swift-clang $BRANCH clang 5 | fetch_git swift-lldb $BRANCH lldb 6 | fetch_git swift-cmark $BRANCH cmark 7 | fetch_git swift-llbuild $BRANCH llbuild 8 | fetch_git swift-package-manager $BRANCH swiftpm 9 | fetch_git swift-compiler-rt $BRANCH compiler-rt 10 | fetch_git swift-corelibs-xctest $BRANCH swift-corelibs-xctest 11 | fetch_git swift-corelibs-foundation $BRANCH swift-corelibs-foundation 12 | fetch_git swift-corelibs-libdispatch $BRANCH swift-corelibs-libdispatch 13 | build_swift 14 | -------------------------------------------------------------------------------- /share/swiftenv-build/3.0.1: -------------------------------------------------------------------------------- 1 | TAG="swift-3.0.1-RELEASE" 2 | fetch_github_release swift $TAG swift 3 | fetch_github_release swift-llvm $TAG llvm 4 | fetch_github_release swift-clang $TAG clang 5 | fetch_github_release swift-lldb $TAG lldb 6 | fetch_github_release swift-cmark $TAG cmark 7 | fetch_github_release swift-llbuild $TAG llbuild 8 | fetch_github_release swift-package-manager $TAG swiftpm 9 | fetch_github_release swift-compiler-rt $TAG compiler-rt 10 | fetch_github_release swift-corelibs-xctest $TAG swift-corelibs-xctest 11 | fetch_github_release swift-corelibs-foundation $TAG swift-corelibs-foundation 12 | fetch_github_release swift-corelibs-libdispatch $TAG swift-corelibs-libdispatch 13 | build_swift 14 | -------------------------------------------------------------------------------- /share/swiftenv-build/3.0.2: -------------------------------------------------------------------------------- 1 | TAG="swift-3.0.2-RELEASE" 2 | fetch_github_release swift $TAG swift 3 | fetch_github_release swift-llvm $TAG llvm 4 | fetch_github_release swift-clang $TAG clang 5 | fetch_github_release swift-lldb $TAG lldb 6 | fetch_github_release swift-cmark $TAG cmark 7 | fetch_github_release swift-llbuild $TAG llbuild 8 | fetch_github_release swift-package-manager $TAG swiftpm 9 | fetch_github_release swift-compiler-rt $TAG compiler-rt 10 | fetch_github_release swift-corelibs-xctest $TAG swift-corelibs-xctest 11 | fetch_github_release swift-corelibs-foundation $TAG swift-corelibs-foundation 12 | fetch_github_release swift-corelibs-libdispatch $TAG swift-corelibs-libdispatch 13 | build_swift 14 | -------------------------------------------------------------------------------- /share/swiftenv-build/3.1: -------------------------------------------------------------------------------- 1 | TAG="swift-3.1-RELEASE" 2 | fetch_github_release swift $TAG swift 3 | fetch_github_release swift-llvm $TAG llvm 4 | fetch_github_release swift-clang $TAG clang 5 | fetch_github_release swift-lldb $TAG lldb 6 | fetch_github_release swift-cmark $TAG cmark 7 | fetch_github_release swift-llbuild $TAG llbuild 8 | fetch_github_release swift-package-manager $TAG swiftpm 9 | fetch_github_release swift-compiler-rt $TAG compiler-rt 10 | fetch_github_release swift-corelibs-xctest $TAG swift-corelibs-xctest 11 | fetch_github_release swift-corelibs-foundation $TAG swift-corelibs-foundation 12 | fetch_github_release swift-corelibs-libdispatch $TAG swift-corelibs-libdispatch 13 | build_swift 14 | -------------------------------------------------------------------------------- /share/swiftenv-build/3.1-dev: -------------------------------------------------------------------------------- 1 | BRANCH="swift-3.1-branch" 2 | fetch_git swift $BRANCH swift 3 | fetch_git swift-llvm $BRANCH llvm 4 | fetch_git swift-clang $BRANCH clang 5 | fetch_git swift-lldb $BRANCH lldb 6 | fetch_git swift-cmark $BRANCH cmark 7 | fetch_git swift-llbuild $BRANCH llbuild 8 | fetch_git swift-package-manager $BRANCH swiftpm 9 | fetch_git swift-compiler-rt $BRANCH compiler-rt 10 | fetch_git swift-corelibs-xctest $BRANCH swift-corelibs-xctest 11 | fetch_git swift-corelibs-foundation $BRANCH swift-corelibs-foundation 12 | fetch_git swift-corelibs-libdispatch $BRANCH swift-corelibs-libdispatch 13 | build_swift 14 | -------------------------------------------------------------------------------- /share/swiftenv-build/3.1.1: -------------------------------------------------------------------------------- 1 | TAG="swift-3.1.1-RELEASE" 2 | fetch_github_release swift $TAG swift 3 | fetch_github_release swift-llvm $TAG llvm 4 | fetch_github_release swift-clang $TAG clang 5 | fetch_github_release swift-lldb $TAG lldb 6 | fetch_github_release swift-cmark $TAG cmark 7 | fetch_github_release swift-llbuild $TAG llbuild 8 | fetch_github_release swift-package-manager $TAG swiftpm 9 | fetch_github_release swift-compiler-rt $TAG compiler-rt 10 | fetch_github_release swift-corelibs-xctest $TAG swift-corelibs-xctest 11 | fetch_github_release swift-corelibs-foundation $TAG swift-corelibs-foundation 12 | fetch_github_release swift-corelibs-libdispatch $TAG swift-corelibs-libdispatch 13 | build_swift 14 | -------------------------------------------------------------------------------- /share/swiftenv-build/4.0: -------------------------------------------------------------------------------- 1 | TAG="swift-4.0-RELEASE" 2 | fetch_github_release swift $TAG swift 3 | fetch_github_release swift-llvm $TAG llvm 4 | fetch_github_release swift-clang $TAG clang 5 | fetch_github_release swift-lldb $TAG lldb 6 | fetch_github_release swift-cmark $TAG cmark 7 | fetch_github_release swift-llbuild $TAG llbuild 8 | fetch_github_release swift-package-manager $TAG swiftpm 9 | fetch_github_release swift-compiler-rt $TAG compiler-rt 10 | fetch_github_release swift-corelibs-xctest $TAG swift-corelibs-xctest 11 | fetch_github_release swift-corelibs-foundation $TAG swift-corelibs-foundation 12 | fetch_github_release swift-corelibs-libdispatch $TAG swift-corelibs-libdispatch 13 | build_swift 14 | -------------------------------------------------------------------------------- /share/swiftenv-build/4.0-dev: -------------------------------------------------------------------------------- 1 | BRANCH="swift-4.0-branch" 2 | fetch_git swift $BRANCH swift 3 | fetch_git swift-llvm $BRANCH llvm 4 | fetch_git swift-clang $BRANCH clang 5 | fetch_git swift-lldb $BRANCH lldb 6 | fetch_git swift-cmark $BRANCH cmark 7 | fetch_git swift-llbuild $BRANCH llbuild 8 | fetch_git swift-package-manager $BRANCH swiftpm 9 | fetch_git swift-compiler-rt $BRANCH compiler-rt 10 | fetch_git swift-corelibs-xctest $BRANCH swift-corelibs-xctest 11 | fetch_git swift-corelibs-foundation $BRANCH swift-corelibs-foundation 12 | fetch_git swift-corelibs-libdispatch $BRANCH swift-corelibs-libdispatch 13 | build_swift 14 | -------------------------------------------------------------------------------- /share/swiftenv-build/4.0.2: -------------------------------------------------------------------------------- 1 | TAG="swift-4.0.2-RELEASE" 2 | fetch_github_release swift $TAG swift 3 | fetch_github_release swift-llvm $TAG llvm 4 | fetch_github_release swift-clang $TAG clang 5 | fetch_github_release swift-lldb $TAG lldb 6 | fetch_github_release swift-cmark $TAG cmark 7 | fetch_github_release swift-llbuild $TAG llbuild 8 | fetch_github_release swift-package-manager $TAG swiftpm 9 | fetch_github_release swift-compiler-rt $TAG compiler-rt 10 | fetch_github_release swift-corelibs-xctest $TAG swift-corelibs-xctest 11 | fetch_github_release swift-corelibs-foundation $TAG swift-corelibs-foundation 12 | fetch_github_release swift-corelibs-libdispatch $TAG swift-corelibs-libdispatch 13 | build_swift 14 | -------------------------------------------------------------------------------- /share/swiftenv-build/4.0.3: -------------------------------------------------------------------------------- 1 | TAG="swift-4.0.3-RELEASE" 2 | fetch_github_release swift $TAG swift 3 | fetch_github_release swift-llvm $TAG llvm 4 | fetch_github_release swift-clang $TAG clang 5 | fetch_github_release swift-lldb $TAG lldb 6 | fetch_github_release swift-cmark $TAG cmark 7 | fetch_github_release swift-llbuild $TAG llbuild 8 | fetch_github_release swift-package-manager $TAG swiftpm 9 | fetch_github_release swift-compiler-rt $TAG compiler-rt 10 | fetch_github_release swift-corelibs-xctest $TAG swift-corelibs-xctest 11 | fetch_github_release swift-corelibs-foundation $TAG swift-corelibs-foundation 12 | fetch_github_release swift-corelibs-libdispatch $TAG swift-corelibs-libdispatch 13 | build_swift 14 | -------------------------------------------------------------------------------- /share/swiftenv-build/4.1: -------------------------------------------------------------------------------- 1 | TAG="swift-4.1-RELEASE" 2 | fetch_github_release swift $TAG swift 3 | fetch_github_release swift-llvm $TAG llvm 4 | fetch_github_release swift-clang $TAG clang 5 | fetch_github_release swift-lldb $TAG lldb 6 | fetch_github_release swift-cmark $TAG cmark 7 | fetch_github_release swift-llbuild $TAG llbuild 8 | fetch_github_release swift-package-manager $TAG swiftpm 9 | fetch_github_release swift-compiler-rt $TAG compiler-rt 10 | fetch_github_release swift-corelibs-xctest $TAG swift-corelibs-xctest 11 | fetch_github_release swift-corelibs-foundation $TAG swift-corelibs-foundation 12 | fetch_github_release swift-corelibs-libdispatch $TAG swift-corelibs-libdispatch 13 | build_swift 14 | -------------------------------------------------------------------------------- /share/swiftenv-build/4.1-dev: -------------------------------------------------------------------------------- 1 | BRANCH="swift-4.1-branch" 2 | fetch_git swift $BRANCH swift 3 | fetch_git swift-llvm $BRANCH llvm 4 | fetch_git swift-clang $BRANCH clang 5 | fetch_git swift-lldb $BRANCH lldb 6 | fetch_git swift-cmark $BRANCH cmark 7 | fetch_git swift-llbuild $BRANCH llbuild 8 | fetch_git swift-package-manager $BRANCH swiftpm 9 | fetch_git swift-compiler-rt $BRANCH compiler-rt 10 | fetch_git swift-corelibs-xctest $BRANCH swift-corelibs-xctest 11 | fetch_git swift-corelibs-foundation $BRANCH swift-corelibs-foundation 12 | fetch_git swift-corelibs-libdispatch $BRANCH swift-corelibs-libdispatch 13 | build_swift 14 | -------------------------------------------------------------------------------- /share/swiftenv-build/4.2-dev: -------------------------------------------------------------------------------- 1 | BRANCH="swift-4.2-branch" 2 | fetch_git swift $BRANCH swift 3 | fetch_git swift-llvm $BRANCH llvm 4 | fetch_git swift-clang $BRANCH clang 5 | fetch_git swift-lldb $BRANCH lldb 6 | fetch_git swift-cmark master cmark 7 | fetch_git swift-llbuild master llbuild 8 | fetch_git swift-package-manager master swiftpm 9 | fetch_git swift-compiler-rt $BRANCH compiler-rt 10 | fetch_git swift-corelibs-xctest $BRANCH swift-corelibs-xctest 11 | fetch_git swift-corelibs-foundation $BRANCH swift-corelibs-foundation 12 | fetch_git swift-corelibs-libdispatch $BRANCH swift-corelibs-libdispatch 13 | build_swift 14 | -------------------------------------------------------------------------------- /share/swiftenv-build/5.0-dev: -------------------------------------------------------------------------------- 1 | BRANCH="swift-5.0-branch" 2 | fetch_git swift $BRANCH swift 3 | fetch_git swift-llvm "swift-4.1-branch" llvm 4 | fetch_git swift-clang "swift-4.1-branch" clang 5 | fetch_git swift-lldb $BRANCH lldb 6 | fetch_git swift-cmark master cmark 7 | fetch_git swift-llbuild master llbuild 8 | fetch_git swift-package-manager master swiftpm 9 | fetch_git swift-compiler-rt "swift-4.1-branch" compiler-rt 10 | fetch_git swift-corelibs-xctest master swift-corelibs-xctest 11 | fetch_git swift-corelibs-foundation master swift-corelibs-foundation 12 | fetch_git swift-corelibs-libdispatch master swift-corelibs-libdispatch 13 | build_swift 14 | -------------------------------------------------------------------------------- /share/swiftenv-install/4.1.3: -------------------------------------------------------------------------------- 1 | case "$PLATFORM" in 2 | 'osx' ) 3 | URL="https://swift.org/builds/swift-4.1.3-release/xcode/swift-4.1.3-RELEASE/swift-4.1.3-RELEASE-osx.pkg" 4 | ;; 5 | 6 | 'ubuntu14.04' ) 7 | URL="https://swift.org/builds/swift-4.1.3-release/ubuntu1404/swift-4.1.3-RELEASE/swift-4.1.3-RELEASE-ubuntu14.04.tar.gz" 8 | ;; 9 | 10 | 'ubuntu16.04' ) 11 | URL="https://swift.org/builds/swift-4.1.3-release/ubuntu1604/swift-4.1.3-RELEASE/swift-4.1.3-RELEASE-ubuntu16.04.tar.gz" 12 | ;; 13 | 14 | 'ubuntu16.10' ) 15 | URL="https://swift.org/builds/swift-4.1.3-release/ubuntu1610/swift-4.1.3-RELEASE/swift-4.1.3-RELEASE-ubuntu16.10.tar.gz" 16 | ;; 17 | 18 | * ) 19 | ;; 20 | esac 21 | -------------------------------------------------------------------------------- /share/swiftenv-install/4.2.4: -------------------------------------------------------------------------------- 1 | case "$PLATFORM" in 2 | 'osx' ) 3 | URL="https://swift.org/builds/swift-4.2.4-release/xcode/swift-4.2.4-RELEASE/swift-4.2.4-RELEASE-osx.pkg" 4 | ;; 5 | 6 | 'ubuntu14.04' ) 7 | URL="https://swift.org/builds/swift-4.2.4-release/ubuntu1404/swift-4.2.4-RELEASE/swift-4.2.4-RELEASE-ubuntu14.04.tar.gz" 8 | ;; 9 | 10 | 'ubuntu16.04' ) 11 | URL="https://swift.org/builds/swift-4.2.4-release/ubuntu1604/swift-4.2.4-RELEASE/swift-4.2.4-RELEASE-ubuntu16.04.tar.gz" 12 | ;; 13 | 14 | 'ubuntu18.04' ) 15 | URL="https://swift.org/builds/swift-4.2.4-release/ubuntu1804/swift-4.2.4-RELEASE/swift-4.2.4-RELEASE-ubuntu18.04.tar.gz" 16 | ;; 17 | 18 | * ) 19 | ;; 20 | esac 21 | -------------------------------------------------------------------------------- /share/swiftenv-install/5.0: -------------------------------------------------------------------------------- 1 | case "$PLATFORM" in 2 | 'osx' ) 3 | URL="https://swift.org/builds/swift-5.0-release/xcode/swift-5.0-RELEASE/swift-5.0-RELEASE-osx.pkg" 4 | ;; 5 | 6 | 'ubuntu14.04' ) 7 | URL="https://swift.org/builds/swift-5.0-release/ubuntu1404/swift-5.0-RELEASE/swift-5.0-RELEASE-ubuntu14.04.tar.gz" 8 | ;; 9 | 10 | 'ubuntu16.04' ) 11 | URL="https://swift.org/builds/swift-5.0-release/ubuntu1604/swift-5.0-RELEASE/swift-5.0-RELEASE-ubuntu16.04.tar.gz" 12 | ;; 13 | 14 | 'ubuntu18.04' ) 15 | URL="https://swift.org/builds/swift-5.0-release/ubuntu1804/swift-5.0-RELEASE/swift-5.0-RELEASE-ubuntu18.04.tar.gz" 16 | ;; 17 | 18 | * ) 19 | ;; 20 | esac 21 | -------------------------------------------------------------------------------- /share/swiftenv-install/5.0.1: -------------------------------------------------------------------------------- 1 | case "$PLATFORM" in 2 | 'osx' ) 3 | URL="https://swift.org/builds/swift-5.0.1-release/xcode/swift-5.0.1-RELEASE/swift-5.0.1-RELEASE-osx.pkg" 4 | ;; 5 | 6 | 'ubuntu14.04' ) 7 | URL="https://swift.org/builds/swift-5.0.1-release/ubuntu1404/swift-5.0.1-RELEASE/swift-5.0.1-RELEASE-ubuntu14.04.tar.gz" 8 | ;; 9 | 10 | 'ubuntu16.04' ) 11 | URL="https://swift.org/builds/swift-5.0.1-release/ubuntu1604/swift-5.0.1-RELEASE/swift-5.0.1-RELEASE-ubuntu16.04.tar.gz" 12 | ;; 13 | 14 | 'ubuntu18.04' ) 15 | URL="https://swift.org/builds/swift-5.0.1-release/ubuntu1804/swift-5.0.1-RELEASE/swift-5.0.1-RELEASE-ubuntu18.04.tar.gz" 16 | ;; 17 | 18 | * ) 19 | ;; 20 | esac 21 | -------------------------------------------------------------------------------- /share/swiftenv-install/5.0.2: -------------------------------------------------------------------------------- 1 | case "$PLATFORM" in 2 | 'osx' ) 3 | URL="https://swift.org/builds/swift-5.0.2-release/xcode/swift-5.0.2-RELEASE/swift-5.0.2-RELEASE-osx.pkg" 4 | ;; 5 | 6 | 'ubuntu14.04' ) 7 | URL="https://swift.org/builds/swift-5.0.2-release/ubuntu1404/swift-5.0.2-RELEASE/swift-5.0.2-RELEASE-ubuntu14.04.tar.gz" 8 | ;; 9 | 10 | 'ubuntu16.04' ) 11 | URL="https://swift.org/builds/swift-5.0.2-release/ubuntu1604/swift-5.0.2-RELEASE/swift-5.0.2-RELEASE-ubuntu16.04.tar.gz" 12 | ;; 13 | 14 | 'ubuntu18.04' ) 15 | URL="https://swift.org/builds/swift-5.0.2-release/ubuntu1804/swift-5.0.2-RELEASE/swift-5.0.2-RELEASE-ubuntu18.04.tar.gz" 16 | ;; 17 | 18 | * ) 19 | ;; 20 | esac 21 | -------------------------------------------------------------------------------- /share/swiftenv-install/5.0.3: -------------------------------------------------------------------------------- 1 | case "$PLATFORM" in 2 | 'osx' ) 3 | URL="https://swift.org/builds/swift-5.0.3-release/xcode/swift-5.0.3-RELEASE/swift-5.0.3-RELEASE-osx.pkg" 4 | ;; 5 | 6 | 'ubuntu14.04' ) 7 | URL="https://swift.org/builds/swift-5.0.3-release/ubuntu1404/swift-5.0.3-RELEASE/swift-5.0.3-RELEASE-ubuntu14.04.tar.gz" 8 | ;; 9 | 10 | 'ubuntu16.04' ) 11 | URL="https://swift.org/builds/swift-5.0.3-release/ubuntu1604/swift-5.0.3-RELEASE/swift-5.0.3-RELEASE-ubuntu16.04.tar.gz" 12 | ;; 13 | 14 | 'ubuntu18.04' ) 15 | URL="https://swift.org/builds/swift-5.0.3-release/ubuntu1804/swift-5.0.3-RELEASE/swift-5.0.3-RELEASE-ubuntu18.04.tar.gz" 16 | ;; 17 | 18 | * ) 19 | ;; 20 | esac 21 | -------------------------------------------------------------------------------- /share/swiftenv-install/5.1: -------------------------------------------------------------------------------- 1 | case "$PLATFORM" in 2 | 'osx' ) 3 | URL="https://swift.org/builds/swift-5.1-release/xcode/swift-5.1-RELEASE/swift-5.1-RELEASE-osx.pkg" 4 | ;; 5 | 6 | 'ubuntu14.04' ) 7 | URL="https://swift.org/builds/swift-5.1-release/ubuntu1404/swift-5.1-RELEASE/swift-5.1-RELEASE-ubuntu14.04.tar.gz" 8 | ;; 9 | 10 | 'ubuntu16.04' ) 11 | URL="https://swift.org/builds/swift-5.1-release/ubuntu1604/swift-5.1-RELEASE/swift-5.1-RELEASE-ubuntu16.04.tar.gz" 12 | ;; 13 | 14 | 'ubuntu18.04' ) 15 | URL="https://swift.org/builds/swift-5.1-release/ubuntu1804/swift-5.1-RELEASE/swift-5.1-RELEASE-ubuntu18.04.tar.gz" 16 | ;; 17 | 18 | * ) 19 | ;; 20 | esac 21 | -------------------------------------------------------------------------------- /share/swiftenv-install/5.2: -------------------------------------------------------------------------------- 1 | case "$PLATFORM" in 2 | 'osx' ) 3 | URL="https://swift.org/builds/swift-5.2-release/xcode/swift-5.2-RELEASE/swift-5.2-RELEASE-osx.pkg" 4 | ;; 5 | 6 | 'ubuntu16.04' ) 7 | URL="https://swift.org/builds/swift-5.2-release/ubuntu1604/swift-5.2-RELEASE/swift-5.2-RELEASE-ubuntu16.04.tar.gz" 8 | ;; 9 | 10 | 'ubuntu18.04' ) 11 | URL="https://swift.org/builds/swift-5.2-release/ubuntu1804/swift-5.2-RELEASE/swift-5.2-RELEASE-ubuntu18.04.tar.gz" 12 | ;; 13 | 14 | * ) 15 | ;; 16 | esac 17 | -------------------------------------------------------------------------------- /share/swiftenv-install/5.2.1: -------------------------------------------------------------------------------- 1 | case "$PLATFORM" in 2 | 'osx' ) 3 | URL="https://swift.org/builds/swift-5.2.1-release/xcode/swift-5.2.1-RELEASE/swift-5.2.1-RELEASE-osx.pkg" 4 | ;; 5 | 6 | 'ubuntu16.04' ) 7 | URL="https://swift.org/builds/swift-5.2.1-release/ubuntu1604/swift-5.2.1-RELEASE/swift-5.2.1-RELEASE-ubuntu16.04.tar.gz" 8 | ;; 9 | 10 | 'ubuntu18.04' ) 11 | URL="https://swift.org/builds/swift-5.2.1-release/ubuntu1804/swift-5.2.1-RELEASE/swift-5.2.1-RELEASE-ubuntu18.04.tar.gz" 12 | ;; 13 | 14 | * ) 15 | ;; 16 | esac 17 | -------------------------------------------------------------------------------- /share/swiftenv-install/5.2.2: -------------------------------------------------------------------------------- 1 | case "$PLATFORM" in 2 | 'osx' ) 3 | URL="https://swift.org/builds/swift-5.2.2-release/xcode/swift-5.2.2-RELEASE/swift-5.2.2-RELEASE-osx.pkg" 4 | ;; 5 | 6 | 'ubuntu16.04' ) 7 | URL="https://swift.org/builds/swift-5.2.2-release/ubuntu1604/swift-5.2.2-RELEASE/swift-5.2.2-RELEASE-ubuntu16.04.tar.gz" 8 | ;; 9 | 10 | 'ubuntu18.04' ) 11 | URL="https://swift.org/builds/swift-5.2.2-release/ubuntu1804/swift-5.2.2-RELEASE/swift-5.2.2-RELEASE-ubuntu18.04.tar.gz" 12 | ;; 13 | 14 | * ) 15 | ;; 16 | esac 17 | -------------------------------------------------------------------------------- /test/exec.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | load helpers 4 | 5 | @test "executes the given binary" { 6 | binpath="$SWIFTENV_ROOT/versions/known-1.2.0/usr/bin" 7 | mkdir -p "$binpath" 8 | echo "#!/usr/bin/env bash" > "$binpath/swift" 9 | echo "echo 'hello world'" >> "$binpath/swift" 10 | chmod +x "$binpath/swift" 11 | export SWIFT_VERSION=known-1.2.0 12 | 13 | run swiftenv exec swift 14 | [ "$status" -eq 0 ] 15 | [ "$lines" = "hello world" ] 16 | } 17 | 18 | @test "exits with the subprocesses exit code" { 19 | binpath="$SWIFTENV_ROOT/versions/known-1.2.0/usr/bin" 20 | mkdir -p "$binpath" 21 | echo "#!/usr/bin/env bash" > "$binpath/swift" 22 | echo "echo 'hello world'" >> "$binpath/swift" 23 | echo "exit 5" >> "$binpath/swift" 24 | chmod +x "$binpath/swift" 25 | export SWIFT_VERSION=known-1.2.0 26 | 27 | run swiftenv exec swift 28 | [ "$status" -eq 5 ] 29 | [ "$lines" = "hello world" ] 30 | } 31 | 32 | -------------------------------------------------------------------------------- /test/global.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | load helpers 4 | 5 | @test "shows the current set global version" { 6 | echo "testg-5.0.0" > "$SWIFTENV_ROOT/version" 7 | 8 | run swiftenv global 9 | [ "$status" -eq 0 ] 10 | [ "$lines" = "testg-5.0.0" ] 11 | } 12 | 13 | @test "allows setting a global version" { 14 | mkdir -p "$SWIFTENV_ROOT/versions/testgs-6.0.0" 15 | run swiftenv global testgs-6.0.0 16 | 17 | [ "$status" -eq 0 ] 18 | [ "$(cat "$SWIFTENV_ROOT/version")" = "testgs-6.0.0" ] 19 | } 20 | -------------------------------------------------------------------------------- /test/helpers.bash: -------------------------------------------------------------------------------- 1 | export SWIFTENV_ROOT="$BATS_TMPDIR/swiftenv/root" 2 | export SWIFTENV_HOME="$BATS_TMPDIR/swiftenv/home" 3 | export XDG_CACHE_HOME="$BATS_TMPDIR/cache" 4 | 5 | setup() { 6 | mkdir -p "$SWIFTENV_ROOT" 7 | mkdir -p "$SWIFTENV_HOME" 8 | cd "$SWIFTENV_HOME" 9 | } 10 | 11 | teardown() { 12 | rm -fr "$SWIFTENV_ROOT" "$SWIFTENV_HOME" 13 | } 14 | -------------------------------------------------------------------------------- /test/init.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | load helpers 4 | 5 | @test "adds shims to PATH for fish" { 6 | run swiftenv init - fish 7 | [ "$status" -eq 0 ] 8 | [ "$lines" = "set -gx PATH '$SWIFTENV_ROOT/shims' \$PATH" ] 9 | } 10 | 11 | @test "adds shims to PATH for bash" { 12 | run swiftenv init - bash 13 | [ "$status" -eq 0 ] 14 | [ "$lines" = "export PATH=\"$SWIFTENV_ROOT/shims:\${PATH}\"" ] 15 | } 16 | 17 | @test "adds shims to PATH for zsh" { 18 | run swiftenv init - bash 19 | [ "$status" -eq 0 ] 20 | [ "$lines" = "export PATH=\"$SWIFTENV_ROOT/shims:\${PATH}\"" ] 21 | } 22 | 23 | @test "adds rehash by default if shims do not exist" { 24 | run swiftenv init - bash 25 | [ "$status" -eq 0 ] 26 | [ "${lines[1]}" = "command swiftenv rehash 2>/dev/null" ] 27 | } 28 | 29 | @test "does not add rehash by default if shims do exist" { 30 | if [[ "$(uname -s)" != "Darwin" ]]; then 31 | skip 32 | fi 33 | 34 | mkdir -p "$SWIFTENV_ROOT/shims" 35 | swiftenv --version > "$SWIFTENV_ROOT/shims/.version" 36 | run swiftenv init - bash 37 | [ "$status" -eq 0 ] 38 | [ "${lines[2]}" = "" ] 39 | } 40 | 41 | @test "rehash is enabled by default, even when shims do exist" { 42 | if [[ "$(uname -s)" == "Darwin" ]]; then 43 | skip 44 | fi 45 | 46 | mkdir -p "$SWIFTENV_ROOT/shims" 47 | swiftenv --version > "$SWIFTENV_ROOT/shims/.version" 48 | run swiftenv init - bash 49 | [ "$status" -eq 0 ] 50 | [ "${lines[1]}" = "command swiftenv rehash 2>/dev/null" ] 51 | } 52 | 53 | @test "adds rehash when you pass --rehash" { 54 | mkdir -p "$SWIFTENV_ROOT/shims" 55 | run swiftenv init - bash --rehash 56 | [ "$status" -eq 0 ] 57 | [ "${lines[1]}" = "command swiftenv rehash 2>/dev/null" ] 58 | } 59 | 60 | @test "does not add rehash when you pass --no-rehash" { 61 | run swiftenv init - bash --no-rehash 62 | [ "$status" -eq 0 ] 63 | [ "${lines[1]}" = "" ] 64 | } 65 | -------------------------------------------------------------------------------- /test/install.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | load helpers 4 | 5 | @test "invoking with an installed version" { 6 | mkdir -p "$SWIFTENV_ROOT/versions/1.0.0" 7 | run swiftenv install 1.0.0 8 | [ "$status" -eq 1 ] 9 | [ "$lines" = "1.0.0 is already installed." ] 10 | } 11 | 12 | @test "invoking with an installed version with skip existing" { 13 | mkdir -p "$SWIFTENV_ROOT/versions/1.0.0" 14 | run swiftenv install -s 1.0.0 15 | [ "$status" -eq 0 ] 16 | [ "$lines" = "1.0.0 is already installed." ] 17 | } 18 | 19 | @test "invoking with the --build option and a version that doesn't have a build profile" { 20 | run swiftenv install --build 1.0.0 21 | [ "$status" -eq 1 ] 22 | [ "$lines" = "We don't have build instructions for 1.0.0." ] 23 | } 24 | 25 | @test "invoking with the --build option and a URL as the version" { 26 | run swiftenv install --build https://swiftenv.fuller.li/test 27 | [ "$status" -eq 1 ] 28 | [ "$lines" = 'The given URL must be to a binary version of Swift, you cannot use the `--build` option with a URL.' ] 29 | } 30 | 31 | @test "invoking with the --list option" { 32 | run swiftenv install --list --no-refresh 33 | [ "$status" -eq 0 ] 34 | [ "${lines[0]}" = "2.2-dev" ] 35 | [ "${lines[1]}" = "2.2" ] 36 | [ "${lines[2]}" = "2.2.1" ] 37 | [ "${lines[3]}" = "3.0-dev" ] 38 | } 39 | 40 | @test "invoking with the -l option as a short option of install --list" { 41 | run swiftenv install -l --no-refresh 42 | [ "$status" -eq 0 ] 43 | [ "${lines[0]}" = "2.2-dev" ] 44 | [ "${lines[1]}" = "2.2" ] 45 | [ "${lines[2]}" = "2.2.1" ] 46 | [ "${lines[3]}" = "3.0-dev" ] 47 | } 48 | 49 | @test "invoking with an installed version with skip existing saves global version" { 50 | mkdir -p "$SWIFTENV_ROOT/versions/1.0.0" 51 | run swiftenv install -s 1.0.0 52 | [ "$status" -eq 0 ] 53 | [ "$lines" = "1.0.0 is already installed." ] 54 | [ "$(cat $SWIFTENV_ROOT/version)" = "1.0.0" ] 55 | } 56 | 57 | @test "invoking with an installed version with skip existing disable global version" { 58 | mkdir -p "$SWIFTENV_ROOT/versions/1.0.0" 59 | run swiftenv install --no-set-global -s 1.0.0 60 | [ "$status" -eq 0 ] 61 | [ "$lines" = "1.0.0 is already installed." ] 62 | [ ! -r "$SWIFTENV_ROOT/version" ] 63 | } 64 | 65 | @test "invoking with an installed version with skip existing and set local version" { 66 | mkdir -p "$SWIFTENV_ROOT/versions/1.0.0" 67 | run swiftenv install --set-local -s 1.0.0 68 | [ "$status" -eq 0 ] 69 | [ "$lines" = "1.0.0 is already installed." ] 70 | [ ! -r "$SWIFTENV_ROOT/version" ] 71 | [ "$(cat .swift-version)" = "1.0.0" ] 72 | } 73 | 74 | @test "invoking with an installed version with skip existing and set global and local version" { 75 | mkdir -p "$SWIFTENV_ROOT/versions/1.0.0" 76 | run swiftenv install --set-local --set-global -s 1.0.0 77 | [ "$status" -eq 0 ] 78 | [ "$lines" = "1.0.0 is already installed." ] 79 | [ "$(cat $SWIFTENV_ROOT/version)" = "1.0.0" ] 80 | [ "$(cat .swift-version)" = "1.0.0" ] 81 | } 82 | 83 | @test "invoking with an installed version with local version doesnt set global" { 84 | echo '1.0.0' > .swift-version 85 | mkdir -p "$SWIFTENV_ROOT/versions/1.0.0" 86 | run swiftenv install -s 87 | [ "$status" -eq 0 ] 88 | [ "$lines" = "1.0.0 is already installed." ] 89 | [ ! -r "$SWIFTENV_ROOT/version" ] 90 | } 91 | 92 | @test "does't allow --no-user on non-macOS" { 93 | if [[ "$(uname)" == "Darwin" ]]; then 94 | skip 95 | fi 96 | 97 | run swiftenv install 4.1 --no-user 98 | [ "$status" -eq 1 ] 99 | [ "$lines" = "--no-user installation is only supported on macOS." ] 100 | } 101 | -------------------------------------------------------------------------------- /test/integration/install.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | @test "can install a Swift stable release" { 4 | if [[ "$(uname -s)" == "Darwin" ]]; then 5 | # Xcode already bundles Swift 6 | skip 7 | fi 8 | 9 | run swiftenv install 5.3 10 | echo "Installed" 11 | echo $lines 12 | [ "$status" -eq 0 ] 13 | 14 | run env SWIFT_VERSION="5.3" swift --version 15 | echo "Version" 16 | echo $lines 17 | [ "$status" -eq 0 ] 18 | [[ "${lines[0]}" = *"Swift version 5.3 (swift-5.3-RELEASE)" ]] 19 | } 20 | 21 | @test "can install a binary Swift development snapshot" { 22 | run swiftenv install DEVELOPMENT-SNAPSHOT-2021-08-17-a 23 | echo "Installed" 24 | echo $lines 25 | [ "$status" -eq 0 ] 26 | 27 | run env SWIFT_VERSION="DEVELOPMENT-SNAPSHOT-2021-08-17-a" swift --version 28 | echo "Version" 29 | echo $lines 30 | [ "$status" -eq 0 ] 31 | [[ "${lines[0]}" = *"Swift version 5.6-dev"* ]] 32 | } 33 | 34 | @test "can install a versioned binary Swift development snapshot" { 35 | run swiftenv install 5.5-DEVELOPMENT-SNAPSHOT-2021-08-19-a 36 | echo "Installed" 37 | echo $lines 38 | [ "$status" -eq 0 ] 39 | 40 | run env SWIFT_VERSION="5.5-DEVELOPMENT-SNAPSHOT-2021-08-19-a" swift --version 41 | echo "Version" 42 | echo $lines 43 | [ "$status" -eq 0 ] 44 | [[ "${lines[0]}" = *"Swift version 5.5-dev"* ]] 45 | } 46 | -------------------------------------------------------------------------------- /test/local.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | load helpers 4 | 5 | @test "shows the current set local version" { 6 | echo "testl-5.0.0" > "$SWIFTENV_HOME/.swift-version" 7 | 8 | run swiftenv local 9 | [ "$status" -eq 0 ] 10 | [ "$lines" = "testl-5.0.0" ] 11 | } 12 | 13 | @test "allows setting a local version" { 14 | mkdir -p "$SWIFTENV_ROOT/versions/testls-6.0.0" 15 | run swiftenv local testls-6.0.0 16 | 17 | [ "$status" -eq 0 ] 18 | [ "$(cat "$SWIFTENV_HOME/.swift-version")" = "testls-6.0.0" ] 19 | } 20 | -------------------------------------------------------------------------------- /test/prefix.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | load helpers 4 | 5 | @test "invoking with an unknown version errors" { 6 | run swiftenv prefix unknown-1.0.0 7 | [ "$status" -eq 1 ] 8 | [ "$lines" = "unknown-1.0.0 is not installed" ] 9 | } 10 | 11 | @test "invoking with known version inside 'SWIFTENV_ROOT/versions'" { 12 | mkdir -p "$SWIFTENV_ROOT/versions/known-1.2.0" 13 | run swiftenv prefix known-1.2.0 14 | [ "$status" -eq 0 ] 15 | [ "$lines" = "$SWIFTENV_ROOT/versions/known-1.2.0" ] 16 | } 17 | -------------------------------------------------------------------------------- /test/swiftenv.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | @test "invoking without any arguments returns help" { 4 | run swiftenv 5 | [ "$status" -eq 1 ] 6 | [ "${lines[0]}" = "Usage: swiftenv [--version] " ] 7 | } 8 | 9 | @test "invoking with '--version' returns the version" { 10 | run swiftenv --version 11 | [ "$status" -eq 0 ] 12 | [[ "$lines" = "swiftenv "* ]] 13 | } 14 | 15 | @test "invoking with '--help' returns the help" { 16 | run swiftenv --help 17 | [ "$status" -eq 0 ] 18 | [ "${lines[0]}" = "Usage: swiftenv [--version] " ] 19 | } 20 | 21 | @test "invoking with command and '--help' returns the help for given command" { 22 | run swiftenv version --help 23 | [ "$status" -eq 0 ] 24 | [ "${lines[0]}" = "Usage: swiftenv version" ] 25 | } 26 | 27 | @test "invoking with command that has a man page and '--help' shows the man page" { 28 | if [ "$CI" ]; then 29 | skip 30 | fi 31 | 32 | run swiftenv install --help 33 | [ "$status" -eq 0 ] 34 | [[ "${lines[0]}" = "SWIFTENV-INSTALL(1)"* ]] 35 | } 36 | 37 | @test "invoking with an unknown command errors" { 38 | run swiftenv unknown-command 39 | [ "$status" -eq 1 ] 40 | [ "$lines" = "no such command \`unknown-command'" ] 41 | } 42 | 43 | @test "invoking with an unknown command and '--help' errors" { 44 | run swiftenv x --help 45 | [ "$status" -eq 1 ] 46 | [ "$lines" = "swiftenv: no such command 'x'" ] 47 | } 48 | -------------------------------------------------------------------------------- /test/version.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | load helpers 4 | 5 | @test "defaults the version to system" { 6 | run swiftenv version 7 | [ "$status" -eq 0 ] 8 | [ "$lines" = "system (set by $SWIFTENV_ROOT/version)" ] 9 | 10 | run swiftenv version-name 11 | [ "$status" -eq 0 ] 12 | [ "$lines" = "system" ] 13 | } 14 | 15 | @test "allows setting a global version" { 16 | echo "test-5.0.0" > $SWIFTENV_ROOT/version 17 | 18 | run swiftenv version 19 | [ "$status" -eq 0 ] 20 | [ "$lines" = "test-5.0.0 (set by $SWIFTENV_ROOT/version)" ] 21 | 22 | run swiftenv version-name 23 | [ "$status" -eq 0 ] 24 | [ "$lines" = "test-5.0.0" ] 25 | } 26 | 27 | @test "allows overridding the global version with a local version" { 28 | echo "test-5.0.0" > $SWIFTENV_ROOT/version 29 | echo "test-4.0.0" > $SWIFTENV_HOME/.swift-version 30 | 31 | run swiftenv version 32 | [ "$status" -eq 0 ] 33 | [ "$lines" = "test-4.0.0 (set by $SWIFTENV_HOME/.swift-version)" ] 34 | 35 | run swiftenv version-name 36 | [ "$status" -eq 0 ] 37 | [ "$lines" = "test-4.0.0" ] 38 | } 39 | 40 | @test "allows overridding both global and local version with env variable" { 41 | echo "test-5.0.0" > $SWIFTENV_ROOT/version 42 | echo "test-4.0.0" > $SWIFTENV_HOME/.swift-version 43 | export SWIFT_VERSION="test-4.5.0" 44 | 45 | run swiftenv version 46 | [ "$status" -eq 0 ] 47 | [ "$lines" = "test-4.5.0 (set by SWIFT_VERSION environment variable)" ] 48 | 49 | run swiftenv version-name 50 | [ "$status" -eq 0 ] 51 | [ "$lines" = "test-4.5.0" ] 52 | } 53 | -------------------------------------------------------------------------------- /test/versions.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | load helpers 4 | 5 | @test "shows the available versions" { 6 | mkdir -p "$SWIFTENV_ROOT/versions/a" "$SWIFTENV_ROOT/versions/b" "$SWIFTENV_ROOT/versions/c" 7 | 8 | run swiftenv versions 9 | [ "$status" -eq 0 ] 10 | [ "${lines[0]}" = "* system" ] 11 | [ "${lines[1]}" = " a" ] 12 | [ "${lines[2]}" = " b" ] 13 | [ "${lines[3]}" = " c" ] 14 | } 15 | 16 | @test "indicates the selected version, and why" { 17 | mkdir -p "$SWIFTENV_ROOT/versions/a" "$SWIFTENV_ROOT/versions/b" "$SWIFTENV_ROOT/versions/c" 18 | echo "b" > "$SWIFTENV_ROOT/version" 19 | 20 | run swiftenv versions 21 | [ "$status" -eq 0 ] 22 | [ "${lines[0]}" = " a" ] 23 | [ "${lines[1]}" = "* b (set by $SWIFTENV_ROOT/version)" ] 24 | [ "${lines[2]}" = " c" ] 25 | } 26 | -------------------------------------------------------------------------------- /test/which.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | load helpers 4 | 5 | @test "finds binary from selected Swift version" { 6 | if [[ "$OSTYPE" == "msys" ]]; then 7 | skip 8 | fi 9 | 10 | binpath="$SWIFTENV_ROOT/versions/known-1.2.0/usr/bin" 11 | mkdir -p "$binpath" 12 | touch "$binpath/swift" 13 | chmod +x "$binpath/swift" 14 | export SWIFT_VERSION=known-1.2.0 15 | 16 | run swiftenv which swift 17 | [ "$status" -eq 0 ] 18 | [ "$lines" = "$binpath/swift" ] 19 | } 20 | 21 | @test "errors when it cannot find the binary in selected Swift version" { 22 | binpath="$SWIFTENV_ROOT/versions/known-1.2.0/usr/bin" 23 | mkdir -p "$binpath" 24 | touch "$binpath/swift" 25 | chmod +x "$binpath/swift" 26 | export SWIFT_VERSION=known-1.2.0 27 | 28 | run swiftenv which swiftc 29 | [ "$status" -eq 127 ] 30 | } 31 | --------------------------------------------------------------------------------