Skip to content

Commit 9a9f8ba

Browse files
authored
fix(cloudformation): Only remap legacy linux builds, if they are avai… (aws#8398)
[fix(cloudformation): Only remap legacy linux builds, if they are available](aws@b5a2c7f) ## Problem ## Solution --- - Treat all work as PUBLIC. Private `feature/x` branches will not be squash-merged at release time. - Your code changes must meet the guidelines in [CONTRIBUTING.md](https://github.com/aws/aws-toolkit-vscode/blob/master/CONTRIBUTING.md#guidelines). - License: I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent 630e156 commit 9a9f8ba

File tree

3 files changed

+128
-26
lines changed

3 files changed

+128
-26
lines changed

packages/core/src/awsService/cloudformation/lsp-server/githubManifestAdapter.ts

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
dedupeAndGetLatestVersions,
1313
extractPlatformAndArch,
1414
useOldLinuxVersion,
15+
mapLegacyLinux,
1516
} from './utils'
1617
import { getLogger } from '../../../shared/logger/logger'
1718
import { ToolkitError } from '../../../shared/errors'
@@ -54,33 +55,11 @@ export class GitHubManifestAdapter {
5455
return manifest
5556
}
5657

57-
getLogger('awsCfnLsp').warn('Using GLIBC compatible version for Linux')
58-
const versions = manifest.versions.map((version) => {
59-
const targets = version.targets
60-
.filter((target) => {
61-
return target.platform !== 'linux'
62-
})
63-
.map((target) => {
64-
if (target.platform !== 'linuxglib2.28') {
65-
return target
66-
}
67-
68-
return {
69-
...target,
70-
platform: 'linux',
71-
}
72-
})
73-
74-
return {
75-
...version,
76-
targets,
77-
}
78-
})
79-
80-
manifest.versions = versions
58+
getLogger('awsCfnLsp').info('In a legacy or sandbox Linux environment')
59+
manifest.versions = mapLegacyLinux(manifest.versions)
8160

