Ejemplo n.º 1
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/"
Ejemplo n.º 2
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)