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

Enable embedding sources inside the sourcemaps json as sourcesContent #9936

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

vegegoku
Copy link
Contributor

@vegegoku vegegoku commented Mar 10, 2024

This PR updates the rebased version of sourcemaps jar and other dependencies to support embedding the source files content into the source maps sourcesContent field.

requires : gwtproject/tools#31

Fixes #9752 #9778 #9790

@vegegoku vegegoku force-pushed the source-content-2-11-test branch 2 times, most recently from a80d0a6 to ddf1364 Compare March 13, 2024 19:41
Copy link
Contributor

@niloc132 niloc132 left a comment

Choose a reason for hiding this comment

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

Some updates from private chat working on this feature:

  • We've learned that SDM won't be improved by this, as the various linking activity doesn't copy source files for in SDM, only in prod code with sourcemaps enabled. The "sourcesContent" part of this patch will only improve SDM in cases where the debugger loads many many sources, to the point where that network traffic could be time better spent reading a giant sourcemap file.
  • This is still a legit way to slightly improve prod build times for projects that deploy with sourcemaps (not many, but they exist), though it might be counterproductive for those only using sourcemaps for stack trace deobfuscation
  • For these reasons, we're leaning towards a config property in CompilerProperties.gwt.xml that would activate this new feature.
  • The patch still has value simply by updating the sourcemap library: both to potentially fix any issues in the last 8ish years since this was updated, and to drop the server-side runtime dependency on protobuf once and for all.

There is also other cleanup possible for compiler.useSourceMaps (since it should work in all browsers today, and not need extra wiring in CoreWithUserAgent), but let's leave that to another patch.

servlet/build.xml Outdated Show resolved Hide resolved
dev/build.xml Show resolved Hide resolved
@vegegoku vegegoku force-pushed the source-content-2-11-test branch 4 times, most recently from 11a0f27 to b39f264 Compare March 18, 2024 23:14
@vegegoku vegegoku requested a review from niloc132 March 19, 2024 01:30
@niloc132
Copy link
Contributor

niloc132 commented Mar 19, 2024

Description should be updated to indicate that this fixes #9752.

Edit: also #9778, #9790

dev/build.xml Outdated Show resolved Hide resolved
@vegegoku vegegoku requested a review from niloc132 April 29, 2024 11:19
@niloc132 niloc132 added this to the 2.12 milestone May 11, 2024
Copy link
Contributor

@niloc132 niloc132 left a comment

Choose a reason for hiding this comment

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

Looks like there may be more classpaths that should be expanded, or code that needs to be corrected to stop walking classes it should ignore (annotations mostly?)

Example from the build:

requestfactory-server:
     [java] Could not find class file for com/google/auto/value/AutoValue
     [java] Could not find class file for com/google/auto/value/AutoValue$Builder
     [java] May 12, 2024 4:55:17 AM com.google.auto.value.AutoValue
     [java] SEVERE: Could not find class file for com/google/auto/value/AutoValue
     [java] May 12, 2024 4:55:17 AM com.google.auto.value.AutoValue.Builder
     [java] SEVERE: Could not find class file for com/google/auto/value/AutoValue$Builder
     [java] Could not find class file for com/google/errorprone/annotations/CanIgnoreReturnValue
     [java] May 12, 2024 4:55:17 AM com.google.errorprone.annotations.CanIgnoreReturnValue
     [java] SEVERE: Could not find class file for com/google/errorprone/annotations/CanIgnoreReturnValue
     [java] Could not find class file for com/google/errorprone/annotations/DoNotCall
     [java] May 12, 2024 4:55:17 AM com.google.errorprone.annotations.DoNotCall
     [java] SEVERE: Could not find class file for com/google/errorprone/annotations/DoNotCall
     [java] Could not find class file for com/google/errorprone/annotations/InlineMe
     [java] May 12, 2024 4:55:17 AM com.google.errorprone.annotations.InlineMe
     [java] SEVERE: Could not find class file for com/google/errorprone/annotations/InlineMe
     [java] Could not find class file for com/google/errorprone/annotations/DoNotMock
     [java] May 12, 2024 4:55:17 AM com.google.errorprone.annotations.DoNotMock
     [java] SEVERE: Could not find class file for com/google/errorprone/annotations/DoNotMock
     [java] Could not find class file for com/google/errorprone/annotations/InlineMeValidationDisabled
     [java] May 12, 2024 4:55:17 AM com.google.errorprone.annotations.InlineMeValidationDisabled
     [java] SEVERE: Could not find class file for com/google/errorprone/annotations/InlineMeValidationDisabled
     [java] Could not find class file for com/google/errorprone/annotations/CompatibleWith
     [java] May 12, 2024 4:55:17 AM com.google.errorprone.annotations.CompatibleWith
     [java] SEVERE: Could not find class file for com/google/errorprone/annotations/CompatibleWith
     [java] Could not find class file for com/google/errorprone/annotations/Immutable
     [java] May 12, 2024 4:55:17 AM com.google.errorprone.annotations.Immutable
     [java] SEVERE: Could not find class file for com/google/errorprone/annotations/Immutable
     [java] Could not find class file for com/google/errorprone/annotations/ForOverride
     [java] Could not find class file for com/google/errorprone/annotations/CheckReturnValue
     [java] Could not find class file for com/google/errorprone/annotations/RestrictedApi
     [java] May 12, 2024 4:55:17 AM com.google.errorprone.annotations.ForOverride
     [java] SEVERE: Could not find class file for com/google/errorprone/annotations/ForOverride
     [java] May 12, 2024 4:55:17 AM com.google.errorprone.annotations.CheckReturnValue
     [java] SEVERE: Could not find class file for com/google/errorprone/annotations/CheckReturnValue
     [java] May 12, 2024 4:55:17 AM com.google.errorprone.annotations.RestrictedApi
     [java] SEVERE: Could not find class file for com/google/errorprone/annotations/RestrictedApi
     [java] Could not find class file for com/google/errorprone/annotations/concurrent/GuardedBy
     [java] May 12, 2024 4:55:17 AM com.google.errorprone.annotations.concurrent.GuardedBy
     [java] SEVERE: Could not find class file for com/google/errorprone/annotations/concurrent/GuardedBy

