Skip to content
This repository was archived by the owner on Nov 10, 2023. It is now read-only.

Commit 92fcfca

Browse files
motiz88facebook-github-bot
authored andcommitted
Pass extraData to library-dependencies command
Reviewed By: mykola-semko fbshipit-source-id: f57f3a53ffa0ad16a6444cb0acc93d8274c11c53
1 parent 737de42 commit 92fcfca

18 files changed

Lines changed: 111 additions & 8 deletions

File tree

src/com/facebook/buck/features/js/JsLibrary.java

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import com.facebook.buck.core.sourcepath.SourcePath;
3030
import com.facebook.buck.core.sourcepath.resolver.SourcePathResolverAdapter;
3131
import com.facebook.buck.io.filesystem.ProjectFilesystem;
32+
import com.facebook.buck.rules.args.Arg;
3233
import com.facebook.buck.rules.modern.BuildCellRelativePathFactory;
3334
import com.facebook.buck.rules.modern.Buildable;
3435
import com.facebook.buck.rules.modern.ModernBuildRule;
@@ -55,7 +56,8 @@ public class JsLibrary extends ModernBuildRule<JsLibrary.JsLibraryImpl> {
5556
BuildTargetSourcePath filesDependency,
5657
ImmutableSortedSet<SourcePath> libraryDependencies,
5758
WorkerTool worker,
58-
boolean withDownwardApi) {
59+
boolean withDownwardApi,
60+
Optional<Arg> extraJson) {
5961
super(
6062
buildTarget,
6163
projectFilesystem,
@@ -66,7 +68,8 @@ public class JsLibrary extends ModernBuildRule<JsLibrary.JsLibraryImpl> {
6668
worker,
6769
buildTarget,
6870
projectFilesystem,
69-
withDownwardApi));
71+
withDownwardApi,
72+
extraJson));
7073
}
7174

7275
/** Abstract buildable implementation that is used by JsLibrary and JsLibrary.Files rules */
@@ -117,17 +120,20 @@ static class JsLibraryImpl extends AbstractJsLibraryBuildable {
117120

118121
@AddToRuleKey private final ImmutableSortedSet<SourcePath> libraryDependencies;
119122
@AddToRuleKey private final BuildTargetSourcePath filesDependency;
123+
@AddToRuleKey private final Optional<Arg> extraJson;
120124

121125
JsLibraryImpl(
122126
ImmutableSortedSet<SourcePath> libraryDependencies,
123127
BuildTargetSourcePath filesDependency,
124128
WorkerTool worker,
125129
BuildTarget buildTarget,
126130
ProjectFilesystem projectFilesystem,
127-
boolean withDownwardApi) {
131+
boolean withDownwardApi,
132+
Optional<Arg> extraJson) {
128133
super(worker, buildTarget, projectFilesystem, withDownwardApi);
129134
this.libraryDependencies = libraryDependencies;
130135
this.filesDependency = filesDependency;
136+
this.extraJson = extraJson;
131137
}
132138

133139
@Override
@@ -148,8 +154,12 @@ ObjectBuilder getJobArgs(
148154
.map(AbsPath::toString)
149155
.collect(JsonBuilder.toArrayOfStrings()))
150156
.addString(
151-
"aggregatedSourceFilesFilePath",
152-
resolver.getAbsolutePath(filesDependency).toString());
157+
"aggregatedSourceFilesFilePath", resolver.getAbsolutePath(filesDependency).toString())
158+
.addRaw("extraData", getExtraJson(resolver));
159+
}
160+
161+
private Optional<String> getExtraJson(SourcePathResolverAdapter sourcePathResolverAdapter) {
162+
return extraJson.map(a -> Arg.stringify(a, sourcePathResolverAdapter));
153163
}
154164
}
155165

