Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(dotnet/analyzer): remove dependency on Runtime #927

Merged
merged 5 commits into from
Nov 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="../NuGet.Metadata.props" />

<PropertyGroup>
Expand All @@ -10,9 +10,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Amazon.JSII.Runtime" Version="$(JsiiVersion)" />
<PackageReference Include="Microsoft.CodeAnalysis" Version="3.2.0" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="3.2.0" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="3.2.0" PrivateAssets="all" />
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure why this needs to be PrivateAssets="all".

Copy link
Contributor Author

@RomainMuller RomainMuller Nov 4, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is part of the (Microsoft-authored) tutorial I have found... So I fixed it up to match... I reckon the reason is that the compiler actually comes with it's own and it's better to not pollute, but I could be wrong.

The reference code from Microsoft's tutorial is here:

https://github.com/dotnet/samples/blob/7b8490d7c76c8e7d73f80883b10c166967f171dd/csharp/roslyn-sdk/Tutorials/MakeConst/MakeConst/MakeConst.csproj#L26

</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@


Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Amazon.JSII.Runtime.IntegrationTests", "Amazon.JSII.Runtime.IntegrationTests\Amazon.JSII.Runtime.IntegrationTests.csproj", "{CE3CAFBD-25F8-422D-925A-8F9CCEA1F548}"
Expand Down
12 changes: 7 additions & 5 deletions packages/jsii-pacmak/lib/targets/dotnet/filegenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import { CodeMaker } from 'codemaker';
import { Assembly } from 'jsii-spec';
import path = require('path');
import xmlbuilder = require('xmlbuilder');
import logging = require('../../logging');
import { DotNetNameUtils } from './nameutils';
import logging = require('../../logging');
import { nextMajorVersion } from '../../util';

