Skip to content

Commit

Permalink
[artifacts] Make various roots consistent between vcpkg and artifacts. (
Browse files Browse the repository at this point in the history
#610)

* [artifacts] Make various roots consistent between vcpkg and artifacts.

This is the first chunk of work for https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1494960 "[vcpkg ce] vcpkg-ce does not find vcpkg.json to find vcpkg-configuration.json"

In keeping with #601 (comment) , this adds new parameters to ce for each of the directories in VcpkgPaths that ce cares about, and wires the C++ code to add parameters filling in those values as needed. TypeScript world keeps fallbacks in place but the vast majority of the time we expect the wrapping exe to be used.

Other changes:
* vcpkg-configuration.json is now the only accepted profile name.
* vcpkg-configuration.global.json is now replaced with $VCPKG_ROOT/vcpkg-configuration.json, which is consistent with what vcpkg does for manifest-less / classic mode operation.
* In several places, "cache" is renamed to "downloads" for consistency with the existing naming elsewhere, and also to avoid confusion with "binary caching" or "artifact caching".
* Implemented "deactivate".
* Updated the scripts tree sha to one that includes the node 16.15.1 update ( microsoft/vcpkg@032d9d0 ) which drops the need for the `--harmony` switch.
* Changes handling of X_VCPKG_REGISTRIES_CACHE to be consistent with all other input paths. This means there is a new intentionally-undocumented-for-now command line switch x-registries-cache .
* Fixes VS Code to create new files with LF extensions by default.

* Delete command list test.

* Restore requirement that X_VCPKG_REGISTRIES_CACHE is an absolute existing directory.
  • Loading branch information
BillyONeal authored Jul 13, 2022
1 parent c7ffa6d commit a5ce80a
Show file tree
Hide file tree
Showing 19 changed files with 184 additions and 207 deletions.
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,5 @@
"source.organizeImports": true
},
"eslint.format.enable": true,
"files.eol": "\n"
}
24 changes: 18 additions & 6 deletions ce/ce/cli/command-line.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export class CommandLine {
#home?: string;
get homeFolder() {
// home folder is determined by
// command line (--vcpkg_root, --vcpkg-root )
// command line ( --vcpkg-root )
// environment (VCPKG_ROOT)
// default 1 $HOME/.vcpkg
// default 2 <tmpdir>/.vcpkg
Expand All @@ -91,16 +91,12 @@ export class CommandLine {

return this.#home || (this.#home = resolvePath(
this.switches['vcpkg-root']?.[0] ||
this.switches['vcpkg_root']?.[0] ||
process.env['VCPKG_ROOT'] ||
join(process.env['HOME'] || process.env['USERPROFILE'] || tmpdir(), '.vcpkg')));
}

#vcpkgCommand?: string;
get vcpkgCommand() {
return this.#vcpkgCommand || (this.#vcpkgCommand = resolvePath(
this.switches['vcpkg-command']?.[0] ||
process.env['VCPKG_COMMAND']));
return this.switches['z-vcpkg-command']?.[0];
}

