diff --git a/.watchmanconfig b/.watchmanconfig index 0ff7cb75d..0d00be406 100644 --- a/.watchmanconfig +++ b/.watchmanconfig @@ -1,12 +1,12 @@ { "ignore_dirs": [ "buck-out", - ".idea", ".buckd", + ".idea", + ".okbuck", "build", ".gradle", ".swp", - "java" ], "fsevents_latency": 0.05, "suppress_recrawl_warnings": true diff --git a/buckw b/buckw index 74ba85066..77b5a8f17 100755 --- a/buckw +++ b/buckw @@ -4,7 +4,7 @@ ## ## Buck wrapper script to invoke okbuck when needed, before running buck ## -## Created by OkBuck Gradle Plugin on : Fri Jan 13 16:41:05 PST 2017 +## Created by OkBuck Gradle Plugin on : Fri Jan 27 01:29:40 PST 2017 ## ######################################################################### @@ -69,16 +69,16 @@ removeWatch ( ) { getToClean ( ) { ensureWatch - watchman --output-encoding=json -j 2>&1 <<-EOT + watchman --output-encoding=json --no-pretty -j 2>&1 <<-EOT ["query", "$WORKING_DIR", { "expression": ["allof", ["type", "f"], ["anyof", - ["imatch", "**/BUCK", "wholename"], - ["imatch", ".buckconfig.local", "wholename"] + ["name", "BUCK"], + ["name", ".buckconfig.local"] ], ["not", - ["imatch", ".okbuck/**/BUCK", "wholename"] + ["dirname", ".okbuck"] ] ], "fields": ["name"] @@ -89,31 +89,31 @@ EOT getChanges ( ) { ensureWatch - WATCHED_CHANGES=`watchman --output-encoding=json -j 2>&1 <<-EOT + WATCHED_CHANGES=`watchman --output-encoding=json --no-pretty -j 2>&1 <<-EOT ["query", "$WORKING_DIR", { "since": "n:okbuck_trig", "expression": ["allof", ["type", "f"], ["anyof", - ["imatch", "**/*.sq", "wholename"], - ["imatch", "**/*.gradle", "wholename"], - ["imatch", "**/gradle-wrapper.properties", "wholename"], - ["imatch", "**/lint.xml", "wholename"], - ["imatch", "**/src/**/AndroidManifest.xml", "wholename"] + ["suffix", "sq"], + ["suffix", "gradle"], + ["name", "gradle-wrapper.properties"], + ["name", "lint.xml"], + ["match", "**/src/**/AndroidManifest.xml", "wholename"] ] ], "fields": ["name"] }] EOT` - SOURCE_ROOTS=`watchman --output-encoding=json -j 2>&1 <<-EOT + SOURCE_ROOTS=`watchman --output-encoding=json --no-pretty -j 2>&1 <<-EOT ["query", ".", { "since": "n:okbuck_source_roots", "expression": ["allof", ["type", "d"], ["anyof", - ["imatch", "**/src/**/java", "wholename"], - ["imatch", "**/src/**/res", "wholename"], - ["imatch", "**/src/**/resources", "wholename"] + ["match", "**/src/**/java", "wholename"], + ["match", "**/src/**/res", "wholename"], + ["match", "**/src/**/resources", "wholename"] ] ], "fields": ["new", "exists", "name"] diff --git a/buildSrc/src/main/java/com/uber/okbuck/extension/WrapperExtension.java b/buildSrc/src/main/java/com/uber/okbuck/extension/WrapperExtension.java index d2a88fc0a..2eae99f7f 100644 --- a/buildSrc/src/main/java/com/uber/okbuck/extension/WrapperExtension.java +++ b/buildSrc/src/main/java/com/uber/okbuck/extension/WrapperExtension.java @@ -2,6 +2,7 @@ import com.google.common.collect.Sets; +import java.util.Collections; import java.util.Set; public class WrapperExtension { @@ -19,7 +20,7 @@ public class WrapperExtension { /** * List of files to leave untouched when generating configuration. */ - public Set keep = Sets.newHashSet(".okbuck/**/BUCK"); + public Set keep = Collections.emptySet(); /** * List of changed files to trigger okbuck runs on diff --git a/buildSrc/src/main/java/com/uber/okbuck/wrapper/BuckWrapperTask.java b/buildSrc/src/main/java/com/uber/okbuck/wrapper/BuckWrapperTask.java index df6eed266..e5c2a0c08 100644 --- a/buildSrc/src/main/java/com/uber/okbuck/wrapper/BuckWrapperTask.java +++ b/buildSrc/src/main/java/com/uber/okbuck/wrapper/BuckWrapperTask.java @@ -3,6 +3,7 @@ import com.google.common.collect.ImmutableMap; import com.uber.okbuck.core.util.FileUtil; +import org.apache.commons.io.FilenameUtils; import org.gradle.api.DefaultTask; import org.gradle.api.tasks.Input; import org.gradle.api.tasks.TaskAction; @@ -16,6 +17,8 @@ @SuppressWarnings({"WeakerAccess", "CanBeFinal", "unused", "ResultOfMethodCallIgnored"}) public class BuckWrapperTask extends DefaultTask { + private static String OKBUCK_DIRNAME = " [\"dirname\", \".okbuck\"]"; + @Input public String repo; @@ -35,23 +38,52 @@ public class BuckWrapperTask extends DefaultTask { @TaskAction void installWrapper() { + String keepExpr = toWatchmanMatchers(keep); + if (keepExpr.isEmpty()) { + keepExpr = OKBUCK_DIRNAME; + } else { + keepExpr = OKBUCK_DIRNAME + "\n" + keepExpr; + } Map templates = ImmutableMap.builder() .put("template-creation-time", new Date().toString()) .put("template-custom-buck-repo", repo) .put("template-remove", toWatchmanMatchers(remove)) - .put("template-keep", toWatchmanMatchers(keep)) + .put("template-keep", keepExpr) .put("template-watch", toWatchmanMatchers(watch)) .put("template-source-roots", toWatchmanMatchers(sourceRoots)) .build(); FileUtil.copyResourceToProject("wrapper/BUCKW_TEMPLATE", wrapper, templates); wrapper.setExecutable(true); + + File watchmanConfig = getProject().file(".watchmanconfig"); + if (!watchmanConfig.exists()) { + FileUtil.copyResourceToProject("wrapper/WATCHMAN_CONFIG", getProject().file(".watchmanconfig")); + } + } + + private static String watchmanExpr(String wildcardPattern) { + String simplifiedPattern = wildcardPattern; + if (wildcardPattern.startsWith("**/")) { + simplifiedPattern = wildcardPattern.replaceAll("\\*\\*/", ""); + } + String basename = FilenameUtils.getBaseName(simplifiedPattern); + String extension = FilenameUtils.getExtension(simplifiedPattern); + if (!simplifiedPattern.contains("/")) { + // simple file name with no path prefixes + if (basename.equals("*")) { // suffix + return " [\"suffix\", \"" + extension + "\"]"; + } else { // name + return " [\"name\", \"" + simplifiedPattern + "\"]"; + } + } + return " [\"match\", \"" + wildcardPattern + "\", \"wholename\"]"; } private static String toWatchmanMatchers(Set wildcardPatterns) { return wildcardPatterns .parallelStream() - .map(pattern -> " [\"imatch\", \"" + pattern + "\", \"wholename\"]") + .map(BuckWrapperTask::watchmanExpr) .collect(Collectors.joining(",\n")); } } diff --git a/buildSrc/src/main/resources/com/uber/okbuck/core/util/wrapper/BUCKW_TEMPLATE b/buildSrc/src/main/resources/com/uber/okbuck/core/util/wrapper/BUCKW_TEMPLATE index a8c0c7082..717fd007e 100644 --- a/buildSrc/src/main/resources/com/uber/okbuck/core/util/wrapper/BUCKW_TEMPLATE +++ b/buildSrc/src/main/resources/com/uber/okbuck/core/util/wrapper/BUCKW_TEMPLATE @@ -69,7 +69,7 @@ removeWatch ( ) { getToClean ( ) { ensureWatch - watchman --output-encoding=json -j 2>&1 <<-EOT + watchman --output-encoding=json --no-pretty -j 2>&1 <<-EOT ["query", "$WORKING_DIR", { "expression": ["allof", ["type", "f"], @@ -88,7 +88,7 @@ EOT getChanges ( ) { ensureWatch - WATCHED_CHANGES=`watchman --output-encoding=json -j 2>&1 <<-EOT + WATCHED_CHANGES=`watchman --output-encoding=json --no-pretty -j 2>&1 <<-EOT ["query", "$WORKING_DIR", { "since": "n:okbuck_trig", "expression": ["allof", @@ -100,7 +100,7 @@ ${template-watch} "fields": ["name"] }] EOT` - SOURCE_ROOTS=`watchman --output-encoding=json -j 2>&1 <<-EOT + SOURCE_ROOTS=`watchman --output-encoding=json --no-pretty -j 2>&1 <<-EOT ["query", ".", { "since": "n:okbuck_source_roots", "expression": ["allof", diff --git a/buildSrc/src/main/resources/com/uber/okbuck/core/util/wrapper/watchman_config b/buildSrc/src/main/resources/com/uber/okbuck/core/util/wrapper/watchman_config new file mode 100644 index 000000000..0d00be406 --- /dev/null +++ b/buildSrc/src/main/resources/com/uber/okbuck/core/util/wrapper/watchman_config @@ -0,0 +1,13 @@ +{ + "ignore_dirs": [ + "buck-out", + ".buckd", + ".idea", + ".okbuck", + "build", + ".gradle", + ".swp", + ], + "fsevents_latency": 0.05, + "suppress_recrawl_warnings": true +}