| /* |
| * Copyright 2012-present Facebook, Inc. |
| * |
| * Licensed under the Apache License, Version 2.0 (the "License"); you may |
| * not use this file except in compliance with the License. You may obtain |
| * a copy of the License at |
| * |
| * http://www.apache.org/licenses/LICENSE-2.0 |
| * |
| * Unless required by applicable law or agreed to in writing, software |
| * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| * License for the specific language governing permissions and limitations |
| * under the License. |
| */ |
| |
| package com.facebook.buck.android; |
| |
| import com.facebook.buck.io.ProjectFilesystem; |
| import com.facebook.buck.model.BuildTarget; |
| import com.facebook.buck.shell.ShellStep; |
| import com.facebook.buck.step.ExecutionContext; |
| import com.facebook.buck.util.HumanReadableException; |
| import com.facebook.buck.util.Verbosity; |
| import com.google.common.collect.ImmutableList; |
| import com.google.common.collect.ImmutableSet; |
| |
| import java.nio.file.Path; |
| import java.nio.file.Paths; |
| import java.util.Set; |
| |
| public class AidlStep extends ShellStep { |
| |
| private final BuildTarget target; |
| private final Path aidlFilePath; |
| private final Set<String> importDirectoryPaths; |
| private final Path destinationDirectory; |
| |
| public AidlStep( |
| BuildTarget target, |
| Path aidlFilePath, |
| Set<String> importDirectoryPaths, |
| Path destinationDirectory) { |
| this.target = target; |
| this.aidlFilePath = aidlFilePath; |
| this.importDirectoryPaths = ImmutableSet.copyOf(importDirectoryPaths); |
| this.destinationDirectory = destinationDirectory; |
| } |
| |
| @Override |
| protected ImmutableList<String> getShellCommandInternal(ExecutionContext context) { |
| ImmutableList.Builder<String> args = ImmutableList.builder(); |
| |
| // The arguments passed to aidl are based off of what I observed when running Ant in verbose |
| // mode. |
| AndroidPlatformTarget androidPlatformTarget = context.getAndroidPlatformTarget(); |
| ProjectFilesystem projectFilesystem = context.getProjectFilesystem(); |
| verifyImportPaths(projectFilesystem, importDirectoryPaths); |
| args.add(androidPlatformTarget.getAidlExecutable().toString()); |
| |
| // For some reason, all of the flags to aidl do not permit a space between the flag name and |
| // the flag value. |
| |
| // fail when trying to compile a parcelable |
| args.add("-b"); |
| |
| // file created by --preprocess to import |
| args.add("-p" + androidPlatformTarget.getAndroidFrameworkIdlFile().toString()); |
| |
| // search path for import statements |
| for (String importDirectoryPath : importDirectoryPaths) { |
| Path resovled = projectFilesystem.resolve(Paths.get(importDirectoryPath)); |
| args.add("-I" + resovled); |
| } |
| |
| // base output folder for generated files |
| args.add("-o" + projectFilesystem.resolve(destinationDirectory)); |
| |
| args.add(aidlFilePath.toString()); |
| |
| return args.build(); |
| } |
| |
| private void verifyImportPaths(ProjectFilesystem filesystem, Set<String> importDirectoryPaths) { |
| for (String path : importDirectoryPaths) { |
| if (!filesystem.exists(Paths.get(path))) { |
| throw new HumanReadableException("%s: Cannot find import path: %s", target, path); |
| } |
| } |
| } |
| |
| @Override |
| protected boolean shouldPrintStderr(Verbosity verbosity) { |
| return verbosity.shouldPrintStandardInformation(); |
| } |
| |
| @Override |
| public String getShortName() { |
| return "aidl"; |
| } |
| |
| } |