<commit_before>// Copyright (C) 2018 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// gofuse is a utility program to help go tools work with bazel generated files.
//
// gofuse will create a new 'fused' directory in the project root which
// contains:
//  • Symlinks to authored .go source files in the GAPID source tree.
//  • Symlinks to bazel-generated .go files.
//  • Symlinks to external 3rd-party .go files.
// These symlinks are 'fused' into a single, common directory structure that
// is expected by the typical GOPATH rules used by go tooling.
//
// Note: Currently gofuse only works on macOS. It should be simple to get this
// working on Linux, but the extensive use of symlinks makes Windows support
// unlikely.
package main

import (
	"fmt"
	"io"
	"os"
	"path/filepath"
	"strings"
)

// Map of bazel external package names to the expected import names.
var externals = map[string]string{
	"com_github_golang_protobuf": filepath.Join("github.com", "golang", "protobuf"),
	"com_github_google_protobuf": filepath.Join("github.com", "google", "protobuf"),
	"com_github_pkg_errors":      filepath.Join("github.com", "pkg", "errors"),
	"llvm":                       "llvm",
}

func main() {
	if err := run(); err != nil {
		fmt.Fprintln(os.Stderr, err.Error())
		os.Exit(1)
	}
}

func run() error {
	// Locate the root of the GAPID project.
	projectRoot, err := projectRoot()
	if err != nil {
		return err
	}

	// fusedRoot is the root of the generated directory.
	fusedRoot := filepath.Join(projectRoot, "fused")

	fmt.Println("Updating fused directory at:", fusedRoot)

	// Collect all the existing symlinks under the fused root.
	fusedFiles := collect(fusedRoot, always).ifTrue(and(hasSuffix(".go"), isFile, isSymlink))

	// Collect all the source (authored) file mappings.
	srcMapping := collect(projectRoot,
		and(<commit_msg>Allow a custom fuse-root for gofuse.<commit_after>// Copyright (C) 2018 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// gofuse is a utility program to help go tools work with bazel generated files.
//
// gofuse will create a new 'fused' directory in the project root which
// contains:
//  • Symlinks to authored .go source files in the GAPID source tree.
//  • Symlinks to bazel-generated .go files.
//  • Symlinks to external 3rd-party .go files.
// These symlinks are 'fused' into a single, common directory structure that
// is expected by the typical GOPATH rules used by go tooling.
//
// Note: Currently gofuse only works on macOS. It should be simple to get this
// working on Linux, but the extensive use of symlinks makes Windows support
// unlikely.
package main

import (
	"flag"
	"fmt"
	"io"
	"os"
	"path/filepath"
	"strings"
)

// Map of bazel external package names to the expected import names.
var externals = map[string]string{
	"com_github_golang_protobuf": filepath.Join("github.com", "golang", "protobuf"),
	"com_github_google_protobuf": filepath.Join("github.com", "google", "protobuf"),
	"com_github_pkg_errors":      filepath.Join("github.com", "pkg", "errors"),
	"llvm":                       "llvm",
}

var (
	fuseDir = flag.String("dir", "", "directory to use as the fuse root")
)

func main() {
	flag.Parse()

	if err := run(); err != nil {
		fmt.Fprintln(os.Stderr, err.Error())
		os.Exit(1)
	}
}

func run() error {
	// Locate the root of the GAPID project.
	projectRoot, err := projectRoot()
	if err != nil {
		return err
	}

	// fusedRoot is the root of the generated directory.
	fusedRoot := filepath.Join(projectRoot, "fused")
	if *fuseDir != "" {
		fusedRoot = *fuseDir
	}

	fmt.Println("Updating fused directory at:", fusedRoot)

	// Collect all the existing symlinks under the fused root.
	fusedFiles := collect(fusedRoot, always).ifTrue(and(hasSuffix(".go"), isFile, isSymlink))

	// Collect all the source (authored) file mappings.
	srcMapping := collect(projectRoot,
		and(
{'fraction_non_alphanumeric': 0.11493784389647442, 'fraction_numerical': 0.004075810067250866, 'mean_word_length': 3.5528756957328387, 'pattern_counts': {'":': 8, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4288507', 'n_tokens_mistral': 1510, 'n_tokens_neox': 1458, 'n_words': 598}