diff options
author | 2018-05-07 09:42:27 -0700 | |
---|---|---|
committer | 2018-05-07 09:44:11 -0700 | |
commit | b5573a6df78527be0bb15da54df03f9981e1302d (patch) | |
tree | 9db4304cc7be651ef4f2e2d63bb94713c0358f95 /src/main/java/com/google/devtools | |
parent | 0d78a8115d82f27c2fe395496b14377fb206475f (diff) |
Rename Staticness to LinkerOrArchiver.
Staticness is confusing, I always have to investigate which is Staticness and
which is LinkStaticness, and even in isolation staticness is not a great name. I
believe LinkerOrArchiver is a better name :)
RELNOTES: None.
PiperOrigin-RevId: 195674810
Diffstat (limited to 'src/main/java/com/google/devtools')
5 files changed, 59 insertions, 58 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcLinkingHelper.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcLinkingHelper.java index 3e3bbcdc78..b77087943b 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcLinkingHelper.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcLinkingHelper.java @@ -46,8 +46,8 @@ import com.google.devtools.build.lib.rules.cpp.CcToolchainFeatures.FeatureConfig import com.google.devtools.build.lib.rules.cpp.CcToolchainFeatures.Variables.VariablesExtension; import com.google.devtools.build.lib.rules.cpp.Link.LinkStaticness; import com.google.devtools.build.lib.rules.cpp.Link.LinkTargetType; +import com.google.devtools.build.lib.rules.cpp.Link.LinkerOrArchiver; import com.google.devtools.build.lib.rules.cpp.Link.Picness; -import com.google.devtools.build.lib.rules.cpp.Link.Staticness; import com.google.devtools.build.lib.rules.cpp.LinkerInputs.LibraryToLink; import com.google.devtools.build.lib.skylarkinterface.SkylarkCallable; import com.google.devtools.build.lib.skylarkinterface.SkylarkModule; @@ -337,7 +337,7 @@ public final class CcLinkingHelper { */ public CcLinkingHelper setStaticLinkType(LinkTargetType linkType) { Preconditions.checkNotNull(linkType); - Preconditions.checkState(linkType.staticness() == Staticness.STATIC); + Preconditions.checkState(linkType.linkerOrArchiver() == LinkerOrArchiver.ARCHIVER); this.linkType = linkType; return this; } @@ -464,7 +464,7 @@ public final class CcLinkingHelper { // // An additional pre-existing issue is that the header check tokens are dropped if we don't // generate any link actions, effectively disabling header checking in some cases. - if (linkType.staticness() == Staticness.STATIC) { + if (linkType.linkerOrArchiver() == LinkerOrArchiver.ARCHIVER) { // TODO(bazel-team): This can't create the link action for a cc_binary yet. ccLinkingOutputs = createCcLinkActions(ccOutputs, nonCodeLinkerInputs); } @@ -715,7 +715,7 @@ public final class CcLinkingHelper { // For now only handle static links. Note that the dynamic library link below ignores linkType. // TODO(bazel-team): Either support non-static links or move this check to setStaticLinkType(). Preconditions.checkState( - linkType.staticness() == Staticness.STATIC, "can only handle static links"); + linkType.linkerOrArchiver() == LinkerOrArchiver.ARCHIVER, "can only handle static links"); CcLinkingOutputs.Builder result = new CcLinkingOutputs.Builder(); if (cppConfiguration.isLipoContextCollector()) { diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppLinkActionBuilder.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppLinkActionBuilder.java index 539af79dbb..c116465270 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppLinkActionBuilder.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppLinkActionBuilder.java @@ -52,7 +52,7 @@ import com.google.devtools.build.lib.rules.cpp.CppLinkAction.LinkArtifactFactory import com.google.devtools.build.lib.rules.cpp.LibrariesToLinkCollector.CollectedLibrariesToLink; import com.google.devtools.build.lib.rules.cpp.Link.LinkStaticness; import com.google.devtools.build.lib.rules.cpp.Link.LinkTargetType; -import com.google.devtools.build.lib.rules.cpp.Link.Staticness; +import com.google.devtools.build.lib.rules.cpp.Link.LinkerOrArchiver; import com.google.devtools.build.lib.rules.cpp.LinkerInputs.LibraryToLink; import com.google.devtools.build.lib.vfs.FileSystemUtils; import com.google.devtools.build.lib.vfs.PathFragment; @@ -617,7 +617,9 @@ public class CppLinkActionBuilder { private ImmutableMap<Artifact, LtoBackendArtifacts> createSharedNonLtoArtifacts( boolean isLtoIndexing) { // Only create the shared LTO artifacts for a statically linked library that has bitcode files. - if (ltoBitcodeFiles == null || isLtoIndexing || linkType.staticness() != Staticness.STATIC) { + if (ltoBitcodeFiles == null + || isLtoIndexing + || linkType.linkerOrArchiver() != LinkerOrArchiver.ARCHIVER) { return ImmutableMap.<Artifact, LtoBackendArtifacts>of(); } @@ -678,7 +680,7 @@ public class CppLinkActionBuilder { } private ImmutableList<String> getToolchainFlags(List<String> linkopts) { - if (Staticness.STATIC.equals(linkType.staticness())) { + if (LinkerOrArchiver.ARCHIVER.equals(linkType.linkerOrArchiver())) { return ImmutableList.of(); } boolean fullyStatic = (linkStaticness == LinkStaticness.FULLY_STATIC); @@ -997,7 +999,7 @@ public class CppLinkActionBuilder { Variables variables = LinkBuildVariables.setupVariables( - this, + getLinkType().linkerOrArchiver().equals(LinkerOrArchiver.LINKER), configuration, output, paramFile, @@ -1034,7 +1036,7 @@ public class CppLinkActionBuilder { interfaceOutput == null, "interface output may only be non-null for dynamic library links"); } - if (linkType.staticness() == Staticness.STATIC) { + if (linkType.linkerOrArchiver() == LinkerOrArchiver.ARCHIVER) { // solib dir must be null for static links toolchainLibrariesSolibDir = null; @@ -1054,7 +1056,9 @@ public class CppLinkActionBuilder { .setLinkTargetType(linkType) .setLinkStaticness(linkStaticness) .setToolchainLibrariesSolibDir( - linkType.staticness() == Staticness.STATIC ? null : toolchainLibrariesSolibDir) + linkType.linkerOrArchiver() == LinkerOrArchiver.ARCHIVER + ? null + : toolchainLibrariesSolibDir) .setNativeDeps(isNativeDeps) .setUseTestOnlyFlags(useTestOnlyFlags) .setParamFile(paramFile) @@ -1082,7 +1086,9 @@ public class CppLinkActionBuilder { // For now, silently ignore linkopts if this is a static library linkoptsForVariables = - linkType.staticness() == Staticness.STATIC ? ImmutableList.of() : linkoptsForVariables; + linkType.linkerOrArchiver() == LinkerOrArchiver.ARCHIVER + ? ImmutableList.of() + : linkoptsForVariables; linkCommandLineBuilder.setLinkopts(linkoptsForVariables); Variables patchedVariables = diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/Link.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/Link.java index 30cdbbe7dd..d347baefa6 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/Link.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/Link.java @@ -75,14 +75,12 @@ public abstract class Link { NOPIC } - /** - * Whether a particular link target linked in statically or dynamically. - */ - public enum Staticness { - STATIC, - DYNAMIC + /** Whether a particular link target linked in statically or dynamically. */ + public enum LinkerOrArchiver { + ARCHIVER, + LINKER } - + /** * Whether a particular link target is executable. */ @@ -99,25 +97,25 @@ public abstract class Link { /** A normal static archive. */ STATIC_LIBRARY( ".a", - Staticness.STATIC, + LinkerOrArchiver.ARCHIVER, "c++-link-static-library", Picness.NOPIC, ArtifactCategory.STATIC_LIBRARY, Executable.NOT_EXECUTABLE), - + /** An objc static archive. */ OBJC_ARCHIVE( - ".a", - Staticness.STATIC, - "objc-archive", + ".a", + LinkerOrArchiver.ARCHIVER, + "objc-archive", Picness.NOPIC, ArtifactCategory.STATIC_LIBRARY, Executable.NOT_EXECUTABLE), - + /** An objc fully linked static archive. */ OBJC_FULLY_LINKED_ARCHIVE( ".a", - Staticness.STATIC, + LinkerOrArchiver.ARCHIVER, "objc-fully-link", Picness.NOPIC, ArtifactCategory.STATIC_LIBRARY, @@ -126,7 +124,7 @@ public abstract class Link { /** An objc executable. */ OBJC_EXECUTABLE( "", - Staticness.DYNAMIC, + LinkerOrArchiver.LINKER, "objc-executable", Picness.NOPIC, ArtifactCategory.EXECUTABLE, @@ -135,7 +133,7 @@ public abstract class Link { /** An objc executable that includes objc++/c++ source. */ OBJCPP_EXECUTABLE( "", - Staticness.DYNAMIC, + LinkerOrArchiver.LINKER, "objc++-executable", Picness.NOPIC, ArtifactCategory.EXECUTABLE, @@ -144,7 +142,7 @@ public abstract class Link { /** A static archive with .pic.o object files (compiled with -fPIC). */ PIC_STATIC_LIBRARY( ".pic.a", - Staticness.STATIC, + LinkerOrArchiver.ARCHIVER, "c++-link-static-library", Picness.PIC, ArtifactCategory.STATIC_LIBRARY, @@ -153,16 +151,16 @@ public abstract class Link { /** An interface dynamic library. */ INTERFACE_DYNAMIC_LIBRARY( ".ifso", - Staticness.DYNAMIC, + LinkerOrArchiver.LINKER, "c++-link-dynamic-library", - Picness.NOPIC, // Actually PIC but it's not indicated in the file name + Picness.NOPIC, // Actually PIC but it's not indicated in the file name ArtifactCategory.INTERFACE_LIBRARY, Executable.NOT_EXECUTABLE), /** A dynamic library built from cc_library srcs. */ NODEPS_DYNAMIC_LIBRARY( ".so", - Staticness.DYNAMIC, + LinkerOrArchiver.LINKER, "c++-link-nodeps-dynamic-library", Picness.NOPIC, // Actually PIC but it's not indicated in the file name ArtifactCategory.DYNAMIC_LIBRARY, @@ -170,7 +168,7 @@ public abstract class Link { /** A transitive dynamic library used for distribution. */ DYNAMIC_LIBRARY( ".so", - Staticness.DYNAMIC, + LinkerOrArchiver.LINKER, "c++-link-dynamic-library", Picness.NOPIC, // Actually PIC but it's not indicated in the file name ArtifactCategory.DYNAMIC_LIBRARY, @@ -179,7 +177,7 @@ public abstract class Link { /** A static archive without removal of unused object files. */ ALWAYS_LINK_STATIC_LIBRARY( ".lo", - Staticness.STATIC, + LinkerOrArchiver.ARCHIVER, "c++-link-static-library", Picness.NOPIC, ArtifactCategory.ALWAYSLINK_STATIC_LIBRARY, @@ -188,7 +186,7 @@ public abstract class Link { /** A PIC static archive without removal of unused object files. */ ALWAYS_LINK_PIC_STATIC_LIBRARY( ".pic.lo", - Staticness.STATIC, + LinkerOrArchiver.ARCHIVER, "c++-link-static-library", Picness.PIC, ArtifactCategory.ALWAYSLINK_STATIC_LIBRARY, @@ -197,14 +195,14 @@ public abstract class Link { /** An executable binary. */ EXECUTABLE( "", - Staticness.DYNAMIC, + LinkerOrArchiver.LINKER, "c++-link-executable", - Picness.NOPIC, // Picness is not indicate in the file name + Picness.NOPIC, // Picness is not indicate in the file name ArtifactCategory.EXECUTABLE, Executable.EXECUTABLE); private final String extension; - private final Staticness staticness; + private final LinkerOrArchiver linkerOrArchiver; private final String actionName; private final ArtifactCategory linkerOutput; private final Picness picness; @@ -212,13 +210,13 @@ public abstract class Link { LinkTargetType( String extension, - Staticness staticness, + LinkerOrArchiver linkerOrArchiver, String actionName, Picness picness, ArtifactCategory linkerOutput, Executable executable) { this.extension = extension; - this.staticness = staticness; + this.linkerOrArchiver = linkerOrArchiver; this.actionName = actionName; this.linkerOutput = linkerOutput; this.picness = picness; @@ -236,8 +234,8 @@ public abstract class Link { return extension; } - public Staticness staticness() { - return staticness; + public LinkerOrArchiver linkerOrArchiver() { + return linkerOrArchiver; } /** Returns an {@code ArtifactCategory} identifying the artifact type this link action emits. */ @@ -264,9 +262,7 @@ public abstract class Link { } } - /** - * The degree of "staticness" of symbol resolution during linking. - */ + /** The degree of "staticness" of symbol resolution during linking. */ public enum LinkStaticness { FULLY_STATIC, // Static binding of all symbols. MOSTLY_STATIC, // Use dynamic binding only for symbols from glibc. diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/LinkBuildVariables.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/LinkBuildVariables.java index 6378640269..7dd22fc247 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/LinkBuildVariables.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/LinkBuildVariables.java @@ -20,7 +20,6 @@ import com.google.devtools.build.lib.analysis.config.BuildConfiguration; import com.google.devtools.build.lib.rules.cpp.CcToolchainFeatures.FeatureConfiguration; import com.google.devtools.build.lib.rules.cpp.CcToolchainFeatures.Variables; import com.google.devtools.build.lib.rules.cpp.CcToolchainFeatures.Variables.SequenceBuilder; -import com.google.devtools.build.lib.rules.cpp.Link.Staticness; import com.google.devtools.build.lib.vfs.PathFragment; /** Enum covering all build variables we create for all various {@link CppLinkAction}. */ @@ -94,7 +93,7 @@ public enum LinkBuildVariables { } public static Variables setupVariables( - CppLinkActionBuilder cppLinkActionBuilder, + boolean isUsingLinkerNotArchiver, BuildConfiguration configuration, Artifact outputArtifact, Artifact paramFile, @@ -132,9 +131,9 @@ public enum LinkBuildVariables { buildVariables.addStringVariable(STRIP_DEBUG_SYMBOLS.getVariableName(), ""); } - if (cppLinkActionBuilder.getLinkType().staticness().equals(Staticness.DYNAMIC) + if (isUsingLinkerNotArchiver && CppHelper.shouldCreatePerObjectDebugInfo( - cppConfiguration, ccToolchainProvider, featureConfiguration)) { + cppConfiguration, ccToolchainProvider, featureConfiguration)) { buildVariables.addStringVariable(IS_USING_FISSION.getVariableName(), ""); } diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/LinkCommandLine.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/LinkCommandLine.java index e39df63b85..9fca9f65ab 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/LinkCommandLine.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/LinkCommandLine.java @@ -27,7 +27,7 @@ import com.google.devtools.build.lib.rules.cpp.CcToolchainFeatures.FeatureConfig import com.google.devtools.build.lib.rules.cpp.CcToolchainFeatures.Variables; import com.google.devtools.build.lib.rules.cpp.Link.LinkStaticness; import com.google.devtools.build.lib.rules.cpp.Link.LinkTargetType; -import com.google.devtools.build.lib.rules.cpp.Link.Staticness; +import com.google.devtools.build.lib.rules.cpp.Link.LinkerOrArchiver; import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec; import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec.VisibleForSerialization; import com.google.devtools.build.lib.util.Pair; @@ -186,7 +186,7 @@ public final class LinkCommandLine extends CommandLine { List<String> args, LinkTargetType linkTargetType) { Preconditions.checkNotNull(paramFile); - if (linkTargetType.staticness() == Staticness.STATIC) { + if (linkTargetType.linkerOrArchiver() == LinkerOrArchiver.ARCHIVER) { // Ar link commands can also generate huge command lines. List<String> paramFileArgs = new ArrayList<>(); List<String> commandlineArgs = new ArrayList<>(); @@ -430,8 +430,8 @@ public final class LinkCommandLine extends CommandLine { } public LinkCommandLine build() { - - if (linkTargetType.staticness() == Staticness.STATIC) { + + if (linkTargetType.linkerOrArchiver() == LinkerOrArchiver.ARCHIVER) { Preconditions.checkArgument( buildInfoHeaderArtifacts.isEmpty(), "build info headers may only be present on dynamic library or executable links"); @@ -475,11 +475,11 @@ public final class LinkCommandLine extends CommandLine { this.featureConfiguration = featureConfiguration; return this; } - + /** * Sets the type of the link. It is an error to try to set this to {@link * LinkTargetType#INTERFACE_DYNAMIC_LIBRARY}. Note that all the static target types (see {@link - * LinkTargetType#staticness}) are equivalent, and there is no check that the output + * LinkTargetType#linkerOrArchiver}) are equivalent, and there is no check that the output * artifact matches the target type extension. */ public Builder setLinkTargetType(LinkTargetType linkTargetType) { @@ -502,7 +502,7 @@ public final class LinkCommandLine extends CommandLine { * Sets the linker options. These are passed to the linker in addition to the other linker * options like linker inputs, symbol count options, etc. The {@link #build} method throws an * exception if the linker options are non-empty for a static link (see {@link - * LinkTargetType#staticness()}). + * LinkTargetType#linkerOrArchiver()}). */ public Builder setLinkopts(ImmutableList<String> linkopts) { this.linkopts = linkopts; @@ -511,7 +511,7 @@ public final class LinkCommandLine extends CommandLine { /** * Sets how static the link is supposed to be. For static target types (see {@link - * LinkTargetType#staticness()}}), the {@link #build} method throws an exception if this + * LinkTargetType#linkerOrArchiver()}}), the {@link #build} method throws an exception if this * is not {@link LinkStaticness#FULLY_STATIC}. The default setting is {@link * LinkStaticness#FULLY_STATIC}. */ @@ -523,7 +523,7 @@ public final class LinkCommandLine extends CommandLine { /** * The build info header artifacts are generated header files that are used for link stamping. * The {@link #build} method throws an exception if the build info header artifacts are - * non-empty for a static link (see {@link LinkTargetType#staticness()}}). + * non-empty for a static link (see {@link LinkTargetType#linkerOrArchiver()}}). */ public Builder setBuildInfoHeaderArtifacts(ImmutableList<Artifact> buildInfoHeaderArtifacts) { this.buildInfoHeaderArtifacts = buildInfoHeaderArtifacts; @@ -533,7 +533,7 @@ public final class LinkCommandLine extends CommandLine { /** * Whether the resulting library is intended to be used as a native library from another * programming language. This influences the rpath. The {@link #build} method throws an - * exception if this is true for a static link (see {@link LinkTargetType#staticness()}}). + * exception if this is true for a static link (see {@link LinkTargetType#linkerOrArchiver()}}). */ public Builder setNativeDeps(boolean nativeDeps) { this.nativeDeps = nativeDeps; |