8261
getLogger('awsCfnLsp').info(
83-
'Remapped candidate versions from platform linuxglib2.28 to linux: %s',
62+
'Remapped candidate versions: %s',
8463
manifest.versions
8564
.map(
8665
(v) =>

packages/core/src/awsService/cloudformation/lsp-server/utils.ts

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,6 @@ export function useOldLinuxVersion(): boolean {
124124
}
125125

126126
if (process.env.SNAP !== undefined) {
127-
getLogger('awsCfnLsp').info('In Linux sandbox environment')
128127
return true
129128
}
130129

@@ -137,3 +136,40 @@ export function useOldLinuxVersion(): boolean {
137136
getLogger('awsCfnLsp').info(`Found GLIBCXX ${toString(glibcxx)}`)
138137
return semver.lt(maxAvailGLibCXX, '3.4.29')
139138
}
139+
140+
const LegacyLinuxGLibPlatform = 'linuxglib2.28'
141+
142+
export function mapLegacyLinux(versions: CfnLspVersion[]): CfnLspVersion[] {
143+
const remappedVersions: CfnLspVersion[] = []
144+
145+
for (const version of versions) {
146+
const hasLegacyLinux = version.targets.some((t) => t.platform === LegacyLinuxGLibPlatform)
147+
148+
if (!hasLegacyLinux) {
149+
getLogger('awsCfnLsp').warn(`Found no compatible legacy linux builds for ${version.serverVersion}`)
150+
remappedVersions.push(version)
151+
} else {
152+
const newTargets = version.targets
153+
.filter((target) => {
154+
return target.platform !== 'linux'
155+
})
156+
.map((target) => {
157+
if (target.platform !== LegacyLinuxGLibPlatform) {
158+
return target
159+
}
160+
161+
return {
162+
...target,
163+
platform: 'linux',
164+
}
165+
})
166+
167+
remappedVersions.push({
168+
...version,
169+
targets: newTargets,
170+
})
171+
}
172+
}
173+
174+
return remappedVersions
175+
}

packages/core/src/test/awsService/cloudformation/lsp-server/utils.test.ts

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ import {
1010
dedupeAndGetLatestVersions,
1111
extractPlatformAndArch,
1212
useOldLinuxVersion,
13+
mapLegacyLinux,
1314
CfnTarget,
15+
CfnLspVersion,
1416
} from '../../../../awsService/cloudformation/lsp-server/utils'
1517
import { CLibCheck } from '../../../../awsService/cloudformation/lsp-server/CLibCheck'
1618
import { LspVersion } from '../../../../shared/lsp/types'
@@ -222,3 +224,88 @@ describe('dedupeAndGetLatestVersions', () => {
222224
})
223225
}
224226
})
227+
228+
describe('mapLegacyLinux', () => {
229+
const darwinContent = { filename: 'darwin.zip', url: 'https://example.com/darwin.zip', hashes: ['abc'], bytes: 100 }
230+
const linuxContent = { filename: 'linux.zip', url: 'https://example.com/linux.zip', hashes: ['def'], bytes: 200 }
231+
const legacyContent = { filename: 'legacy.zip', url: 'https://example.com/legacy.zip', hashes: ['ghi'], bytes: 300 }
232+
const winContent = { filename: 'win.zip', url: 'https://example.com/win.zip', hashes: ['jkl'], bytes: 400 }
233+
234+
it('remaps linuxglib2.28 to linux and removes original linux target', () => {
235+
const versions: CfnLspVersion[] = [
236+
{
237+
serverVersion: '1.0.0',
238+
isDelisted: false,
239+
targets: [
240+
{ platform: 'darwin', arch: 'arm64', contents: [darwinContent] },
241+
{ platform: 'linux', arch: 'x64', contents: [linuxContent] },
242+
{ platform: 'linuxglib2.28', arch: 'x64', contents: [legacyContent], nodejs: '18' },
243+
{ platform: 'win32', arch: 'x64', contents: [winContent] },
244+
],
245+
},
246+
]
247+
248+
const result = mapLegacyLinux(versions)
249+
250+
assert.strictEqual(result.length, 1)
251+
assert.strictEqual(result[0].serverVersion, '1.0.0')
252+
assert.strictEqual(result[0].isDelisted, false)
253+
assert.strictEqual(result[0].targets.length, 3)
254+
assert.deepStrictEqual(result[0].targets[0], { platform: 'darwin', arch: 'arm64', contents: [darwinContent] })
255+
assert.deepStrictEqual(result[0].targets[1], {
256+
platform: 'linux',
257+
arch: 'x64',
258+
contents: [legacyContent],
259+
nodejs: '18',
260+
})
261+
assert.deepStrictEqual(result[0].targets[2], { platform: 'win32', arch: 'x64', contents: [winContent] })
262+
})
263+
264+
it('returns version unchanged when no linuxglib2.28 target exists', () => {
265+
const versions: CfnLspVersion[] = [
266+
{
267+
serverVersion: '2.0.0',
268+
isDelisted: true,
269+
targets: [
270+
{ platform: 'darwin', arch: 'arm64', contents: [darwinContent] },
271+
{ platform: 'linux', arch: 'x64', contents: [linuxContent] },
272+
],
273+
},
274+
]
275+
276+
const result = mapLegacyLinux(versions)
277+
278+
assert.strictEqual(result.length, 1)
279+
assert.deepStrictEqual(result[0], versions[0])
280+
})
281+
282+
it('handles multiple versions with mixed legacy targets', () => {
283+
const versions: CfnLspVersion[] = [
284+
{
285+
serverVersion: '1.0.0',
286+
isDelisted: false,
287+
targets: [
288+
{ platform: 'darwin', arch: 'arm64', contents: [] },
289+
{ platform: 'linuxglib2.28', arch: 'x64', contents: [legacyContent] },
290+
],
291+
},
292+
{
293+
serverVersion: '2.0.0',
294+
isDelisted: false,
295+
targets: [{ platform: 'darwin', arch: 'arm64', contents: [] }],
296+
},
297+
]
298+
299+
const result = mapLegacyLinux(versions)
300+
301+
assert.strictEqual(result.length, 2)
302+
assert.strictEqual(result[0].serverVersion, '1.0.0')
303+
assert.strictEqual(result[0].targets.length, 2)
304+
assert.deepStrictEqual(result[0].targets[1], { platform: 'linux', arch: 'x64', contents: [legacyContent] })
305+
assert.deepStrictEqual(result[1], versions[1])
306+
})
307+
308+
it('handles empty versions array', () => {
309+
assert.deepStrictEqual(mapLegacyLinux([]), [])
310+
})
311+
})

0 commit comments

Comments
 (0)