Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a translateOnly mode that skips compilation-dependent tasks. #349

Merged
merged 1 commit into from
Aug 16, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions FAQ.md
Original file line number Diff line number Diff line change
Expand Up @@ -244,10 +244,12 @@ 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).
[minimum requirements](README.md#minimum-requirements). You can attempt just
j2objcCycleFinder and j2objcTranslate by adding the following line to your local.properties
file only on Windows machines.

To experiment on Windows (skipping the unsupported tasks), the following may work:

./gradlew shared:j2objcAssembleSource shared:j2objcAssembleResources
```properties
j2objc.translateOnlyMode=true
```

Please note that this will not build the packed libraries or update your Xcode project.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will make it work on Windows but break the Mac OS X in the process. I think the name and logic should be:

translateOnlyWhenNotMacOSX = false

Then add reference to that in the FAQ... and point to that FAQ if you attempt a post-translate task on Windows, explaining how to use it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what you mean. translateOnly works on all platforms (I'm now using it actually for one case where I want to transform the source myself, on Mac).

The faq already has a comment regarding the use of this on Windows.

Per the discussion on #345 (comment), the point is to not have windows-specific code, this is just a new cross-platform feature.



// Do not use groovydoc, this option should remain undocumented.
// WARNING: Do not use this unless you know what you are doing.
Expand Down Expand Up @@ -511,16 +517,20 @@ 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'))
// Enable only if explicitly present in either the project config OR the local config.
boolean translateOnlyMode = this.translateOnlyMode ||
Boolean.parseBoolean(Utils.getLocalProperty(project, 'translateOnlyMode', 'false'))

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
Expand All @@ -529,7 +539,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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -112,6 +111,10 @@ class J2objcPlugin implements Plugin<Project> {
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ class Utils {
Collections.unmodifiableList(Arrays.asList(
'debug.enabled',
'home',
'release.enabled'
'release.enabled',
'translateOnlyMode'
))

private static final String PROPERTY_KEY_PREFIX = 'j2objc.'
Expand Down