From 3127778e2dda43079568c4a76453e73a951f17bf Mon Sep 17 00:00:00 2001 From: Advay Mengle Date: Fri, 14 Aug 2015 03:36:35 -0700 Subject: [PATCH] Add a translateOnly mode that skips compilation-dependent tasks. Related to #345; Fixes #347 --- FAQ.md | 17 ++++++++---- .../j2objcgradle/J2objcConfig.groovy | 26 ++++++++++++++++--- .../j2objcgradle/J2objcPlugin.groovy | 5 +++- 3 files changed, 38 insertions(+), 10 deletions(-) diff --git a/FAQ.md b/FAQ.md index e7058bca..2e4edfe4 100644 --- a/FAQ.md +++ b/FAQ.md @@ -223,7 +223,7 @@ and building the J2ObjC source: 3. Configure j2objcConfig in `shared/build.gradle` so CycleFinder uses the annotated J2ObjC source and whitelist. Note how this gives and expected cycles of zero. -``` +```gradle // File: shared/build.gradle j2objcConfig { cycleFinderArgs '--whitelist', 'J2OBJC_REPO/jre_emul/cycle_whitelist.txt' @@ -244,10 +244,17 @@ Development is officially supported only on Mac OS X. This matches the In practice, the j2objcCycleFinder and j2objcTranslate tasks may work, though it is strongly suggested to use this for experimentation only and do all proper development on OS X. The team will reject any bugs related to systems that don't meet the -[minimum requirements](README.md#minimum-requirements). - -To experiment on Windows (skipping the unsupported tasks), the following may work: +[minimum requirements](README.md#minimum-requirements). You can attempt just +j2objcCycleFinder and j2objcTranslate tasks with: - ./gradlew shared:j2objcAssembleSource shared:j2objcAssembleResources +```gradle + // File: shared/build.gradle + j2objcConfig { + ... + translateOnlyMode = true + ... + finalConfigure() + } +``` Please note that this will not build the packed libraries or update your Xcode project. diff --git a/src/main/groovy/com/github/j2objccontrib/j2objcgradle/J2objcConfig.groovy b/src/main/groovy/com/github/j2objccontrib/j2objcgradle/J2objcConfig.groovy index 8f2e2273..fd65b576 100644 --- a/src/main/groovy/com/github/j2objccontrib/j2objcgradle/J2objcConfig.groovy +++ b/src/main/groovy/com/github/j2objccontrib/j2objcgradle/J2objcConfig.groovy @@ -212,6 +212,12 @@ class J2objcConfig { appendArgs(this.translateSourcepaths, 'translateSourcepaths', translateSourcepaths) } + /** + * True iff only translation (and cycle finding, if applicable) should be attempted, + * skipping all compilation, linking, and testing tasks. + */ + boolean translateOnlyMode = false + // Do not use groovydoc, this option should remain undocumented. // WARNING: Do not use this unless you know what you are doing. @@ -511,16 +517,16 @@ class J2objcConfig { assert destSrcMainDir != null assert destSrcTestDir != null - // For convenience, disable all debug and/or release tasks if the user desires. - // Note all J2objcPlugin-created tasks are of the form `j2objc.*(Debug|Release)?` - // however Native plugin-created tasks (on our behalf) are of the form `.*((D|d)ebug|(R|r)elease).*(j|J)2objc.*' - // so these patterns find all such tasks. // Disable only if explicitly present and not true. boolean debugEnabled = Boolean.parseBoolean(Utils.getLocalProperty(project, 'debug.enabled', 'true')) boolean releaseEnabled = Boolean.parseBoolean(Utils.getLocalProperty(project, 'release.enabled', 'true')) project.tasks.all { Task task -> String name = task.name + // For convenience, disable all debug and/or release tasks if the user desires. + // Note all J2objcPlugin-created tasks are of the form `j2objc.*(Debug|Release)?` + // however Native plugin-created tasks (on our behalf) are of the form `.*((D|d)ebug|(R|r)elease).*(j|J)2objc.*' + // so these patterns find all such tasks. if (name.contains('j2objc') || name.contains('J2objc')) { if (!debugEnabled && (name.contains('debug') || name.contains('Debug'))) { task.enabled = false @@ -529,7 +535,19 @@ class J2objcConfig { task.enabled = false } } + + // Support translation-only mode. + if (translateOnlyMode) { + // First pattern matches all native-compilation tasks. + // Second pattern matches plugin-specific tasks beyond translation. + if ((name =~ /^.*((J|j)2objc(Executable|StaticLibrary|SharedLibrary|Objc))$/).matches() || + (name =~ /^j2objc(Assemble|PackLibraries|Test)(Debug|Release)$/).matches()) { + task.enabled = false + } + } } + + } boolean isFinalConfigured() { return finalConfigured diff --git a/src/main/groovy/com/github/j2objccontrib/j2objcgradle/J2objcPlugin.groovy b/src/main/groovy/com/github/j2objccontrib/j2objcgradle/J2objcPlugin.groovy index 0fc418d6..5e8b2fe1 100644 --- a/src/main/groovy/com/github/j2objccontrib/j2objcgradle/J2objcPlugin.groovy +++ b/src/main/groovy/com/github/j2objccontrib/j2objcgradle/J2objcPlugin.groovy @@ -26,7 +26,6 @@ import com.github.j2objccontrib.j2objcgradle.tasks.TranslateTask import com.github.j2objccontrib.j2objcgradle.tasks.Utils import com.github.j2objccontrib.j2objcgradle.tasks.XcodeTask import org.gradle.api.DefaultTask -import org.gradle.api.InvalidUserDataException import org.gradle.api.Plugin import org.gradle.api.Project import org.gradle.api.Task @@ -112,6 +111,10 @@ class J2objcPlugin implements Plugin { description "Run the cycle_finder tool on all Java source files" enabled false } + + // NOTE: When adding new tasks, consider whether they fall under 'translate-only' mode, and + // filter them in J2objcConfig.finalConfigure otherwise. + // Note the '(debug|release)TestJ2objcExecutable' tasks are dynamically created by the Objective-C plugin. // It is specified by the testJ2objc native component in NativeCompilation.groovy. // TODO: copy and run debug and release tests within j2objcTestContent at the