-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change-Id: I010e867941ad3c94f44ac303269e713360bb697d Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/259657 Reviewed-by: Asad Memon <[email protected]> Commit-Queue: Chad Norvell <[email protected]> Docs-Not-Needed: Chad Norvell <[email protected]> Lint: Lint 🤖 <[email protected]>
- Loading branch information
1 parent
7cee22f
commit a8a94ac
Showing
17 changed files
with
2,302 additions
and
1,269 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// Copyright 2025 The Pigweed Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); you may not | ||
// use this file except in compliance with the License. You may obtain a copy of | ||
// the License at | ||
// | ||
// https://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
// License for the specific language governing permissions and limitations under | ||
// the License. | ||
|
||
import { loadLegacySettings } from './legacy'; | ||
|
||
describe('load legacy settings', () => { | ||
test('successfully loads valid settings', async () => { | ||
const settingsData = `config_title: pw_ide | ||
default_target: pw_strict_host_clang_debug | ||
compdb_gen_cmd: gn gen out`; | ||
|
||
const settings = await loadLegacySettings(settingsData); | ||
expect(settings).toHaveProperty('default_target'); | ||
expect(settings?.default_target).toBe('pw_strict_host_clang_debug'); | ||
}); | ||
|
||
test('returns null on invalid settings', async () => { | ||
const settingsData = `default_target: | ||
- pw_strict_host_clang_debug`; | ||
|
||
const settings = await loadLegacySettings(settingsData); | ||
expect(settings).toBeNull(); | ||
}); | ||
|
||
test('returns null on unparsable settings', async () => { | ||
const settingsData = '- 2a05:4800:1:100::'; | ||
|
||
const settings = await loadLegacySettings(settingsData); | ||
expect(settings).toBeNull(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
// Copyright 2025 The Pigweed Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); you may not | ||
// use this file except in compliance with the License. You may obtain a copy of | ||
// the License at | ||
// | ||
// https://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
// License for the specific language governing permissions and limitations under | ||
// the License. | ||
|
||
import * as fs from 'fs'; | ||
import * as fs_p from 'fs/promises'; | ||
import * as path from 'path'; | ||
|
||
import { parse as parseYaml } from 'yaml'; | ||
import { z } from 'zod'; | ||
import { workingDir } from './vscode'; | ||
|
||
const DEFAULT_BUILD_DIR_NAME = 'out'; | ||
const DEFAULT_TARGET_INFERENCE = '?'; | ||
const DEFAULT_WORKSPACE_ROOT = workingDir.get(); | ||
const DEFAULT_WORKING_DIR = workingDir.get(); | ||
const LEGACY_SETTINGS_FILE_PATH = path.join(workingDir.get(), '.pw_ide.yaml'); | ||
|
||
const legacySettingsSchema = z.object({ | ||
cascade_settings: z.boolean().default(false), | ||
clangd_alternate_path: z.string().optional(), | ||
clangd_additional_query_drivers: z.array(z.string()).default([]), | ||
compdb_gen_cmd: z.string().optional(), | ||
compdb_search_paths: z | ||
.array(z.array(z.string())) | ||
.default([[DEFAULT_BUILD_DIR_NAME, DEFAULT_TARGET_INFERENCE]]), | ||
default_target: z.string().optional(), | ||
// TODO(chadnorvell): Test that this works with a non-default value. | ||
workspace_root: z.string().default(DEFAULT_WORKSPACE_ROOT), | ||
// needs some thought | ||
sync: z.string().optional(), | ||
targets_exclude: z.array(z.string()).default([]), | ||
targets_include: z.array(z.string()).default([]), | ||
target_inference: z.string().default('?'), | ||
// TODO(chadnorvell): Test that this works with a non-default value. | ||
working_dir: z.string().default(DEFAULT_WORKING_DIR), | ||
}); | ||
|
||
type LegacySettings = z.infer<typeof legacySettingsSchema>; | ||
|
||
export async function loadLegacySettings( | ||
settingsData: string, | ||
onFailureReturnDefault: true, | ||
): Promise<LegacySettings>; | ||
|
||
export async function loadLegacySettings( | ||
settingsData: string, | ||
onFailureReturnDefault?: false, | ||
): Promise<LegacySettings | null>; | ||
|
||
export async function loadLegacySettings( | ||
settingsData: string, | ||
onFailureReturnDefault = false, | ||
): Promise<LegacySettings | null> { | ||
const fallback = onFailureReturnDefault | ||
? legacySettingsSchema.parse({}) | ||
: null; | ||
|
||
const parsed = parseYaml(settingsData); | ||
if (!parsed) return fallback; | ||
|
||
try { | ||
return legacySettingsSchema.parse(parsed); | ||
} catch { | ||
return fallback; | ||
} | ||
} | ||
|
||
export async function loadLegacySettingsFile(): Promise<string | null> { | ||
if (!fs.existsSync(LEGACY_SETTINGS_FILE_PATH)) return null; | ||
const data = await fs_p.readFile(LEGACY_SETTINGS_FILE_PATH); | ||
return data.toString(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters