Exemple #1
0
 def test_csproj_get_assembly_version(self):
     """Test CsProj.get_assembly_version - returns assembly version path from a csproj / AssemblyInfo file """
     with temp_dir() as tmp_root_dir:
         csproj_root = os.path.join(tmp_root_dir, "test")
         shutil.copytree(get_fixture_dir(), csproj_root)
         csproj = CsProj(os.path.join(csproj_root, _TEST_CSPROJ))
         assert csproj.get_assembly_version() == "1.2.3"
Exemple #2
0
 def test_csproj_get_assembly_name(self):
     """Test CsProj.get_assembly_name - returns assembly name from a csproj file """
     with temp_dir() as tmp_root_dir:
         csproj_root = os.path.join(tmp_root_dir, "test")
         shutil.copytree(get_fixture_dir(), csproj_root)
         csproj = CsProj(os.path.join(csproj_root, _TEST_CSPROJ))
         assert csproj.get_assembly_name() == "MyProject"
Exemple #3
0
    def _locate_nupkg_at_path(self, path, output_dir):
        """
        Finds .nupkg file.
        If no explicit path to the .nupkg file is provided, .csproj file will be searched for in path.
        .csproj will be used to determine name and version of the package, while package itself will be seached
        in the output_dir.
        """
        if path.endswith(".nupkg"):
            if not os.path.isfile(path):
                raise click.FileError(path)
            return path

        csproj_path = CsProj.get_csproj_at_path(path)

        if not csproj_path:
            raise click.UsageError(
                "Failed to find Nuget Package (.nupkg) or Visual Studio project at path "
                + path)

        csproj = CsProj(csproj_path)

        assembly_name = csproj.get_assembly_name()
        version = csproj.get_assembly_version()

        nupkg_filename = "{0}.{1}.nupkg".format(assembly_name, version)
        nupkg_path = os.path.normpath(os.path.join(output_dir, nupkg_filename))

        if not os.path.isfile(nupkg_path):
            raise click.UsageError(
                "Failed to find Nuget Package (.nupkg) or Visual Studio project at path "
                + path)

        return nupkg_path
Exemple #4
0
 def test_csproj_get_output_path(self):
     """Test CsProj.get_output_path - returns csproj output path from a csproj file """
     with temp_dir() as tmp_root_dir:
         csproj_root = os.path.join(tmp_root_dir, "test")
         shutil.copytree(get_fixture_dir(), csproj_root)
         csproj = CsProj(os.path.join(csproj_root, _TEST_CSPROJ))
         assert csproj.get_output_path("Debug") == "bin/Debug/"
         assert csproj.get_output_path("Release") == "bin/Release/"
Exemple #5
0
    def pack(self, path, output_dir, nuget_path, unitypackage_path,
             configuration, unity_project_path,
             unitypackage_root_path_relative):
        """
        Packs NuGet Package.
        :param path: Path to the .csproj or .nuspec, or a directory containing either
        :param output_dir: Output directory - this is where .nupkg file will be built
        :param nuget_path: Path to the NuGet executable
        :param unitypackage_path: Path to the .unitypackge
        :param configuration: Configuration - Debug/Release
        :return: Exit code of the NuGet Pack command
        """
        # Locate nuget executable
        nuget_path = self._locate_nuget_path(nuget_path)
        nuget_runner = NuGetRunner(nuget_path, self.debug)

        # Locate project name and version
        csproj_file_path = CsProj.get_csproj_at_path(path)
        if csproj_file_path is not None:
            csproj = CsProj(path, self.debug)
            package_id = csproj.get_assembly_name()
            version = csproj.get_assembly_version()
        else:
            nuspec_file_path = NuSpec.get_nuspec_at_path(path)
            if nuspec_file_path is not None:
                nuspec = NuSpec(path, self.debug)
                package_id = nuspec.get_package_id()
                version = nuspec.get_package_version()
            else:
                raise click.UsageError(
                    "Path must be a valid path to .nuspec, .csproj, or directory containing either"
                )

        if not package_id:
            raise click.UsageError("Failed to identify package id.")
        if not version:
            raise click.UsageError("Failed to identify package version.")

        if not unitypackage_path:
            unitypackage_name = utils.get_unitypackage_filename(
                package_id, version, configuration)
            unitypackage_path = os.path.join(output_dir, unitypackage_name)

        if not unitypackage_root_path_relative:
            unitypackage_root_path_relative = package_id

        unitypackage_export_root = self._get_unity_package_export_root(
            unity_project_path, unitypackage_root_path_relative)

        return nuget_runner.pack(path, output_dir, configuration,
                                 unitypackage_path, unitypackage_export_root)
