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

Commit 55154bb

Browse files
ndmitchellfacebook-github-bot
authored andcommitted
Support macros in ocamldep_flags
Summary: The things passed to ocamldep_flags in the OCaml rules are often preprocessors, e.g. `buck/platform009/build/supercaml/share/dotopam/default/lib/lwt_ppx/ppx.exe`. However, because they are added as strings, Buck has no idea they are files, and because they are files not targets, it is a kind of package boundary violation. To fix the macros we need to switch to make a proper `export_file` target and use `$(location ...)`. To make that work, `ocamldep_flags` needs to take macros, which this diff does. Reviewed By: IanChilds fbshipit-source-id: 9816dd932d97406c375e09d514a6cf2a636b1dd8
1 parent e2bf51a commit 55154bb

5 files changed

Lines changed: 33 additions & 13 deletions

File tree

src/com/facebook/buck/features/ocaml/OcamlBinaryDescription.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,13 @@ public BuildRule createBuildRule(
101101
args.getCompilerFlags(),
102102
args.getWarningsFlags());
103103

104+
ImmutableList<Arg> ocamldepFlags =
105+
OcamlDescriptionEnhancer.toStringWithMacrosArgs(
106+
buildTarget,
107+
context.getCellPathResolver(),
108+
context.getActionGraphBuilder(),
109+
args.getOcamldepFlags());
110+
104111
BuildTarget compileBuildTarget = OcamlRuleBuilder.createOcamlLinkTarget(buildTarget);
105112

106113
ImmutableList<BuildRule> rules;
@@ -119,7 +126,7 @@ public BuildRule createBuildRule(
119126
/* isLibrary */ false,
120127
args.getBytecodeOnly().orElse(false),
121128
flags,
122-
args.getOcamldepFlags(),
129+
ocamldepFlags,
123130
/* buildNativePlugin */ false,
124131
withDownwardApi);
125132
rules = result.getRules();
@@ -138,7 +145,7 @@ public BuildRule createBuildRule(
138145
/* isLibrary */ false,
139146
args.getBytecodeOnly().orElse(false),
140147
flags,
141-
args.getOcamldepFlags(),
148+
ocamldepFlags,
142149
withDownwardApi);
143150
rules = ImmutableList.of(ocamlLibraryBuild);
144151
}
@@ -180,7 +187,7 @@ default PatternMatchedCollection<ImmutableList<String>> getPlatformLinkerFlags()
180187
return PatternMatchedCollection.of();
181188
}
182189

183-
ImmutableList<String> getOcamldepFlags();
190+
ImmutableList<StringWithMacros> getOcamldepFlags();
184191

185192
Optional<String> getWarningsFlags();
186193

src/com/facebook/buck/features/ocaml/OcamlBuildContext.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ abstract class OcamlBuildContext implements AddsToRuleKey {
7676
public abstract List<Arg> getFlags();
7777

7878
@AddToRuleKey
79-
public abstract ImmutableList<String> getOcamlDepFlags();
79+
public abstract List<Arg> getOcamlDepFlags();
8080

8181
@AddToRuleKey
8282
public abstract List<SourcePath> getInput();

src/com/facebook/buck/features/ocaml/OcamlBuildStep.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,9 @@ public OcamlBuildStep(
8787
ImmutableList.<String>builder()
8888
.addAll(
8989
this.ocamlContext.getIncludeFlags(/* isBytecode */ false, /* excludeDeps */ true))
90-
.addAll(this.ocamlContext.getOcamlDepFlags())
90+
.addAll(
91+
Arg.stringify(
92+
this.ocamlContext.getOcamlDepFlags(), buildContext.getSourcePathResolver()))
9193
.build();
9294

9395
this.depToolStep =

src/com/facebook/buck/features/ocaml/OcamlLibraryDescription.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,13 @@ public BuildRule createBuildRule(
113113
.getMatchingValues(ocamlPlatform.get().getFlavor().toString())))),
114114
args.getWarningsFlags());
115115

116+
ImmutableList<Arg> ocamldepFlags =
117+
OcamlDescriptionEnhancer.toStringWithMacrosArgs(
118+
buildTarget,
119+
context.getCellPathResolver(),
120+
context.getActionGraphBuilder(),
121+
args.getOcamldepFlags());
122+
116123
BuildTarget compileBuildTarget = OcamlRuleBuilder.createStaticLibraryBuildTarget(buildTarget);
117124

