Giter Site home page Giter Site logo

Comments (7)

ndmitchell avatar ndmitchell commented on April 28, 2024

CC @wendy728 (I have no idea)

from buck2.

wendy728 avatar wendy728 commented on April 28, 2024

Have you tried get_path_without_materialization()? That should work with the artifact type. As for the error message about artifact and artifact not matching, this is an unfortunate typing issue where the starlark types are the same, but the underlying rust types are different. We would need to do some kind of migration to fix that. Regardless, abs_path_unsafe() is not the right function here since that's only for source artifacts, not declared or build/output artifacts.

I will add a some docs about that method since people have a hard time finding it in our generated docs, and also work on improving the error message for abs_path_unsafe().

As for the restrictions on ensured artifact, yes the API is intentionally restrictive so that people don't accidentally use the paths as strings, which might break in actions ran remotely, for example. See more. here.

from buck2.

zjturner avatar zjturner commented on April 28, 2024

I’ll try this. Is there any reason it would be a bad idea for abs_path_unsafe to work with any kind of artifact?

I think what’s difficult about finding this function is that it doesn’t really make sense as a global. There’s already ctx.fs with similar methods. Or why not just as a member function on the artifact itself? These are the natural places one would expect to find such a method

from buck2.

wendy728 avatar wendy728 commented on April 28, 2024

The functions available on ctx.fs are for source files/artifacts. So abs_path_unsafe works with string literals that represent source files, actual source file nodes, or cell paths that are supposed to be source files, and there are no plans to make it work with build artifacts or other types of artifacts.

from buck2.

zjturner avatar zjturner commented on April 28, 2024

In that case, how about a method on the artifact object? I tried get_path_without_materializations(), and it worked perfectly, im just trying to think from an api design standpoint so that more things become self documenting / self discoverable. It's a very unusual and specific function to be a global.

I actually have a local patch that adds this method to output artifact, im just wondering if it’s worth trying to upstream or if it will be seen as making it too easy to do unsafe things.

I understand the desire to make it difficult to shoot yourself in the foot by doing unsafe things, but at the same time one of the primary motivating use cases of bxl (IDE project generation) has heavy reliance on these kinds of unsafe operations.

from buck2.

wendy728 avatar wendy728 commented on April 28, 2024

The issue is that the artifact type is shared between normal rules and BXL. We could probably get it to only be exposed in BXL, but I would have to do some investigation on how to implement it correctly, but also that could be confusing if an object method is only available in BXL vs rules.

from buck2.

zjturner avatar zjturner commented on April 28, 2024

Just my own 2c, but I think bxl is a natural place for methods which are really unsafe for rules but quite natural when you want to introspect. IDE project generation, for example, often relies on absolute paths, but you’d never want to use an absolute path in a rule. So bxl should make it easy to get absolute paths for all kinds of things.

from buck2.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.