Exemple #6
0
 def test_csproj_path_is_csproj_file(self):
     """Test CsProj.path_is_csproj_file - returns true path is a .csproj file"""
     file_name = "MyProject.csproj"
     with temp_dir() as tmp_root_dir:
         path = os.path.normpath(os.path.join(tmp_root_dir, file_name))
         create_empty_file(path)
         assert CsProj.path_is_csproj_file(path)
Exemple #7
0
 def test_csproj_get_csproj_at_path_when_path_contains_csproj(self):
     """Test CsProj.get_csproj_at_path - returns path if path is a file"""
     file_name = "MyProject.csproj"
     with temp_dir() as tmp_root_dir:
         path = os.path.normpath(os.path.join(tmp_root_dir, file_name))
         create_empty_file(path)
         assert CsProj.get_csproj_at_path(tmp_root_dir) == path
Exemple #8
0
    def _locate_nupkg_at_path(self, path, output_dir):
        """
        Finds .nupkg file.
        If no explicit path to the .nupkg file is provided, .csproj file will be searched for in path.
        .csproj will be used to determine name and version of the package, while package itself will be seached
        in the output_dir.
        """
        if path.endswith(".nupkg"):
            if not os.path.isfile(path):
                raise click.FileError(path)
            return path

        csproj_path = CsProj.get_csproj_at_path(path)

        if csproj_path:
            csproj = CsProj(csproj_path)

            assembly_name = csproj.get_assembly_name()
            version = csproj.get_assembly_version()
            normalized_version = NuGetRunner.get_normalized_nuget_pack_version(version)

            nupkg_filename = "{0}.{1}.nupkg".format(assembly_name, normalized_version)
            nupkg_path = os.path.normpath(os.path.join(output_dir, nupkg_filename))

            if not os.path.isfile(nupkg_path):
                raise click.UsageError("Failed to find Nuget Package (.nupkg) at path " + nupkg_path)

        else:
            nuspec_file_path = NuSpec.get_nuspec_at_path(path)
            if nuspec_file_path is not None:
                nuspec = NuSpec(path, self.debug)
                package_id = nuspec.get_package_id()
                version = nuspec.get_package_version()
                normalized_version = NuGetRunner.get_normalized_nuget_pack_version(version)

                nupkg_filename = "{0}.{1}.nupkg".format(package_id, normalized_version)
                nupkg_path = os.path.normpath(os.path.join(output_dir, nupkg_filename))
            else:
                raise click.UsageError("Path must be a valid path to .nuspec, .csproj, or directory containing either")

        return nupkg_path
Exemple #9
0
    def _locate_csproj_at_path(self, path):
        """
        Finds .csproj file at the provided path
        :param path:
        :return:
        """
        if path.endswith(".csproj"):
            if not os.path.isfile(path):
                raise click.FileError(path)
            return path

        csproj_path = CsProj.get_csproj_at_path(path)

        if not csproj_path:
            raise click.UsageError("Failed to find Nuget Package (.nupkg) or Visual Studio project at path " + path)

        return csproj_path