Comment on lines +404 to +410
if (nonNull(cis)) {
try {
cis.close();
} catch (IOException e) {
logger.log(TreeLogger.Type.WARN, "Error closing input stream ", e);
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Could also be

Suggested change
if (nonNull(cis)) {
try {
cis.close();
} catch (IOException e) {
logger.log(TreeLogger.Type.WARN, "Error closing input stream ", e);
}
}
Utility.close(cis);

Comment on lines +48 to 49
import com.google.gwt.thirdparty.guava.common.collect.Maps;
import java.io.ByteArrayOutputStream;
Copy link
Contributor

Choose a reason for hiding this comment

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

from checkstyle:

/home/runner/work/gwt/gwt/gwt/dev/core/src/com/google/gwt/core/linker/SymbolMapsLinker.java:49:1: warning: 'java.io.ByteArrayOutputStream' should be separated from previous imports. (com.puppycrawl.tools.checkstyle.checks.imports.ImportOrderCheck)
Suggested change
import com.google.gwt.thirdparty.guava.common.collect.Maps;
import java.io.ByteArrayOutputStream;
import com.google.gwt.thirdparty.guava.common.collect.Maps;
import java.io.ByteArrayOutputStream;

Comment on lines +333 to +334
totalPrefixLines,
sourceMapString, partialPath);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
totalPrefixLines,
sourceMapString, partialPath);
totalPrefixLines, sourceMapString, partialPath);

Comment on lines +337 to +342
new SourceMapGeneratorV3.ExtensionMergeAction() {
@Override
public Object merge(String extKey, Object oldVal, Object newVal) {
return newVal;
}
});
Copy link
Contributor

Choose a reason for hiding this comment

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

IJ suggests replacing this with a lambda, seems like a good improvement?

Suggested change
new SourceMapGeneratorV3.ExtensionMergeAction() {
@Override
public Object merge(String extKey, Object oldVal, Object newVal) {
return newVal;
}
});
(extKey, oldVal, newVal) -> newVal);

Comment on lines +371 to +373
Iterator<Entry<String, Object>> extensions = section.getExtensions().entrySet().iterator();

while (extensions.hasNext()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Iterator<Entry<String, Object>> extensions = section.getExtensions().entrySet().iterator();
while (extensions.hasNext()) {
for (Entry<String, Object> entry : section.getExtensions().entrySet()) {

@@ -131,6 +131,7 @@ public int compare(SelectionProperty o1, SelectionProperty o2) {
private ResourceOracle publicResourceOracle;

private final SortedSet<SelectionProperty> selectionProperties;
private ModuleDef module;
Copy link
Contributor

Choose a reason for hiding this comment

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

final

@@ -537,6 +539,10 @@ public void produceOutput(TreeLogger logger, ArtifactSet artifacts,
}
}

public ModuleDef getModule() {
Copy link
Contributor

Choose a reason for hiding this comment

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

As we discussed when first working out how to plumb this, I don't really like exposing this here. I don't have a good enough answer to ask you to change it, so just documenting my thoughts in case something strikes one of us (or someone sees this PR in a few years and wants to know why on earth we made this change).

One option is to make a specific getter, shouldEmbedSourcesInModuleSourcemaps() sort of thing that just does return module.isEmbedSourcesContent(). That would better match getModuleName()/getModuleFunctionName()/getModuleLastModified() - though those three are part of LinkerContext itself. I don't think this should be added to LinkerContext.

I dislike this option the least. However, it does suggest that we should do the same in CompilerContext - but CompilerContext has a bunch of other calls to getModule() already, so it feels a bit inconsistent.

Another option would be to remove the other three getters, and have all the callers instead call getModule().getName() and so on. This provides access to too much of ModuleDef I think, and it isn't immutable, so I really don't care for this.


Separately, I don't love the name isEmbedSourcesContent as a method on ModuleDef, nor do I love that the method exists there at all. No other properties exist on ModuleDef itself, so it seems silly to have this one be special enough to be there. That said, it is needed by both the various pre/compile stages and linkers too, so it either needs to be somewhere very accessible, or needs to be duplicated - so I think I'm okay with it staying in ModuleDef or pushing it down into Properties (so you have to call getModule().getProperties.isBlahBlah() - that does happen in other places, so it wouldn't be terrible). Renaming it: how about we get SourceMaps in the name somehow - shouldEmbedSourceMapContents() perhaps? sourceMapContentsEmbedEnabled()?

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.

Please remove protobuf pom from gwt-servlet
2 participants