// Represents a dependency in the dependency tree.
export class DotNetDependency {
Expand Down Expand Up @@ -95,13 +96,14 @@ export class FileGenerator {
const embeddedResource = itemGroup1.ele('EmbeddedResource');
embeddedResource.att('Include', this.tarballFileName);

// Strip " (build abcdef)" from the jsii version
const jsiiVersion = assembly.jsiiVersion.replace(/ .*$/, '');
const jsiiVersionNextMajor = nextMajorVersion(jsiiVersion);

const itemGroup2 = rootNode.ele('ItemGroup');
const packageReference = itemGroup2.ele('PackageReference');
packageReference.att('Include', 'Amazon.JSII.Runtime');

// Strip " (build abcdef)" from the jsii version
const jsiiVersionSimple = assembly.jsiiVersion.replace(/ .*$/, '');
packageReference.att('Version', jsiiVersionSimple);
packageReference.att('Version', `[${jsiiVersion},${jsiiVersionNextMajor})`);

dependencies.forEach((value: DotNetDependency) => {
const dependencyReference = itemGroup2.ele('PackageReference');
Expand Down
25 changes: 24 additions & 1 deletion packages/jsii-pacmak/lib/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import fs = require('fs-extra');
import spec = require('jsii-spec');
import os = require('os');
import path = require('path');
import semver = require('semver');
import logging = require('./logging');

export interface ShellOptions extends SpawnOptions {
Expand Down Expand Up @@ -120,4 +121,26 @@ export class Scratch<A> {
await fs.remove(this.directory);
}
}
}
}

/**
* Determines the next major version from a given current version. This honors
* the specificities of pre-1.0.0 releases, too.
*
* @param version the current version from which to bump.
*
* @returns the next Major Version string.
*/
export function nextMajorVersion(version: string): string {
const v = semver.parse(version);
if (!v) {
throw new Error(`Invalid semantic version identifier: ${version}`);
}
if (v.major !== 0) {
return v.inc('major').version;
}
if (v.minor !== 0) {
return v.inc('minor').version;
}
return v.inc('patch').version;
}
1 change: 1 addition & 0 deletions packages/jsii-pacmak/test/diff-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ function assert-generator() {
done
}

assert-generator jsii-calc-base-of-base
assert-generator jsii-calc-base
assert-generator jsii-calc-lib
assert-generator jsii-calc
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
{
"author": {
"name": "Amazon Web Services",
"organization": true,
"roles": [
"author"
],
"url": "https://aws.amazon.com"
},
"description": "An example transitive dependency for jsii-calc.",
"homepage": "https://github.com/aws/jsii",
"jsiiVersion": "0.20.0",
"license": "Apache-2.0",
"name": "@scope/jsii-calc-base-of-base",
"repository": {
"directory": "packages/jsii-calc-base-of-base",
"type": "git",
"url": "https://github.com/aws/jsii.git"
},
"schema": "jsii/0.10.0",
"targets": {
"dotnet": {
"namespace": "Amazon.JSII.Tests.CalculatorNamespace.BaseOfBaseNamespace",
"packageId": "Amazon.JSII.Tests.CalculatorPackageId.BaseOfBasePackageId"
},
"java": {
"maven": {
"artifactId": "calculator-base-of-base",
"groupId": "software.amazon.jsii.tests"
},
"package": "software.amazon.jsii.tests.calculator.baseofbase"
},
"js": {
"npm": "@scope/jsii-calc-base-of-base"
},
"python": {
"distName": "scope.jsii-calc-base-of-base",
"module": "scope.jsii_calc_base_of_base"
}
},
"types": {
"@scope/jsii-calc-base-of-base.IVeryBaseInterface": {
"assembly": "@scope/jsii-calc-base-of-base",
"fqn": "@scope/jsii-calc-base-of-base.IVeryBaseInterface",
"kind": "interface",
"locationInModule": {
"filename": "lib/index.ts",
"line": 1
},
"methods": [
{
"abstract": true,
"locationInModule": {
"filename": "lib/index.ts",
"line": 2
},
"name": "foo"
}
],
"name": "IVeryBaseInterface"
},
"@scope/jsii-calc-base-of-base.Very": {
"assembly": "@scope/jsii-calc-base-of-base",
"fqn": "@scope/jsii-calc-base-of-base.Very",
"initializer": {},
"kind": "class",
"locationInModule": {
"filename": "lib/index.ts",
"line": 9
},
"methods": [
{
"locationInModule": {
"filename": "lib/index.ts",
"line": 10
},
"name": "hey",
"returns": {
"type": {
"primitive": "number"
}
}
}
],
"name": "Very"
},
"@scope/jsii-calc-base-of-base.VeryBaseProps": {
"assembly": "@scope/jsii-calc-base-of-base",
"datatype": true,
"fqn": "@scope/jsii-calc-base-of-base.VeryBaseProps",
"kind": "interface",
"locationInModule": {
"filename": "lib/index.ts",
"line": 5
},
"name": "VeryBaseProps",
"properties": [
{
"abstract": true,
"immutable": true,
"locationInModule": {
"filename": "lib/index.ts",
"line": 6
},
"name": "foo",
"type": {
"fqn": "@scope/jsii-calc-base-of-base.Very"
}
}
]
}
},
"version": "0.20.0",
"fingerprint": "4yJsyi5ch/E1bHSJMcEEBX/WvJK/zroW/a+Ta8Tc6lk="
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<!-- Package Identification -->
<Description>An example transitive dependency for jsii-calc.</Description>
<PackageId>Amazon.JSII.Tests.CalculatorPackageId.BaseOfBasePackageId</PackageId>
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
<PackageVersion>0.20.0</PackageVersion>
<!-- Additional Metadata -->
<Authors>Amazon Web Services</Authors>
<Company>Amazon Web Services</Company>
<Language>en-US</Language>
<ProjectUrl>https://github.com/aws/jsii</ProjectUrl>
<RepositoryUrl>https://github.com/aws/jsii.git</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<!-- Build Configuration -->
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<IncludeSymbols>true</IncludeSymbols>
<IncludeSource>true</IncludeSource>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<TargetFramework>netcoreapp3.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<EmbeddedResource Include="scope-jsii-calc-base-of-base-0.20.0.tgz" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Amazon.JSII.Runtime" Version="[0.20.0,0.21.0)" />
</ItemGroup>
</Project>

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using Amazon.JSII.Runtime.Deputy;

namespace Amazon.JSII.Tests.CalculatorNamespace.BaseOfBaseNamespace
{
[JsiiInterface(nativeType: typeof(IVeryBaseInterface), fullyQualifiedName: "@scope/jsii-calc-base-of-base.IVeryBaseInterface")]
public interface IVeryBaseInterface
{
[JsiiMethod(name: "foo")]
void Foo();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using Amazon.JSII.Runtime.Deputy;

namespace Amazon.JSII.Tests.CalculatorNamespace.BaseOfBaseNamespace
{
[JsiiTypeProxy(nativeType: typeof(IVeryBaseInterface), fullyQualifiedName: "@scope/jsii-calc-base-of-base.IVeryBaseInterface")]
internal sealed class IVeryBaseInterfaceProxy : DeputyBase, Amazon.JSII.Tests.CalculatorNamespace.BaseOfBaseNamespace.IVeryBaseInterface
{
private IVeryBaseInterfaceProxy(ByRefValue reference): base(reference)
{
}

[JsiiMethod(name: "foo")]
public void Foo()
{
InvokeInstanceVoidMethod(new System.Type[]{}, new object[]{});
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using Amazon.JSII.Runtime.Deputy;

namespace Amazon.JSII.Tests.CalculatorNamespace.BaseOfBaseNamespace
{
[JsiiInterface(nativeType: typeof(IVeryBaseProps), fullyQualifiedName: "@scope/jsii-calc-base-of-base.VeryBaseProps")]
public interface IVeryBaseProps
{
[JsiiProperty(name: "foo", typeJson: "{\"fqn\":\"@scope/jsii-calc-base-of-base.Very\"}")]
Amazon.JSII.Tests.CalculatorNamespace.BaseOfBaseNamespace.Very Foo
{
get;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace Amazon.JSII.Tests.CalculatorNamespace.BaseOfBaseNamespace.Internal.DependencyResolution
{
public class Anchor
{
public Anchor()
{
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using Amazon.JSII.Runtime.Deputy;

namespace Amazon.JSII.Tests.CalculatorNamespace.BaseOfBaseNamespace
{
[JsiiClass(nativeType: typeof(Amazon.JSII.Tests.CalculatorNamespace.BaseOfBaseNamespace.Very), fullyQualifiedName: "@scope/jsii-calc-base-of-base.Very")]
public class Very : DeputyBase
{
public Very(): base(new DeputyProps(new object[]{}))
{
}

protected Very(ByRefValue reference): base(reference)
{
}

protected Very(DeputyProps props): base(props)
{
}

[JsiiMethod(name: "hey", returnsJson: "{\"type\":{\"primitive\":\"number\"}}")]
public virtual double Hey()
{
return InvokeInstanceMethod<double>(new System.Type[]{}, new object[]{});
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using Amazon.JSII.Runtime.Deputy;

namespace Amazon.JSII.Tests.CalculatorNamespace.BaseOfBaseNamespace
{
[JsiiByValue(fqn: "@scope/jsii-calc-base-of-base.VeryBaseProps")]
public class VeryBaseProps : Amazon.JSII.Tests.CalculatorNamespace.BaseOfBaseNamespace.IVeryBaseProps
{
[JsiiProperty(name: "foo", typeJson: "{\"fqn\":\"@scope/jsii-calc-base-of-base.Very\"}", isOverride: true)]
public Amazon.JSII.Tests.CalculatorNamespace.BaseOfBaseNamespace.Very Foo
{
get;
set;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using Amazon.JSII.Runtime.Deputy;

namespace Amazon.JSII.Tests.CalculatorNamespace.BaseOfBaseNamespace
{
[JsiiTypeProxy(nativeType: typeof(IVeryBaseProps), fullyQualifiedName: "@scope/jsii-calc-base-of-base.VeryBaseProps")]
internal sealed class VeryBasePropsProxy : DeputyBase, Amazon.JSII.Tests.CalculatorNamespace.BaseOfBaseNamespace.IVeryBaseProps
{
private VeryBasePropsProxy(ByRefValue reference): base(reference)
{
}

[JsiiProperty(name: "foo", typeJson: "{\"fqn\":\"@scope/jsii-calc-base-of-base.Very\"}")]
public Amazon.JSII.Tests.CalculatorNamespace.BaseOfBaseNamespace.Very Foo
{
get => GetInstanceProperty<Amazon.JSII.Tests.CalculatorNamespace.BaseOfBaseNamespace.Very>();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
using Amazon.JSII.Runtime.Deputy;

[assembly: JsiiAssembly("@scope/jsii-calc-base-of-base", "0.20.0", "scope-jsii-calc-base-of-base-0.20.0.tgz")]
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Placeholder for the expected module tarball
The diff-test.sh harness will replace it with the real expected tarball
Loading