Skip to content

Commit

Permalink
Merge pull request #200 from PyO3/resolve-workspace-target-dir
Browse files Browse the repository at this point in the history
Resolve workspace target dir from `cargo metadata` output
  • Loading branch information
messense authored Aug 6, 2023
2 parents fad2ba4 + db76b49 commit e196597
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
15 changes: 12 additions & 3 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11488,7 +11488,7 @@ function getCliValue(args, key) {
}
return undefined;
}
function getCargoTargetDir(args) {
async function getCargoTargetDir(args) {
let targetDir = 'target';
const val = getCliValue(args, '--target-dir');
const manifestPath = getCliValue(args, '--manifest-path') || getCliValue(args, '-m');
Expand All @@ -11500,7 +11500,16 @@ function getCargoTargetDir(args) {
targetDir = process.env.CARGO_TARGET_DIR;
}
else if (manifestPath && manifestPath.length > 0) {
targetDir = path.join(path.dirname(manifestPath), 'target');
const res = await mexec.exec('cargo', ['metadata', '--format-version', '1', '--manifest-path', manifestPath], true);
if (res.success) {
const metadata = JSON.parse(res.stdout);
targetDir = metadata.target_directory;
}
else {
core.warning('Failed to get Cargo target directory from `cargo metadata`');
core.debug(res.stderr);
targetDir = path.join(path.dirname(manifestPath), 'target');
}
}
return targetDir;
}
Expand Down Expand Up @@ -11715,7 +11724,7 @@ async function dockerBuild(container, maturinRelease, args) {
const scriptPath = path.join(os.tmpdir(), 'run-maturin-action.sh');
(0, fs_1.writeFileSync)(scriptPath, commands.join('\n'));
await fs_1.promises.chmod(scriptPath, 0o755);
const targetDir = getCargoTargetDir(args);
const targetDir = await getCargoTargetDir(args);
core.startGroup('Cleanup build scripts artifact directory');
const debugBuildDir = path.join(targetDir, 'debug', 'build');
if ((0, fs_1.existsSync)(debugBuildDir)) {
Expand Down
18 changes: 15 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ function getCliValue(args: string[], key: string): string | undefined {
return undefined
}

function getCargoTargetDir(args: string[]): string {
async function getCargoTargetDir(args: string[]): Promise<string> {
let targetDir = 'target'
const val = getCliValue(args, '--target-dir')
const manifestPath =
Expand All @@ -233,7 +233,19 @@ function getCargoTargetDir(args: string[]): string {
) {
targetDir = process.env.CARGO_TARGET_DIR
} else if (manifestPath && manifestPath.length > 0) {
targetDir = path.join(path.dirname(manifestPath), 'target')
const res = await mexec.exec(
'cargo',
['metadata', '--format-version', '1', '--manifest-path', manifestPath],
true
)
if (res.success) {
const metadata = JSON.parse(res.stdout)
targetDir = metadata.target_directory
} else {
core.warning('Failed to get Cargo target directory from `cargo metadata`')
core.debug(res.stderr)
targetDir = path.join(path.dirname(manifestPath), 'target')
}
}
return targetDir
}
Expand Down Expand Up @@ -537,7 +549,7 @@ async function dockerBuild(
writeFileSync(scriptPath, commands.join('\n'))
await fs.chmod(scriptPath, 0o755)

const targetDir = getCargoTargetDir(args)
const targetDir = await getCargoTargetDir(args)

core.startGroup('Cleanup build scripts artifact directory')
const debugBuildDir = path.join(targetDir, 'debug', 'build')
Expand Down

0 comments on commit e196597

Please sign in to comment.