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

Commit cb07ca6

Browse files
Allison Chanfacebook-github-bot
authored andcommitted
Add lang to aidl step
Summary: Looking to add ndk support for native binder. This can be done with the `--lang=` from the aidl tool. The first step is to add this flag without changing existing behaviour. https://source.android.com/devices/architecture/aidl/aidl-backends Reviewed By: vener91 fbshipit-source-id: c923180a9b2b1d6c2091b6fb5b50bb483bebc17c
1 parent 549d425 commit cb07ca6

4 files changed

Lines changed: 36 additions & 4 deletions

File tree

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* Copyright (c) Facebook, Inc. and its affiliates.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.facebook.buck.android;
18+
19+
enum AidlBackend {
20+
java,
21+
ndk
22+
}

src/com/facebook/buck/android/AidlStep.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ public class AidlStep extends IsolatedShellStep {
4040
private final Path aidlFilePath;
4141
private final Set<String> importDirectoryPaths;
4242
private final Path destinationDirectory;
43+
private final AidlBackend backend;
4344

4445
public AidlStep(
4546
ProjectFilesystem filesystem,
@@ -49,7 +50,8 @@ public AidlStep(
4950
Set<String> importDirectoryPaths,
5051
Path destinationDirectory,
5152
RelPath cellPath,
52-
boolean withDownwardApi) {
53+
boolean withDownwardApi,
54+
AidlBackend backend) {
5355
super(filesystem.getRootPath(), cellPath, withDownwardApi);
5456

5557
this.filesystem = filesystem;
@@ -58,6 +60,7 @@ public AidlStep(
5860
this.aidlFilePath = aidlFilePath;
5961
this.importDirectoryPaths = ImmutableSet.copyOf(importDirectoryPaths);
6062
this.destinationDirectory = destinationDirectory;
63+
this.backend = backend;
6164
}
6265

6366
@Override
@@ -82,6 +85,9 @@ protected ImmutableList<String> getShellCommandInternal(IsolatedExecutionContext
8285
// file created by --preprocess to import
8386
args.add("-p" + androidPlatformTarget.getAndroidFrameworkIdlFile());
8487

88+
// target language
89+
args.add("--lang=" + backend.name());
90+
8591
// search path for import statements
8692
for (String importDirectoryPath : importDirectoryPaths) {
8793
Path resolved = filesystem.getPathForRelativePath(Paths.get(importDirectoryPath));

src/com/facebook/buck/android/GenAidl.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,8 @@ public ImmutableList<Step> getBuildSteps(
132132
outputDirectory.getPath(),
133133
ProjectFilesystemUtils.relativize(
134134
getProjectFilesystem().getRootPath(), context.getBuildCellRootPath()),
135-
withDownwardApi);
135+
withDownwardApi,
136+
AidlBackend.java);
136137
commands.add(command);
137138

138139
// Files must ultimately be written to GEN_DIR to be used as source paths.

test/com/facebook/buck/android/GenAidlTest.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ public class GenAidlTest {
7373
private String pathToFrameworkAidl;
7474
private String importPath;
7575
private AndroidPlatformTarget androidPlatformTarget;
76+
private AidlBackend backend;
7677

7778
@Before
7879
public void setUp() throws IOException {
@@ -104,6 +105,7 @@ public void setUp() throws IOException {
104105

105106
target = BuildTargetFactory.newInstance("//java/com/example/base:IWhateverService");
106107
pathResolver = new TestActionGraphBuilder().getSourcePathResolver();
108+
backend = AidlBackend.java;
107109
}
108110

109111
private GenAidl createGenAidlRule(ImmutableSortedSet<SourcePath> aidlSourceDeps) {
@@ -152,14 +154,15 @@ public void testSimpleGenAidlRule() {
152154
assertEquals(
153155
"gen_aidl() should use the aidl binary to write .java files.",
154156
String.format(
155-
"(cd %s && %s -p%s -I%s -o%s %s)",
157+
"(cd %s && %s -p%s --lang=%s -I%s -o%s %s)",
156158
stubFilesystem.getRootPath(),
157159
pathToAidlExecutable,
158160
pathToFrameworkAidl,
161+
backend.name(),
159162
stubFilesystem.resolve(importPath),
160163
stubFilesystem.resolve(outputDirectory),
161164
pathToAidl.getRelativePath()),
162-
aidlStep.getDescription(TestExecutionContext.newBuilder().build()));
165+
aidlStep.getDescription(TestExecutionContext.newBuilder().build()).replace("'", ""));
163166

164167
assertEquals(7, steps.size());
165168
}

0 commit comments

Comments
 (0)