Skip to content

Commit

Permalink
Revert "Delete --project from all vcpkg-artifacts commands and use ex…
Browse files Browse the repository at this point in the history
…isting vcpkg switches to control where the manifest is located instead. (microsoft#731)" (microsoft#750)

This reverts commit 8dc83cc.
  • Loading branch information
BillyONeal authored Oct 17, 2022
1 parent c91aa61 commit 3247920
Show file tree
Hide file tree
Showing 16 changed files with 125 additions and 65 deletions.
4 changes: 0 additions & 4 deletions ce/ce/cli/command-line.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,6 @@ export class CommandLine {
return this.switches['z-vcpkg-registries-cache']?.[0];
}

get vcpkgManifestDirectory() {
return this.switches['z-vcpkg-manifest-dir']?.[0];
}

get telemetryEnabled() {
return !!this.switches['z-enable-metrics'];
}
Expand Down
7 changes: 6 additions & 1 deletion ce/ce/cli/commands/acquire-project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,16 @@ import { i } from '../../i18n';
import { session } from '../../main';
import { acquireArtifacts, showArtifacts } from '../artifacts';
import { Command } from '../command';
import { error } from '../styling';
import { Project } from '../switches/project';

export class AcquireProjectCommand extends Command {
readonly command = 'acquire-project';
readonly aliases = [];
seeAlso = [];
argumentsHelp = [];
project: Project = new Project(this);

get summary() {
return i`Acquires everything referenced by a project, without activating`;
}
Expand All @@ -23,8 +27,9 @@ export class AcquireProjectCommand extends Command {
}

override async run() {
const projectManifest = await session.loadRequiredProjectProfile();
const projectManifest = await this.project.manifest;
if (!projectManifest) {
error(i`Unable to find project in folder (or parent folders) for ${session.currentDirectory.fsPath}`);
return false;
}

Expand Down
4 changes: 3 additions & 1 deletion ce/ce/cli/commands/acquire.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { acquireArtifacts, selectArtifacts, showArtifacts } from '../artifacts';
import { Command } from '../command';
import { cmdSwitch } from '../format';
import { debug, error, log, warning } from '../styling';
import { Project } from '../switches/project';
import { Version } from '../switches/version';

export class AcquireCommand extends Command {
Expand All @@ -17,6 +18,7 @@ export class AcquireCommand extends Command {
seeAlso = [];
argumentsHelp = [];
version: Version = new Version(this);
project: Project = new Project(this);

get summary() {
return i`Acquire artifacts in the registry`;
Expand All @@ -41,7 +43,7 @@ export class AcquireCommand extends Command {
}

const resolver = session.globalRegistryResolver.with(
await buildRegistryResolver(session, (await session.loadProjectProfile())?.metadata.registries));
await buildRegistryResolver(session, (await this.project.manifest)?.metadata.registries));
const resolved = await selectArtifacts(session, new Map(this.inputs.map((v, i) => [v, versions[i] || '*'])), resolver, 1);
if (!resolved) {
debug('No artifacts selected - stopping');
Expand Down
7 changes: 6 additions & 1 deletion ce/ce/cli/commands/activate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,17 @@ import { showArtifacts } from '../artifacts';
import { Command } from '../command';
import { projectFile } from '../format';
import { activate } from '../project';
import { error } from '../styling';
import { Json } from '../switches/json';
import { MSBuildProps } from '../switches/msbuild-props';
import { Project } from '../switches/project';

export class ActivateCommand extends Command {
readonly command = 'activate';
readonly aliases = [];
seeAlso = [];
argumentsHelp = [];
project: Project = new Project(this);
msbuildProps: MSBuildProps = new MSBuildProps(this);
json : Json = new Json(this);

Expand All @@ -32,8 +35,10 @@ export class ActivateCommand extends Command {
}

override async run() {
const projectManifest = await session.loadRequiredProjectProfile();
const projectManifest = await this.project.manifest;

if (!projectManifest) {
error(i`Unable to find project in folder (or parent folders) for ${session.currentDirectory.fsPath}`);
return false;
}

Expand Down
6 changes: 5 additions & 1 deletion ce/ce/cli/commands/add.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { selectArtifacts, showArtifacts } from '../artifacts';
import { Command } from '../command';
import { cmdSwitch } from '../format';
import { error } from '../styling';
import { Project } from '../switches/project';
import { Version } from '../switches/version';

export class AddCommand extends Command {
Expand All @@ -17,6 +18,7 @@ export class AddCommand extends Command {
argumentsHelp = [];

version = new Version(this);
project: Project = new Project(this);

get summary() {
return i`Adds an artifact to the project`;
Expand All @@ -29,8 +31,10 @@ export class AddCommand extends Command {
}

override async run() {
const projectManifest = await session.loadRequiredProjectProfile();
const projectManifest = await this.project.manifest;

if (!projectManifest) {
error(i`Unable to find project in folder (or parent folders) for ${session.currentDirectory.fsPath}`);
return false;
}

Expand Down
10 changes: 7 additions & 3 deletions ce/ce/cli/commands/deactivate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ import { session } from '../../main';
import { Command } from '../command';
import { projectFile } from '../format';
import { log } from '../styling';
import { Project } from '../switches/project';

export class DeactivateCommand extends Command {
readonly command = 'deactivate';
readonly aliases = [];
seeAlso = [];
argumentsHelp = [];
project = new Project(this);

get summary() {
return i`Deactivates the current session`;
Expand All @@ -24,12 +26,14 @@ export class DeactivateCommand extends Command {
}

override async run() {
const project = await session.findProjectProfile();
if (project) {
log(i`Deactivating project ${projectFile(project)}`);
const project = await this.project.resolvedValue;
if (!project) {
return false;
}

log(i`Deactivating project ${projectFile(project)}`);
await session.deactivate();

return true;
}
}
4 changes: 3 additions & 1 deletion ce/ce/cli/commands/find.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { session } from '../../main';
import { Command } from '../command';
import { Table } from '../markdown-table';
import { error, log } from '../styling';
import { Project } from '../switches/project';
import { Version } from '../switches/version';

export class FindCommand extends Command {
Expand All @@ -17,6 +18,7 @@ export class FindCommand extends Command {
seeAlso = [];
argumentsHelp = [];
version = new Version(this);
project = new Project(this);

get summary() {
return i`Find artifacts in the registry`;
Expand All @@ -31,7 +33,7 @@ export class FindCommand extends Command {
override async run() {
// load registries (from the current project too if available)
const resolver = session.globalRegistryResolver.with(
await buildRegistryResolver(session, (await session.loadProjectProfile())?.metadata.registries));
await buildRegistryResolver(session, (await this.project.manifest)?.metadata.registries));
const table = new Table('Artifact', 'Version', 'Summary');

for (const each of this.inputs) {
Expand Down
6 changes: 5 additions & 1 deletion ce/ce/cli/commands/generate-msbuild-props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ import { showArtifacts } from '../artifacts';
import { Command } from '../command';
import { error } from '../styling';
import { MSBuildProps } from '../switches/msbuild-props';
import { Project } from '../switches/project';

export class GenerateMSBuildPropsCommand extends Command {
readonly command = 'generate-msbuild-props';
readonly aliases = [];
seeAlso = [];
argumentsHelp = [];
project: Project = new Project(this);
msbuildProps: MSBuildProps = new MSBuildProps(this, 'out');

get summary() {
Expand All @@ -29,8 +31,10 @@ export class GenerateMSBuildPropsCommand extends Command {
return false;
}

const projectManifest = await session.loadRequiredProjectProfile();
const projectManifest = await this.project.manifest;

if (!projectManifest) {
error(i`Unable to find project in folder (or parent folders) for ${session.currentDirectory.fsPath}`);
return false;
}

Expand Down
6 changes: 5 additions & 1 deletion ce/ce/cli/commands/remove.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ import { i } from '../../i18n';
import { session } from '../../main';
import { Command } from '../command';
import { error, log } from '../styling';
import { Project } from '../switches/project';

export class RemoveCommand extends Command {
readonly command = 'remove';
readonly aliases = [];
seeAlso = [];
argumentsHelp = [];
project: Project = new Project(this);

get summary() {
return i`Removes an artifact from a project`;
Expand All @@ -23,8 +25,10 @@ export class RemoveCommand extends Command {
}

override async run() {
const projectManifest = await session.loadRequiredProjectProfile();
const projectManifest = await this.project.manifest;

if (!projectManifest) {
error(i`Unable to find project in folder (or parent folders) for ${session.currentDirectory.fsPath}`);
return false;
}

Expand Down
4 changes: 3 additions & 1 deletion ce/ce/cli/commands/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ import { Command } from '../command';
import { CommandLine } from '../command-line';
import { count } from '../format';
import { error, log, writeException } from '../styling';
import { Project } from '../switches/project';

export class UpdateCommand extends Command {
readonly command = 'update';
readonly aliases = [];
seeAlso = [];
argumentsHelp = [];
project: Project = new Project(this);

get summary() {
return i`update the registry from the remote`;
Expand All @@ -29,7 +31,7 @@ export class UpdateCommand extends Command {

override async run() {
const resolver = session.globalRegistryResolver.with(
await buildRegistryResolver(session, (await session.loadProjectProfile())?.metadata.registries));
await buildRegistryResolver(session, (await this.project.manifest)?.metadata.registries));
for (const registryName of this.inputs) {
const registry = resolver.getRegistryByName(registryName);
if (registry) {
Expand Down
4 changes: 3 additions & 1 deletion ce/ce/cli/commands/use.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { cmdSwitch } from '../format';
import { activate } from '../project';
import { error, log, warning } from '../styling';
import { MSBuildProps } from '../switches/msbuild-props';
import { Project } from '../switches/project';
import { Version } from '../switches/version';

export class UseCommand extends Command {
Expand All @@ -18,6 +19,7 @@ export class UseCommand extends Command {
seeAlso = [];
argumentsHelp = [];
version = new Version(this);
project = new Project(this);
msbuildProps = new MSBuildProps(this);

get summary() {
Expand All @@ -37,7 +39,7 @@ export class UseCommand extends Command {
}

const resolver = session.globalRegistryResolver.with(
await buildRegistryResolver(session, (await session.loadProjectProfile())?.metadata.registries));
await buildRegistryResolver(session, (await this.project.manifest)?.metadata.registries));
const versions = this.version.values;
if (versions.length && this.inputs.length !== versions.length) {
error(i`Multiple packages specified, but not an equal number of ${cmdSwitch('version')} switches`);
Expand Down
71 changes: 71 additions & 0 deletions ce/ce/cli/switches/project.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

import { resolve } from 'path';
import { ProjectManifest } from '../../artifacts/artifact';
import { configurationName } from '../../constants';
import { FileType } from '../../fs/filesystem';
import { i } from '../../i18n';
import { session } from '../../main';
import { Uri } from '../../util/uri';
import { projectFile } from '../format';
import { debug, error } from '../styling';
import { Switch } from '../switch';

interface ResolvedProjectUri {
filename: string;
uri: Uri;
}

export class Project extends Switch {
switch = 'project';
get help() {
return [
i`override the path to the project folder`
];
}

async resolveProjectUri() : Promise<ResolvedProjectUri | undefined> {
const v = this.value;
if (v) {
const uri = session.fileSystem.file(resolve(v));
const stat = await uri.stat();

if (stat.type & FileType.File) {
return {'filename': v, uri: uri};
}
if (stat.type & FileType.Directory) {
const project = uri.join(configurationName);
if (await project.exists()) {
return {'filename': project.fsPath, uri: project};
}
}

error(i`Unable to find project environment ${projectFile(uri)}`);
return undefined;
}

const sessionProject = await session.findProjectProfile();
if (sessionProject) {
return {'filename': sessionProject.fsPath, 'uri': sessionProject};
}

return undefined;
}

get resolvedValue(): Promise<Uri | undefined> {
return this.resolveProjectUri().then(v => v?.uri);
}

get manifest(): Promise<ProjectManifest | undefined> {
return this.resolveProjectUri().then(async (resolved) => {
if (!resolved) {
debug('No project manifest');
return undefined;
}

debug(`Loading project manifest ${resolved.filename} `);
return await new ProjectManifest(session, await session.openManifest(resolved.filename, resolved.uri));
});
}
}
Loading

0 comments on commit 3247920

Please sign in to comment.