Search in sources :

Example 6 with BuildSystemName

use of com.google.idea.blaze.base.settings.BuildSystemName in project intellij by bazelbuild.

the class FastBuildServiceImpl method getBlazeInfo.

private BlazeInfo getBlazeInfo(BlazeContext context, FastBuildParameters buildParameters) {
    BuildSystemName buildSystemName = Blaze.getBuildSystemName(project);
    ListenableFuture<BlazeInfo> blazeInfoFuture = BlazeInfoRunner.getInstance().runBlazeInfo(context, buildSystemName, buildParameters.blazeBinary(), WorkspaceRoot.fromProject(project), buildParameters.infoFlags());
    BlazeInfo info = FutureUtil.waitForFuture(context, blazeInfoFuture).timed(buildSystemName.getName() + "Info", EventType.BlazeInvocation).withProgressMessage(String.format("Running %s info...", buildSystemName.getLowerCaseName())).onError(String.format("Could not run %s info", buildSystemName.getLowerCaseName())).run().result();
    if (info == null) {
        throw new RuntimeException(String.format("%s info failed", buildSystemName.getLowerCaseName()));
    }
    return info;
}
Also used : BlazeInfo(com.google.idea.blaze.base.command.info.BlazeInfo) BuildSystemName(com.google.idea.blaze.base.settings.BuildSystemName)

Example 7 with BuildSystemName

use of com.google.idea.blaze.base.settings.BuildSystemName in project intellij by bazelbuild.

the class BlazeInfo method createMockBlazeInfo.

/**
 * Creates a mock blaze info with the minimum information required for syncing.
 */
@VisibleForTesting
public static BlazeInfo createMockBlazeInfo(String outputBase, String executionRoot, String blazeBin, String blazeGenFiles, String blazeTestlogs) {
    BuildSystemName buildSystemName = BuildSystemName.Bazel;
    ImmutableMap.Builder<String, String> blazeInfoMap = ImmutableMap.<String, String>builder().put(OUTPUT_BASE_KEY, outputBase).put(EXECUTION_ROOT_KEY, executionRoot).put(blazeBinKey(buildSystemName), blazeBin).put(blazeGenfilesKey(buildSystemName), blazeGenFiles).put(blazeTestlogsKey(buildSystemName), blazeTestlogs);
    return BlazeInfo.create(buildSystemName, blazeInfoMap.build());
}
Also used : BuildSystemName(com.google.idea.blaze.base.settings.BuildSystemName) ImmutableMap(com.google.common.collect.ImmutableMap) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 8 with BuildSystemName

use of com.google.idea.blaze.base.settings.BuildSystemName in project intellij by bazelbuild.

the class BlazeTypeScriptConfig method parsePaths.

