Example #1
0
func main() {
	var path string
	var cmdRun = &cobra.Command{
		Use:   "checkouttool --path [path]",
		Short: "Small tool for testing VCS checkout",
		Long:  `A small tool for testing VCS checkout against a path`,
		Run: func(cmd *cobra.Command, args []string) {
			if path == "" {
				fmt.Println("Expected path")
				return
			}

			fmt.Printf("Performing checkout for path: %v\n", path)

			pkgCacheDirectory := ".pkg"
			packagePath, err, warning := vcs.PerformVCSCheckout(path, pkgCacheDirectory)

			fmt.Printf("Path: %s\n", packagePath)
			fmt.Printf("Error: %v\n", err)
			fmt.Printf("Warning: %s\n", warning)
		},
	}

	cmdRun.Flags().StringVar(&path, "path", "", "The path to checkout")
	cmdRun.Execute()
}
Example #2
0
// loadVCSPackage loads the package found at the given VCS path.
func (p *PackageLoader) loadVCSPackage(packagePath pathInformation) {
	// Lock on the package path to ensure no other checkouts occur for this path.
	pathLock := p.vcsLockMap.GetLock(packagePath.path)
	pathLock.Lock()
	defer pathLock.Unlock()

	existingCheckoutDir, exists := p.vcsPathsLoaded.Get(packagePath.path)
	if exists {
		// Note: existingCheckoutDir will be empty if there was an error loading the VCS.
		if existingCheckoutDir != "" {
			// Push the now-local directory onto the package loading channel.
			p.pushPathWithId(packagePath.referenceId, packagePath.sourceKind, pathLocalPackage, existingCheckoutDir.(string), packagePath.sal)
			return
		}
	}

	rootDirectory := path.Dir(p.rootSourceFile)
	pkgDirectory := path.Join(rootDirectory, SerulianPackageDirectory)

	// Perform the checkout of the VCS package.
	checkoutDirectory, err, warning := vcs.PerformVCSCheckout(packagePath.path, pkgDirectory, p.vcsDevelopmentDirectories...)
	if err != nil {
		p.vcsPathsLoaded.Set(packagePath.path, "")
		p.errors <- compilercommon.SourceErrorf(packagePath.sal, "Error loading VCS package '%s': %v", packagePath.path, err)
		return
	}

	p.vcsPathsLoaded.Set(packagePath.path, checkoutDirectory)
	if warning != "" {
		p.warnings <- compilercommon.NewSourceWarning(packagePath.sal, warning)
	}

	// Push the now-local directory onto the package loading channel.
	p.pushPathWithId(packagePath.referenceId, packagePath.sourceKind, pathLocalPackage, checkoutDirectory, packagePath.sal)
}