Skip to content

Commit 4d41091

Browse files
author
Your Name
committed
Fix command line flags for cache
1 parent e86ef8f commit 4d41091

File tree

3 files changed

+32
-16
lines changed

3 files changed

+32
-16
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ jobs:
8787
- name: Download tools
8888
run: |
8989
yarn --frozen-lockfile --ignore-scripts --prefer-offline
90-
yarn download-tools --target ${{ matrix.target }}
90+
yarn download-tools --target ${{ matrix.target }} --no-cache
9191
9292
- name: Create vsix package
9393
run: |

DEVELOPMENT.md

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313

1414
## Building
1515

16-
Major parts are platform independent but due to the inclusion of binary tools the resulting packages become platform-specific, i.e. for on `<target>`.
16+
Major parts are platform independent but due to the inclusion of binary tools the resulting
17+
packages become platform-specific, i.e. for on `<target>`.
1718

1819
Supported `<target>`s are:
1920

@@ -24,7 +25,8 @@ Supported `<target>`s are:
2425
- darwin-x64 (MacOS, Intel, x86-64)
2526
- darwin-arm64 (MacOS, Arm, aarch64)
2627

27-
1. Open a terminal and execute the following command to download NPM dependencies and tools, and to build the Typescript code:
28+
1. Open a terminal and execute the following command to download NPM dependencies and tools, and
29+
to build the Typescript code:
2830

2931
```sh
3032
> yarn
@@ -33,10 +35,12 @@ Supported `<target>`s are:
3335
2. Download binary tools
3436

3537
```sh
36-
> yarn download-tools [--target <target>]
38+
> yarn download-tools [--target <target>] [--no-cache]
3739
```
3840

3941
If no `<target>` is specified the local system's architecture is used by default.
42+
By default, tool downloads are cached in the yarn cache (see `yarn cache dir`) to prevent
43+
recurring downloads of exact same archives on clean builds.
4044
4145
3. Package the extension as a locally installable VSIX file:
4246
@@ -46,13 +50,16 @@ Supported `<target>`s are:
4650
4751
## Developing
4852
49-
1. If you are developing and debugging this extension, we recommend you run the following command after an initial build:
53+
1. If you are developing and debugging this extension, we recommend you run the following command
54+
after an initial build:
5055
5156
```sh
5257
> yarn watch
5358
```
5459
55-
While just calling `yarn` creates a production build of the extension, running the above creates a build dedicated for debug. Additionally, it sets up a watch which detects code changes and rebuilds them incrementally.
60+
While just calling `yarn` creates a production build of the extension, running the above
61+
creates a build dedicated for debug. Additionally, it sets up a watch which detects code
62+
changes and rebuilds them incrementally.
5663
5764
2. Switch to the VS Code `Run and Debug` view.
5865

scripts/download-tools.ts

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ async function retrieveSha256(url?: string, token?: string) {
101101
}
102102

103103
async function download(url: string, options?: ToolOptions & { cache_key?: string }) {
104-
const cachePath = (options?.cache && options?.cache_key) ? path.join(options.cache, options.cache_key): undefined;
104+
const cachePath = (options?.cache && options?.cache_key) ? path.join(options.cache, options.cache_key) : undefined;
105105
if (cachePath && existsSync(cachePath)) {
106106
console.debug(`Found asset in cache ${cachePath} ...`);
107107
return { mode: 'cache', path: cachePath};
@@ -170,7 +170,12 @@ async function downloadPyOCD(target: VsceTarget, dest: string, options?: ToolOpt
170170
}
171171
}
172172

173-
const { mode, path: extractPath } = await download(asset.url, { token: githubToken, cache: options?.cache, cache_key: `cmsis-pyocd-${version}-${sha256sum}` });
173+
const dloptions = {
174+
token: githubToken,
175+
cache: options?.cache,
176+
cache_key: sha256sum ? `cmsis-pyocd-${version}-${sha256sum}` : undefined
177+
};
178+
const { mode, path: extractPath } = await download(asset.url, dloptions);
174179

175180
if (existsSync(destPath)) {
176181
console.debug(`Removing existing ${destPath} ...`);
@@ -197,7 +202,7 @@ async function main() {
197202
const yarnCacheDir = execSync('yarn cache dir').toString().trim();
198203
console.debug(`Yarn cache directory: ${yarnCacheDir}`);
199204

200-
const { target, dest, cache, cache_disable, tools } = yargs
205+
const { target, dest, cache, tools } = yargs
201206
.option('t', {
202207
alias: 'target',
203208
description: 'VS Code extension target, defaults to system',
@@ -214,11 +219,6 @@ async function main() {
214219
description: 'Directory for caching tool downloads',
215220
default: yarnCacheDir
216221
})
217-
.option('no-cache', {
218-
description: 'Disable caching of tool downloads',
219-
type: 'boolean',
220-
default: false
221-
})
222222
.version(false)
223223
.strict()
224224
.command('$0 [<tools> ...]', 'Downloads the tool(s) for the given architecture and OS', y => {
@@ -229,14 +229,23 @@ async function main() {
229229
default: Object.keys(TOOLS)
230230
});
231231
})
232-
.argv as unknown as { target: VsceTarget, dest: string, cache: string, cache_disable: boolean, tools: (keyof typeof TOOLS)[] };
232+
.argv as unknown as { target: VsceTarget, dest: string, cache: string | boolean, tools: (keyof typeof TOOLS)[] };
233233

234234
if (!existsSync(dest)) {
235235
mkdirSync(dest, { recursive: true });
236236
}
237237

238+
const cacheFolder = (cache: string | boolean) => {
239+
if (typeof cache === 'string') {
240+
return cache;
241+
} else if(cache === true) {
242+
return yarnCacheDir;
243+
}
244+
return undefined;
245+
}
246+
238247
for (const tool of new Set(tools)) {
239-
TOOLS[tool](target, dest, { cache: cache_disable ? undefined : cache });
248+
TOOLS[tool](target, dest, { cache: cacheFolder(cache) });
240249
}
241250
}
242251

0 commit comments

Comments
 (0)