func computeCommon()

in internal/platform/commoncontext/compute.go [102:165]


func computeCommon(
	analyzer product.Analyzer,
	projectDir string,
	repositoryRoot string,
	cacheDirFromCliOptions string,
	resultsDirFromCliOptions string,
	reportDirFromCliOptions string,
	clearCache bool,
	qodanaCloudToken string,
) Context {
	qodanaId := computeId(analyzer, projectDir)
	systemDir := computeQodanaSystemDir(cacheDirFromCliOptions)
	linterDir := filepath.Join(systemDir, qodanaId)
	resultsDir := computeResultsDir(resultsDirFromCliOptions, linterDir)
	cacheDir := computeCacheDir(cacheDirFromCliOptions, linterDir)
	reportDir := computeReportDir(reportDirFromCliOptions, resultsDir)

	commonCtx := Context{
		Analyzer:        analyzer,
		IsClearCache:    clearCache,
		CacheDir:        cacheDir,
		ResultsDir:      resultsDir,
		QodanaSystemDir: systemDir,
		ReportDir:       reportDir,
		Id:              qodanaId,
		QodanaToken:     qodanaCloudToken,
	}

	if repositoryRoot == "" {
		vcsRoot, err := git.Root(projectDir, commonCtx.LogDir())

		if err != nil {
			repositoryRoot = projectDir
		} else {
			repositoryRoot = vcsRoot
		}
	}

	normalizedProjectDir, err := normalizePath(projectDir)
	if err != nil {
		log.Fatalf("Can not normalize project dir %s: %v", projectDir, err)
	}

	// Normalize repositoryRoot to be a substring of projectDir path
	// This handles case-insensitive filesystems where /tmp/PROJECT and /tmp/project are the same
	normalizedRepoRoot, err := normalizeRepositoryRoot(normalizedProjectDir, repositoryRoot)
	if err != nil {
		log.Fatalf(
			"The project directory must be located inside repository root. Please, specify correct --repository-root argument. ProjectDir: %s. RepositoryRoot: %s. Error: %v",
			normalizedProjectDir,
			normalizedRepoRoot,
			err,
		)
	}

	log.Debugf("Repository root: %q", repositoryRoot)
	log.Debugf("Normalized repository root: %q", normalizedRepoRoot)
	log.Debugf("Project root: %q", projectDir)
	log.Debugf("Normalized project root: %q", normalizedProjectDir)

	commonCtx.ProjectDir = normalizedProjectDir
	commonCtx.RepositoryRoot = normalizedRepoRoot
	return commonCtx
}