aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.github/workflows/ci.yaml41
-rw-r--r--Cargo.lock43
-rw-r--r--crates/ra_hir_expand/src/name.rs5
-rw-r--r--crates/ra_lsp_server/src/caps.rs1
-rw-r--r--xtask/src/cmd.rs53
-rw-r--r--xtask/src/help.rs46
-rw-r--r--xtask/src/install.rs178
-rw-r--r--xtask/src/lib.rs125
-rw-r--r--xtask/src/main.rs301
-rw-r--r--xtask/src/pre_commit.rs36
10 files changed, 423 insertions, 406 deletions
diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml
index abdec602e..e7e0d599e 100644
--- a/.github/workflows/ci.yaml
+++ b/.github/workflows/ci.yaml
@@ -18,6 +18,8 @@ jobs:
18 RUSTFLAGS: -D warnings 18 RUSTFLAGS: -D warnings
19 CARGO_INCREMENTAL: 0 19 CARGO_INCREMENTAL: 0
20 RUN_SLOW_TESTS: 1 20 RUN_SLOW_TESTS: 1
21 RUSTUP_MAX_RETRIES: 10
22 CARGO_NET_RETRY: 10
21 steps: 23 steps:
22 24
23 - name: Checkout repository 25 - name: Checkout repository
@@ -39,7 +41,19 @@ jobs:
39 override: true 41 override: true
40 components: rustfmt, rust-src 42 components: rustfmt, rust-src
41 43
42 - name: Cargo target cache 44 - name: Cache cargo registry
45 uses: actions/cache@v1
46 with:
47 path: ~/.cargo/registry
48 key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}
49
50 - name: Cache cargo index
51 uses: actions/cache@v1
52 with:
53 path: ~/.cargo/git
54 key: ${{ runner.os }}-cargo-index-${{ hashFiles('**/Cargo.lock') }}
55
56 - name: Cache cargo target dir
43 uses: actions/cache@v1 57 uses: actions/cache@v1
44 with: 58 with:
45 path: target 59 path: target
@@ -56,28 +70,13 @@ jobs:
56 with: 70 with:
57 command: test 71 command: test
58 72
59 - name: Prepare build directory for cache (UNIX) 73 - name: Prepare cache
60 if: matrix.os == 'ubuntu-latest' || matrix.os == 'macos-latest' 74 run: cargo xtask pre-cache
61 run: |
62 find ./target/debug -maxdepth 1 -type f -delete \
63 && rm -fr ./target/debug/{deps,.fingerprint}/{*ra_*,*heavy_test*,*gen_lsp*,*thread_worker*} \
64 && rm -f ./target/.rustc_info.json \
65 && rm ./target/.slow_tests_cookie
66 75
67 - name: Prepare build directory for cache (Windows) 76 - name: Prepare cache 2
68 if: matrix.os == 'windows-latest' 77 if: matrix.os == 'windows-latest'
69 run: >- 78 run: Remove-Item ./target/debug/xtask.exe
70 (Get-ChildItem ./target/debug -Recurse -Depth 1 -File | Remove-Item) -and 79
71 (Remove-Item -Force -Recurse ./target/debug/deps/*ra_*) -and
72 (Remove-Item -Force -Recurse ./target/debug/deps/*heavy_test*) -and
73 (Remove-Item -Force -Recurse ./target/debug/deps/*gen_lsp*) -and
74 (Remove-Item -Force -Recurse ./target/debug/deps/*thread_worker*) -and
75 (Remove-Item -Force -Recurse ./target/debug/.fingerprint/*ra_*) -and
76 (Remove-Item -Force -Recurse ./target/debug/.fingerprint/*heavy_test*) -and
77 (Remove-Item -Force -Recurse ./target/debug/.fingerprint/*gen_lsp*) -and
78 (Remove-Item -Force -Recurse ./target/debug/.fingerprint/*thread_worker*) -and
79 (Remove-Item -Force ./target/.rustc_info.json) -and
80 (Remove-Item ./target/.slow_tests_cookie)
81 80
82 type-script: 81 type-script:
83 name: TypeScript 82 name: TypeScript
diff --git a/Cargo.lock b/Cargo.lock
index 79f28f7cd..312240bd2 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -54,7 +54,7 @@ name = "backtrace-sys"
54version = "0.1.32" 54version = "0.1.32"
55source = "registry+https://github.com/rust-lang/crates.io-index" 55source = "registry+https://github.com/rust-lang/crates.io-index"
56dependencies = [ 56dependencies = [
57 "cc 1.0.48 (registry+https://github.com/rust-lang/crates.io-index)", 57 "cc 1.0.49 (registry+https://github.com/rust-lang/crates.io-index)",
58 "libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)", 58 "libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)",
59] 59]
60 60
@@ -115,7 +115,7 @@ dependencies = [
115 115
116[[package]] 116[[package]]
117name = "cc" 117name = "cc"
118version = "1.0.48" 118version = "1.0.49"
119source = "registry+https://github.com/rust-lang/crates.io-index" 119source = "registry+https://github.com/rust-lang/crates.io-index"
120 120
121[[package]] 121[[package]]
@@ -402,12 +402,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
402 402
403[[package]] 403[[package]]
404name = "getrandom" 404name = "getrandom"
405version = "0.1.13" 405version = "0.1.14"
406source = "registry+https://github.com/rust-lang/crates.io-index" 406source = "registry+https://github.com/rust-lang/crates.io-index"
407dependencies = [ 407dependencies = [
408 "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", 408 "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)",
409 "libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)", 409 "libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)",
410 "wasi 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", 410 "wasi 0.9.0+wasi-snapshot-preview1 (registry+https://github.com/rust-lang/crates.io-index)",
411] 411]
412 412
413[[package]] 413[[package]]
@@ -466,7 +466,7 @@ dependencies = [
466 466
467[[package]] 467[[package]]
468name = "inotify" 468name = "inotify"
469version = "0.6.1" 469version = "0.7.0"
470source = "registry+https://github.com/rust-lang/crates.io-index" 470source = "registry+https://github.com/rust-lang/crates.io-index"
471dependencies = [ 471dependencies = [
472 "bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", 472 "bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -532,7 +532,7 @@ name = "jemalloc-sys"
532version = "0.3.2" 532version = "0.3.2"
533source = "registry+https://github.com/rust-lang/crates.io-index" 533source = "registry+https://github.com/rust-lang/crates.io-index"
534dependencies = [ 534dependencies = [
535 "cc 1.0.48 (registry+https://github.com/rust-lang/crates.io-index)", 535 "cc 1.0.49 (registry+https://github.com/rust-lang/crates.io-index)",
536 "fs_extra 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", 536 "fs_extra 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
537 "libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)", 537 "libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)",
538] 538]
@@ -619,7 +619,7 @@ dependencies = [
619 619
620[[package]] 620[[package]]
621name = "lsp-types" 621name = "lsp-types"
622version = "0.68.0" 622version = "0.68.1"
623source = "registry+https://github.com/rust-lang/crates.io-index" 623source = "registry+https://github.com/rust-lang/crates.io-index"
624dependencies = [ 624dependencies = [
625 "base64 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", 625 "base64 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -700,15 +700,14 @@ dependencies = [
700 700
701[[package]] 701[[package]]
702name = "notify" 702name = "notify"
703version = "4.0.14" 703version = "4.0.15"
704source = "registry+https://github.com/rust-lang/crates.io-index" 704source = "registry+https://github.com/rust-lang/crates.io-index"
705dependencies = [ 705dependencies = [
706 "bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", 706 "bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
707 "filetime 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", 707 "filetime 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
708 "fsevent 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", 708 "fsevent 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
709 "fsevent-sys 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)", 709 "fsevent-sys 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
710 "inotify 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", 710 "inotify 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
711 "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
712 "libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)", 711 "libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)",
713 "mio 0.6.21 (registry+https://github.com/rust-lang/crates.io-index)", 712 "mio 0.6.21 (registry+https://github.com/rust-lang/crates.io-index)",
714 "mio-extras 2.0.6 (registry+https://github.com/rust-lang/crates.io-index)", 713 "mio-extras 2.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -900,7 +899,7 @@ dependencies = [
900 "insta 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)", 899 "insta 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)",
901 "jod-thread 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", 900 "jod-thread 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
902 "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", 901 "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
903 "lsp-types 0.68.0 (registry+https://github.com/rust-lang/crates.io-index)", 902 "lsp-types 0.68.1 (registry+https://github.com/rust-lang/crates.io-index)",
904 "parking_lot 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)", 903 "parking_lot 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)",
905 "serde_json 1.0.44 (registry+https://github.com/rust-lang/crates.io-index)", 904 "serde_json 1.0.44 (registry+https://github.com/rust-lang/crates.io-index)",
906] 905]
@@ -1064,7 +1063,7 @@ dependencies = [
1064 "jod-thread 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", 1063 "jod-thread 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
1065 "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", 1064 "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
1066 "lsp-server 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", 1065 "lsp-server 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
1067 "lsp-types 0.68.0 (registry+https://github.com/rust-lang/crates.io-index)", 1066 "lsp-types 0.68.1 (registry+https://github.com/rust-lang/crates.io-index)",
1068 "parking_lot 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)", 1067 "parking_lot 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)",
1069 "ra_cargo_watch 0.1.0", 1068 "ra_cargo_watch 0.1.0",
1070 "ra_ide 0.1.0", 1069 "ra_ide 0.1.0",
@@ -1170,7 +1169,7 @@ dependencies = [
1170 "crossbeam-channel 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", 1169 "crossbeam-channel 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
1171 "jod-thread 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", 1170 "jod-thread 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
1172 "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", 1171 "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
1173 "notify 4.0.14 (registry+https://github.com/rust-lang/crates.io-index)", 1172 "notify 4.0.15 (registry+https://github.com/rust-lang/crates.io-index)",
1174 "parking_lot 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)", 1173 "parking_lot 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)",
1175 "relative-path 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", 1174 "relative-path 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
1176 "rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", 1175 "rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -1208,7 +1207,7 @@ name = "rand"
1208version = "0.7.2" 1207version = "0.7.2"
1209source = "registry+https://github.com/rust-lang/crates.io-index" 1208source = "registry+https://github.com/rust-lang/crates.io-index"
1210dependencies = [ 1209dependencies = [
1211 "getrandom 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)", 1210 "getrandom 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)",
1212 "libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)", 1211 "libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)",
1213 "rand_chacha 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", 1212 "rand_chacha 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
1214 "rand_core 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", 1213 "rand_core 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -1252,7 +1251,7 @@ name = "rand_core"
1252version = "0.5.1" 1251version = "0.5.1"
1253source = "registry+https://github.com/rust-lang/crates.io-index" 1252source = "registry+https://github.com/rust-lang/crates.io-index"
1254dependencies = [ 1253dependencies = [
1255 "getrandom 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)", 1254 "getrandom 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)",
1256] 1255]
1257 1256
1258[[package]] 1257[[package]]
@@ -1698,7 +1697,7 @@ dependencies = [
1698 1697
1699[[package]] 1698[[package]]
1700name = "wasi" 1699name = "wasi"
1701version = "0.7.0" 1700version = "0.9.0+wasi-snapshot-preview1"
1702source = "registry+https://github.com/rust-lang/crates.io-index" 1701source = "registry+https://github.com/rust-lang/crates.io-index"
1703 1702
1704[[package]] 1703[[package]]
@@ -1783,7 +1782,7 @@ dependencies = [
1783"checksum byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a7c3dd8985a7111efc5c80b44e23ecdd8c007de8ade3b96595387e812b957cf5" 1782"checksum byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a7c3dd8985a7111efc5c80b44e23ecdd8c007de8ade3b96595387e812b957cf5"
1784"checksum c2-chacha 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "214238caa1bf3a496ec3392968969cab8549f96ff30652c9e56885329315f6bb" 1783"checksum c2-chacha 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "214238caa1bf3a496ec3392968969cab8549f96ff30652c9e56885329315f6bb"
1785"checksum cargo_metadata 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)" = "46e3374c604fb39d1a2f35ed5e4a4e30e60d01fab49446e08f1b3e9a90aef202" 1784"checksum cargo_metadata 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)" = "46e3374c604fb39d1a2f35ed5e4a4e30e60d01fab49446e08f1b3e9a90aef202"
1786"checksum cc 1.0.48 (registry+https://github.com/rust-lang/crates.io-index)" = "f52a465a666ca3d838ebbf08b241383421412fe7ebb463527bba275526d89f76" 1785"checksum cc 1.0.49 (registry+https://github.com/rust-lang/crates.io-index)" = "e450b8da92aa6f274e7c6437692f9f2ce6d701fb73bacfcf87897b3f89a4c20e"
1787"checksum cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" 1786"checksum cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822"
1788"checksum chalk-derive 0.1.0 (git+https://github.com/rust-lang/chalk.git?rev=ff65b5ac9860f3c36bd892c865ab23d5ff0bbae5)" = "<none>" 1787"checksum chalk-derive 0.1.0 (git+https://github.com/rust-lang/chalk.git?rev=ff65b5ac9860f3c36bd892c865ab23d5ff0bbae5)" = "<none>"
1789"checksum chalk-engine 0.9.0 (git+https://github.com/rust-lang/chalk.git?rev=ff65b5ac9860f3c36bd892c865ab23d5ff0bbae5)" = "<none>" 1788"checksum chalk-engine 0.9.0 (git+https://github.com/rust-lang/chalk.git?rev=ff65b5ac9860f3c36bd892c865ab23d5ff0bbae5)" = "<none>"
@@ -1818,14 +1817,14 @@ dependencies = [
1818"checksum fuchsia-cprng 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba" 1817"checksum fuchsia-cprng 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba"
1819"checksum fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82" 1818"checksum fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82"
1820"checksum fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7" 1819"checksum fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7"
1821"checksum getrandom 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)" = "e7db7ca94ed4cd01190ceee0d8a8052f08a247aa1b469a7f68c6a3b71afcf407" 1820"checksum getrandom 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)" = "7abc8dd8451921606d809ba32e95b6111925cd2906060d2dcc29c070220503eb"
1822"checksum globset 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)" = "925aa2cac82d8834e2b2a4415b6f6879757fb5c0928fc445ae76461a12eed8f2" 1821"checksum globset 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)" = "925aa2cac82d8834e2b2a4415b6f6879757fb5c0928fc445ae76461a12eed8f2"
1823"checksum heck 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "20564e78d53d2bb135c343b3f47714a56af2061f1c928fdb541dc7b9fdd94205" 1822"checksum heck 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "20564e78d53d2bb135c343b3f47714a56af2061f1c928fdb541dc7b9fdd94205"
1824"checksum hermit-abi 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "eff2656d88f158ce120947499e971d743c05dbcbed62e5bd2f38f1698bbc3772" 1823"checksum hermit-abi 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "eff2656d88f158ce120947499e971d743c05dbcbed62e5bd2f38f1698bbc3772"
1825"checksum humantime 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "df004cfca50ef23c36850aaaa59ad52cc70d0e90243c3c7737a4dd32dc7a3c4f" 1824"checksum humantime 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "df004cfca50ef23c36850aaaa59ad52cc70d0e90243c3c7737a4dd32dc7a3c4f"
1826"checksum idna 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "02e2673c30ee86b5b96a9cb52ad15718aa1f966f5ab9ad54a8b95d5ca33120a9" 1825"checksum idna 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "02e2673c30ee86b5b96a9cb52ad15718aa1f966f5ab9ad54a8b95d5ca33120a9"
1827"checksum indexmap 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712d7b3ea5827fcb9d4fda14bf4da5f136f0db2ae9c8f4bd4e2d1c6fde4e6db2" 1826"checksum indexmap 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712d7b3ea5827fcb9d4fda14bf4da5f136f0db2ae9c8f4bd4e2d1c6fde4e6db2"
1828"checksum inotify 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "40b54539f3910d6f84fbf9a643efd6e3aa6e4f001426c0329576128255994718" 1827"checksum inotify 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "24e40d6fd5d64e2082e0c796495c8ef5ad667a96d03e5aaa0becfd9d47bcbfb8"
1829"checksum inotify-sys 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "e74a1aa87c59aeff6ef2cc2fa62d41bc43f54952f55652656b18a02fd5e356c0" 1828"checksum inotify-sys 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "e74a1aa87c59aeff6ef2cc2fa62d41bc43f54952f55652656b18a02fd5e356c0"
1830"checksum insta 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)" = "0d499dc062e841590a67230d853bce62d0abeb91304927871670b7c55c461349" 1829"checksum insta 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)" = "0d499dc062e841590a67230d853bce62d0abeb91304927871670b7c55c461349"
1831"checksum iovec 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "b2b3ea6ff95e175473f8ffe6a7eb7c00d054240321b84c57051175fe3c1e075e" 1830"checksum iovec 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "b2b3ea6ff95e175473f8ffe6a7eb7c00d054240321b84c57051175fe3c1e075e"
@@ -1845,7 +1844,7 @@ dependencies = [
1845"checksum lock_api 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "79b2de95ecb4691949fea4716ca53cdbcfccb2c612e19644a8bad05edcf9f47b" 1844"checksum lock_api 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "79b2de95ecb4691949fea4716ca53cdbcfccb2c612e19644a8bad05edcf9f47b"
1846"checksum log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)" = "14b6052be84e6b71ab17edffc2eeabf5c2c3ae1fdb464aae35ac50c67a44e1f7" 1845"checksum log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)" = "14b6052be84e6b71ab17edffc2eeabf5c2c3ae1fdb464aae35ac50c67a44e1f7"
1847"checksum lsp-server 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "5383e043329615624bbf45e1ba27bd75c176762b2592855c659bc28ac580a06b" 1846"checksum lsp-server 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "5383e043329615624bbf45e1ba27bd75c176762b2592855c659bc28ac580a06b"
1848"checksum lsp-types 0.68.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1b08121a463f43ee67f09da45c0a61d447793adc8dc23e52b009e8cf80278a16" 1847"checksum lsp-types 0.68.1 (registry+https://github.com/rust-lang/crates.io-index)" = "19b79f72914b929daa263483134b8974962cdebc731593b11508afb7f9acec80"
1849"checksum matches 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "7ffc5c5338469d4d3ea17d269fa8ea3512ad247247c30bd2df69e68309ed0a08" 1848"checksum matches 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "7ffc5c5338469d4d3ea17d269fa8ea3512ad247247c30bd2df69e68309ed0a08"
1850"checksum memchr 2.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "88579771288728879b57485cc7d6b07d648c9f0141eb955f8ab7f9d45394468e" 1849"checksum memchr 2.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "88579771288728879b57485cc7d6b07d648c9f0141eb955f8ab7f9d45394468e"
1851"checksum memoffset 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "75189eb85871ea5c2e2c15abbdd541185f63b408415e5051f5cac122d8c774b9" 1850"checksum memoffset 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "75189eb85871ea5c2e2c15abbdd541185f63b408415e5051f5cac122d8c774b9"
@@ -1853,7 +1852,7 @@ dependencies = [
1853"checksum mio-extras 2.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "52403fe290012ce777c4626790c8951324a2b9e3316b3143779c72b029742f19" 1852"checksum mio-extras 2.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "52403fe290012ce777c4626790c8951324a2b9e3316b3143779c72b029742f19"
1854"checksum miow 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "8c1f2f3b1cf331de6896aabf6e9d55dca90356cc9960cca7eaaf408a355ae919" 1853"checksum miow 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "8c1f2f3b1cf331de6896aabf6e9d55dca90356cc9960cca7eaaf408a355ae919"
1855"checksum net2 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)" = "42550d9fb7b6684a6d404d9fa7250c2eb2646df731d1c06afc06dcee9e1bcf88" 1854"checksum net2 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)" = "42550d9fb7b6684a6d404d9fa7250c2eb2646df731d1c06afc06dcee9e1bcf88"
1856"checksum notify 4.0.14 (registry+https://github.com/rust-lang/crates.io-index)" = "199628fc33b21bc767baa057490b00b382ecbae030803a7b36292422d15b778b" 1855"checksum notify 4.0.15 (registry+https://github.com/rust-lang/crates.io-index)" = "80ae4a7688d1fab81c5bf19c64fc8db920be8d519ce6336ed4e7efe024724dbd"
1857"checksum num-traits 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)" = "d4c81ffc11c212fa327657cb19dd85eb7419e163b5b076bede2bdb5c974c07e4" 1856"checksum num-traits 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)" = "d4c81ffc11c212fa327657cb19dd85eb7419e163b5b076bede2bdb5c974c07e4"
1858"checksum num_cpus 1.11.1 (registry+https://github.com/rust-lang/crates.io-index)" = "76dac5ed2a876980778b8b85f75a71b6cbf0db0b1232ee12f826bccb00d09d72" 1857"checksum num_cpus 1.11.1 (registry+https://github.com/rust-lang/crates.io-index)" = "76dac5ed2a876980778b8b85f75a71b6cbf0db0b1232ee12f826bccb00d09d72"
1859"checksum once_cell 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "891f486f630e5c5a4916c7e16c4b24a53e78c860b646e9f8e005e4f16847bfed" 1858"checksum once_cell 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "891f486f630e5c5a4916c7e16c4b24a53e78c860b646e9f8e005e4f16847bfed"
@@ -1932,7 +1931,7 @@ dependencies = [
1932"checksum uuid 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "9fde2f6a4bea1d6e007c4ad38c6839fa71cbb63b6dbf5b595aa38dc9b1093c11" 1931"checksum uuid 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "9fde2f6a4bea1d6e007c4ad38c6839fa71cbb63b6dbf5b595aa38dc9b1093c11"
1933"checksum version_check 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)" = "078775d0255232fb988e6fccf26ddc9d1ac274299aaedcedce21c6f72cc533ce" 1932"checksum version_check 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)" = "078775d0255232fb988e6fccf26ddc9d1ac274299aaedcedce21c6f72cc533ce"
1934"checksum walkdir 2.2.9 (registry+https://github.com/rust-lang/crates.io-index)" = "9658c94fa8b940eab2250bd5a457f9c48b748420d71293b165c8cdbe2f55f71e" 1933"checksum walkdir 2.2.9 (registry+https://github.com/rust-lang/crates.io-index)" = "9658c94fa8b940eab2250bd5a457f9c48b748420d71293b165c8cdbe2f55f71e"
1935"checksum wasi 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b89c3ce4ce14bdc6fb6beaf9ec7928ca331de5df7e5ea278375642a2f478570d" 1934"checksum wasi 0.9.0+wasi-snapshot-preview1 (registry+https://github.com/rust-lang/crates.io-index)" = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519"
1936"checksum winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a" 1935"checksum winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a"
1937"checksum winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)" = "8093091eeb260906a183e6ae1abdba2ef5ef2257a21801128899c3fc699229c6" 1936"checksum winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)" = "8093091eeb260906a183e6ae1abdba2ef5ef2257a21801128899c3fc699229c6"
1938"checksum winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc" 1937"checksum winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc"
diff --git a/crates/ra_hir_expand/src/name.rs b/crates/ra_hir_expand/src/name.rs
index e62693b68..b3fa1efba 100644
--- a/crates/ra_hir_expand/src/name.rs
+++ b/crates/ra_hir_expand/src/name.rs
@@ -93,7 +93,10 @@ impl AsName for ast::FieldKind {
93 fn as_name(&self) -> Name { 93 fn as_name(&self) -> Name {
94 match self { 94 match self {
95 ast::FieldKind::Name(nr) => nr.as_name(), 95 ast::FieldKind::Name(nr) => nr.as_name(),
96 ast::FieldKind::Index(idx) => Name::new_tuple_field(idx.text().parse().unwrap()), 96 ast::FieldKind::Index(idx) => {
97 let idx = idx.text().parse::<usize>().unwrap_or(0);
98 Name::new_tuple_field(idx)
99 }
97 } 100 }
98 } 101 }
99} 102}
diff --git a/crates/ra_lsp_server/src/caps.rs b/crates/ra_lsp_server/src/caps.rs
index adfc9fb2c..db502c200 100644
--- a/crates/ra_lsp_server/src/caps.rs
+++ b/crates/ra_lsp_server/src/caps.rs
@@ -56,6 +56,7 @@ pub fn server_capabilities() -> ServerCapabilities {
56 color_provider: None, 56 color_provider: None,
57 execute_command_provider: None, 57 execute_command_provider: None,
58 workspace: None, 58 workspace: None,
59 call_hierarchy_provider: None,
59 experimental: Default::default(), 60 experimental: Default::default(),
60 } 61 }
61} 62}
diff --git a/xtask/src/cmd.rs b/xtask/src/cmd.rs
new file mode 100644
index 000000000..2027f4893
--- /dev/null
+++ b/xtask/src/cmd.rs
@@ -0,0 +1,53 @@
1use std::process::{Command, Output, Stdio};
2
3use anyhow::{Context, Result};
4
5use crate::project_root;
6
7pub struct Cmd<'a> {
8 pub unix: &'a str,
9 pub windows: &'a str,
10 pub work_dir: &'a str,
11}
12
13impl Cmd<'_> {
14 pub fn run(self) -> Result<()> {
15 if cfg!(windows) {
16 run(self.windows, self.work_dir)
17 } else {
18 run(self.unix, self.work_dir)
19 }
20 }
21 pub fn run_with_output(self) -> Result<Output> {
22 if cfg!(windows) {
23 run_with_output(self.windows, self.work_dir)
24 } else {
25 run_with_output(self.unix, self.work_dir)
26 }
27 }
28}
29
30pub fn run(cmdline: &str, dir: &str) -> Result<()> {
31 do_run(cmdline, dir, &mut |c| {
32 c.stdout(Stdio::inherit());
33 })
34 .map(|_| ())
35}
36
37pub fn run_with_output(cmdline: &str, dir: &str) -> Result<Output> {
38 do_run(cmdline, dir, &mut |_| {})
39}
40
41fn do_run(cmdline: &str, dir: &str, f: &mut dyn FnMut(&mut Command)) -> Result<Output> {
42 eprintln!("\nwill run: {}", cmdline);
43 let proj_dir = project_root().join(dir);
44 let mut args = cmdline.split_whitespace();
45 let exec = args.next().unwrap();
46 let mut cmd = Command::new(exec);
47 f(cmd.args(args).current_dir(proj_dir).stderr(Stdio::inherit()));
48 let output = cmd.output().with_context(|| format!("running `{}`", cmdline))?;
49 if !output.status.success() {
50 anyhow::bail!("`{}` exited with {}", cmdline, output.status);
51 }
52 Ok(output)
53}
diff --git a/xtask/src/help.rs b/xtask/src/help.rs
deleted file mode 100644
index f4e25dcde..000000000
--- a/xtask/src/help.rs
+++ /dev/null
@@ -1,46 +0,0 @@
1//! FIXME: write short doc here
2
3pub const GLOBAL_HELP: &str = "tasks
4
5USAGE:
6 ra_tools <SUBCOMMAND>
7
8FLAGS:
9 -h, --help Prints help information
10
11SUBCOMMANDS:
12 format
13 install-pre-commit-hook
14 fuzz-tests
15 codegen
16 install
17 lint";
18
19pub const INSTALL_HELP: &str = "ra_tools-install
20
21USAGE:
22 ra_tools.exe install [FLAGS]
23
24FLAGS:
25 --client-code
26 -h, --help Prints help information
27 --jemalloc
28 --server";
29
30pub fn print_no_param_subcommand_help(subcommand: &str) {
31 eprintln!(
32 "ra_tools-{}
33
34USAGE:
35 ra_tools {}
36
37FLAGS:
38 -h, --help Prints help information",
39 subcommand, subcommand
40 );
41}
42
43pub const INSTALL_RA_CONFLICT: &str =
44 "error: The argument `--server` cannot be used with `--client-code`
45
46For more information try --help";
diff --git a/xtask/src/install.rs b/xtask/src/install.rs
new file mode 100644
index 000000000..fa82633de
--- /dev/null
+++ b/xtask/src/install.rs
@@ -0,0 +1,178 @@
1//! Installs rust-analyzer language server and/or editor plugin.
2
3use std::{env, path::PathBuf, str};
4
5use anyhow::{Context, Result};
6
7use crate::cmd::{run, run_with_output, Cmd};
8
9// Latest stable, feel free to send a PR if this lags behind.
10const REQUIRED_RUST_VERSION: u32 = 40;
11
12pub struct InstallCmd {
13 pub client: Option<ClientOpt>,
14 pub server: Option<ServerOpt>,
15}
16
17pub enum ClientOpt {
18 VsCode,
19}
20
21pub struct ServerOpt {
22 pub jemalloc: bool,
23}
24
25impl InstallCmd {
26 pub fn run(self) -> Result<()> {
27 if cfg!(target_os = "macos") {
28 fix_path_for_mac().context("Fix path for mac")?
29 }
30 if let Some(server) = self.server {
31 install_server(server).context("install server")?;
32 }
33 if let Some(client) = self.client {
34 install_client(client).context("install client")?;
35 }
36 Ok(())
37 }
38}
39
40fn fix_path_for_mac() -> Result<()> {
41 let mut vscode_path: Vec<PathBuf> = {
42 const COMMON_APP_PATH: &str =
43 r"/Applications/Visual Studio Code.app/Contents/Resources/app/bin";
44 const ROOT_DIR: &str = "";
45 let home_dir = match env::var("HOME") {
46 Ok(home) => home,
47 Err(e) => anyhow::bail!("Failed getting HOME from environment with error: {}.", e),
48 };
49
50 [ROOT_DIR, &home_dir]
51 .iter()
52 .map(|dir| String::from(*dir) + COMMON_APP_PATH)
53 .map(PathBuf::from)
54 .filter(|path| path.exists())
55 .collect()
56 };
57
58 if !vscode_path.is_empty() {
59 let vars = match env::var_os("PATH") {
60 Some(path) => path,
61 None => anyhow::bail!("Could not get PATH variable from env."),
62 };
63
64 let mut paths = env::split_paths(&vars).collect::<Vec<_>>();
65 paths.append(&mut vscode_path);
66 let new_paths = env::join_paths(paths).context("build env PATH")?;
67 env::set_var("PATH", &new_paths);
68 }
69
70 Ok(())
71}
72
73fn install_client(ClientOpt::VsCode: ClientOpt) -> Result<()> {
74 let npm_version = Cmd {
75 unix: r"npm --version",
76 windows: r"cmd.exe /c npm --version",
77 work_dir: "./editors/code",
78 }
79 .run();
80
81 if npm_version.is_err() {
82 eprintln!("\nERROR: `npm --version` failed, `npm` is required to build the VS Code plugin")
83 }
84
85 Cmd { unix: r"npm install", windows: r"cmd.exe /c npm install", work_dir: "./editors/code" }
86 .run()?;
87 Cmd {
88 unix: r"npm run package --scripts-prepend-node-path",
89 windows: r"cmd.exe /c npm run package",
90 work_dir: "./editors/code",
91 }
92 .run()?;
93
94 let code_binary = ["code", "code-insiders", "codium", "code-oss"].iter().find(|bin| {
95 Cmd {
96 unix: &format!("{} --version", bin),
97 windows: &format!("cmd.exe /c {}.cmd --version", bin),
98 work_dir: "./editors/code",
99 }
100 .run()
101 .is_ok()
102 });
103
104 let code_binary = match code_binary {
105 Some(it) => it,
106 None => anyhow::bail!("Can't execute `code --version`. Perhaps it is not in $PATH?"),
107 };
108
109 Cmd {
110 unix: &format!(r"{} --install-extension ./ra-lsp-0.0.1.vsix --force", code_binary),
111 windows: &format!(
112 r"cmd.exe /c {}.cmd --install-extension ./ra-lsp-0.0.1.vsix --force",
113 code_binary
114 ),
115 work_dir: "./editors/code",
116 }
117 .run()?;
118
119 let output = Cmd {
120 unix: &format!(r"{} --list-extensions", code_binary),
121 windows: &format!(r"cmd.exe /c {}.cmd --list-extensions", code_binary),
122 work_dir: ".",
123 }
124 .run_with_output()?;
125
126 if !str::from_utf8(&output.stdout)?.contains("ra-lsp") {
127 anyhow::bail!(
128 "Could not install the Visual Studio Code extension. \
129 Please make sure you have at least NodeJS 10.x together with the latest version of VS Code installed and try again."
130 );
131 }
132
133 Ok(())
134}
135
136fn install_server(opts: ServerOpt) -> Result<()> {
137 let mut old_rust = false;
138 if let Ok(output) = run_with_output("cargo --version", ".") {
139 if let Ok(stdout) = String::from_utf8(output.stdout) {
140 println!("{}", stdout);
141 if !check_version(&stdout, REQUIRED_RUST_VERSION) {
142 old_rust = true;
143 }
144 }
145 }
146
147 if old_rust {
148 eprintln!(
149 "\nWARNING: at least rust 1.{}.0 is required to compile rust-analyzer\n",
150 REQUIRED_RUST_VERSION,
151 )
152 }
153
154 let res = if opts.jemalloc {
155 run("cargo install --path crates/ra_lsp_server --locked --force --features jemalloc", ".")
156 } else {
157 run("cargo install --path crates/ra_lsp_server --locked --force", ".")
158 };
159
160 if res.is_err() && old_rust {
161 eprintln!(
162 "\nWARNING: at least rust 1.{}.0 is required to compile rust-analyzer\n",
163 REQUIRED_RUST_VERSION,
164 )
165 }
166
167 res
168}
169
170fn check_version(version_output: &str, min_minor_version: u32) -> bool {
171 // Parse second the number out of
172 // cargo 1.39.0-beta (1c6ec66d5 2019-09-30)
173 let minor: Option<u32> = version_output.split('.').nth(1).and_then(|it| it.parse().ok());
174 match minor {
175 None => true,
176 Some(minor) => minor >= min_minor_version,
177 }
178}
diff --git a/xtask/src/lib.rs b/xtask/src/lib.rs
index 51a868dee..e46c21db7 100644
--- a/xtask/src/lib.rs
+++ b/xtask/src/lib.rs
@@ -1,18 +1,22 @@
1//! FIXME: write short doc here 1//! FIXME: write short doc here
2 2
3mod cmd;
4pub mod install;
5pub mod pre_commit;
6
3pub mod codegen; 7pub mod codegen;
4mod ast_src; 8mod ast_src;
5 9
6use anyhow::Context; 10use anyhow::Context;
7pub use anyhow::Result;
8use std::{ 11use std::{
9 env, fs, 12 env, fs,
10 io::{Error as IoError, ErrorKind},
11 path::{Path, PathBuf}, 13 path::{Path, PathBuf},
12 process::{Command, Output, Stdio}, 14 process::{Command, Stdio},
13}; 15};
14 16
15use crate::codegen::Mode; 17use crate::{cmd::run, codegen::Mode};
18
19pub use anyhow::Result;
16 20
17const TOOLCHAIN: &str = "stable"; 21const TOOLCHAIN: &str = "stable";
18 22
@@ -26,40 +30,6 @@ pub fn project_root() -> PathBuf {
26 .to_path_buf() 30 .to_path_buf()
27} 31}
28 32
29pub struct Cmd<'a> {
30 pub unix: &'a str,
31 pub windows: &'a str,
32 pub work_dir: &'a str,
33}
34
35impl Cmd<'_> {
36 pub fn run(self) -> Result<()> {
37 if cfg!(windows) {
38 run(self.windows, self.work_dir)
39 } else {
40 run(self.unix, self.work_dir)
41 }
42 }
43 pub fn run_with_output(self) -> Result<Output> {
44 if cfg!(windows) {
45 run_with_output(self.windows, self.work_dir)
46 } else {
47 run_with_output(self.unix, self.work_dir)
48 }
49 }
50}
51
52pub fn run(cmdline: &str, dir: &str) -> Result<()> {
53 do_run(cmdline, dir, |c| {
54 c.stdout(Stdio::inherit());
55 })
56 .map(|_| ())
57}
58
59pub fn run_with_output(cmdline: &str, dir: &str) -> Result<Output> {
60 do_run(cmdline, dir, |_| {})
61}
62
63pub fn run_rustfmt(mode: Mode) -> Result<()> { 33pub fn run_rustfmt(mode: Mode) -> Result<()> {
64 match Command::new("rustup") 34 match Command::new("rustup")
65 .args(&["run", TOOLCHAIN, "--", "cargo", "fmt", "--version"]) 35 .args(&["run", TOOLCHAIN, "--", "cargo", "fmt", "--version"])
@@ -79,23 +49,11 @@ pub fn run_rustfmt(mode: Mode) -> Result<()> {
79 Ok(()) 49 Ok(())
80} 50}
81 51
82pub fn install_rustfmt() -> Result<()> { 52fn install_rustfmt() -> Result<()> {
83 run(&format!("rustup toolchain install {}", TOOLCHAIN), ".")?; 53 run(&format!("rustup toolchain install {}", TOOLCHAIN), ".")?;
84 run(&format!("rustup component add rustfmt --toolchain {}", TOOLCHAIN), ".") 54 run(&format!("rustup component add rustfmt --toolchain {}", TOOLCHAIN), ".")
85} 55}
86 56
87pub fn install_pre_commit_hook() -> Result<()> {
88 let result_path =
89 PathBuf::from(format!("./.git/hooks/pre-commit{}", std::env::consts::EXE_SUFFIX));
90 if !result_path.exists() {
91 let me = std::env::current_exe()?;
92 fs::copy(me, result_path)?;
93 } else {
94 Err(IoError::new(ErrorKind::AlreadyExists, "Git hook already created"))?;
95 }
96 Ok(())
97}
98
99pub fn run_clippy() -> Result<()> { 57pub fn run_clippy() -> Result<()> {
100 match Command::new("rustup") 58 match Command::new("rustup")
101 .args(&["run", TOOLCHAIN, "--", "cargo", "clippy", "--version"]) 59 .args(&["run", TOOLCHAIN, "--", "cargo", "clippy", "--version"])
@@ -125,7 +83,7 @@ pub fn run_clippy() -> Result<()> {
125 Ok(()) 83 Ok(())
126} 84}
127 85
128pub fn install_clippy() -> Result<()> { 86fn install_clippy() -> Result<()> {
129 run(&format!("rustup toolchain install {}", TOOLCHAIN), ".")?; 87 run(&format!("rustup toolchain install {}", TOOLCHAIN), ".")?;
130 run(&format!("rustup component add clippy --toolchain {}", TOOLCHAIN), ".") 88 run(&format!("rustup component add clippy --toolchain {}", TOOLCHAIN), ".")
131} 89}
@@ -144,41 +102,40 @@ pub fn run_fuzzer() -> Result<()> {
144 run("rustup run nightly -- cargo fuzz run parser", "./crates/ra_syntax") 102 run("rustup run nightly -- cargo fuzz run parser", "./crates/ra_syntax")
145} 103}
146 104
147pub fn reformat_staged_files() -> Result<()> { 105/// Cleans the `./target` dir after the build such that only
148 run_rustfmt(Mode::Overwrite)?; 106/// dependencies are cached on CI.
149 let root = project_root(); 107pub fn run_pre_cache() -> Result<()> {
150 let output = Command::new("git") 108 let slow_tests_cookie = Path::new("./target/.slow_tests_cookie");
151 .arg("diff") 109 if !slow_tests_cookie.exists() {
152 .arg("--diff-filter=MAR") 110 panic!("slow tests were skipped on CI!")
153 .arg("--name-only")
154 .arg("--cached")
155 .current_dir(&root)
156 .output()?;
157 if !output.status.success() {
158 anyhow::bail!(
159 "`git diff --diff-filter=MAR --name-only --cached` exited with {}",
160 output.status
161 );
162 } 111 }
163 for line in String::from_utf8(output.stdout)?.lines() { 112 rm_rf(slow_tests_cookie)?;
164 run(&format!("git update-index --add {}", root.join(line).to_string_lossy()), ".")?; 113
114 for entry in Path::new("./target/debug").read_dir()? {
115 let entry = entry?;
116 if entry.file_type().map(|it| it.is_file()).ok() == Some(true) {
117 // Can't delete yourself on windows :-(
118 if !entry.path().ends_with("xtask.exe") {
119 rm_rf(&entry.path())?
120 }
121 }
122 }
123
124 fs::remove_file("./target/.rustc_info.json")?;
125 let to_delete = ["ra_", "heavy_test"];
126 for &dir in ["./target/debug/deps", "target/debug/.fingerprint"].iter() {
127 for entry in Path::new(dir).read_dir()? {
128 let entry = entry?;
129 if to_delete.iter().any(|&it| entry.path().display().to_string().contains(it)) {
130 rm_rf(&entry.path())?
131 }
132 }
165 } 133 }
134
166 Ok(()) 135 Ok(())
167} 136}
168 137
169fn do_run<F>(cmdline: &str, dir: &str, mut f: F) -> Result<Output> 138fn rm_rf(path: &Path) -> Result<()> {
170where 139 if path.is_file() { fs::remove_file(path) } else { fs::remove_dir_all(path) }
171 F: FnMut(&mut Command), 140 .with_context(|| format!("failed to remove {:?}", path))
172{
173 eprintln!("\nwill run: {}", cmdline);
174 let proj_dir = project_root().join(dir);
175 let mut args = cmdline.split_whitespace();
176 let exec = args.next().unwrap();
177 let mut cmd = Command::new(exec);
178 f(cmd.args(args).current_dir(proj_dir).stderr(Stdio::inherit()));
179 let output = cmd.output().with_context(|| format!("running `{}`", cmdline))?;
180 if !output.status.success() {
181 anyhow::bail!("`{}` exited with {}", cmdline, output.status);
182 }
183 Ok(output)
184} 141}
diff --git a/xtask/src/main.rs b/xtask/src/main.rs
index 9cefad925..053453e6e 100644
--- a/xtask/src/main.rs
+++ b/xtask/src/main.rs
@@ -7,272 +7,109 @@
7//! 7//!
8//! This binary is integrated into the `cargo` command line by using an alias in 8//! This binary is integrated into the `cargo` command line by using an alias in
9//! `.cargo/config`. 9//! `.cargo/config`.
10mod help;
11 10
12use std::{env, fmt::Write, path::PathBuf, str}; 11use std::env;
13 12
14use anyhow::Context;
15use pico_args::Arguments; 13use pico_args::Arguments;
16use xtask::{ 14use xtask::{
17 codegen::{self, Mode}, 15 codegen::{self, Mode},
18 install_pre_commit_hook, reformat_staged_files, run, run_clippy, run_fuzzer, run_rustfmt, 16 install::{ClientOpt, InstallCmd, ServerOpt},
19 run_with_output, Cmd, Result, 17 pre_commit, run_clippy, run_fuzzer, run_pre_cache, run_rustfmt, Result,
20}; 18};
21 19
22// Latest stable, feel free to send a PR if this lags behind.
23const REQUIRED_RUST_VERSION: u32 = 40;
24
25struct InstallOpt {
26 client: Option<ClientOpt>,
27 server: Option<ServerOpt>,
28}
29
30enum ClientOpt {
31 VsCode,
32}
33
34struct ServerOpt {
35 jemalloc: bool,
36}
37
38fn main() -> Result<()> { 20fn main() -> Result<()> {
39 if env::args().next().map(|it| it.contains("pre-commit")) == Some(true) { 21 if env::args().next().map(|it| it.contains("pre-commit")) == Some(true) {
40 return reformat_staged_files(); 22 return pre_commit::run_hook();
41 } 23 }
42 24
43 let subcommand = match std::env::args_os().nth(1) { 25 let subcommand = std::env::args().nth(1).unwrap_or_default();
44 None => { 26 let mut args = Arguments::from_vec(std::env::args_os().skip(2).collect());
45 eprintln!("{}", help::GLOBAL_HELP); 27
46 return Ok(()); 28 match subcommand.as_str() {
47 }
48 Some(s) => s,
49 };
50 let mut matches = Arguments::from_vec(std::env::args_os().skip(2).collect());
51 let subcommand = &*subcommand.to_string_lossy();
52 match subcommand {
53 "install" => { 29 "install" => {
54 if matches.contains(["-h", "--help"]) { 30 if args.contains(["-h", "--help"]) {
55 eprintln!("{}", help::INSTALL_HELP); 31 eprintln!(
32 "\
33cargo xtask install
34Install rust-analyzer server or editor plugin.
35
36USAGE:
37 cargo xtask install [FLAGS]
38
39FLAGS:
40 --client-code Install only VS Code plugin
41 --server Install only the language server
42 --jemalloc Use jemalloc for server
43 -h, --help Prints help information
44 "
45 );
56 return Ok(()); 46 return Ok(());
57 } 47 }
58 let server = matches.contains("--server"); 48 let server = args.contains("--server");
59 let client_code = matches.contains("--client-code"); 49 let client_code = args.contains("--client-code");
60 if server && client_code { 50 if server && client_code {
61 eprintln!("{}", help::INSTALL_RA_CONFLICT); 51 eprintln!(
52 "error: The argument `--server` cannot be used with `--client-code`\n\n\
53 For more information try --help"
54 );
62 return Ok(()); 55 return Ok(());
63 } 56 }
64 let jemalloc = matches.contains("--jemalloc"); 57
65 matches.finish().or_else(handle_extra_flags)?; 58 let jemalloc = args.contains("--jemalloc");
66 let opts = InstallOpt { 59
60 args.finish()?;
61
62 InstallCmd {
67 client: if server { None } else { Some(ClientOpt::VsCode) }, 63 client: if server { None } else { Some(ClientOpt::VsCode) },
68 server: if client_code { None } else { Some(ServerOpt { jemalloc }) }, 64 server: if client_code { None } else { Some(ServerOpt { jemalloc }) },
69 }; 65 }
70 install(opts)? 66 .run()
71 } 67 }
72 "codegen" => { 68 "codegen" => {
73 if matches.contains(["-h", "--help"]) { 69 args.finish()?;
74 help::print_no_param_subcommand_help(&subcommand);
75 return Ok(());
76 }
77 codegen::generate_syntax(Mode::Overwrite)?; 70 codegen::generate_syntax(Mode::Overwrite)?;
78 codegen::generate_parser_tests(Mode::Overwrite)?; 71 codegen::generate_parser_tests(Mode::Overwrite)?;
79 codegen::generate_assists_docs(Mode::Overwrite)?; 72 codegen::generate_assists_docs(Mode::Overwrite)?;
73 Ok(())
80 } 74 }
81 "format" => { 75 "format" => {
82 if matches.contains(["-h", "--help"]) { 76 args.finish()?;
83 help::print_no_param_subcommand_help(&subcommand); 77 run_rustfmt(Mode::Overwrite)
84 return Ok(());
85 }
86 run_rustfmt(Mode::Overwrite)?
87 } 78 }
88 "install-pre-commit-hook" => { 79 "install-pre-commit-hook" => {
89 if matches.contains(["-h", "--help"]) { 80 args.finish()?;
90 help::print_no_param_subcommand_help(&subcommand); 81 pre_commit::install_hook()
91 return Ok(());
92 }
93 install_pre_commit_hook()?
94 } 82 }
95 "lint" => { 83 "lint" => {
96 if matches.contains(["-h", "--help"]) { 84 args.finish()?;
97 help::print_no_param_subcommand_help(&subcommand); 85 run_clippy()
98 return Ok(());
99 }
100 run_clippy()?
101 } 86 }
102 "fuzz-tests" => { 87 "fuzz-tests" => {
103 if matches.contains(["-h", "--help"]) { 88 args.finish()?;
104 help::print_no_param_subcommand_help(&subcommand); 89 run_fuzzer()
105 return Ok(());
106 }
107 run_fuzzer()?
108 } 90 }
109 _ => eprintln!("{}", help::GLOBAL_HELP), 91 "pre-cache" => {
110 } 92 args.finish()?;
111 Ok(()) 93 run_pre_cache()
112}
113
114fn handle_extra_flags(e: pico_args::Error) -> Result<()> {
115 if let pico_args::Error::UnusedArgsLeft(flags) = e {
116 let mut invalid_flags = String::new();
117 for flag in flags {
118 write!(&mut invalid_flags, "{}, ", flag)?;
119 }
120 let (invalid_flags, _) = invalid_flags.split_at(invalid_flags.len() - 2);
121 anyhow::bail!("Invalid flags: {}", invalid_flags)
122 } else {
123 anyhow::bail!(e.to_string())
124 }
125}
126
127fn install(opts: InstallOpt) -> Result<()> {
128 if cfg!(target_os = "macos") {
129 fix_path_for_mac().context("Fix path for mac")?
130 }
131 if let Some(server) = opts.server {
132 install_server(server).context("install server")?;
133 }
134 if let Some(client) = opts.client {
135 install_client(client).context("install client")?;
136 }
137 Ok(())
138}
139
140fn fix_path_for_mac() -> Result<()> {
141 let mut vscode_path: Vec<PathBuf> = {
142 const COMMON_APP_PATH: &str =
143 r"/Applications/Visual Studio Code.app/Contents/Resources/app/bin";
144 const ROOT_DIR: &str = "";
145 let home_dir = match env::var("HOME") {
146 Ok(home) => home,
147 Err(e) => anyhow::bail!("Failed getting HOME from environment with error: {}.", e),
148 };
149
150 [ROOT_DIR, &home_dir]
151 .iter()
152 .map(|dir| String::from(*dir) + COMMON_APP_PATH)
153 .map(PathBuf::from)
154 .filter(|path| path.exists())
155 .collect()
156 };
157
158 if !vscode_path.is_empty() {
159 let vars = match env::var_os("PATH") {
160 Some(path) => path,
161 None => anyhow::bail!("Could not get PATH variable from env."),
162 };
163
164 let mut paths = env::split_paths(&vars).collect::<Vec<_>>();
165 paths.append(&mut vscode_path);
166 let new_paths = env::join_paths(paths).context("build env PATH")?;
167 env::set_var("PATH", &new_paths);
168 }
169
170 Ok(())
171}
172
173fn install_client(ClientOpt::VsCode: ClientOpt) -> Result<()> {
174 let npm_version = Cmd {
175 unix: r"npm --version",
176 windows: r"cmd.exe /c npm --version",
177 work_dir: "./editors/code",
178 }
179 .run();
180
181 if npm_version.is_err() {
182 eprintln!("\nERROR: `npm --version` failed, `npm` is required to build the VS Code plugin")
183 }
184
185 Cmd { unix: r"npm install", windows: r"cmd.exe /c npm install", work_dir: "./editors/code" }
186 .run()?;
187 Cmd {
188 unix: r"npm run package --scripts-prepend-node-path",
189 windows: r"cmd.exe /c npm run package",
190 work_dir: "./editors/code",
191 }
192 .run()?;
193
194 let code_binary = ["code", "code-insiders", "codium"].iter().find(|bin| {
195 Cmd {
196 unix: &format!("{} --version", bin),
197 windows: &format!("cmd.exe /c {}.cmd --version", bin),
198 work_dir: "./editors/code",
199 } 94 }
200 .run() 95 _ => {
201 .is_ok() 96 eprintln!(
202 }); 97 "\
203 98cargo xtask
204 let code_binary = match code_binary { 99Run custom build command.
205 Some(it) => it, 100
206 None => anyhow::bail!("Can't execute `code --version`. Perhaps it is not in $PATH?"), 101USAGE:
207 }; 102 cargo xtask <SUBCOMMAND>
208 103
209 Cmd { 104SUBCOMMANDS:
210 unix: &format!(r"{} --install-extension ./ra-lsp-0.0.1.vsix --force", code_binary), 105 format
211 windows: &format!( 106 install-pre-commit-hook
212 r"cmd.exe /c {}.cmd --install-extension ./ra-lsp-0.0.1.vsix --force", 107 fuzz-tests
213 code_binary 108 codegen
214 ), 109 install
215 work_dir: "./editors/code", 110 lint"
216 } 111 );
217 .run()?; 112 Ok(())
218
219 let output = Cmd {
220 unix: &format!(r"{} --list-extensions", code_binary),
221 windows: &format!(r"cmd.exe /c {}.cmd --list-extensions", code_binary),
222 work_dir: ".",
223 }
224 .run_with_output()?;
225
226 if !str::from_utf8(&output.stdout)?.contains("ra-lsp") {
227 anyhow::bail!(
228 "Could not install the Visual Studio Code extension. \
229 Please make sure you have at least NodeJS 10.x together with the latest version of VS Code installed and try again."
230 );
231 }
232
233 Ok(())
234}
235
236fn install_server(opts: ServerOpt) -> Result<()> {
237 let mut old_rust = false;
238 if let Ok(output) = run_with_output("cargo --version", ".") {
239 if let Ok(stdout) = String::from_utf8(output.stdout) {
240 println!("{}", stdout);
241 if !check_version(&stdout, REQUIRED_RUST_VERSION) {
242 old_rust = true;
243 }
244 } 113 }
245 } 114 }
246
247 if old_rust {
248 eprintln!(
249 "\nWARNING: at least rust 1.{}.0 is required to compile rust-analyzer\n",
250 REQUIRED_RUST_VERSION,
251 )
252 }
253
254 let res = if opts.jemalloc {
255 run("cargo install --path crates/ra_lsp_server --locked --force --features jemalloc", ".")
256 } else {
257 run("cargo install --path crates/ra_lsp_server --locked --force", ".")
258 };
259
260 if res.is_err() && old_rust {
261 eprintln!(
262 "\nWARNING: at least rust 1.{}.0 is required to compile rust-analyzer\n",
263 REQUIRED_RUST_VERSION,
264 )
265 }
266
267 res
268}
269
270fn check_version(version_output: &str, min_minor_version: u32) -> bool {
271 // Parse second the number out of
272 // cargo 1.39.0-beta (1c6ec66d5 2019-09-30)
273 let minor: Option<u32> = version_output.split('.').nth(1).and_then(|it| it.parse().ok());
274 match minor {
275 None => true,
276 Some(minor) => minor >= min_minor_version,
277 }
278} 115}
diff --git a/xtask/src/pre_commit.rs b/xtask/src/pre_commit.rs
new file mode 100644
index 000000000..88e868ca6
--- /dev/null
+++ b/xtask/src/pre_commit.rs
@@ -0,0 +1,36 @@
1//! pre-commit hook for code formatting.
2
3use std::{fs, path::PathBuf};
4
5use anyhow::{bail, Result};
6
7use crate::{cmd::run_with_output, project_root, run, run_rustfmt, Mode};
8
9// FIXME: if there are changed `.ts` files, also reformat TypeScript (by
10// shelling out to `npm fmt`).
11pub fn run_hook() -> Result<()> {
12 run_rustfmt(Mode::Overwrite)?;
13
14 let diff = run_with_output("git diff --diff-filter=MAR --name-only --cached", ".")?;
15
16 let root = project_root();
17 for line in String::from_utf8(diff.stdout)?.lines() {
18 run(&format!("git update-index --add {}", root.join(line).to_string_lossy()), ".")?;
19 }
20
21 Ok(())
22}
23
24pub fn install_hook() -> Result<()> {
25 let hook_path: PathBuf =
26 format!("./.git/hooks/pre-commit{}", std::env::consts::EXE_SUFFIX).into();
27
28 if hook_path.exists() {
29 bail!("Git hook already created");
30 }
31
32 let me = std::env::current_exe()?;
33 fs::copy(me, hook_path)?;
34
35 Ok(())
36}