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 design-time build for Antlr-generated files #1002

Merged
merged 3 commits into from
Oct 31, 2017

Conversation

DustinCampbell
Copy link
Contributor

Fixes dotnet/vscode-csharp#1822

This change may fix several issues, but it particular it fixes files not appearing in the OmniSharpWorkspace that were generated through Antlr. Essentially, we had failed to set the BuildingInsideVisualStudio property when running a design-time build in OmniSharp. Antlr uses this property to determine whether the antlr design-time grammar compilation target runs (link).

In addition, there a couple of other tweaks in this change that are somewhat unrelated:

  1. There was a type in the ProvideCommandLineArgs property.
  2. We should run two targets: Compile and CoreCompile. This is needed to produce items from ProvideCommandLineArgs.

@DustinCampbell
Copy link
Contributor Author

cc @sharwell as he may find this amusing. 😄

@@ -130,7 +130,7 @@ internal ProjectFileInfo(string filePath)
}

var projectInstance = project.CreateProjectInstance();
var buildResult = projectInstance.Build(TargetNames.Compile,
var buildResult = projectInstance.Build(new string[] { TargetNames.Compile, TargetNames.CoreCompile },
Copy link

Choose a reason for hiding this comment

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

Is this going to result in unintended behavior changes in other projects?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It shouldn't. This is also what we do in Visual Studio.

Copy link
Member

@david-driscoll david-driscoll left a comment

Choose a reason for hiding this comment

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

👍

<PackageReference Include="Antlr4.Runtime" Version="4.6.4" />
</ItemGroup>
<ItemGroup>
<Antlr4 Include="Grammar.g4">
Copy link
Contributor

Choose a reason for hiding this comment

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

📝 This block will no longer be necessary with 4.6.5-beta002.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

FWIW, this is a test project directly from a customer. So, I want to ensure we don't regress it.

{ PropertyNames.BuildProjectReferences, "false" },
{ PropertyNames._ResolveReferenceDependencies, "true" },
{ PropertyNames.SolutionDir, solutionDirectory + Path.DirectorySeparatorChar },

// This properties allow the design-time build to handle the Compile target without actually invoking the compiler.
// See https://github.com/dotnet/roslyn/pull/4604 for details.
{ PropertyNames.ProvideCommandLineInvocation, "true" },
{ PropertyNames.ProvideCommandLineArgs, "true" },
Copy link
Contributor

Choose a reason for hiding this comment

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

💭 I'm somewhat surprised this is needed. Or was that a different issue?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's a different issue. Per my PR comment, there a couple of unrelated changes.

@@ -249,13 +249,14 @@ public bool IsUnityProject()
var globalProperties = new Dictionary<string, string>
{
{ PropertyNames.DesignTimeBuild, "true" },
{ PropertyNames.BuildingInsideVisualStudio, "true" },
Copy link
Contributor

Choose a reason for hiding this comment

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

😆 I don't see any way to avoid this one.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, the property name is kind of a misnomer. Originally, it was added for design-time scenarios like code generators in VS.

<TargetFramework>netcoreapp2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Antlr4.CodeGenerator" Version="4.6.4" />
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Starting with 4.6.5-beta001 (already released), it is possible to eliminate the Java runtime requirement from the ANTLR build. If you don't currently require a Java installation for some other purpose, it might make sense to update the version and use the new code generator as described in the release notes:

https://github.com/tunnelvisionlabs/antlr4cs/releases/tag/v4.6.5-beta001

Copy link
Contributor Author

Choose a reason for hiding this comment

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

FWIW, I haven't seen a Java installation requirement. I was able to get a design-time build of this without having Java installed.

@DustinCampbell
Copy link
Contributor Author

CI is failing because I need to update some other tests that are now getting a couple of additional temporary files. Will do that after lunch. 😀

@DustinCampbell
Copy link
Contributor Author

I've fixed the tests. CoreCompile generates a few 0-length temporary files that are unnecessary. FWIW, these are also specifically removed in Roslyn's MSBuildWorkspace.

@DustinCampbell
Copy link
Contributor Author

OK. After chatting with @sharwell, it sounds like there are some known issues with the Antlr4 code generators that can make it fail on OSX (e.g. tunnelvisionlabs/antlr4cs#244 and tunnelvisionlabs/antlr4cs#243).

I'm going to disable this test on non-Windows for now.

@sharwell
Copy link
Contributor

I'll work to get a build up that allows the test to be enabled on all platforms.

@DustinCampbell
Copy link
Contributor Author

I'll work to get a build up that allows the test to be enabled on all platforms.

No rush. I know you're super-busy. 😄

This change may fix several issues, but it particular it fixes files not appearing in the OmniSharpWorkspace that were generated through Antlr. Essentially, we had failed to set the `BuildingInsideVisualStudio` property when running a design-time build in OmniSharp. Antlr uses this property to determine whether the antlr design-time grammar compilation target runs ([link](https://github.com/tunnelvisionlabs/antlr4cs/blob/f62010862bd1e38b3c6e3940931dcde949bdaa91/runtime/CSharp/Antlr4BuildTasks/Antlr4.net40.targets#L95)).

In addition, there a couple of other tweaks in this change that are somewhat unrelated:

1. There was a type in the `ProvideCommandLineArgs` property.
2. We should run two targets: `Compile` and `CoreCompile`. This is needed to produce items from `ProvideCommandLineArgs`.
@DustinCampbell DustinCampbell merged commit 4a17dc9 into OmniSharp:master Oct 31, 2017
@DustinCampbell DustinCampbell deleted the antlr-generated-files branch October 31, 2017 00:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Need to add "Compile Include ..." to use files generated during the build but this causes more errors
4 participants