private void parsePaths(JsonObject json) {
    String runfilesPrefix = null;
    List<String> alternativePrefixes = new ArrayList<>();
    VirtualFile base = baseUrlFile.getValue();
    if (base != null) {
        Path baseUrlPath = VfsUtil.virtualToIoFile(base).toPath();
        BuildSystemName buildSystem = Blaze.getBuildSystemName(project);
        File workspaceRoot = WorkspaceRoot.fromProject(project).directory();
        File blazeBin = new File(workspaceRoot, BlazeInfo.blazeBinKey(buildSystem));
        File blazeGenfiles = new File(workspaceRoot, BlazeInfo.blazeGenfilesKey(buildSystem));
        // modules are resolved in this order
        alternativePrefixes.add(baseUrlPath.relativize(workspaceRoot.toPath()).toString());
        alternativePrefixes.add(baseUrlPath.relativize(blazeBin.toPath()).toString());
        alternativePrefixes.add(baseUrlPath.relativize(blazeGenfiles.toPath()).toString());
        FileOperationProvider fOps = FileOperationProvider.getInstance();
        if (fOps.isSymbolicLink(blazeBin)) {
            try {
                alternativePrefixes.add(baseUrlPath.relativize(fOps.readSymbolicLink(blazeBin).toPath()).toString());
            } catch (IOException e) {
                logger.warn(e);
            }
        }
        if (fOps.isSymbolicLink(blazeGenfiles)) {
            try {
                alternativePrefixes.add(baseUrlPath.relativize(fOps.readSymbolicLink(blazeGenfiles).toPath()).toString());
            } catch (IOException e) {
                logger.warn(e);
            }
        }
        runfilesPrefix = "./" + label.targetName() + ".runfiles/" + workspaceRoot.getName();
    }
    for (Map.Entry<String, JsonElement> entry : json.entrySet()) {
        String name = entry.getKey();
        List<String> mappings = new ArrayList<>();
        for (JsonElement path : entry.getValue().getAsJsonArray()) {
            String pathString = path.getAsString();
            if (pathString.startsWith(workspaceRelativePathPrefix)) {
                pathString = workspaceRelativePathReplacement + pathString.substring(workspaceRelativePathPrefix.length());
            }
            mappings.add(pathString);
        }
        paths.add(new PathSubstitution(name, mappings, alternativePrefixes, runfilesPrefix));
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Path(java.nio.file.Path) ArrayList(java.util.ArrayList) IOException(java.io.IOException) JsonElement(com.google.gson.JsonElement) FileOperationProvider(com.google.idea.blaze.base.io.FileOperationProvider) JSModulePathSubstitution(com.intellij.lang.javascript.frameworks.modules.JSModulePathSubstitution) BuildSystemName(com.google.idea.blaze.base.settings.BuildSystemName) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) Map(java.util.Map)

Example 9 with BuildSystemName

use of com.google.idea.blaze.base.settings.BuildSystemName in project intellij by bazelbuild.

the class BlazeNewProjectBuilder method commit.

/**
 * Commits the project. May report errors.
 */
public void commit() throws BlazeProjectCommitException {
    this.workspaceRoot = workspaceData.workspaceRoot();
    projectViewOption.commit();
    BuildSystemName buildSystemName = workspaceData.buildSystem();
    writeWorkspaceHistory(buildSystemName, workspaceRoot.toString());
    if (!StringUtil.isEmpty(projectDataDirectory)) {
        File projectDataDir = new File(projectDataDirectory);
        if (!projectDataDir.exists()) {
            if (!projectDataDir.mkdirs()) {
                throw new BlazeProjectCommitException("Unable to create the project directory: " + projectDataDirectory);
            }
        }
    }
    try {
        logger.assertTrue(projectViewFile != null);
        ProjectViewStorageManager.getInstance().writeProjectView(ProjectViewParser.projectViewToString(projectView), projectViewFile);
    } catch (IOException e) {
        throw new BlazeProjectCommitException("Could not create project view file", e);
    }
    BlazeImportSettingsManager.setPendingProjectSettings(getImportSettings());
}
Also used : IOException(java.io.IOException) BuildSystemName(com.google.idea.blaze.base.settings.BuildSystemName) File(java.io.File)

Example 10 with BuildSystemName

use of com.google.idea.blaze.base.settings.BuildSystemName in project intellij by bazelbuild.

the class BlazeModuleSystemDependentLibrariesIntegrationTest method setup.

@Before
public void setup() {
    final String recyclerView = "//third_party/recyclerview:recyclerview";
    final String constraintLayout = "//third_party/constraint_layout:constraint_layout";
    final String quantum = "//third_party/quantum:values";
    final String aarFile = "//third_party/aar:an_aar";
    final String individualLibrary = "//third_party/individualLibrary:values";
    final String guava = "//third_party/guava:java";
    final String main = "//java/com/google:app";
    final String intermediateDependency = "//java/com/google/intermediate:intermediate";
    // BlazeAndroidRunConfigurationCommonState.isNativeDebuggingEnabled() always
    // returns false if this experiment is false. Enable it by setting it to true.
    MockExperimentService experimentService = new MockExperimentService();
    registerApplicationComponent(ExperimentService.class, experimentService);
    registerExtension(MavenArtifactLocator.EP_NAME, new MavenArtifactLocator() {

        @Override
        public Label labelFor(GradleCoordinate coordinate) {
            switch(GoogleMavenArtifactId.forCoordinate(coordinate)) {
                case RECYCLERVIEW_V7:
                    return Label.create("//third_party/recyclerview:recyclerview");
                case CONSTRAINT_LAYOUT:
                    return Label.create("//third_party/constraint_layout:constraint_layout");
                default:
                    return null;
            }
        }

        @Override
        public BuildSystemName buildSystem() {
            return BuildSystemName.Blaze;
        }
    });
    // This MainActivity.java file is needed because blaze sync will fail if the source
    // directory is empty, so we put something there. The fact that it's MainActivity.java
    // doesn't mean anything.
    workspace.createFile(new WorkspacePath("java/com/google/app/MainActivity.java"), "package com.google.app", "import android.app.Activity;", "public class MainActivity extends Activity {", "}");
    // Make JARs appear nonempty so that they aren't filtered out
    registerApplicationService(FileOperationProvider.class, new FileOperationProvider() {

        @Override
        public long getFileSize(File file) {
            return file.getName().endsWith("jar") ? 500L : super.getFileSize(file);
        }
    });
    setProjectView("directories:", "  java/com/google", "targets:", "  //java/com/google:app", "android_sdk_platform: android-27");
    MockSdkUtil.registerSdk(workspace, "27");
    NbAarTarget aarTarget = aar_import(aarFile).aar("lib_aar.aar").generated_jar("_aar/an_aar/classes_and_libs_merged.jar");
    AarLibraryFileBuilder.aar(workspaceRoot, aarTarget.getAar().getRelativePath()).src("res/values/colors.xml", ImmutableList.of("<?xml version=\"1.0\" encoding=\"utf-8\"?>", "<resources>", "    <color name=\"aarColor\">#ffffff</color>", "</resources>")).build();
    NbAndroidTarget binaryTarget = android_binary(main).source_jar("app.jar").res("res").res_folder("//third_party/shared/res", "app-third_party-shared-res.aar").src("app/MainActivity.java").dep(guava, quantum, aarFile, intermediateDependency);
    binaryTarget.getAarList().forEach(aar -> AarLibraryFileBuilder.aar(workspaceRoot, aar.getRelativePath()).build());
    NbAndroidTarget quantumTarget = android_library(quantum).res_folder("//third_party/quantum/res", "values-third_party-quantum-res.aar");
    quantumTarget.getAarList().forEach(aar -> AarLibraryFileBuilder.aar(workspaceRoot, aar.getRelativePath()).build());
    NbAndroidTarget constraintLayoutTarget = android_library(constraintLayout).res_folder("//third_party/constraint_layout/res", "constraint_layout-third_party-constraint_layout-res.aar");
    constraintLayoutTarget.getAarList().forEach(aar -> AarLibraryFileBuilder.aar(workspaceRoot, aar.getRelativePath()).build());
    setTargetMap(binaryTarget, android_library(individualLibrary).res("res"), java_library(guava).source_jar("//third_party/guava-21.jar"), quantumTarget, aarTarget, android_library(recyclerView).res("res"), android_library(intermediateDependency).res("res").dep(constraintLayout), constraintLayoutTarget);
    runFullBlazeSyncWithNoIssues();
    Module appModule = ModuleManager.getInstance(getProject()).findModuleByName("java.com.google.app");
    appModuleSystem = BlazeModuleSystem.getInstance(appModule);
    Module workspaceModule = ModuleManager.getInstance(getProject()).findModuleByName(BlazeDataStorage.WORKSPACE_MODULE_NAME);
    workspaceModuleSystem = BlazeModuleSystem.getInstance(workspaceModule);
}
Also used : MockExperimentService(com.google.idea.common.experiments.MockExperimentService) MavenArtifactLocator(com.google.idea.blaze.android.projectsystem.MavenArtifactLocator) WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) GradleCoordinate(com.android.ide.common.repository.GradleCoordinate) Label(com.google.idea.blaze.base.model.primitives.Label) NbAarTarget(com.google.idea.blaze.android.targetmapbuilder.NbAarTarget) PathString(com.android.ide.common.util.PathString) NbAndroidTarget(com.google.idea.blaze.android.targetmapbuilder.NbAndroidTarget) FileOperationProvider(com.google.idea.blaze.base.io.FileOperationProvider) BuildSystemName(com.google.idea.blaze.base.settings.BuildSystemName) Module(com.intellij.openapi.module.Module) File(java.io.File) Before(org.junit.Before)