src/com/facebook/buck/features/js/JsLibraryDescription.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import com.facebook.buck.core.util.immutables.RuleArg;
4343
import com.facebook.buck.downwardapi.config.DownwardApiConfig;
4444
import com.facebook.buck.io.filesystem.ProjectFilesystem;
45+
import com.facebook.buck.rules.args.Arg;
4546
import com.facebook.buck.rules.query.Query;
4647
import com.facebook.buck.rules.query.QueryUtils;
4748
import com.facebook.buck.shell.ProvidesWorkerTool;
@@ -176,7 +177,11 @@ public BuildRule createBuildRule(
176177
Stream<BuildTarget> declaredDeps = args.getDeps().stream();
177178
Stream<BuildTarget> deps = Stream.concat(declaredDeps, queryDeps);
178179
return new LibraryBuilder(
179-
context.getTargetGraph(), graphBuilder, buildTarget, withDownwardApi)
180+
context.getTargetGraph(),
181+
graphBuilder,
182+
buildTarget,
183+
withDownwardApi,
184+
JsUtil.getExtraJson(args, buildTarget, graphBuilder, cellRoots))
180185
.setLibraryDependencies(deps)
181186
.build(projectFilesystem, worker);
182187
}
@@ -315,18 +320,21 @@ private static class LibraryBuilder {
315320
private final ActionGraphBuilder graphBuilder;
316321
private final BuildTarget baseTarget;
317322
private final boolean withDownwardApi;
323+
private final Optional<Arg> extraJson;
318324

319325
@Nullable private ImmutableList<JsLibrary> libraryDependencies;
320326

321327
private LibraryBuilder(
322328
TargetGraph targetGraph,
323329
ActionGraphBuilder graphBuilder,
324330
BuildTarget baseTarget,
325-
boolean withDownwardApi) {
331+
boolean withDownwardApi,
332+
Optional<Arg> extraJson) {
326333
this.targetGraph = targetGraph;
327334
this.baseTarget = baseTarget;
328335
this.graphBuilder = graphBuilder;
329336
this.withDownwardApi = withDownwardApi;
337+
this.extraJson = extraJson;
330338
}
331339

332340
private LibraryBuilder setLibraryDependencies(Stream<BuildTarget> deps) {
@@ -353,7 +361,8 @@ private JsLibrary build(ProjectFilesystem projectFilesystem, WorkerTool worker)
353361
.map(JsLibrary::getSourcePathToOutput)
354362
.collect(ImmutableSortedSet.toImmutableSortedSet(Ordering.natural())),
355363
worker,
356-
withDownwardApi);
364+
withDownwardApi,
365+
extraJson);
357366
}
358367