get force() {
Expand All @@ -115,6 +111,22 @@ export class CommandLine {
return !!this.switches['verbose'];
}

get vcpkgArtifactsRoot() {
return this.switches['z-vcpkg-artifacts-root']?.[0];
}

get vcpkgDownloads() {
return this.switches['z-vcpkg-downloads']?.[0];
}

get vcpkgRegistriesCache() {
return this.switches['z-vcpkg-registries-cache']?.[0];
}

get telemetryEnabled() {
return !!this.switches['z-enable-metrics'];
}

get language() {
const l = this.switches['language'] || [];
strict.ok((l?.length || 0) < 2, i`Expected a single value for ${cmdSwitch('language')} - found multiple`);
Expand Down
10 changes: 5 additions & 5 deletions ce/ce/cli/commands/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ export class CacheCommand extends Command {

override async run() {
if (this.clear.active) {
await session.cache.delete({ recursive: true });
await session.cache.createDirectory();
log(i`Cache folder cleared (${session.cache.fsPath}) `);
await session.downloads.delete({ recursive: true });
await session.downloads.createDirectory();
log(i`Downloads folder cleared (${session.downloads.fsPath}) `);
return true;
}
let files: Array<[Uri, FileType]> = [];
try {
files = await session.cache.readDirectory();
files = await session.downloads.readDirectory();
} catch {
// shh
}
Expand All @@ -59,4 +59,4 @@ export class CacheCommand extends Command {

return true;
}
}
}
18 changes: 9 additions & 9 deletions ce/ce/cli/commands/clean.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ export class All extends Switch {
}
}

export class Cache extends Switch {
switch = 'cache';
export class Downloads extends Switch {
switch = 'downloads';
get help() {
return [
i`cleans out the cache`
i`cleans out the downloads cache`
];
}
}
Expand All @@ -42,7 +42,7 @@ export class CleanCommand extends Command {
argumentsHelp = [];
all = new All(this);
artifacts = new Artifacts(this);
cache = new Cache(this);
downloads = new Downloads(this);
whatIf = new WhatIf(this);

get summary() {
Expand All @@ -67,12 +67,12 @@ export class CleanCommand extends Command {
log(i`Installed Artifact folder cleared (${session.installFolder.fsPath}) `);
}

if (this.all.active || this.cache.active) {
await session.cache.delete({ recursive: true });
await session.cache.createDirectory();
log(i`Cache folder cleared (${session.cache.fsPath}) `);
if (this.all.active || this.downloads.active) {
await session.downloads.delete({ recursive: true });
await session.downloads.createDirectory();
log(i`Cache folder cleared (${session.downloads.fsPath}) `);
}

return true;
}
}
}
4 changes: 2 additions & 2 deletions ce/ce/cli/constants.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

export const cli = 'ce';
export const product = 'vcpkg-ce';
export const cli = 'vcpkg';
export const product = 'vcpkg-artifacts';
export const project = 'vcpkg-configuration.json';
export const blank = '\n';
7 changes: 4 additions & 3 deletions ce/ce/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ export const undo = 'Z_VCPKG_UNDO';
export const postscriptVariable = 'Z_VCPKG_POSTSCRIPT';
export const blank = '\n';
export const latestVersion = '*';
export const vcpkgDownloadFolder = 'VCPKG_DOWNLOADS';
export const globalConfigurationFile = 'vcpkg-configuration.global.json';
export const profileNames = ['vcpkg-configuration.json', 'vcpkg-configuration.yaml', 'environment.yaml', 'environment.yml', 'environment.json'];
export const vcpkgDownloadVariable = 'VCPKG_DOWNLOADS';
export const globalConfigurationFile = 'vcpkg-configuration.json';
export const manifestName = 'vcpkg.json';
export const configurationName = 'vcpkg-configuration.json';
export const registryIndexFile = 'index.yaml';

export const defaultConfig =
Expand Down
9 changes: 4 additions & 5 deletions ce/ce/fs/acquire.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ export interface AcquireOptions extends Hash {
}

export async function acquireArtifactFile(session: Session, uris: Array<Uri>, outputFilename: string, events: Partial<AcquireEvents>, options?: AcquireOptions) {
await session.cache.createDirectory();
const outputFile = session.cache.join(outputFilename);
await session.downloads.createDirectory();
const outputFile = session.downloads.join(outputFilename);
session.channels.debug(`Acquire file '${outputFilename}' from [${uris.map(each => each.toString()).join(',')}]`);

if (options?.algorithm && options?.value) {
Expand Down Expand Up @@ -85,8 +85,8 @@ async function https(session: Session, uris: Array<Uri>, outputFilename: string,
session.channels.debug(`Attempting to download file '${outputFilename}' from [${uris.map(each => each.toString()).join(',')}]`);

let resumeAtOffset = 0;
await session.cache.createDirectory();
const outputFile = session.cache.join(outputFilename);
await session.downloads.createDirectory();
const outputFile = session.downloads.join(outputFilename);

if (options?.force) {
session.channels.debug(`Acquire '${outputFilename}': force specified, forcing download`);
Expand Down Expand Up @@ -246,4 +246,3 @@ export async function resolveNugetUrl(session: Session, pkg: string) {
export async function acquireNugetFile(session: Session, pkg: string, outputFilename: string, events: Partial<AcquireEvents>, options?: AcquireOptions): Promise<Uri> {
return https(session, [await resolveNugetUrl(session, pkg)], outputFilename, events, options);
}

52 changes: 26 additions & 26 deletions ce/ce/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { MetadataFile } from './amf/metadata-file';
import { Activation, deactivate } from './artifacts/activation';
import { Artifact, InstalledArtifact } from './artifacts/artifact';
import { Registry } from './artifacts/registry';
import { defaultConfig, globalConfigurationFile, postscriptVariable, profileNames, registryIndexFile, undo, vcpkgDownloadFolder } from './constants';
import { configurationName, defaultConfig, globalConfigurationFile, postscriptVariable, registryIndexFile, undo } from './constants';
import { FileSystem, FileType } from './fs/filesystem';
import { HttpsFileSystem } from './fs/http-filesystem';
import { LocalFileSystem } from './fs/local-filesystem';
Expand Down Expand Up @@ -56,6 +56,15 @@ export type Context = { [key: string]: Array<string> | undefined; } & {
readonly arm64: boolean;
}

export type SessionSettings = {
readonly vcpkgCommand?: string;
readonly homeFolder?: string;
readonly vcpkgArtifactsRoot?: string;
readonly vcpkgDownloads?: string;
readonly vcpkgRegistriesCache?: string;
readonly telemetryEnabled: boolean;
}

/**
* The Session class is used to hold a reference to the
* message channels,
Expand All @@ -72,11 +81,12 @@ export class Session {
readonly tmpFolder: Uri;
readonly installFolder: Uri;
readonly registryFolder: Uri;
readonly vcpkgCommand?: string;
readonly activation: Activation = new Activation(this);
get vcpkgCommand() { return this.settings.vcpkgCommand; }

readonly globalConfig: Uri;
readonly cache: Uri;
readonly downloads: Uri;
readonly telemetryEnabled: boolean;
currentDirectory: Uri;
configuration!: MetadataFile;

Expand All @@ -91,9 +101,11 @@ export class Session {
readonly defaultRegistry: AggregateRegistry;
private readonly registries = new Registries(this);

telemetryEnabled = false;
processVcpkgArg(argSetting: string | undefined, defaultName: string): Uri {
return argSetting ? this.fileSystem.file(argSetting) : this.homeFolder.join(defaultName);
}

constructor(currentDirectory: string, public readonly context: Context, public readonly settings: Record<string, string>, public readonly environment: NodeJS.ProcessEnv) {
constructor(currentDirectory: string, public readonly context: Context, public readonly settings: SessionSettings, public readonly environment: NodeJS.ProcessEnv) {
this.fileSystem = new UnifiedFileSystem(this).
register('file', new LocalFileSystem(this)).
register('vsix', new VsixLocalFilesystem(this)).
Expand All @@ -102,18 +114,18 @@ export class Session {

this.channels = new Channels(this);

this.telemetryEnabled = this.settings['telemetryEnabled'];

this.setupLogging();

this.homeFolder = this.fileSystem.file(settings['homeFolder']!);
this.cache = this.environment[vcpkgDownloadFolder] ? this.parseUri(this.environment[vcpkgDownloadFolder]!) : this.homeFolder.join('downloads');
this.homeFolder = this.fileSystem.file(settings.homeFolder!);
this.downloads = this.processVcpkgArg(settings.vcpkgDownloads, 'downloads');
this.globalConfig = this.homeFolder.join(globalConfigurationFile);

this.vcpkgCommand = settings['vcpkgCommand'];

this.tmpFolder = this.homeFolder.join('tmp');
this.installFolder = this.homeFolder.join('artifacts');

this.registryFolder = this.homeFolder.join('registries');
this.registryFolder = this.processVcpkgArg(settings.vcpkgRegistriesCache, 'registries').join('artifact');
this.installFolder = this.processVcpkgArg(settings.vcpkgArtifactsRoot, 'artifacts');

this.currentDirectory = this.fileSystem.file(currentDirectory);

Expand Down Expand Up @@ -301,26 +313,14 @@ export class Session {
}
}

if (this.context['sendmetrics']) {
// is it forced to be on?
this.telemetryEnabled = true;
} else {
// otherwise, check for the file that turns it off.
if (await this.vcpkgInstalled) {
this.telemetryEnabled = ! await this.homeFolder.exists('vcpkg.disable-metrics');
}
}

return this;
}

async findProjectProfile(startLocation = this.currentDirectory, search = true): Promise<Uri | undefined> {
let location = startLocation;
for (const loc of profileNames) {
const path = location.join(loc);
if (await this.fileSystem.isFile(path)) {
return path;
}
const path = location.join(configurationName);
if (await this.fileSystem.isFile(path)) {
return path;
}
location = location.join('..');
if (search) {
Expand Down
5 changes: 5 additions & 0 deletions ce/test/core/SuiteLocal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,12 @@ export class SuiteLocal {
constructor() {
this.tempFolder = uniqueTempFolder();
this.session = new Session(this.tempFolder, <any>{}, {
vcpkgCommand: undefined,
homeFolder: join(this.tempFolder, 'vcpkg_root'),
vcpkgArtifactsRoot: join(this.tempFolder, 'artifacts'),
vcpkgDownloads: join(this.tempFolder, 'downloads'),
vcpkgRegistriesCache: join(this.tempFolder, 'registries'),
telemetryEnabled: false
}, {});

this.fs = new LocalFileSystem(this.session);
Expand Down
11 changes: 11 additions & 0 deletions include/vcpkg/commands.deactivate.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#pragma once

#include <vcpkg/commands.interface.h>

namespace vcpkg::Commands
{
struct DeactivateCommand : PathsCommand
{
void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths) const override;
};
}
3 changes: 3 additions & 0 deletions include/vcpkg/vcpkgcmdarguments.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@ namespace vcpkg
std::unique_ptr<std::string> builtin_ports_root_dir;
constexpr static StringLiteral BUILTIN_REGISTRY_VERSIONS_DIR_ARG = "x-builtin-registry-versions-dir";
std::unique_ptr<std::string> builtin_registry_versions_dir;
constexpr static StringLiteral REGISTRIES_CACHE_DIR_ENV = "X_VCPKG_REGISTRIES_CACHE";
constexpr static StringLiteral REGISTRIES_CACHE_DIR_ARG = "x-registries-cache";
std::unique_ptr<std::string> registries_cache_dir;

constexpr static StringLiteral DEFAULT_VISUAL_STUDIO_PATH_ENV = "VCPKG_VISUAL_STUDIO_PATH";
std::unique_ptr<std::string> default_visual_studio_path;
Expand Down
4 changes: 3 additions & 1 deletion include/vcpkg/vcpkgpaths.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ namespace vcpkg
Path build_dir(const PackageSpec& spec) const;
Path build_dir(StringView package_name) const;
Path build_info_file_path(const PackageSpec& spec) const;
Path spdx_resource_dir(const PackageSpec& spec) const;

bool is_valid_triplet(Triplet t) const;
const std::vector<std::string> get_available_triplets_names() const;
Expand Down Expand Up @@ -175,5 +174,8 @@ namespace vcpkg
const Path& builtin_ports_directory() const;

bool use_git_default_registry() const;

const Path& artifacts() const;
const Path& registries_cache() const;
};
}
Loading

0 comments on commit a5ce80a

Please sign in to comment.