118125
if (OcamlRuleBuilder.shouldUseFineGrainedRules(context.getActionGraphBuilder(), srcs)) {
@@ -129,7 +136,7 @@ public BuildRule createBuildRule(
129136
/* isLibrary */ true,
130137
args.getBytecodeOnly(),
131138
flags,
132-
args.getOcamldepFlags(),
139+
ocamldepFlags,
133140
!args.getBytecodeOnly() && args.getNativePlugin(),
134141
downwardApiConfig.isEnabledForOCaml());
135142
return new OcamlStaticLibrary(
@@ -169,7 +176,7 @@ public BuildRule createBuildRule(
169176
/* isLibrary */ true,
170177
args.getBytecodeOnly(),
171178
flags,
172-
args.getOcamldepFlags(),
179+
ocamldepFlags,
173180
downwardApiConfig.isEnabledForOCaml());
174181
return new OcamlStaticLibrary(
175182
buildTarget,
@@ -299,7 +306,7 @@ default PatternMatchedCollection<ImmutableList<StringWithMacros>> getPlatformCom
299306
return PatternMatchedCollection.of();
300307
}
301308

302-
ImmutableList<String> getOcamldepFlags();
309+
ImmutableList<StringWithMacros> getOcamldepFlags();
303310

304311
ImmutableList<StringWithMacros> getLinkerFlags();
305312

src/com/facebook/buck/features/ocaml/OcamlRuleBuilder.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ static OcamlBuild createBulkCompileRule(
205205
boolean isLibrary,
206206
boolean bytecodeOnly,
207207
ImmutableList<Arg> argFlags,
208-
ImmutableList<String> ocamlDepFlags,
208+
ImmutableList<Arg> ocamlDepFlags,
209209
boolean withDownwardApi) {
210210
CxxPreprocessorInput cxxPreprocessorInputFromDeps =
211211
CxxPreprocessorInput.concat(
@@ -338,7 +338,7 @@ static OcamlGeneratedBuildRules createFineGrainedBuildRules(
338338
boolean isLibrary,
339339
boolean bytecodeOnly,
340340
ImmutableList<Arg> argFlags,
341-
ImmutableList<String> ocamlDepFlags,
341+
ImmutableList<Arg> ocamlDepFlags,
342342
boolean buildNativePlugin,
343343
boolean withDownwardApi) {
344344

@@ -442,7 +442,8 @@ static OcamlGeneratedBuildRules createFineGrainedBuildRules(
442442

443443
AbsPath baseDir = projectFilesystem.getRootPath();
444444
ImmutableMap<Path, ImmutableList<Path>> mlInput =
445-
getMLInputWithDeps(baseDir, ocamlContext, withDownwardApi);
445+
getMLInputWithDeps(
446+
baseDir, ocamlContext, graphBuilder.getSourcePathResolver(), withDownwardApi);
446447

447448
ImmutableList<SourcePath> cInput = getCInput(graphBuilder.getSourcePathResolver(), srcs);
448449

@@ -477,12 +478,15 @@ private static ImmutableList<SourcePath> getCInput(
477478
}
478479

479480
private static ImmutableMap<Path, ImmutableList<Path>> getMLInputWithDeps(
480-
AbsPath baseDir, OcamlBuildContext ocamlContext, boolean withDownwardApi) {
481+
AbsPath baseDir,
482+
OcamlBuildContext ocamlContext,
483+
SourcePathResolverAdapter resolverAdapter,
484+
boolean withDownwardApi) {
481485

482486
ImmutableList<String> ocamlDepFlags =
483487
ImmutableList.<String>builder()
484488
.addAll(ocamlContext.getIncludeFlags(/* isBytecode */ false, /* excludeDeps */ true))
485-
.addAll(ocamlContext.getOcamlDepFlags())
489+
.addAll(Arg.stringify(ocamlContext.getOcamlDepFlags(), resolverAdapter))
486490
.build();
487491

488492
OcamlDepToolStep depToolStep =

0 commit comments

Comments
 (0)