play build: absolute --dir stays absolute; gradlew without exec bit is made executable

This commit is contained in:
CRTkafa 2026-10-29 19:45:18 +07:00
parent 0ea7292164
commit ab69ce020c
5 changed files with 29 additions and 5 deletions

View file

@ -3,7 +3,7 @@
// properties through ORG_GRADLE_PROJECT_* variables, so passwords never appear on a command line), and read
// package / versionCode / versionName back from the built AAB (its manifest is protocol buffers, aapt2 format).
import { existsSync, readdirSync, readFileSync, statSync } from 'node:fs';
import { join, relative } from 'node:path';
import { join, relative, resolve } from 'node:path';
import type { AndroidSigning } from './credentials';
import * as rt from './rt';
import { zipEntries, zipRead } from './zip';
@ -38,7 +38,8 @@ export function pickGradle(root: string, cfg: PlayBuildConfig = {}): GradleTarge
: ['capacitor.config.ts', 'capacitor.config.json', 'capacitor.config.js'].some(f => existsSync(join(root, f))) ? 'capacitor'
: (() => { try { const p = JSON.parse(readFileSync(join(root, 'package.json'), 'utf8')); return !!(p.dependencies?.['react-native'] ?? p.devDependencies?.['react-native']); } catch { return false; } })() ? 'react-native'
: 'native';
const dirs = cfg.dir ? [join(root, cfg.dir)] : [join(root, 'android'), root];
// resolve, not join: an absolute play.build.dir / --dir stays absolute (join made /Users/... a folder under the root)
const dirs = cfg.dir ? [resolve(root, cfg.dir)] : [join(root, 'android'), root];
let dir = dirs.find(isGradleDir);
if (!dir) throw new Error(`no Gradle project (settings.gradle) in ${dirs.map(d => relative(root, d) || '.').join(' or ')}: set play.build.dir${framework === 'capacitor' ? ' (or npx cap add android)' : ''}`);
const unity = existsSync(join(dir, 'launcher')) && existsSync(join(dir, 'unityLibrary'));

View file

@ -14,7 +14,7 @@
// The comparison (webStaleness) and the capacitor config reading (webDirOf) are pure.
import { createHash } from 'node:crypto';
import { existsSync, readdirSync, readFileSync, statSync } from 'node:fs';
import { dirname, join, relative, sep } from 'node:path';
import { dirname, join, relative, resolve, sep } from 'node:path';
import type { ShipConfig } from './config';
import { log, warn } from './log';
import { pump } from './runner';
@ -89,7 +89,7 @@ export function capacitorCandidates(root: string): string[] {
*/
export function capacitorProject(root: string, hint?: string): CapProject | null {
if (hint) {
for (let d = join(root, hint); ; d = dirname(d)) {
for (let d = resolve(root, hint); ; d = dirname(d)) {
const rel = relative(root, d);
if (rel.startsWith('..')) break;
const c = capAt(root, rel.split(sep).join('/'));

View file

@ -14,7 +14,7 @@
// Before Gradle runs, the app module's build file must read -PversionCode / -PversionName in defaultConfig (a literal
// or an env var keeps the AAB at that value; android.injected.version.* does not override it for bundleRelease): a
// warning with the exact line to use. After the build, an AAB whose versionCode is not the planned one is a hard stop.
import { copyFileSync, existsSync, mkdirSync, writeFileSync } from 'node:fs';
import { chmodSync, copyFileSync, existsSync, mkdirSync, statSync, writeFileSync } from 'node:fs';
import { join, relative } from 'node:path';
import { androidSigning } from '../lib/credentials';
import type { Ctx } from '../lib/ctx';
@ -108,6 +108,11 @@ export async function run(ctx: Ctx): Promise<void> {
shipPhase('build', `${plan.task}, versionCode ${code || '?'}`);
const started = Date.now();
mkdirSync(out, { recursive: true });
// a gradlew committed from Windows has no exec bit: macOS / Linux then say "Executable not found: ./gradlew"
if (hasWrapper && process.platform !== 'win32') {
const w = join(t.dir, 'gradlew');
if ((statSync(w).mode & 0o111) === 0) { chmodSync(w, statSync(w).mode | 0o755); log(TAG, `${relative(root, w)} had no exec bit (committed from Windows?): made it executable; commit it with git update-index --chmod=+x`); }
}
const p = rt.spawn(argv, { cwd, stdout: 'pipe', stderr: 'pipe', env: { ...process.env, ...androidSdkEnv(sdk), ...signingEnv(signing) } });
const lines: string[] = [];
const each = (line: string): void => {