Aggregations

BuildSystemName (com.google.idea.blaze.base.settings.BuildSystemName)11 File (java.io.File)5 IOException (java.io.IOException)4 WorkspacePath (com.google.idea.blaze.base.model.primitives.WorkspacePath)3 WorkspaceRoot (com.google.idea.blaze.base.model.primitives.WorkspaceRoot)3 ProjectViewSet (com.google.idea.blaze.base.projectview.ProjectViewSet)3 Nullable (javax.annotation.Nullable)3 GradleCoordinate (com.android.ide.common.repository.GradleCoordinate)2 MavenArtifactLocator (com.google.idea.blaze.android.projectsystem.MavenArtifactLocator)2 BlazeInfo (com.google.idea.blaze.base.command.info.BlazeInfo)2 FileOperationProvider (com.google.idea.blaze.base.io.FileOperationProvider)2 Label (com.google.idea.blaze.base.model.primitives.Label)2 BlazeContext (com.google.idea.blaze.base.scope.BlazeContext)2 Scope (com.google.idea.blaze.base.scope.Scope)2 Logger (com.intellij.openapi.diagnostic.Logger)2 List (java.util.List)2 Before (org.junit.Before)2 PathString (com.android.ide.common.util.PathString)1 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 ImmutableMap (com.google.common.collect.ImmutableMap)1