From c193fc40c2f6f11e30d18cb6191b17810aeda9c5 Mon Sep 17 00:00:00 2001 From: Googler Date: Fri, 19 Jan 2018 21:10:09 -0800 Subject: Non functional changes. Just shuffling code in the build() method to simplify future review. 1. Reuse result of getRootRelativePath() 2. Delay linkerInputs generation 3. allowLtoIndexing ? thinltoParamFile : null -> thinltoParamFile it must be null if indexing is not allowed RELNOTES: None PiperOrigin-RevId: 182626938 --- .../build/lib/rules/cpp/CppLinkActionBuilder.java | 31 +++++++++++----------- 1 file changed, 16 insertions(+), 15 deletions(-) (limited to 'src/main/java/com/google/devtools/build') 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 31e287a4cd..63e9e0336d 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 @@ -806,17 +806,6 @@ public class CppLinkActionBuilder { } final Iterable objectArtifacts = LinkerInputs.toLibraryArtifacts(objectFileInputs); - final Iterable linkerInputs = - IterablesChain.builder() - .add(objectFileInputs) - .add( - ImmutableIterable.from( - Link.mergeInputsCmdLine( - uniqueLibraries, - needWholeArchive, - CppHelper.getArchiveType(cppConfiguration, toolchain)))) - .build(); - final LibraryToLink outputLibrary = linkType.isExecutable() ? null @@ -839,6 +828,7 @@ public class CppLinkActionBuilder { /* sharedNonLtoBackends= */ null); @Nullable Artifact thinltoParamFile = null; + PathFragment outputRootPath = output.getRootRelativePath(); if (allowLtoIndexing && allLtoArtifacts != null) { // Create artifact for the file that the LTO indexing step will emit // object file names into for any that were included in the link as @@ -847,8 +837,7 @@ public class CppLinkActionBuilder { // Note that the paths emitted into this file will have their prefixes // replaced with the final output directory, so they will be the paths // of the native object files not the input bitcode files. - PathFragment linkerParamFileRootPath = - ParameterFile.derivePath(output.getRootRelativePath(), "lto-final"); + PathFragment linkerParamFileRootPath = ParameterFile.derivePath(outputRootPath, "lto-final"); thinltoParamFile = linkArtifactFactory.create(ruleContext, configuration, linkerParamFileRootPath); } @@ -872,11 +861,22 @@ public class CppLinkActionBuilder { symbolCounts); } + final Iterable linkerInputs = + IterablesChain.builder() + .add(objectFileInputs) + .add( + ImmutableIterable.from( + Link.mergeInputsCmdLine( + uniqueLibraries, + needWholeArchive, + CppHelper.getArchiveType(cppConfiguration, toolchain)))) + .build(); + ImmutableList runtimeLinkerInputs = ImmutableList.copyOf(LinkerInputs.simpleLinkerInputs(runtimeInputs, runtimeType)); PathFragment paramRootPath = - ParameterFile.derivePath(output.getRootRelativePath(), (isLtoIndexing) ? "lto-index" : "2"); + ParameterFile.derivePath(outputRootPath, (isLtoIndexing) ? "lto-index" : "2"); @Nullable final Artifact paramFile = @@ -887,6 +887,7 @@ public class CppLinkActionBuilder { // Add build variables necessary to template link args into the crosstool. Variables.Builder buildVariablesBuilder = new Variables.Builder(toolchain.getBuildVariables()); Preconditions.checkState(!isLtoIndexing || allowLtoIndexing); + Preconditions.checkState(allowLtoIndexing || thinltoParamFile == null); CppLinkVariablesExtension variablesExtension = isLtoIndexing ? new CppLinkVariablesExtension( @@ -909,7 +910,7 @@ public class CppLinkActionBuilder { runtimeLinkerInputs, output, paramFile, - allowLtoIndexing ? thinltoParamFile : null, + thinltoParamFile, /* ltoOutputRootPrefix= */ PathFragment.EMPTY_FRAGMENT, allowLtoIndexing, toolchain.getInterfaceSoBuilder(), -- cgit v1.2.3