From 8e7c62cff854054dc733ab4afb0b3b9b6c4a37e2 Mon Sep 17 00:00:00 2001 From: Andreia Gaita Date: Tue, 13 Aug 2019 15:08:27 +0200 Subject: [PATCH] Split upm and packman packaging --- .gitignore | 4 +- .yamato/build.yml | 10 +- .yamato/pack.yml | 8 +- common/packaging.targets | 10 +- common/unitypackaging.targets | 2 +- packaging/create-unity-packages/run.ps1 | 9 +- .../src/cmdlineoptions.ts | 13 +- packaging/create-unity-packages/src/index.ts | 118 ++++++++++-------- .../src/packmanPackager.ts | 14 +-- .../create-unity-packages/src/upmPackager.ts | 28 +++++ scripts/Create-Packages.ps1 | 26 +++- src/com.unity.git.api/.npmignore | 6 +- src/com.unity.git.api/Api/Api.csproj | 10 +- src/com.unity.git.ui/.npmignore | 6 +- src/com.unity.git.ui/UI/UI.csproj | 7 +- .../Unity.VersionControl.Git.Version.cs.meta | 0 ...VersionControl.Git.Logging.Version.cs.meta | 11 ++ ...nity.VersionControl.Git.UI.Version.cs.meta | 0 18 files changed, 186 insertions(+), 96 deletions(-) create mode 100644 packaging/create-unity-packages/src/upmPackager.ts rename src/extras/com.unity.git.api/{ => Api}/Unity.VersionControl.Git.Version.cs.meta (100%) create mode 100644 src/extras/com.unity.git.api/Logging/Unity.VersionControl.Git.Logging.Version.cs.meta rename src/extras/com.unity.git.ui/{ => UI}/Unity.VersionControl.Git.UI.Version.cs.meta (100%) diff --git a/.gitignore b/.gitignore index 455b69ab..57209572 100644 --- a/.gitignore +++ b/.gitignore @@ -307,4 +307,6 @@ sysinfo.txt /embedded-git.json lib/deps.zip nbgv.exe -.store \ No newline at end of file +.store +.Editor +PackageSources/ \ No newline at end of file diff --git a/.yamato/build.yml b/.yamato/build.yml index 60f85351..8f525119 100644 --- a/.yamato/build.yml +++ b/.yamato/build.yml @@ -19,7 +19,10 @@ commands: Pop-Location Write-Output "Packaging version $($version.AssemblyInformationalVersion)" - scripts\Create-Packages.ps1 $($version.AssemblyInformationalVersion) -Verbose + scripts\Create-Packages.ps1 $($version.AssemblyInformationalVersion) "PackageSources" -SkipUnity -SkipPackman + New-Item -itemtype Directory -Path "upm-ci~\packages" -Force + Copy-Item "artifacts\*.tgz" "upm-ci~\packages\" + Copy-Item "artifacts\packages.json" "upm-ci~\packages\" triggers: branches: @@ -28,4 +31,7 @@ triggers: artifacts: packages: paths: - - "artifacts/*.tgz" + - "upm-ci~/packages/**/*" + sources: + paths: + - "PackageSources/**/*" diff --git a/.yamato/pack.yml b/.yamato/pack.yml index a606e8f4..83f4fdc3 100644 --- a/.yamato/pack.yml +++ b/.yamato/pack.yml @@ -1,8 +1,4 @@ -packages: - - name: com.unity.git.api - path: artifacts/package/com.unity.git.api - - name: com.unity.git.ui - path: artifacts/package/com.unity.git.ui +{% metadata_file .yamato_config/configuration.yml %} --- name: Pack agent: @@ -16,7 +12,7 @@ dependencies: commands: # - npm install # - npm install upm-ci-utils@stable -g --registry https://api.bintray.com/npm/unity/unity-npm - - dir artifacts /s + - dir PackageSources /s {% for package in packages %} # - upm-ci package pack --packages-path {{ package.path }} {% endfor %} diff --git a/common/packaging.targets b/common/packaging.targets index 4bb09184..b4a0ab87 100644 --- a/common/packaging.targets +++ b/common/packaging.targets @@ -4,9 +4,9 @@ $(SolutionDir)\build\packages - + - + @@ -15,12 +15,14 @@ + + \ No newline at end of file diff --git a/common/unitypackaging.targets b/common/unitypackaging.targets index e780a2f3..a935771b 100644 --- a/common/unitypackaging.targets +++ b/common/unitypackaging.targets @@ -6,7 +6,7 @@ - + { skipPackaging: options.skip === true, ignores: [], doUnityPackage: !options.skipUnity, - doPackmanPackage: !options.skipPackman, - tmpPath: (await validateOptionPath(options, 'tmp', true)) + doPackmanPackage: !options.skipPackage, + doUpmPackage: !options.skipUpm, + tmpPath: (await validateOptionPath(options, 'tmp', true)), + other: [] }; if (extras) { @@ -81,82 +84,95 @@ async function parseCommandLine() : Promise { const parsed = await parseCommandLine(); - let tmpBuildDir = parsed.tmpPath || `build/tmp`; + let tmpBuildDir = parsed.tmpPath || p.join(p.dirname(parsed.targetPath), 'obj'); if (!p.isAbsolute(tmpBuildDir)) { tmpBuildDir = p.resolve(tmpBuildDir); } - tmpBuildDir = p.join(tmpBuildDir, parsed.packageName); - if (!parsed.tmpPath) { - console.warn(`--tmp arg not specified, reusing ${tmpBuildDir}.`); - } + parsed.tmpPath = tmpBuildDir; - if (!parsed.skipPackaging) { - if (await asyncfile.exists(tmpBuildDir)) { - await asyncfile.delete(tmpBuildDir); - } - } - - const tmpPackmanSourceTree = parsed.skipPackaging ? p.join(parsed.targetPath, 'package', parsed.packageName) : tmpBuildDir; - - if (!(await asyncfile.exists(tmpPackmanSourceTree))) { - await asyncfile.mkdirp(tmpPackmanSourceTree); - } - - const tmpUnitySourceTree = parsed.skipPackaging ? p.join(parsed.targetPath, "unitypackage") : await FileTreeWalker.getTempDir(); + console.log(parsed); const packmanPackager = new PackmanPackager(); + const upmPackager = new UpmPackager(); const unityPackager = new UnityPackager(); - const packageJson = await packmanPackager.prepare(parsed.sourcePath, parsed.version, parsed.ignores, tmpPackmanSourceTree); - - if (parsed.doUnityPackage) { - await unityPackager.prepareSource(tmpPackmanSourceTree, tmpUnitySourceTree, parsed.baseInstallationPath); - } - let packages: { [key: string] : any, manifest?: PackageFile } = {}; const manifest: string = p.join(parsed.targetPath, `manifest.json`); if (await asyncfile.exists(manifest)) { packages = JSON.parse(await asyncfile.readTextFile(manifest)); } - if (parsed.skipPackaging) { - if (parsed.doPackmanPackage) - packages[PackageType.Source].push({ type: PackageType.Source, path: tmpPackmanSourceTree }); - if (parsed.doUnityPackage) - packages[PackageType.Source].push({ type: PackageType.Source, path: tmpUnitySourceTree }); - } else { + if (parsed.doPackmanPackage || parsed.doUnityPackage) { + const tmpPackmanSourceTree = p.join(parsed.skipPackaging ? parsed.targetPath : tmpBuildDir, 'package', parsed.packageName); + + // unity and package use the same source + await packmanPackager.prepare(parsed.sourcePath, parsed.version, parsed.ignores, tmpPackmanSourceTree); + + if (parsed.doUnityPackage) { + const tmpUnitySourceTree = parsed.skipPackaging ? p.join(parsed.targetPath, "unitypackage") : await FileTreeWalker.getTempDir(); + + await unityPackager.prepareSource(tmpPackmanSourceTree, tmpUnitySourceTree, parsed.baseInstallationPath); + + if (parsed.skipPackaging) { + packages[PackageType.Source].push({ type: PackageType.Source, path: tmpUnitySourceTree }); + } else { + let files = await unityPackager.package(tmpUnitySourceTree, parsed.targetPath, parsed.packageName, parsed.version); + files.map(x => { + if (!packages[x.type]) packages[x.type] = []; + packages[x.type].push(x); + }); + } + } + if (parsed.doPackmanPackage) { - let files = await packmanPackager.package(tmpPackmanSourceTree, parsed.targetPath, parsed.packageName, parsed.version); - let packmanPackageFile: PackageFile = files.find(x => x.type === PackageType.PackmanPackage)!; + if (parsed.skipPackaging) { + packages[PackageType.Source].push({ type: PackageType.Source, path: tmpPackmanSourceTree }); + } else { + let files = await packmanPackager.package(tmpPackmanSourceTree, parsed.targetPath, parsed.packageName, parsed.version); + files.map(x => { + if (!packages[x.type]) packages[x.type] = []; + packages[x.type].push(x); + }); + } + } + } + + + if (parsed.doUpmPackage) { + const tmpUpmSourceTree = p.join(parsed.skipPackaging ? parsed.targetPath : tmpBuildDir, parsed.packageName); + // do the upm package first. it always has a -preview suffix + let versionMetadataIndex = parsed.version.indexOf('+'); + parsed.version = parsed.version.substring(0, versionMetadataIndex > 0 ? versionMetadataIndex : undefined ) + "-preview"; + + let packageJson = await upmPackager.prepare(parsed.sourcePath, parsed.version, parsed.ignores, tmpUpmSourceTree); + + if (parsed.skipPackaging) { + packages[PackageType.Source].push({ type: PackageType.Source, path: tmpUpmSourceTree }); + } else { + + let files = await upmPackager.package(tmpUpmSourceTree, parsed.targetPath, parsed.packageName, parsed.version); + let upmPackageFile: PackageFile = files.find(x => x.type === PackageType.PackmanPackage)!; files.map(x => { if (!packages[x.type]) packages[x.type] = []; packages[x.type].push(x); }); if (packageJson) { - const packmanPackageManifest: string = p.join(parsed.targetPath, `packages.json`); + const upmManifest: string = p.join(parsed.targetPath, `packages.json`); let packageManifest: { [key: string]: string } = {}; - if (await asyncfile.exists(packmanPackageManifest)) { - packageManifest = JSON.parse(await asyncfile.readTextFile(packmanPackageManifest)); + if (await asyncfile.exists(upmManifest)) { + packageManifest = JSON.parse(await asyncfile.readTextFile(upmManifest)); } - packageManifest[p.basename(packmanPackageFile.path)] = JSON.parse(await asyncfile.readTextFile(packageJson)); - await asyncfile.writeTextFile(packmanPackageManifest, JSON.stringify(packageManifest)); - packages[PackageType.Manifest] = { type: PackageType.Manifest, path: packmanPackageManifest}; - } + packageManifest[p.basename(upmPackageFile.path)] = JSON.parse(await asyncfile.readTextFile(packageJson)); + await asyncfile.writeTextFile(upmManifest, JSON.stringify(packageManifest)); + packages[PackageType.Manifest] = { type: PackageType.Manifest, path: upmManifest}; + } } - - if (parsed.doUnityPackage) { - let files = await unityPackager.package(tmpUnitySourceTree, parsed.targetPath, parsed.packageName, parsed.version); - files.map(x => { - if (!packages[x.type]) packages[x.type] = []; - packages[x.type].push(x); - }); - } - - await asyncfile.writeTextFile(manifest, JSON.stringify(packages)); } + + await asyncfile.writeTextFile(manifest, JSON.stringify(packages)); })(); diff --git a/packaging/create-unity-packages/src/packmanPackager.ts b/packaging/create-unity-packages/src/packmanPackager.ts index 4af961e5..a56438cd 100644 --- a/packaging/create-unity-packages/src/packmanPackager.ts +++ b/packaging/create-unity-packages/src/packmanPackager.ts @@ -1,9 +1,7 @@ import * as asyncfile from 'async-file'; import * as p from 'path'; -import { Ignores } from './RecursiveReaddir'; import md5 = require('md5'); -import { FileTreeWalker } from './TreeWalker'; -import { Packager, PackageType, createTar, createZip, PackageFile } from './packager'; +import { Packager, PackageType, createZip, PackageFile } from './packager'; export class PackmanPackager extends Packager { @@ -13,9 +11,6 @@ export class PackmanPackager extends Packager { public async package(sourcePath: string, targetPath: string, packageName: string, version: string) : Promise{ - const tgzPath: string = p.join(targetPath, `${packageName}-${version}.tgz`); - const tgzMd5Path: string = p.join(targetPath, `${packageName}-${version}.tgz.md5`); - const zipPath: string = p.join(targetPath, `${packageName}-${version}.zip`); const zipMd5Path: string = p.join(targetPath, `${packageName}-${version}.zip.md5`); @@ -23,13 +18,8 @@ export class PackmanPackager extends Packager { let ret: PackageFile[] = []; - await createTar(sourcePath, tgzPath, 'package'); - let hash = md5(await asyncfile.readFile(tgzPath)); - await asyncfile.writeTextFile(tgzMd5Path, hash); - ret.push({ type: PackageType.PackmanPackage, path: tgzPath, md5Path: tgzMd5Path, md5Hash: hash }); - await createZip(sourcePath, zipPath, p.dirname(sourcePath) === packageName ? packageName : undefined); - hash = md5(await asyncfile.readFile(zipPath)); + let hash = md5(await asyncfile.readFile(zipPath)); await asyncfile.writeTextFile(zipMd5Path, hash); ret.push({ type: PackageType.PackmanSource, path: zipPath, md5Path: zipMd5Path, md5Hash: hash }); diff --git a/packaging/create-unity-packages/src/upmPackager.ts b/packaging/create-unity-packages/src/upmPackager.ts new file mode 100644 index 00000000..6230b763 --- /dev/null +++ b/packaging/create-unity-packages/src/upmPackager.ts @@ -0,0 +1,28 @@ +import * as asyncfile from 'async-file'; +import * as p from 'path'; +import md5 = require('md5'); +import { Packager, PackageType, createTar, PackageFile } from './packager'; + +export class UpmPackager extends Packager { + + public constructor() { + super(); + } + + public async package(sourcePath: string, targetPath: string, packageName: string, version: string) : Promise{ + + const tgzPath: string = p.join(targetPath, `${packageName}-${version}.tgz`); + const tgzMd5Path: string = p.join(targetPath, `${packageName}-${version}.tgz.md5`); + + await asyncfile.mkdirp(targetPath); + + let ret: PackageFile[] = []; + + await createTar(sourcePath, tgzPath, 'package'); + let hash = md5(await asyncfile.readFile(tgzPath)); + await asyncfile.writeTextFile(tgzMd5Path, hash); + ret.push({ type: PackageType.PackmanPackage, path: tgzPath, md5Path: tgzMd5Path, md5Hash: hash }); + + return ret; + } +} \ No newline at end of file diff --git a/scripts/Create-Packages.ps1 b/scripts/Create-Packages.ps1 index 5b9c3232..78454ab4 100644 --- a/scripts/Create-Packages.ps1 +++ b/scripts/Create-Packages.ps1 @@ -10,6 +10,14 @@ Param( [string] $Version, + [string] + $TmpDir = '', + [switch] + $SkipUnity = $false, + [switch] + $SkipPackman = $false, + [switch] + $SkipUpm = $false, [switch] $Trace = $false ) @@ -32,35 +40,41 @@ if ($Trace) { Die -1 "You need to pass the -Version parameter" } + $tmpDir=$TmpDir + if ($tmpDir -eq '') { + $tmpDir="$rootDirectory\obj" + } elseif (![System.IO.Path]::IsPathRooted($tmpDir)) { + $tmpDir="$rootDirectory\$tmpDir" + } + $artifactDir="$rootDirectory\artifacts" - $tmpDir="$rootDirectory\obj" $packageDir="$rootDirectory\build\packages" $srcDir="$rootDirectory\src" $packagingScriptsDir="$rootDirectory\packaging\create-unity-packages" - Write-Output "Cleaning up previous build artifacts..." + Write-Output "Cleaning up previous build artifacts from $tmpDir..." Remove-Item $tmpDir -Force -Recurse -ErrorAction SilentlyContinue Remove-Item $artifactDir -Force -Recurse -ErrorAction SilentlyContinue $pkgName="com.unity.git.api" $pkgSrcDir="$packageDir\$pkgName" - $extrasDir="$srcDir\extras\$pkgName" + $extrasDir="" $ignorefile="$srcDir\$pkgName\.npmignore" $baseInstall="Packages\$pkgName" $outDir=$artifactDir Write-Verbose "$packagingScriptsDir\run.ps1 $pkgSrcDir $outDir $pkgName $Version $extrasDir $ignorefile $baseInstall" Write-Output "Packaging $pkgName..." - Run-Command -Fatal { & $packagingScriptsDir\run.ps1 $pkgSrcDir $outDir $pkgName $Version $extrasDir $ignorefile $baseInstall -Tmp $tmpDir } + Run-Command -Fatal { & $packagingScriptsDir\run.ps1 $pkgSrcDir $outDir $pkgName $Version $extrasDir $ignorefile $baseInstall -Tmp $tmpDir -SkipUnity:$SkipUnity -SkipPackman:$SkipPackman -SkipUpm:$SkipUpm } $pkgName="com.unity.git.ui" $pkgSrcDir="$packageDir\$pkgName" - $extrasDir="$srcDir\extras\$pkgName" + $extrasDir="" $ignorefile="$srcDir\$pkgName\.npmignore" $baseInstall="Packages\$pkgName" $outDir=$artifactDir Write-Verbose "$packagingScriptsDir\run.ps1 $pkgSrcDir $outDir $pkgName $Version $extrasDir $ignorefile $baseInstall" Write-Output "Packaging $pkgName..." - Run-Command -Fatal { & $packagingScriptsDir\run.ps1 $pkgSrcDir $outDir $pkgName $Version $extrasDir $ignorefile $baseInstall -Tmp $tmpDir } + Run-Command -Fatal { & $packagingScriptsDir\run.ps1 $pkgSrcDir $outDir $pkgName $Version $extrasDir $ignorefile $baseInstall -Tmp $tmpDir -SkipUnity:$SkipUnity -SkipPackman:$SkipPackman -SkipUpm:$SkipUpm } } \ No newline at end of file diff --git a/src/com.unity.git.api/.npmignore b/src/com.unity.git.api/.npmignore index 6f3a91a0..73727d4d 100644 --- a/src/com.unity.git.api/.npmignore +++ b/src/com.unity.git.api/.npmignore @@ -7,11 +7,9 @@ Api/version.json Api/version.json.meta # some directories we don't want -obj/ +obj/** obj.meta -node_modules/ +node_modules/** node_modules.meta -UnityTests/ -UnityTests.meta Third Party Notices - net35.md Third Party Notices - net35.md.meta diff --git a/src/com.unity.git.api/Api/Api.csproj b/src/com.unity.git.api/Api/Api.csproj index 93c5b50e..3247096c 100644 --- a/src/com.unity.git.api/Api/Api.csproj +++ b/src/com.unity.git.api/Api/Api.csproj @@ -57,9 +57,17 @@ - $([System.IO.Path]::GetFullPath('$(MSBuildThisFileDirectory)..\')) + $([System.IO.Path]::GetFullPath('$(MSBuildThisFileDirectory)..\..\')) com.unity.git.api + + + Api + + + Logging + + diff --git a/src/com.unity.git.ui/.npmignore b/src/com.unity.git.ui/.npmignore index 44f5a135..c49066a9 100644 --- a/src/com.unity.git.ui/.npmignore +++ b/src/com.unity.git.ui/.npmignore @@ -5,11 +5,9 @@ git*.zip* .npmignore-net35 # some directories we don't want -obj/ +obj/** obj.meta -node_modules/ +node_modules/** node_modules.meta -UnityTests/ -UnityTests.meta Third Party Notices - net35.md Third Party Notices - net35.md.meta diff --git a/src/com.unity.git.ui/UI/UI.csproj b/src/com.unity.git.ui/UI/UI.csproj index 67cd9dd2..5f26c5c2 100644 --- a/src/com.unity.git.ui/UI/UI.csproj +++ b/src/com.unity.git.ui/UI/UI.csproj @@ -38,9 +38,14 @@ - $([System.IO.Path]::GetFullPath('$(MSBuildThisFileDirectory)..\')) + $([System.IO.Path]::GetFullPath('$(MSBuildThisFileDirectory)..\..\')) com.unity.git.ui + + + UI + + diff --git a/src/extras/com.unity.git.api/Unity.VersionControl.Git.Version.cs.meta b/src/extras/com.unity.git.api/Api/Unity.VersionControl.Git.Version.cs.meta similarity index 100% rename from src/extras/com.unity.git.api/Unity.VersionControl.Git.Version.cs.meta rename to src/extras/com.unity.git.api/Api/Unity.VersionControl.Git.Version.cs.meta diff --git a/src/extras/com.unity.git.api/Logging/Unity.VersionControl.Git.Logging.Version.cs.meta b/src/extras/com.unity.git.api/Logging/Unity.VersionControl.Git.Logging.Version.cs.meta new file mode 100644 index 00000000..90458d30 --- /dev/null +++ b/src/extras/com.unity.git.api/Logging/Unity.VersionControl.Git.Logging.Version.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 51b4865f934150f48bb99d4aff015eca +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/src/extras/com.unity.git.ui/Unity.VersionControl.Git.UI.Version.cs.meta b/src/extras/com.unity.git.ui/UI/Unity.VersionControl.Git.UI.Version.cs.meta similarity index 100% rename from src/extras/com.unity.git.ui/Unity.VersionControl.Git.UI.Version.cs.meta rename to src/extras/com.unity.git.ui/UI/Unity.VersionControl.Git.UI.Version.cs.meta