359368
private boolean hasFlavors() {

test/com/facebook/buck/features/js/testdata/js_rules/android_library_bundle.expected/js/bundle-with-android-lib#android,release/js/android-bundle.js.expected

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@
2828
"outputPath" : "@/buck-out/gen/js/extras#android,release,transform-profile-default.jslib",
2929
"dependencyLibraryFilePaths" : [ ],
3030
"aggregatedSourceFilesFilePath" : "@/buck-out/gen/js/extras#_files_,android,release,transform-profile-default.jslib",
31+
"extraData" : {
32+
"arbitrary" : "extra",
33+
"json" : 1
34+
},
3135
"flavors" : [
3236
"android",
3337
"release"
@@ -179,6 +183,10 @@ var pear;
179183
"outputPath" : "@/buck-out/gen/js/extras#android,release,transform-profile-default.jslib",
180184
"dependencyLibraryFilePaths" : [ ],
181185
"aggregatedSourceFilesFilePath" : "@/buck-out/gen/js/extras#_files_,android,release,transform-profile-default.jslib",
186+
"extraData" : {
187+
"arbitrary" : "extra",
188+
"json" : 1
189+
},
182190
"flavors" : [
183191
"android",
184192
"release"

test/com/facebook/buck/features/js/testdata/js_rules/bundle_genrules.expected/js/genrule-inner/js/renamed.bundle.expected

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@
2424
"outputPath" : "@/buck-out/gen/js/extras#transform-profile-default.jslib",
2525
"dependencyLibraryFilePaths" : [ ],
2626
"aggregatedSourceFilesFilePath" : "@/buck-out/gen/js/extras#_files_,transform-profile-default.jslib",
27+
"extraData" : {
28+
"arbitrary" : "extra",
29+
"json" : 1
30+
},
2731
"flavors" : [ ]
2832
}
2933
{

test/com/facebook/buck/features/js/testdata/js_rules/bundle_genrules.expected/js/genrule-outer/js/postprocessed.txt.expected

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@
2424
"outputPath" : "@/buck-out/gen/js/extras#transform-profile-default.jslib",
2525
"dependencyLibraryFilePaths" : [ ],
2626
"aggregatedSourceFilesFilePath" : "@/buck-out/gen/js/extras#_files_,transform-profile-default.jslib",
27+
"extraData" : {
28+
"arbitrary" : "extra",
29+
"json" : 1
30+
},
2731
"flavors" : [ ]
2832
}
2933
{

test/com/facebook/buck/features/js/testdata/js_rules/dependencies.expected/js/fruit-salad-in-a-bundle#dependencies,ios,release.deps.expected

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@
3535
"outputPath" : "@/buck-out/gen/js/extras#ios,release,transform-profile-default.jslib",
3636
"dependencyLibraryFilePaths" : [ ],
3737
"aggregatedSourceFilesFilePath" : "@/buck-out/gen/js/extras#_files_,ios,release,transform-profile-default.jslib",
38+
"extraData" : {
39+
"arbitrary" : "extra",
40+
"json" : 1
41+
},
3842
"flavors" : [
3943
"ios",
4044
"release"
@@ -186,6 +190,10 @@ var pear;
186190
"outputPath" : "@/buck-out/gen/js/extras#ios,release,transform-profile-default.jslib",
187191
"dependencyLibraryFilePaths" : [ ],
188192
"aggregatedSourceFilesFilePath" : "@/buck-out/gen/js/extras#_files_,ios,release,transform-profile-default.jslib",
193+
"extraData" : {
194+
"arbitrary" : "extra",
195+
"json" : 1
196+
},
189197
"flavors" : [
190198
"ios",
191199
"release"

test/com/facebook/buck/features/js/testdata/js_rules/dependencies.expected/js/fruit-with-extras#android,dependencies.deps.expected

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@
2626
"outputPath" : "@/buck-out/gen/js/extras#android,transform-profile-default.jslib",
2727
"dependencyLibraryFilePaths" : [ ],
2828
"aggregatedSourceFilesFilePath" : "@/buck-out/gen/js/extras#_files_,android,transform-profile-default.jslib",
29+
"extraData" : {
30+
"arbitrary" : "extra",
31+
"json" : 1
32+
},
2933
"flavors" : [
3034
"android"
3135
]

test/com/facebook/buck/features/js/testdata/js_rules/deps_file_genrule.expected/js/deps-file-genrule/deps-file-genrule.deps.expected

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@
2323
"outputPath" : "@/buck-out/gen/js/extras#transform-profile-default.jslib",
2424
"dependencyLibraryFilePaths" : [ ],
2525
"aggregatedSourceFilesFilePath" : "@/buck-out/gen/js/extras#_files_,transform-profile-default.jslib",
26+
"extraData" : {
27+
"arbitrary" : "extra",
28+
"json" : 1
29+
},
2630
"flavors" : [ ]
2731
}
2832
{

test/com/facebook/buck/features/js/testdata/js_rules/ios_app.expected/ios/DemoApp#iphonesimulator-x86_64,no-debug,no-include-frameworks/DemoApp.app/fruit-salad-in-a-bundle.js.expected

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@
3636
"outputPath" : "@/buck-out/gen/js/extras#ios,transform-profile-default.jslib",
3737
"dependencyLibraryFilePaths" : [ ],
3838
"aggregatedSourceFilesFilePath" : "@/buck-out/gen/js/extras#_files_,ios,transform-profile-default.jslib",
39+
"extraData" : {
40+
"arbitrary" : "extra",
41+
"json" : 1
42+
},
3943
"flavors" : [
4044
"ios"
4145
]
@@ -167,6 +171,10 @@ var pear;
167171
"outputPath" : "@/buck-out/gen/js/extras#ios,transform-profile-default.jslib",
168172
"dependencyLibraryFilePaths" : [ ],
169173
"aggregatedSourceFilesFilePath" : "@/buck-out/gen/js/extras#_files_,ios,transform-profile-default.jslib",
174+
"extraData" : {
175+
"arbitrary" : "extra",
176+
"json" : 1
177+
},
170178
"flavors" : [
171179
"ios"
172180
]

test/com/facebook/buck/features/js/testdata/js_rules/ios_app_with_genrule.expected/ios/DemoAppWithJsBundleGenrule#iphonesimulator-x86_64,no-debug,no-include-frameworks/DemoAppWithJsBundleGenrule.app/postprocessed.txt.expected

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@
2828
"outputPath" : "@/buck-out/gen/js/extras#ios,transform-profile-default.jslib",
2929
"dependencyLibraryFilePaths" : [ ],
3030
"aggregatedSourceFilesFilePath" : "@/buck-out/gen/js/extras#_files_,ios,transform-profile-default.jslib",
31+
"extraData" : {
32+
"arbitrary" : "extra",
33+
"json" : 1
34+
},
3135
"flavors" : [
3236
"ios"
3337
]

0 commit comments

Comments
 (0)