Exemple #10
0
    def create(self, csproj_path, output_dir, configuration, unity_project_path,
               root_dir, assembly_relative_dir, clean):
        """
        Creates .unitypackage that contains project assembly and assets
        :param path: Path to .csproj
        :param output_dir: Output directory into which .unitypackage is being built
        :param configuration: Debug or Release
        :param unity_project_path: Path to the unity project used to build .unitypackage
        :param root_dir: Root path inside a unity_project_path used to export .unitypackage
        :param assembly_relative_dir: Relative path from $unity_project_path/$root_dir to export assemblies.
        :param clean: If set, other Unity Packages will be removed from the output folder if they match configuration
        """
        csproj = CsProj(csproj_path)

        # Read csproj properties - assembly name, version and output directory
        assembly_name = csproj.get_assembly_name()
        if not assembly_name:
            raise click.UsageError("Failed to identify package id.")

        version = csproj.get_assembly_version()
        if not version:
            raise click.UsageError("Failed to identify package version.")

        csproj_dir_path = os.path.dirname(csproj.path)
        csproj_configuration_output_path = csproj.get_output_path(configuration)

        if csproj_configuration_output_path is None:
            raise click.UsageError('Failed to locate output path for a csproject: {0} configuration {1}'
                                   .format(csproj.path, configuration))

        csproj_output_dir = os.path.join(csproj_dir_path, csproj_configuration_output_path)
        if not csproj_output_dir or not os.path.isdir(csproj_output_dir):
            raise click.UsageError('Output directory {0} not found'.format(csproj_output_dir))

        dll_name = assembly_name + ".dll"
        pdb_name = assembly_name + ".pdb"

        dll_path = os.path.join(csproj_output_dir, dll_name)
        pdb_path = os.path.join(csproj_output_dir, pdb_name)

        # Copy output dll and pdb into unity project folder
        if not os.path.isfile(dll_path):
            raise RuntimeError('Assembly not found at path {0}. Did you forget to build the project?'.format(dll_path))
        if not os.path.isfile(pdb_path):
            raise RuntimeError('Debug symbols not found at path {0}. Make sure project is set up to generate debug '
                               'symbols.'.format(pdb_path))

        if not root_dir:
            root_dir = assembly_name

        unitypackage_export_root = self._get_unity_package_export_root(unity_project_path, root_dir)
        assembly_export_root = os.path.join(unitypackage_export_root, assembly_relative_dir)

        if not os.path.exists(unitypackage_export_root):
            os.makedirs(unitypackage_export_root)
        elif not os.path.isdir(unitypackage_export_root):
            raise IOError("Can't copy assembly into Unity Project; path is not a valid directory: {0}"
                          .format(unitypackage_export_root))

        shutil.copyfile(dll_path, os.path.abspath(os.path.join(assembly_export_root, dll_name)))
        shutil.copyfile(pdb_path, os.path.abspath(os.path.join(assembly_export_root, pdb_name)))

        # Copy unity project folder into a temporary build location
        unitypackage_name = self.UNITYPACKAGE_FORMAT.format(name=assembly_name, version=version,
                                                            configuration=configuration)

        if not os.path.exists(output_dir):
            os.makedirs(output_dir)

        unitypackage_path = os.path.abspath(os.path.join(output_dir, unitypackage_name))

        # Create .unitypackage
        unity_runner = UnityPackageRunner(self.debug)
        click.secho("Exporting Unitypackage: {0}".format(unitypackage_name))
        unity_runner.export_unitypackage(os.path.abspath(unitypackage_export_root), unitypackage_path)

        if not os.path.isfile(unitypackage_path):
            raise RuntimeError("UnityPackage not found at path: " + unitypackage_path)
        click.secho("Unity package has successfully been built: " + unitypackage_path)

        # If clean flag is provided, remove other unity packages located at the output directory
        if clean:
            self._remove_old_unitypackages(output_dir, assembly_name, configuration, version)