diff options
4 files changed, 83 insertions, 41 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/rules/SkylarkActionFactory.java b/src/main/java/com/google/devtools/build/lib/rules/SkylarkActionFactory.java index 4360561628..2f87704d83 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/SkylarkActionFactory.java +++ b/src/main/java/com/google/devtools/build/lib/rules/SkylarkActionFactory.java @@ -263,7 +263,7 @@ public class SkylarkActionFactory implements SkylarkValue { type = Object.class, allowedTypes = { @ParamType(type = Artifact.class), - @ParamType(type = PathFragment.class), + @ParamType(type = String.class), }, named = true, positional = false, @@ -371,12 +371,12 @@ public class SkylarkActionFactory implements SkylarkValue { } else { builder.setExecutable(provider); } - } else if (executableUnchecked instanceof PathFragment) { - builder.setExecutable((PathFragment) executableUnchecked); + } else if (executableUnchecked instanceof String) { + builder.setExecutable(PathFragment.create((String) executableUnchecked)); } else { throw new EvalException( null, - "expected file or PathFragment for " + "expected file or string for " + "executable but got " + EvalUtils.getDataTypeName(executableUnchecked) + " instead"); diff --git a/src/main/java/com/google/devtools/build/lib/rules/SkylarkRuleImplementationFunctions.java b/src/main/java/com/google/devtools/build/lib/rules/SkylarkRuleImplementationFunctions.java index f565442c22..3ed41bcd39 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/SkylarkRuleImplementationFunctions.java +++ b/src/main/java/com/google/devtools/build/lib/rules/SkylarkRuleImplementationFunctions.java @@ -106,7 +106,7 @@ public class SkylarkRuleImplementationFunctions { type = Object.class, allowedTypes = { @ParamType(type = Artifact.class), - @ParamType(type = PathFragment.class), + @ParamType(type = String.class), @ParamType(type = Runtime.NoneType.class), }, defaultValue = "None", diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppConfiguration.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppConfiguration.java index dfa3e40a3e..13612763ce 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppConfiguration.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppConfiguration.java @@ -983,11 +983,6 @@ public class CppConfiguration extends BuildConfiguration.Fragment { return useStartEndLib() ? Link.ArchiveType.START_END_LIB : Link.ArchiveType.REGULAR; } - /** - * Returns the built-in list of system include paths for the toolchain compiler. All paths in this - * list should be relative to the exec directory. They may be absolute if they are also installed - * on the remote build nodes or for local compilation. - */ @SkylarkCallable( name = "built_in_include_directories", structField = true, @@ -996,11 +991,19 @@ public class CppConfiguration extends BuildConfiguration.Fragment { + " should be relative to the exec directory. They may be absolute if they are also" + " installed on the remote build nodes or for local compilation." ) - public ImmutableList<PathFragment> getBuiltInIncludeDirectories() + public ImmutableList<String> getBuiltInIncludeDirectoriesForSkylark() throws InvalidConfigurationException { - return getBuiltInIncludeDirectories(nonConfiguredSysroot); + return getBuiltInIncludeDirectories(nonConfiguredSysroot) + .stream() + .map(PathFragment::getPathString) + .collect(ImmutableList.toImmutableList()); } + /** + * Returns the built-in list of system include paths for the toolchain compiler. All paths in this + * list should be relative to the exec directory. They may be absolute if they are also installed + * on the remote build nodes or for local compilation. + */ public ImmutableList<PathFragment> getBuiltInIncludeDirectories(PathFragment sysroot) throws InvalidConfigurationException { ImmutableList.Builder<PathFragment> builtInIncludeDirectoriesBuilder = ImmutableList.builder(); @@ -1019,8 +1022,8 @@ public class CppConfiguration extends BuildConfiguration.Fragment { doc = "Returns the sysroot to be used. If the toolchain compiler does not support " + "different sysroots, or the sysroot is the same as the default sysroot, then " + "this method returns <code>None</code>.") - public PathFragment getSysroot() { - return nonConfiguredSysroot; + public String getSysroot() { + return nonConfiguredSysroot.getPathString(); } public Label getSysrootLabel() { @@ -1547,20 +1550,34 @@ public class CppConfiguration extends BuildConfiguration.Fragment { structField = true, doc = "Path to GNU binutils 'objcopy' binary." ) - public PathFragment getObjCopyExecutable() { - return getToolPathFragment(CppConfiguration.Tool.OBJCOPY); + public String getObjCopyExecutableForSkylark() { + PathFragment objCopyExecutable = getObjCopyExecutable(); + return objCopyExecutable != null ? objCopyExecutable.getPathString() : ""; } /** - * Returns the path to the GNU binutils 'gcc' binary that should be used by this build. This - * binary should support compilation of both C (*.c) and C++ (*.cc) files. Relative paths are - * relative to the execution root. + * Returns the path to the GNU binutils 'objcopy' binary to use for this build. (Corresponds to + * $(OBJCOPY) in make-dbg.) Relative paths are relative to the execution root. */ + public PathFragment getObjCopyExecutable() { + return getToolPathFragment(CppConfiguration.Tool.OBJCOPY); + } + @SkylarkCallable( name = "compiler_executable", structField = true, doc = "Path to C/C++ compiler binary." ) + public String getCppExecutableForSkylark() { + PathFragment cppExecutable = getCppExecutable(); + return cppExecutable != null ? cppExecutable.getPathString() : ""; + } + + /** + * Returns the path to the GNU binutils 'gcc' binary that should be used by this build. This + * binary should support compilation of both C (*.c) and C++ (*.cc) files. Relative paths are + * relative to the execution root. + */ public PathFragment getCppExecutable() { return getToolPathFragment(CppConfiguration.Tool.GCC); } @@ -1574,15 +1591,20 @@ public class CppConfiguration extends BuildConfiguration.Fragment { return getToolPathFragment(CppConfiguration.Tool.GCC); } - /** - * Returns the path to the GNU binutils 'cpp' binary that should be used by this build. Relative - * paths are relative to the execution root. - */ @SkylarkCallable( name = "preprocessor_executable", structField = true, doc = "Path to C/C++ preprocessor binary." ) + public String getCpreprocessorExecutableForSkylark() { + PathFragment cpreprocessorExecutable = getCpreprocessorExecutable(); + return cpreprocessorExecutable != null ? cpreprocessorExecutable.getPathString() : ""; + } + + /** + * Returns the path to the GNU binutils 'cpp' binary that should be used by this build. Relative + * paths are relative to the execution root. + */ public PathFragment getCpreprocessorExecutable() { return getToolPathFragment(CppConfiguration.Tool.CPP); } @@ -1604,54 +1626,74 @@ public class CppConfiguration extends BuildConfiguration.Fragment { return getToolPathFragment(CppConfiguration.Tool.GCOVTOOL); } - /** - * Returns the path to the GNU binutils 'nm' executable that should be used by this build. Used - * only for testing. Relative paths are relative to the execution root. - */ @SkylarkCallable( name = "nm_executable", structField = true, doc = "Path to GNU binutils 'nm' binary." ) - public PathFragment getNmExecutable() { - return getToolPathFragment(CppConfiguration.Tool.NM); + public String getNmExecutableForSkylark() { + PathFragment nmExecutable = getNmExecutable(); + return nmExecutable != null ? nmExecutable.getPathString() : ""; } /** - * Returns the path to the GNU binutils 'objdump' executable that should be used by this build. - * Used only for testing. Relative paths are relative to the execution root. + * Returns the path to the GNU binutils 'nm' executable that should be used by this build. Used + * only for testing. Relative paths are relative to the execution root. */ + public PathFragment getNmExecutable() { + return getToolPathFragment(CppConfiguration.Tool.NM); + } + @SkylarkCallable( name = "objdump_executable", structField = true, doc = "Path to GNU binutils 'objdump' binary." ) - public PathFragment getObjdumpExecutable() { - return getToolPathFragment(CppConfiguration.Tool.OBJDUMP); + public String getObjdumpExecutableForSkylark() { + PathFragment objdumpExecutable = getObjdumpExecutable(); + return objdumpExecutable != null ? objdumpExecutable.getPathString() : ""; } /** - * Returns the path to the GNU binutils 'ar' binary to use for this build. Relative paths are - * relative to the execution root. + * Returns the path to the GNU binutils 'objdump' executable that should be used by this build. + * Used only for testing. Relative paths are relative to the execution root. */ + public PathFragment getObjdumpExecutable() { + return getToolPathFragment(CppConfiguration.Tool.OBJDUMP); + } + @SkylarkCallable( name = "ar_executable", structField = true, doc = "Path to GNU binutils 'ar' binary." ) - public PathFragment getArExecutable() { - return getToolPathFragment(CppConfiguration.Tool.AR); + public String getArExecutableForSkylark() { + PathFragment arExecutable = getArExecutable(); + return arExecutable != null ? arExecutable.getPathString() : ""; } /** - * Returns the path to the GNU binutils 'strip' executable that should be used by this build. - * Relative paths are relative to the execution root. + * Returns the path to the GNU binutils 'ar' binary to use for this build. Relative paths are + * relative to the execution root. */ + public PathFragment getArExecutable() { + return getToolPathFragment(CppConfiguration.Tool.AR); + } + @SkylarkCallable( name = "strip_executable", structField = true, doc = "Path to GNU binutils 'strip' binary." ) + public String getStripExecutableForSkylark() { + PathFragment stripExecutable = getStripExecutable(); + return stripExecutable != null ? stripExecutable.getPathString() : ""; + } + + /** + * Returns the path to the GNU binutils 'strip' executable that should be used by this build. + * Relative paths are relative to the execution root. + */ public PathFragment getStripExecutable() { return getToolPathFragment(CppConfiguration.Tool.STRIP); } diff --git a/src/test/java/com/google/devtools/build/lib/skylark/SkylarkRuleImplementationFunctionsTest.java b/src/test/java/com/google/devtools/build/lib/skylark/SkylarkRuleImplementationFunctionsTest.java index 72ae65e0b4..6a7f2e278f 100644 --- a/src/test/java/com/google/devtools/build/lib/skylark/SkylarkRuleImplementationFunctionsTest.java +++ b/src/test/java/com/google/devtools/build/lib/skylark/SkylarkRuleImplementationFunctionsTest.java @@ -295,12 +295,12 @@ public class SkylarkRuleImplementationFunctionsTest extends SkylarkTestCase { public void testCreateSpawnActionArgumentsBadExecutable() throws Exception { checkErrorContains( createRuleContext("//foo:foo"), - "expected file or PathFragment for executable but got string instead", + "expected file or string for executable but got int instead", "ruleContext.actions.run(", " inputs = ruleContext.files.srcs,", " outputs = ruleContext.files.srcs,", " arguments = ['--a','--b'],", - " executable = 'xyz.exe')"); + " executable = 123)"); } @Test |