diff options
author | Xavier Ducrohet <xav@android.com> | 2011-02-01 13:23:48 -0800 |
---|---|---|
committer | Android Code Review <code-review@android.com> | 2011-02-01 13:23:48 -0800 |
commit | dad5a1712c76cdf5859603b436c1fdc179ccd71b (patch) | |
tree | 79637b7c400a05b03a123ccc0eb667647e6aa320 | |
parent | f3fa02c6e326fe1cb6c35788b3287b07e1ec2f3b (diff) | |
parent | 9bf7eaf8969ed3c28467aae1f7d7debf5bc1917c (diff) | |
download | sdk-dad5a1712c76cdf5859603b436c1fdc179ccd71b.zip sdk-dad5a1712c76cdf5859603b436c1fdc179ccd71b.tar.gz sdk-dad5a1712c76cdf5859603b436c1fdc179ccd71b.tar.bz2 |
Merge "Improvements to RenderScript support:"
8 files changed, 112 insertions, 36 deletions
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/AndroidConstants.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/AndroidConstants.java index 0ed318a..85e265c 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/AndroidConstants.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/AndroidConstants.java @@ -162,6 +162,8 @@ public class AndroidConstants { public final static String RE_AIDL_EXT = "\\" + DOT_AIDL + "$"; //$NON-NLS-1$ //$NON-NLS-2$ /** Regexp for rs extension, i.e. "\.rs$" */ public final static String RE_RS_EXT = "\\" + DOT_RS + "$"; //$NON-NLS-1$ //$NON-NLS-2$ + /** Regexp for .d extension, i.e. "\.d$" */ + public final static String RE_DEP_EXT = "\\" + DOT_DEP + "$"; //$NON-NLS-1$ //$NON-NLS-2$ /** * Namespace pattern for the custom resource XML, i.e. "http://schemas.android.com/apk/res/%s" diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/build/AidlGenerator.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/build/AidlGenerator.java index 3b28107..a3c587f 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/build/AidlGenerator.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/build/AidlGenerator.java @@ -56,9 +56,9 @@ public class AidlGenerator extends JavaGenerator { /** * Single line aidl error<br> - * "<path>:<line>: <error>" - * or - * "<path>:<line> <error>" + * {@code <path>:<line>: <error>}<br> + * or<br> + * {@code <path>:<line> <error>}<br> */ private static Pattern sAidlPattern1 = Pattern.compile("^(.+?):(\\d+):?\\s(.+)$"); //$NON-NLS-1$ diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/build/GeneratorDeltaVisitor.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/build/GeneratorDeltaVisitor.java index aeda16b..01cd13e 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/build/GeneratorDeltaVisitor.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/build/GeneratorDeltaVisitor.java @@ -90,7 +90,7 @@ public class GeneratorDeltaVisitor { return false; } - public void addFileToCompile(IFile file) { + protected void addFileToCompile(IFile file) { mToCompile.add(file); } @@ -98,7 +98,7 @@ public class GeneratorDeltaVisitor { return mToCompile; } - public void addRemovedFile(IFile file) { + protected void addRemovedFile(IFile file) { mRemoved.add(file); } @@ -111,6 +111,10 @@ public class GeneratorDeltaVisitor { mRemoved.clear(); } + protected JavaGenerator getGenerator() { + return mGenerator; + } + void init(JavaGenerator generator) { mGenerator = generator; } diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/build/JavaGenerator.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/build/JavaGenerator.java index 33f3947..9e38031 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/build/JavaGenerator.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/build/JavaGenerator.java @@ -176,6 +176,8 @@ public abstract class JavaGenerator { buildSourceFileList(); mToCompile.addAll(mFiles.keySet()); + + saveState(project); } public final void doneVisiting(IProject project) { @@ -281,7 +283,7 @@ public abstract class JavaGenerator { public final void saveState(IProject project) { // TODO: Optimize by saving only the files that need compilation ProjectHelper.saveStringProperty(project, getSavePropertyName(), - Boolean.toString(getToCompile().size() > 0)); + Boolean.toString(mToCompile.size() > 0)); } protected abstract void loadOutputAndDependencies(); diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/build/RenderScriptGenerator.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/build/RenderScriptGenerator.java index 4a8abe5..458f1b5 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/build/RenderScriptGenerator.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/build/RenderScriptGenerator.java @@ -33,6 +33,9 @@ import org.eclipse.core.resources.IFolder; import org.eclipse.core.resources.IMarker; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.IResourceDelta; +import org.eclipse.core.resources.IWorkspaceRoot; +import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IProgressMonitor; @@ -56,12 +59,56 @@ public class RenderScriptGenerator extends JavaGenerator { private static final String PROPERTY_COMPILE_RS = "compileRenderScript"; //$NON-NLS-1$ /** - * Single line llvm-rs-cc error<br> - * "<path>:<line>:<col>: <error>" + * Single line llvm-rs-cc error: {@code <path>:<line>:<col>: <error>} */ private static Pattern sLlvmPattern1 = Pattern.compile("^(.+?):(\\d+):(\\d+):\\s(.+)$"); //$NON-NLS-1$ - private static class RSDeltaVisitor extends GeneratorDeltaVisitor { + private static class RsDeltaVisitor extends GeneratorDeltaVisitor { + + @Override + public boolean handleGeneratedFile(IFile file, int kind) { + boolean r = super.handleGeneratedFile(file, kind); + if (r == false && + kind == IResourceDelta.REMOVED && + AndroidConstants.EXT_DEP.equalsIgnoreCase(file.getFileExtension())) { + // This looks to be an extension file. + // For futureproofness let's make sure this dependency file was generated by + // this generator even if it's the only generator using them for now. + + // look for the original file. + // We know we are in the gen folder, so make a path to the dependency file + // relative to the gen folder. Convert this into a Renderscript source file, + // and look to see if this file exists. + JavaGenerator generator = getGenerator(); + IFolder genFolder = generator.getGenFolder(); + IPath relative = file.getFullPath().makeRelativeTo(genFolder.getFullPath()); + // remove the file name segment + relative = relative.removeLastSegments(1); + // add the file name of a Renderscript file. + relative = relative.append(file.getName().replaceAll(AndroidConstants.RE_DEP_EXT, + AndroidConstants.DOT_RS)); + + // now look for a match in the source folders. + List<IPath> sourceFolders = BaseProjectHelper.getSourceClasspaths( + generator.getJavaProject()); + IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); + + for (IPath sourceFolderPath : sourceFolders) { + IFolder sourceFolder = root.getFolder(sourceFolderPath); + // we don't look in the 'gen' source folder as there will be no source in there. + if (sourceFolder.exists() && sourceFolder.equals(genFolder) == false) { + IFile sourceFile = sourceFolder.getFile(relative); + NonJavaFileBundle bundle = generator.getBundle(sourceFile); + if (bundle != null) { + addFileToCompile(sourceFile); + return true; + } + } + } + } + + return r; + } @Override protected boolean filterResourceFolder(IContainer folder) { @@ -70,7 +117,7 @@ public class RenderScriptGenerator extends JavaGenerator { } public RenderScriptGenerator(IJavaProject javaProject, IFolder genFolder) { - super(javaProject, genFolder, new RSDeltaVisitor()); + super(javaProject, genFolder, new RsDeltaVisitor()); } @Override @@ -100,23 +147,25 @@ public class RenderScriptGenerator extends JavaGenerator { IFolder rawFolder = project.getFolder( new Path(SdkConstants.FD_RES).append(SdkConstants.FD_RAW)); + int depIndex; + // create the command line String[] command = new String[13]; int index = 0; command[index++] = sdkOsPath + SdkConstants.OS_SDK_PLATFORM_TOOLS_FOLDER + SdkConstants.FN_RENDERSCRIPT; - command[index++] = "-I"; + command[index++] = "-I"; //$NON-NLS-1$ command[index++] = projectTarget.getPath(IAndroidTarget.ANDROID_RS_CLANG); - command[index++] = "-I"; + command[index++] = "-I"; //$NON-NLS-1$ command[index++] = projectTarget.getPath(IAndroidTarget.ANDROID_RS); - command[index++] = "-p"; + command[index++] = "-p"; //$NON-NLS-1$ command[index++] = genFolder.getLocation().toOSString(); - command[index++] = "-o"; + command[index++] = "-o"; //$NON-NLS-1$ command[index++] = rawFolder.getLocation().toOSString(); - command[index++] = "-d"; - command[index++] = getDependencyFolder().getLocation().toOSString(); - command[index++] = "-MD"; + command[index++] = "-d"; //$NON-NLS-1$ + command[depIndex = index++] = null; + command[index++] = "-MD"; //$NON-NLS-1$ boolean verbose = AdtPrefs.getPrefs().getBuildVerbosity() == BuildVerbosity.VERBOSE; boolean someSuccess = false; @@ -148,6 +197,7 @@ public class RenderScriptGenerator extends JavaGenerator { String osSourcePath = sourcePath.toOSString(); // finish to set the command line. + command[depIndex] = getDependencyFolder(sourceFile).getLocation().toOSString(); command[index] = osSourcePath; // launch the process @@ -323,11 +373,14 @@ public class RenderScriptGenerator extends JavaGenerator { protected void loadOutputAndDependencies() { Collection<NonJavaFileBundle> bundles = getBundles(); for (NonJavaFileBundle bundle : bundles) { - parseDependencyFileFor(bundle.getSourceFile()); + // parse the dependency file. If this fails, force compilation of the file. + if (parseDependencyFileFor(bundle.getSourceFile()) == false) { + addFileToCompile(bundle.getSourceFile()); + } } } - private void parseDependencyFileFor(IFile sourceFile) { + private boolean parseDependencyFileFor(IFile sourceFile) { IFile depFile = getDependencyFileFor(sourceFile); File f = depFile.getLocation().toFile(); if (f.exists()) { @@ -337,15 +390,31 @@ public class RenderScriptGenerator extends JavaGenerator { addBundle(bundle); } parseDependencyFile(bundle, f); + return true; } + + return false; } - private IFolder getDependencyFolder() { - return getJavaProject().getProject().getFolder(SdkConstants.FD_OUTPUT); + private IFolder getDependencyFolder(IFile sourceFile) { + IPath sourceFolderPath = getSourceFolderFor(sourceFile); + + // this really shouldn't happen since the sourceFile must be in a source folder + // since it comes from the delta visitor + if (sourceFolderPath != null) { + // make a path to the source file relative to the source folder. + IPath relative = sourceFile.getFullPath().makeRelativeTo(sourceFolderPath); + // remove the file name. This is now the destination folder. + relative = relative.removeLastSegments(1); + + return getGenFolder().getFolder(relative); + } + + return null; } private IFile getDependencyFileFor(IFile sourceFile) { - IFolder depFolder = getDependencyFolder(); + IFolder depFolder = getDependencyFolder(sourceFile); return depFolder.getFile(sourceFile.getName().replaceAll(AndroidConstants.RE_RS_EXT, AndroidConstants.DOT_DEP)); } @@ -365,11 +434,11 @@ public class RenderScriptGenerator extends JavaGenerator { // output1 output2 [...]: dep1 dep2 [...] // expect it's likely split on several lines. So let's move it back on a single line // first - String[] lines = content.split("\n"); + String[] lines = content.split("\n"); //$NON-NLS-1$ StringBuilder sb = new StringBuilder(); for (String line : lines) { line = line.trim(); - if (line.endsWith("\\")) { + if (line.endsWith("\\")) { //$NON-NLS-1$ line = line.substring(0, line.length() - 1); } @@ -377,13 +446,13 @@ public class RenderScriptGenerator extends JavaGenerator { } // split the left and right part - String[] files = sb.toString().split(":"); + String[] files = sb.toString().split(":"); //$NON-NLS-1$ // get the output files: - String[] outputs = files[0].trim().split(" "); + String[] outputs = files[0].trim().split(" "); //$NON-NLS-1$ // and the dependency files: - String[] dependencies = files[1].trim().split(" "); + String[] dependencies = files[1].trim().split(" "); //$NON-NLS-1$ List<IFile> outputFiles = new ArrayList<IFile>(); List<IFile> dependencyFiles = new ArrayList<IFile>(); diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/build/builders/PostCompilerBuilder.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/build/builders/PostCompilerBuilder.java index 5df7f22..8dd92a7 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/build/builders/PostCompilerBuilder.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/build/builders/PostCompilerBuilder.java @@ -446,7 +446,6 @@ public class PostCompilerBuilder extends BaseBuilder { // remove some aapt_package only markers. removeMarkersFromContainer(project, AndroidConstants.MARKER_AAPT_PACKAGE); - // need to figure out some path before we can execute aapt; try { helper.packageResources(manifestFile, libProjects, null /*resfilter*/, 0 /*versionCode */, osBinPath, diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/build/builders/PreCompilerDeltaVisitor.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/build/builders/PreCompilerDeltaVisitor.java index b39236a..f7365e5 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/build/builders/PreCompilerDeltaVisitor.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/build/builders/PreCompilerDeltaVisitor.java @@ -272,13 +272,11 @@ class PreCompilerDeltaVisitor extends BaseDeltaVisitor implements IResourceDelta // we want a warning outputWarning = true; } else { - // look to see if this java file was generated by a generator. - if (AndroidConstants.EXT_JAVA.equalsIgnoreCase(file.getFileExtension())) { - for (GeneratorDeltaVisitor dv : mGeneratorDeltaVisitors) { - if (dv.handleGeneratedFile(file, kind)) { - outputWarning = true; - break; // there shouldn't be 2 generators that handle the same file. - } + // look to see if this file was generated by a generator. + for (GeneratorDeltaVisitor dv : mGeneratorDeltaVisitors) { + if (dv.handleGeneratedFile(file, kind)) { + outputWarning = true; + break; // there shouldn't be 2 generators that handle the same file. } } } diff --git a/sdkmanager/libs/sdklib/src/com/android/sdklib/build/ApkBuilder.java b/sdkmanager/libs/sdklib/src/com/android/sdklib/build/ApkBuilder.java index 8c18c3a..c066dff 100644 --- a/sdkmanager/libs/sdklib/src/com/android/sdklib/build/ApkBuilder.java +++ b/sdkmanager/libs/sdklib/src/com/android/sdklib/build/ApkBuilder.java @@ -872,12 +872,14 @@ public final class ApkBuilder { * @return true if the file should be packaged as standard java resources. */ public static boolean checkFileForPackaging(String fileName, String extension) { - // Note: this method is used by com.android.ide.eclipse.adt.internal.build.ApkBuilder if (fileName.charAt(0) == '.') { // ignore hidden files. return false; } return "aidl".equalsIgnoreCase(extension) == false && // Aidl files + "rs".equalsIgnoreCase(extension) == false && // RenderScript files + "rsh".equalsIgnoreCase(extension) == false && // RenderScript header files + "d".equalsIgnoreCase(extension) == false && // Dependency files "java".equalsIgnoreCase(extension) == false && // Java files "class".equalsIgnoreCase(extension) == false && // Java class files "scc".equalsIgnoreCase(extension) == false && // VisualSourceSafe |